From 7fa495cdf750c257ed897eca189aabc3a62d5f2b Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 10 Nov 2018 11:20:12 +0000 Subject: Hurd: Fix ulinks in fd table reallocation * 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. --- sysdeps/mach/hurd/spawni.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'sysdeps/mach/hurd/spawni.c') diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c index 4fd0cdd..c08f2a5 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; \ } \ @@ -468,6 +468,16 @@ __spawni (pid_t *pid, const char *file, 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]; -- cgit v1.1