From patchwork Sat Nov 10 11:27:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 995873 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-97127-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="qvpRj7FO"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42sZW54cg5z9s8F for ; Sat, 10 Nov 2018 22:27:29 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; q=dns; s=default; b=yZt BXMowl0elT/Oi+G7+P4eOWGg/SoDRU/H+uegz5j2Dzzt5J9AfvCAKLO767oRD6Do ZoVFe4jFs0I9lvjXkc+Cfzk/3JD4o4MagjyzodmIS0Ba68zftxC5fAErIAI7h53r rNIe+4OSChiOHolVaw83H62sq4JSpE33nmPhJpac= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=default; bh=lzNxeEVfg YNgLO/Z4+gxRiNKedo=; b=qvpRj7FOhlcqgOsjxYRglovdcnUrE6d9TKjErhSqK UsYB0JR/2LAAHQoBUiUgfarq65lffG87I96zIFfazd30ttAFsBgTVGlAwuy0RiFu jPCEhmoRZRW5E309BPL6Rl8oi87Q//cJksFqwJfJ9RqTf8ZQ9K6PKQnoj241qbb4 44= Received: (qmail 29630 invoked by alias); 10 Nov 2018 11:27:21 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 29612 invoked by uid 89); 10 Nov 2018 11:27:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy= X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd,commited] Hurd: Fix ulinks in fd table reallocation Date: Sat, 10 Nov 2018 12:27:15 +0100 Message-Id: <20181110112715.4505-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 * hurd/hurd/userlink.h (_hurd_userlink_move): New function. * hurd/hurd/port.h (_hurd_port_move): New function. * sysdeps/mach/hurd/spawni.c (NEW_ULINK_TABLE): New macro. (EXPAND_DTABLE): Use NEW_ULINK_TABLE macro for ulink_dtable. --- ChangeLog | 4 ++++ hurd/hurd/port.h | 25 +++++++++++++++++++++++++ hurd/hurd/userlink.h | 24 ++++++++++++++++++++++++ sysdeps/mach/hurd/spawni.c | 12 +++++++++++- 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0b7752345b..8546c2d336 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ (reauthenticate): Test and use ccwdir. (child_init_port): In non-resetids case, test and use ccwdir. (child_chdir): New nested function to set ccwdir. + * hurd/hurd/userlink.h (_hurd_userlink_move): New function. + * hurd/hurd/port.h (_hurd_port_move): New function. + * sysdeps/mach/hurd/spawni.c (NEW_ULINK_TABLE): New macro. + (EXPAND_DTABLE): Use NEW_ULINK_TABLE macro for ulink_dtable. 2018-11-09 Martin Sebor diff --git a/hurd/hurd/port.h b/hurd/hurd/port.h index 0779578d03..769e44b5cc 100644 --- a/hurd/hurd/port.h +++ b/hurd/hurd/port.h @@ -127,6 +127,31 @@ _hurd_port_get (struct hurd_port *port, #endif +/* Relocate LINK to NEW_LINK. + To be used when e.g. reallocating a link array. */ + +extern void +_hurd_port_move (struct hurd_port *port, + struct hurd_userlink *new_link, + struct hurd_userlink *link); + +#if defined __USE_EXTERN_INLINES && defined _LIBC +# if IS_IN (libc) +_HURD_PORT_H_EXTERN_INLINE void +_hurd_port_move (struct hurd_port *port, + struct hurd_userlink *new_link, + struct hurd_userlink *link) +{ + HURD_CRITICAL_BEGIN; + __spin_lock (&port->lock); + _hurd_userlink_move (new_link, link); + __spin_unlock (&port->lock); + HURD_CRITICAL_END; +} +# endif +#endif + + /* Free a reference gotten with `USED_PORT = _hurd_port_get (PORT, LINK);' */ extern void diff --git a/hurd/hurd/userlink.h b/hurd/hurd/userlink.h index f9362557cb..484706a67a 100644 --- a/hurd/hurd/userlink.h +++ b/hurd/hurd/userlink.h @@ -142,6 +142,30 @@ _hurd_userlink_unlink (struct hurd_userlink *link) # endif #endif +/* Relocate LINK to NEW_LINK. + To be used when e.g. reallocating a link array. */ + +extern void _hurd_userlink_move (struct hurd_userlink *new_link, + struct hurd_userlink *link); + +#if defined __USE_EXTERN_INLINES && defined _LIBC +# if IS_IN (libc) +_HURD_USERLINK_H_EXTERN_INLINE void +_hurd_userlink_move (struct hurd_userlink *new_link, + struct hurd_userlink *link) +{ + *new_link = *link; + + if (new_link->resource.next != NULL) + new_link->resource.next->resource.prevp = &new_link->resource.next; + *new_link->resource.prevp = link; + + if (new_link->thread.next != NULL) + new_link->thread.next->thread.prevp = &new_link->thread.next; + *new_link->thread.prevp = link; +} +# endif +#endif /* Clear all users from *CHAINP. Call this when the resource *CHAINP protects is changing. If the return value is nonzero, no users are on diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c index 4fd0cdd520..c08f2a5b5a 100644 --- a/sysdeps/mach/hurd/spawni.c +++ b/sysdeps/mach/hurd/spawni.c @@ -457,7 +457,7 @@ __spawni (pid_t *pid, const char *file, { \ /* We need to expand the dtable for the child. */ \ NEW_TABLE (dtable, newfd); \ - NEW_TABLE (ulink_dtable, newfd); \ + NEW_ULINK_TABLE (ulink_dtable, newfd); \ NEW_TABLE (dtable_cells, newfd); \ dtablesize = newfd + 1; \ } \ @@ -467,6 +467,16 @@ __spawni (pid_t *pid, const char *file, do { __typeof (x) new_##x = __alloca ((newfd + 1) * sizeof (x[0])); \ memcpy (new_##x, x, dtablesize * sizeof (x[0])); \ memset (&new_##x[dtablesize], 0, (newfd + 1 - dtablesize) * sizeof (x[0])); \ + x = new_##x; } while (0) +#define NEW_ULINK_TABLE(x, newfd) \ + do { __typeof (x) new_##x = __alloca ((newfd + 1) * sizeof (x[0])); \ + unsigned i; \ + for (i = 0; i < dtablesize; i++) \ + if (dtable_cells[i] != NULL) \ + _hurd_port_move (dtable_cells[i], &new_##x[i], &x[i]); \ + else \ + memset(&new_##x[i], 0, sizeof(new_##x[i])); \ + memset (&new_##x[dtablesize], 0, (newfd + 1 - dtablesize) * sizeof (x[0])); \ x = new_##x; } while (0) struct __spawn_action *action = &file_actions->__actions[i];