summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.topdeps2
-rw-r--r--.topmsg11
-rw-r--r--Makerules51
-rw-r--r--aclocal.m41
-rw-r--r--bits/in.h38
-rwxr-xr-xconfigure3
-rw-r--r--configure.ac9
-rw-r--r--csu/libc-start.c2
-rw-r--r--elf/dl-support.c3
-rw-r--r--elf/rtld.c2
-rw-r--r--hurd/Makefile7
-rw-r--r--hurd/Versions30
-rw-r--r--hurd/ctty-input.c16
-rw-r--r--hurd/ctty-output.c16
-rw-r--r--hurd/dtable.c2
-rw-r--r--hurd/exc2signal.c52
-rw-r--r--hurd/fcntl-internal.h60
-rw-r--r--hurd/hurd.h4
-rw-r--r--hurd/hurd/fd.h47
-rw-r--r--hurd/hurd/port.h43
-rw-r--r--hurd/hurd/signal.h94
-rw-r--r--hurd/hurd/sigpreempt.h4
-rw-r--r--hurd/hurd/threadvar.h89
-rw-r--r--hurd/hurd/userlink.h20
-rw-r--r--hurd/hurdauth.c1
-rw-r--r--hurd/hurdexec.c11
-rw-r--r--hurd/hurdfault.c4
-rw-r--r--hurd/hurdfchdir.c1
-rw-r--r--hurd/hurdinit.c2
-rw-r--r--hurd/hurdioctl.c1
-rw-r--r--hurd/hurdlock.c247
-rw-r--r--hurd/hurdlock.h117
-rw-r--r--hurd/hurdlookup.c2
-rw-r--r--hurd/hurdmalloc.c15
-rw-r--r--hurd/hurdmalloc.h4
-rw-r--r--hurd/hurdmsg.c24
-rw-r--r--hurd/hurdpid.c3
-rw-r--r--hurd/hurdselect.c262
-rw-r--r--hurd/hurdsig.c584
-rw-r--r--hurd/hurdsock.c5
-rw-r--r--hurd/hurdstartup.c1
-rw-r--r--hurd/intern-fd.c1
-rw-r--r--hurd/lookup-at.c13
-rw-r--r--hurd/lookup-retry.c38
-rw-r--r--hurd/setauth.c6
-rw-r--r--hurd/seteuids.c1
-rw-r--r--hurd/sigunwind.c4
-rw-r--r--hurd/sysvshm.c98
-rw-r--r--hurd/sysvshm.h52
-rw-r--r--hurd/thread-cancel.c3
-rw-r--r--include/errno.h14
-rw-r--r--include/fcntl.h3
-rw-r--r--include/unistd.h1
-rw-r--r--include/verify.h140
-rw-r--r--locale/programs/locarchive.c18
-rw-r--r--mach/Makefile6
-rw-r--r--mach/Versions9
-rw-r--r--mach/lock-intern.h95
-rw-r--r--mach/lowlevellock.h80
-rw-r--r--mach/mach.h3
-rw-r--r--mach/mach/mig_support.h3
-rw-r--r--mach/mutex-init.c7
-rw-r--r--mach/setup-thread.c30
-rw-r--r--mach/spin-lock.c1
-rw-r--r--malloc/Makefile9
-rw-r--r--manual/errno.texi12
-rw-r--r--misc/Makefile4
-rw-r--r--misc/getauxval.c2
-rw-r--r--misc/sys/file.h1
-rw-r--r--misc/tst-sbrk-pie.c3
-rw-r--r--misc/tst-sbrk-static.c3
-rw-r--r--misc/tst-sbrk.c49
-rw-r--r--nscd/Depend1
-rw-r--r--po/fr.po4
-rw-r--r--resolv/Depend1
-rw-r--r--resolv/gai_sigqueue.c1
-rw-r--r--rt/Depend1
-rw-r--r--rt/aio_sigqueue.c1
-rwxr-xr-xscripts/check-local-headers.sh2
-rw-r--r--sysdeps/generic/dl-fcntl.h (renamed from sysdeps/mach/hurd/libc-tsd.h)23
-rw-r--r--sysdeps/generic/ldsodefs.h3
-rw-r--r--sysdeps/generic/machine-lock.h12
-rw-r--r--sysdeps/generic/machine-sp.h4
-rw-r--r--sysdeps/generic/not-cancel.h28
-rw-r--r--sysdeps/generic/symbol-hacks.h3
-rw-r--r--sysdeps/generic/thread_state.h1
-rw-r--r--sysdeps/i386/atomic-machine.h107
-rw-r--r--sysdeps/mach/Makefile21
-rw-r--r--sysdeps/mach/configure2
-rw-r--r--sysdeps/mach/configure.ac2
-rw-r--r--sysdeps/mach/hurd/Makefile14
-rw-r--r--sysdeps/mach/hurd/Versions4
-rw-r--r--sysdeps/mach/hurd/access.c120
-rw-r--r--sysdeps/mach/hurd/bind.c17
-rw-r--r--sysdeps/mach/hurd/bits/errno.h8
-rw-r--r--sysdeps/mach/hurd/bits/fcntl.h15
-rw-r--r--sysdeps/mach/hurd/bits/local_lim.h9
-rw-r--r--sysdeps/mach/hurd/bits/posix_opt.h46
-rw-r--r--sysdeps/mach/hurd/bits/sigaction.h81
-rw-r--r--sysdeps/mach/hurd/brk.c6
-rw-r--r--sysdeps/mach/hurd/cthreads.c2
-rw-r--r--sysdeps/mach/hurd/dl-fcntl.h22
-rw-r--r--sysdeps/mach/hurd/dl-sysdep.c49
-rw-r--r--sysdeps/mach/hurd/errno-loc.c22
-rw-r--r--sysdeps/mach/hurd/errno.c1
-rw-r--r--sysdeps/mach/hurd/euidaccess.c31
-rw-r--r--sysdeps/mach/hurd/f_setlk.c68
-rw-r--r--sysdeps/mach/hurd/faccessat.c151
-rw-r--r--sysdeps/mach/hurd/fcntl.c57
-rw-r--r--sysdeps/mach/hurd/fork.c55
-rw-r--r--sysdeps/mach/hurd/ftok.c41
-rw-r--r--sysdeps/mach/hurd/futimens.c50
-rw-r--r--sysdeps/mach/hurd/gai_misc.h44
-rw-r--r--sysdeps/mach/hurd/getcwd.c12
-rw-r--r--sysdeps/mach/hurd/hp-timing.h42
-rw-r--r--sysdeps/mach/hurd/i386/Makefile5
-rw-r--r--sysdeps/mach/hurd/i386/____longjmp_chk.S7
-rw-r--r--sysdeps/mach/hurd/i386/bits/sigcontext.h4
-rw-r--r--sysdeps/mach/hurd/i386/exc2signal.c123
-rw-r--r--sysdeps/mach/hurd/i386/getcontext.S74
-rw-r--r--sysdeps/mach/hurd/i386/init-first.c91
-rw-r--r--sysdeps/mach/hurd/i386/makecontext-helper.c71
-rw-r--r--sysdeps/mach/hurd/i386/makecontext.S130
-rw-r--r--sysdeps/mach/hurd/i386/setcontext.S92
-rw-r--r--sysdeps/mach/hurd/i386/sigreturn.c79
-rw-r--r--sysdeps/mach/hurd/i386/swapcontext.S110
-rw-r--r--sysdeps/mach/hurd/i386/tls.h97
-rw-r--r--sysdeps/mach/hurd/i386/tlsdesc.sym19
-rw-r--r--sysdeps/mach/hurd/i386/trampoline.c132
-rw-r--r--sysdeps/mach/hurd/i386/ucontext_i.sym29
-rw-r--r--sysdeps/mach/hurd/ifaddrs.c306
-rw-r--r--sysdeps/mach/hurd/jmp-unwind.c3
-rw-r--r--sysdeps/mach/hurd/kernel-features.h2
-rw-r--r--sysdeps/mach/hurd/kill.c2
-rw-r--r--sysdeps/mach/hurd/libc-lock.h213
-rw-r--r--sysdeps/mach/hurd/malloc-machine.h11
-rw-r--r--sysdeps/mach/hurd/mig-reply.c39
-rw-r--r--sysdeps/mach/hurd/openat.c2
-rw-r--r--sysdeps/mach/hurd/pipe.c21
-rw-r--r--sysdeps/mach/hurd/pipe2.c60
-rw-r--r--sysdeps/mach/hurd/profil.c10
-rw-r--r--sysdeps/mach/hurd/ptsname.c18
-rw-r--r--sysdeps/mach/hurd/reboot.c5
-rw-r--r--sysdeps/mach/hurd/recvmsg.c234
-rw-r--r--sysdeps/mach/hurd/sendmsg.c109
-rw-r--r--sysdeps/mach/hurd/setegid.c1
-rw-r--r--sysdeps/mach/hurd/seteuid.c1
-rw-r--r--sysdeps/mach/hurd/setgid.c1
-rw-r--r--sysdeps/mach/hurd/setgroups.c1
-rw-r--r--sysdeps/mach/hurd/setitimer.c25
-rw-r--r--sysdeps/mach/hurd/setpgid.c10
-rw-r--r--sysdeps/mach/hurd/setregid.c1
-rw-r--r--sysdeps/mach/hurd/setresgid.c1
-rw-r--r--sysdeps/mach/hurd/setresuid.c1
-rw-r--r--sysdeps/mach/hurd/setreuid.c1
-rw-r--r--sysdeps/mach/hurd/setsid.c11
-rw-r--r--sysdeps/mach/hurd/setuid.c1
-rw-r--r--sysdeps/mach/hurd/shmat.c82
-rw-r--r--sysdeps/mach/hurd/shmctl.c132
-rw-r--r--sysdeps/mach/hurd/shmdt.c51
-rw-r--r--sysdeps/mach/hurd/shmget.c242
-rw-r--r--sysdeps/mach/hurd/sigaction.c16
-rw-r--r--sysdeps/mach/hurd/sigpending.c6
-rw-r--r--sysdeps/mach/hurd/sigprocmask.c8
-rw-r--r--sysdeps/mach/hurd/sigsuspend.c15
-rw-r--r--sysdeps/mach/hurd/sigwait.c21
-rw-r--r--sysdeps/mach/hurd/socket.c15
-rw-r--r--sysdeps/mach/hurd/socketpair.c25
-rw-r--r--sysdeps/mach/hurd/spawni.c27
-rw-r--r--sysdeps/mach/hurd/sysdep-cancel.h9
-rw-r--r--sysdeps/mach/hurd/tls.h13
-rw-r--r--sysdeps/mach/i386/machine-lock.h12
-rw-r--r--sysdeps/mach/i386/thread_state.h11
-rw-r--r--sysdeps/mach/libc-lock.h190
-rw-r--r--sysdeps/mach/pagecopy.h5
-rw-r--r--sysdeps/mach/thread_state.h3
-rw-r--r--sysdeps/pthread/allocalim.h7
-rw-r--r--sysdeps/pthread/timer_routines.c10
-rw-r--r--sysdeps/unix/bsd/unlockpt.c2
-rw-r--r--sysdeps/unix/clock_settime.c3
180 files changed, 5332 insertions, 1509 deletions
diff --git a/.topdeps b/.topdeps
index a4b3b1ff6d..1722905774 100644
--- a/.topdeps
+++ b/.topdeps
@@ -1 +1,3 @@
+t/regenerate_configure
t/master_backports
+t/tcbhead_t
diff --git a/.topmsg b/.topmsg
index ffafb64cf0..7b9619422a 100644
--- a/.topmsg
+++ b/.topmsg
@@ -1,4 +1,9 @@
-Subject: [PATCH] ____longjmp_chk for GNU Hurd on x86
+Commited to git
-The guts have been merged, but there are still TODOs to be resolved in
-sysdeps/mach/hurd/i386/____longjmp_chk.S, and testing is needed.
+From: Samuel Thibault <samuel.thibault@ens-lyon.org>
+Subject: [PATCH] hurd: Make libc able to call pthread stubs
+
+* sysdeps/mach/hurd/bits/libc-lock.h [_LIBC]: Include
+<bits/libc-lockP.h>
+
+Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
diff --git a/Makerules b/Makerules
index 53eabfaba8..c67bc8d04f 100644
--- a/Makerules
+++ b/Makerules
@@ -562,6 +562,54 @@ $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
PROVIDE(__start___libc_thread_subfreeres = .);\
__libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
PROVIDE(__stop___libc_thread_subfreeres = .);\
+ PROVIDE(__start__hurd_fd_subinit = .);\
+ _hurd_fd_subinit : { *(_hurd_fd_subinit) }\
+ PROVIDE(__stop__hurd_fd_subinit = .);\
+ PROVIDE(__start__hurd_XXX = .);\
+ _hurd_XXX : { *(_hurd_XXX) }\
+ PROVIDE(__stop__hurd_XXX = .);\
+ PROVIDE(__start__hurd_subinit = .);\
+ _hurd_subinit : { *(_hurd_subinit) }\
+ PROVIDE(__stop__hurd_subinit = .);\
+ PROVIDE(__start__hurd_proc_subinit = .);\
+ _hurd_proc_subinit : { *(_hurd_proc_subinit) }\
+ PROVIDE(__stop__hurd_proc_subinit = .);\
+ PROVIDE(__start__hurd_reauth_hook = .);\
+ _hurd_reauth_hook : { *(_hurd_reauth_hook) }\
+ PROVIDE(__stop__hurd_reauth_hook = .);\
+ PROVIDE(__start__hurd_pgrp_changed_hook = .);\
+ _hurd_pgrp_changed_hook : { *(_hurd_pgrp_changed_hook) }\
+ PROVIDE(__stop__hurd_pgrp_changed_hook = .);\
+ PROVIDE(__start__hurd_preinit_hook = .);\
+ _hurd_preinit_hook : { *(_hurd_preinit_hook) }\
+ PROVIDE(__stop__hurd_preinit_hook = .);\
+ PROVIDE(__start__hurd_fork_prepare_hook = .);\
+ _hurd_fork_prepare_hook : { *(_hurd_fork_prepare_hook) }\
+ PROVIDE(__stop__hurd_fork_prepare_hook = .);\
+ PROVIDE(__start__hurd_fork_setup_hook = .);\
+ _hurd_fork_setup_hook : { *(_hurd_fork_setup_hook) }\
+ PROVIDE(__stop__hurd_fork_setup_hook = .);\
+ PROVIDE(__start__hurd_fork_child_hook = .);\
+ _hurd_fork_child_hook : { *(_hurd_fork_child_hook) }\
+ PROVIDE(__stop__hurd_fork_child_hook = .);\
+ PROVIDE(__start__hurd_fork_parent_hook = .);\
+ _hurd_fork_parent_hook : { *(_hurd_fork_parent_hook) }\
+ PROVIDE(__stop__hurd_fork_parent_hook = .);\
+ PROVIDE(__start__hurd_atfork_prepare_hook = .);\
+ _hurd_atfork_prepare_hook : { *(_hurd_atfork_prepare_hook) }\
+ PROVIDE(__stop__hurd_atfork_prepare_hook = .);\
+ PROVIDE(__start__hurd_atfork_child_hook = .);\
+ _hurd_atfork_child_hook : { *(_hurd_atfork_child_hook) }\
+ PROVIDE(__stop__hurd_atfork_child_hook = .);\
+ PROVIDE(__start__hurd_atfork_parent_hook = .);\
+ _hurd_atfork_parent_hook : { *(_hurd_atfork_parent_hook) }\
+ PROVIDE(__stop__hurd_atfork_parent_hook = .);\
+ PROVIDE(__start__hurd_fork_locks = .);\
+ _hurd_fork_locks : { *(_hurd_fork_locks) }\
+ PROVIDE(__stop__hurd_fork_locks = .);\
+ PROVIDE(__start___pthread_init = .);\
+ __pthread_init : { *(__pthread_init) }\
+ PROVIDE(__stop___pthread_init = .);\
/DISCARD/ : { *(.gnu.glibc-stub.*) }@'
test -s $@T
mv -f $@T $@
@@ -1066,6 +1114,9 @@ $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
'$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
) > $@.new
+ifeq ($(patsubst gnu%,,$(config-os)),)
+ echo 'INPUT ( AS_NEEDED ( -lmachuser -lhurduser ) )' >> $@.new
+endif
mv -f $@.new $@
endif
diff --git a/aclocal.m4 b/aclocal.m4
index 3d64f7773d..5fcbb1397e 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -16,6 +16,7 @@ dnl AC_REQUIREs or AC_BEFOREs duplicating their code.
dnl
define([GLIBC_PROVIDES], [dnl
AC_PROVIDE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
+AC_PROVIDE([_AC_INCLUDES_DEFAULT_REQUIREMENTS])dnl
AC_PROVIDE([AC_CONFIG_SUBDIRS])dnl
AC_PROVIDE([_AS_ECHO_N_PREPARE])dnl
AC_PROVIDE([_AS_ECHO_PREPARE])dnl
diff --git a/bits/in.h b/bits/in.h
index e6f4696117..d517115bb2 100644
--- a/bits/in.h
+++ b/bits/in.h
@@ -56,17 +56,17 @@ struct ip_opts
/* IPV6 socket options. */
#define IPV6_ADDRFORM 1
-#define IPV6_PKTINFO 2
-#define IPV6_HOPOPTS 3
-#define IPV6_DSTOPTS 4
-#define IPV6_RTHDR 5
-#define IPV6_PKTOPTIONS 6
+#define IPV6_2292PKTINFO 2
+#define IPV6_2292HOPOPTS 3
+#define IPV6_2292DSTOPTS 4
+#define IPV6_2292RTHDR 5
+#define IPV6_2292PKTOPTIONS 6
#define IPV6_CHECKSUM 7
-#define IPV6_HOPLIMIT 8
+#define IPV6_2292HOPLIMIT 8
-#define IPV6_RXINFO IPV6_PKTINFO
-#define IPV6_TXINFO IPV6_PKTINFO
-#define SCM_SRCINFO IPV6_PKTINFO
+#define IPV6_RXINFO IPV6_2292PKTINFO
+#define IPV6_TXINFO IPV6_RXINFO
+#define SCM_SRCINFO IPV6_TXINFO
#define SCM_SRCRT IPV6_RXSRCRT
#define IPV6_UNICAST_HOPS 16
@@ -83,11 +83,27 @@ struct ip_opts
#define IPV6_JOIN_ANYCAST 27
#define IPV6_LEAVE_ANYCAST 28
+/* Advanced API (RFC3542) (1). */
+#define IPV6_RECVPKTINFO 49
+#define IPV6_PKTINFO 50
+#define IPV6_RECVHOPLIMIT 51
+#define IPV6_HOPLIMIT 52
+#define IPV6_RECVHOPOPTS 53
+#define IPV6_HOPOPTS 54
+#define IPV6_RTHDRDSTOPTS 55
+#define IPV6_RECVRTHDR 56
+#define IPV6_RTHDR 57
+#define IPV6_RECVDSTOPTS 58
+#define IPV6_DSTOPTS 59
+#define IPV6_RECVPATHMTU 60
+#define IPV6_PATHMTU 61
+#define IPV6_DONTFRAG 62
+
/* Obsolete synonyms for the above. */
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
-#define IPV6_RXHOPOPTS IPV6_HOPOPTS
-#define IPV6_RXDSTOPTS IPV6_DSTOPTS
+#define IPV6_RXHOPOPTS IPV6_2292HOPOPTS
+#define IPV6_RXDSTOPTS IPV6_2292DSTOPTS
/* Routing header options for IPv6. */
#define IPV6_RTHDR_LOOSE 0 /* Hop doesn't need to be neighbour. */
diff --git a/configure b/configure
index 06ea87e9ab..1f9f0a9189 100755
--- a/configure
+++ b/configure
@@ -2163,7 +2163,8 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
-# Glibc should not depend on any header files
+# Do not make decisions based on the host system's C library, as we must be
+# independent of it.
# We require GCC, and by default use its preprocessor. Override AC_PROG_CPP
diff --git a/configure.ac b/configure.ac
index 3c766b7409..89781e1407 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,7 +12,8 @@ AC_DEFINE_UNQUOTED([PKGVERSION], ["$PKGVERSION"],
AC_DEFINE_UNQUOTED([REPORT_BUGS_TO], ["$REPORT_BUGS_TO"],
[Bug reporting address])
-# Glibc should not depend on any header files
+# Do not make decisions based on the host system's C library, as we must be
+# independent of it.
AC_DEFUN([_AC_INCLUDES_DEFAULT_REQUIREMENTS],
[m4_divert_text([DEFAULTS],
[ac_includes_default='/* none */'])])
@@ -286,10 +287,10 @@ AC_ARG_ENABLE([all-warnings],
AC_SUBST(all_warnings)
AC_ARG_ENABLE([werror],
- AC_HELP_STRING([--disable-werror],
- [do not build with -Werror]),
+ AC_HELP_STRING([--enable-werror],
+ [build with -Werror]),
[enable_werror=$enableval],
- [enable_werror=yes])
+ [enable_werror=no])
AC_SUBST(enable_werror)
AC_ARG_ENABLE([multi-arch],
diff --git a/csu/libc-start.c b/csu/libc-start.c
index f4aa01a988..bf5eb69b27 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -190,10 +190,12 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
/* Perform IREL{,A} relocations. */
apply_irel ();
+#ifndef __GNU__
/* Initialize the thread library at least a bit since the libgcc
functions are using thread functions if these are available and
we need to setup errno. */
__pthread_initialize_minimal ();
+#endif
/* Set up the stack checker's canary. */
uintptr_t stack_chk_guard = _dl_setup_stack_chk_guard (_dl_random);
diff --git a/elf/dl-support.c b/elf/dl-support.c
index c30194c7b7..f450ab5978 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -135,7 +135,7 @@ hp_timing_t _dl_cpuclock_offset;
void (*_dl_init_static_tls) (struct link_map *) = &_dl_nothread_init_static_tls;
-size_t _dl_pagesize = EXEC_PAGESIZE;
+size_t _dl_pagesize = /* EXEC_PAGESIZE */ 4096;
int _dl_inhibit_cache;
@@ -186,6 +186,7 @@ int (*_dl_make_stack_executable_hook) (void **) internal_function
/* Function in libpthread to wait for termination of lookups. */
void (*_dl_wait_lookup_done) (void);
+int volatile _dl_thread_gscope_count;
struct dl_scope_free_list *_dl_scope_free_list;
#ifdef NEED_DL_SYSINFO
diff --git a/elf/rtld.c b/elf/rtld.c
index 647661ca45..f468c1177d 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -162,7 +162,7 @@ struct rtld_global_ro _rtld_global_ro attribute_relro =
._dl_hwcap_mask = HWCAP_IMPORTANT,
._dl_lazy = 1,
._dl_fpu_control = _FPU_DEFAULT,
- ._dl_pagesize = EXEC_PAGESIZE,
+ ._dl_pagesize = /* EXEC_PAGESIZE */ 4096,
._dl_inhibit_cache = 0,
/* Function pointers. */
diff --git a/hurd/Makefile b/hurd/Makefile
index 1e7d808ea8..122a5d63ac 100644
--- a/hurd/Makefile
+++ b/hurd/Makefile
@@ -29,11 +29,12 @@ inline-headers = hurd.h $(addprefix hurd/,fd.h signal.h \
# The RPC interfaces go in a separate library.
interface-library := libhurduser
user-interfaces := $(addprefix hurd/,\
- auth startup \
+ auth auth_request auth_reply startup \
process process_request \
msg msg_reply msg_request \
exec exec_startup crash interrupt \
- fs fsys io term tioctl socket ifsock \
+ fs fsys io io_reply io_request \
+ term tioctl socket ifsock \
login password pfinet \
)
server-interfaces := hurd/msg faultexc
@@ -54,6 +55,8 @@ routines = hurdstartup hurdinit \
vpprintf \
ports-get ports-set hurdports hurdmsg \
errno-loc \
+ sysvshm \
+ hurdlock \
$(sig) $(dtable) $(inlines) port-cleanup report-wait xattr
sig = hurdsig hurdfault siginfo hurd-raise preempt-sig \
trampoline longjmp-ts catch-exc exc2signal hurdkill sigunwind \
diff --git a/hurd/Versions b/hurd/Versions
index 77f5b4271e..7502d32a22 100644
--- a/hurd/Versions
+++ b/hurd/Versions
@@ -4,14 +4,9 @@ libc {
_end;
# variables used in macros & inline functions
- __hurd_sigthread_stack_base; __hurd_sigthread_stack_end;
- __hurd_sigthread_variables;
__hurd_threadvar_max;
__hurd_threadvar_stack_mask; __hurd_threadvar_stack_offset;
- # functions used in macros & inline functions
- __hurd_errno_location;
-
# functions used in libmachuser and libhurduser
_S_catch_exception_raise;
_S_catch_exception_raise_state;
@@ -129,10 +124,26 @@ libc {
# functions used in macros & inline functions
__errno_location;
}
+ GLIBC_2.15 {
+ # functions used by libpthread and <hurd/signal.h>
+ _hurd_sigstate_set_global_rcv;
+ _hurd_sigstate_lock;
+ _hurd_sigstate_pending;
+ _hurd_sigstate_unlock;
+ _hurd_sigstate_delete;
+ GLIBC_2.19 {
+ # These always existed as inlines but the real functions were not exported.
+ _hurd_fd_error_signal; _hurd_fd_error;
+ __hurd_dfail; __hurd_sockfail;
+ __hurd_threadvar_location_from_sp;
+ __hurd_threadvar_location;
+ _hurd_userlink_link; _hurd_userlink_unlink; _hurd_userlink_clear;
+ }
HURD_CTHREADS_0.3 {
# weak refs to libthreads functions that libc calls iff libthreads in use
cthread_fork; cthread_detach;
+ pthread_getattr_np; pthread_attr_getstack;
# variables used for detecting cthreads
_cthread_exit_routine; _cthread_init_routine;
@@ -141,4 +152,13 @@ libc {
cthread_keycreate; cthread_getspecific; cthread_setspecific;
__libc_getspecific;
}
+
+ GLIBC_PRIVATE {
+ # Used by other libs.
+ lll_xwait; lll_timed_wait; lll_timed_xwait;
+ __lll_abstimed_wait; __lll_abstimed_xwait;
+ __lll_abstimed_lock; lll_robust_lock;
+ __lll_robust_abstimed_lock; lll_robust_trylock;
+ lll_set_wake; lll_robust_unlock; lll_requeue;
+ }
}
diff --git a/hurd/ctty-input.c b/hurd/ctty-input.c
index 25463fd0b0..b17e43750f 100644
--- a/hurd/ctty-input.c
+++ b/hurd/ctty-input.c
@@ -43,12 +43,15 @@ _hurd_ctty_input (io_t port, io_t ctty, error_t (*rpc) (io_t))
else
{
struct hurd_sigstate *ss = _hurd_self_sigstate ();
- __spin_lock (&ss->lock);
+ struct sigaction *actions;
+
+ _hurd_sigstate_lock (ss);
+ actions = _hurd_sigstate_actions (ss);
if (__sigismember (&ss->blocked, SIGTTIN) ||
- ss->actions[SIGTTIN].sa_handler == SIG_IGN)
+ actions[SIGTTIN].sa_handler == SIG_IGN)
/* We are blocking or ignoring SIGTTIN. Just fail. */
err = EIO;
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
if (err == EBACKGROUND)
{
@@ -65,10 +68,11 @@ _hurd_ctty_input (io_t port, io_t ctty, error_t (*rpc) (io_t))
SIGTTIN or resumed after being stopped. Now this is
still a "system call", so check to see if we should
restart it. */
- __spin_lock (&ss->lock);
- if (!(ss->actions[SIGTTIN].sa_flags & SA_RESTART))
+ _hurd_sigstate_lock (ss);
+ actions = _hurd_sigstate_actions (ss);
+ if (!(actions[SIGTTIN].sa_flags & SA_RESTART))
err = EINTR;
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
}
}
}
diff --git a/hurd/ctty-output.c b/hurd/ctty-output.c
index 41286fb556..0cbe2e09ef 100644
--- a/hurd/ctty-output.c
+++ b/hurd/ctty-output.c
@@ -34,16 +34,19 @@ _hurd_ctty_output (io_t port, io_t ctty, error_t (*rpc) (io_t))
do
{
+ struct sigaction *actions;
+
/* Don't use the ctty io port if we are blocking or ignoring
SIGTTOU. We redo this check at the top of the loop in case
the signal handler changed the state. */
- __spin_lock (&ss->lock);
+ _hurd_sigstate_lock (ss);
+ actions = _hurd_sigstate_actions (ss);
if (__sigismember (&ss->blocked, SIGTTOU) ||
- ss->actions[SIGTTOU].sa_handler == SIG_IGN)
+ actions[SIGTTOU].sa_handler == SIG_IGN)
err = EIO;
else
err = 0;
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
if (err)
return (*rpc) (port);
@@ -70,10 +73,11 @@ _hurd_ctty_output (io_t port, io_t ctty, error_t (*rpc) (io_t))
SIGTTOU or resumed after being stopped. Now this is
still a "system call", so check to see if we should
restart it. */
- __spin_lock (&ss->lock);
- if (!(ss->actions[SIGTTOU].sa_flags & SA_RESTART))
+ _hurd_sigstate_lock (ss);
+ actions = _hurd_sigstate_actions (ss);
+ if (!(actions[SIGTTOU].sa_flags & SA_RESTART))
err = EINTR;
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
}
}
/* If the last RPC generated a SIGTTOU, loop to try it again. */
diff --git a/hurd/dtable.c b/hurd/dtable.c
index 32ec49536a..73e60280ef 100644
--- a/hurd/dtable.c
+++ b/hurd/dtable.c
@@ -235,6 +235,7 @@ ctty_new_pgrp (void)
__mutex_unlock (&_hurd_dtable_lock);
HURD_CRITICAL_END;
+ /* TODO: handle EINTR! */
(void) &ctty_new_pgrp; /* Avoid "defined but not used" warning. */
}
@@ -297,6 +298,7 @@ reauth_dtable (void)
__mutex_unlock (&_hurd_dtable_lock);
HURD_CRITICAL_END;
+ /* TODO: handle EINTR! */
(void) &reauth_dtable; /* Avoid "defined but not used" warning. */
}
diff --git a/hurd/exc2signal.c b/hurd/exc2signal.c
index 3a2ec08124..2027630d56 100644
--- a/hurd/exc2signal.c
+++ b/hurd/exc2signal.c
@@ -17,6 +17,7 @@
<http://www.gnu.org/licenses/>. */
#include <hurd.h>
+#include <hurd/signal.h>
/* This file must be modified with machine-dependent details. */
#error "need to write sysdeps/mach/hurd/MACHINE/exc2signal.c"
@@ -24,47 +25,66 @@
/* Translate the Mach exception codes, as received in an `exception_raise' RPC,
into a signal number and signal subcode. */
-void
-_hurd_exception2signal (int exception, int code, int subcode,
- int *signo, int *sigcode, int *error)
+static void
+exception2signal (struct hurd_signal_detail *detail, int *signo, int posix)
{
- *error = 0;
+ detail->error = 0;
- switch (exception)
+ switch (detail->exc)
{
default:
*signo = SIGIOT;
- *sigcode = exception;
+ detail->code = detail->exc;
break;
case EXC_BAD_ACCESS:
- if (code == KERN_PROTECTION_FAILURE)
- *signo = SIGSEGV;
- else
- *signo = SIGBUS;
- *sigcode = subcode;
- *error = code;
+ switch (detail->exc_code)
+ {
+ case KERN_PROTECTION_FAILURE:
+ *signo = SIGSEGV;
+ detail->code = posix ? SEGV_ACCERR : detail->exc_subcode;
+ break;
+
+ default:
+ *signo = SIGBUS;
+ detail->code = 0;
+ break;
+ }
+ detail->error = detail->exc_code;
break;
case EXC_BAD_INSTRUCTION:
*signo = SIGILL;
- *sigcode = 0;
+ detail->code = 0;
break;
case EXC_ARITHMETIC:
*signo = SIGFPE;
- *sigcode = 0;
+ detail->code = 0;
break;
case EXC_EMULATION:
case EXC_SOFTWARE:
*signo = SIGEMT;
- *sigcode = 0;
+ detail->code = 0;
break;
case EXC_BREAKPOINT:
*signo = SIGTRAP;
- *sigcode = 0;
+ detail->code = 0;
break;
}
}
+
+void
+_hurd_exception2signal (struct hurd_signal_detail *detail, int *signo)
+{
+ exception2signal (detail, signo, 1);
+}
+
+void
+_hurd_exception2signal_legacy (struct hurd_signal_detail *detail, int *signo)
+{
+ exception2signal (detail, signo, 0);
+}
+
diff --git a/hurd/fcntl-internal.h b/hurd/fcntl-internal.h
new file mode 100644
index 0000000000..5cd4542b7c
--- /dev/null
+++ b/hurd/fcntl-internal.h
@@ -0,0 +1,60 @@
+/* Copyright (C) 2008-2015 Free Software Foundation, Inc.
+
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <verify.h>
+
+/* Do some compile-time checks for the SOCK_* constants, which we rely on. */
+verify (SOCK_CLOEXEC == O_CLOEXEC);
+verify ((SOCK_MAX | SOCK_TYPE_MASK) == SOCK_TYPE_MASK);
+verify ((SOCK_CLOEXEC & SOCK_TYPE_MASK) == 0);
+verify ((SOCK_NONBLOCK & SOCK_TYPE_MASK) == 0);
+
+
+/* Helper functions for translating between O_* and SOCK_* flags. */
+
+__extern_always_inline
+int
+sock_to_o_flags (int in)
+{
+ int out = 0;
+
+ if (in & SOCK_NONBLOCK)
+ out |= O_NONBLOCK;
+ /* Others are passed through unfiltered. */
+ out |= in & ~(SOCK_NONBLOCK);
+
+ return out;
+}
+
+__extern_always_inline
+int
+o_to_sock_flags (int in)
+{
+ int out = 0;
+
+ if (in & O_NONBLOCK)
+ out |= SOCK_NONBLOCK;
+ /* Others are passed through unfiltered. */
+ out |= in & ~(O_NONBLOCK);
+
+ return out;
+}
diff --git a/hurd/hurd.h b/hurd/hurd.h
index 022abb59bf..3d99c27ce5 100644
--- a/hurd/hurd.h
+++ b/hurd/hurd.h
@@ -46,6 +46,9 @@
#define _HURD_H_EXTERN_INLINE __extern_inline
#endif
+int __hurd_fail (error_t err);
+
+#ifdef __USE_EXTERN_INLINES
_HURD_H_EXTERN_INLINE int
__hurd_fail (error_t err)
{
@@ -75,6 +78,7 @@ __hurd_fail (error_t err)
errno = err;
return -1;
}
+#endif
/* Basic ports and info, initialized by startup. */
diff --git a/hurd/hurd/fd.h b/hurd/hurd/fd.h
index 54951024a4..e75cb146fa 100644
--- a/hurd/hurd/fd.h
+++ b/hurd/hurd/fd.h
@@ -26,6 +26,7 @@
#include <hurd/hurd_types.h>
#include <hurd/port.h>
#include <sys/socket.h>
+#include <fcntl.h>
/* Structure representing a file descriptor. */
@@ -58,6 +59,10 @@ extern struct mutex _hurd_dtable_lock; /* Locks those two variables. */
NULL. The cell is unlocked; when ready to use it, lock it and check for
it being unused. */
+struct hurd_fd *_hurd_fd_get (int fd);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
_HURD_FD_H_EXTERN_INLINE struct hurd_fd *
_hurd_fd_get (int fd)
{
@@ -90,6 +95,8 @@ _hurd_fd_get (int fd)
return descriptor;
}
+# endif
+#endif
/* Evaluate EXPR with the variable `descriptor' bound to a pointer to the
@@ -137,6 +144,9 @@ _hurd_fd_get (int fd)
/* Check if ERR should generate a signal.
Returns the signal to take, or zero if none. */
+int _hurd_fd_error_signal (error_t err);
+
+#ifdef __USE_EXTERN_INLINES
_HURD_FD_H_EXTERN_INLINE int
_hurd_fd_error_signal (error_t err)
{
@@ -153,11 +163,15 @@ _hurd_fd_error_signal (error_t err)
return 0;
}
}
+#endif
/* Handle an error from an RPC on a file descriptor's port. You should
always use this function to handle errors from RPCs made on file
descriptor ports. Some errors are translated into signals. */
+error_t _hurd_fd_error (int fd, error_t err);
+
+#ifdef __USE_EXTERN_INLINES
_HURD_FD_H_EXTERN_INLINE error_t
_hurd_fd_error (int fd, error_t err)
{
@@ -170,20 +184,28 @@ _hurd_fd_error (int fd, error_t err)
}
return err;
}
+#endif
/* Handle error code ERR from an RPC on file descriptor FD's port.
Set `errno' to the appropriate error code, and always return -1. */
+int __hurd_dfail (int fd, error_t err);
+
+#ifdef __USE_EXTERN_INLINES
_HURD_FD_H_EXTERN_INLINE int
__hurd_dfail (int fd, error_t err)
{
errno = _hurd_fd_error (fd, err);
return -1;
}
+#endif
/* Likewise, but do not raise SIGPIPE on EPIPE if flags contain
MSG_NOSIGNAL. */
+int __hurd_sockfail (int fd, int flags, error_t err);
+
+#ifdef __USE_EXTERN_INLINES
_HURD_FD_H_EXTERN_INLINE int
__hurd_sockfail (int fd, int flags, error_t err)
{
@@ -192,6 +214,7 @@ __hurd_sockfail (int fd, int flags, error_t err)
errno = err;
return -1;
}
+#endif
/* Set up *FD to have PORT its server port, doing appropriate ctty magic.
Does no locking or unlocking. */
@@ -254,6 +277,30 @@ extern int _hurd_select (int nfds, struct pollfd *pollfds,
const struct timespec *timeout,
const sigset_t *sigmask);
+/* Apply AT_FLAGS on FLAGS, in preparation for calling
+ __hurd_file_name_lookup. */
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
+_HURD_FD_H_EXTERN_INLINE error_t
+__hurd_at_flags (int *at_flags, int *flags)
+{
+ if ((*at_flags & AT_SYMLINK_FOLLOW) && (*at_flags & AT_SYMLINK_NOFOLLOW))
+ return EINVAL;
+
+ *flags |= (*at_flags & AT_SYMLINK_NOFOLLOW) ? O_NOLINK : 0;
+ *at_flags &= ~AT_SYMLINK_NOFOLLOW;
+ if (*at_flags & AT_SYMLINK_FOLLOW)
+ *flags &= ~O_NOLINK;
+ *at_flags &= ~AT_SYMLINK_FOLLOW;
+ if (*at_flags != 0)
+ return EINVAL;
+
+ return 0;
+}
+# endif
+#endif
+
/* Variant of file_name_lookup used in *at function implementations.
AT_FLAGS may only contain AT_SYMLINK_FOLLOW or AT_SYMLINK_NOFOLLOW,
which will remove and add O_NOLINK from FLAGS respectively.
diff --git a/hurd/hurd/port.h b/hurd/hurd/port.h
index 4fea1aa4d2..8afee90e29 100644
--- a/hurd/hurd/port.h
+++ b/hurd/hurd/port.h
@@ -60,6 +60,10 @@ struct hurd_port
/* Initialize *PORT to INIT. */
+void _hurd_port_init (struct hurd_port *port, mach_port_t init);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
_HURD_PORT_H_EXTERN_INLINE void
_hurd_port_init (struct hurd_port *port, mach_port_t init)
{
@@ -67,6 +71,8 @@ _hurd_port_init (struct hurd_port *port, mach_port_t init)
port->users = NULL;
port->port = init;
}
+# endif
+#endif
/* Cleanup function for non-local exits. */
@@ -75,6 +81,12 @@ extern void _hurd_port_cleanup (void *, jmp_buf, int);
/* Get a reference to *PORT, which is locked.
Pass return value and LINK to _hurd_port_free when done. */
+mach_port_t
+_hurd_port_locked_get (struct hurd_port *port,
+ struct hurd_userlink *link);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
_HURD_PORT_H_EXTERN_INLINE mach_port_t
_hurd_port_locked_get (struct hurd_port *port,
struct hurd_userlink *link)
@@ -90,9 +102,17 @@ _hurd_port_locked_get (struct hurd_port *port,
__spin_unlock (&port->lock);
return result;
}
+# endif
+#endif
/* Same, but locks PORT first. */
+mach_port_t
+_hurd_port_get (struct hurd_port *port,
+ struct hurd_userlink *link);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
_HURD_PORT_H_EXTERN_INLINE mach_port_t
_hurd_port_get (struct hurd_port *port,
struct hurd_userlink *link)
@@ -104,10 +124,19 @@ _hurd_port_get (struct hurd_port *port,
HURD_CRITICAL_END;
return result;
}
+# endif
+#endif
/* Free a reference gotten with `USED_PORT = _hurd_port_get (PORT, LINK);' */
+void
+_hurd_port_free (struct hurd_port *port,
+ struct hurd_userlink *link,
+ mach_port_t used_port);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
_HURD_PORT_H_EXTERN_INLINE void
_hurd_port_free (struct hurd_port *port,
struct hurd_userlink *link,
@@ -127,11 +156,17 @@ _hurd_port_free (struct hurd_port *port,
if (dealloc)
__mach_port_deallocate (__mach_task_self (), used_port);
}
+# endif
+#endif
/* Set *PORT's port to NEWPORT. NEWPORT's reference is consumed by PORT->port.
PORT->lock is locked. */
+void _hurd_port_locked_set (struct hurd_port *port, mach_port_t newport);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
_HURD_PORT_H_EXTERN_INLINE void
_hurd_port_locked_set (struct hurd_port *port, mach_port_t newport)
{
@@ -142,9 +177,15 @@ _hurd_port_locked_set (struct hurd_port *port, mach_port_t newport)
if (old != MACH_PORT_NULL)
__mach_port_deallocate (__mach_task_self (), old);
}
+# endif
+#endif
/* Same, but locks PORT first. */
+void _hurd_port_set (struct hurd_port *port, mach_port_t newport);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
_HURD_PORT_H_EXTERN_INLINE void
_hurd_port_set (struct hurd_port *port, mach_port_t newport)
{
@@ -153,6 +194,8 @@ _hurd_port_set (struct hurd_port *port, mach_port_t newport)
_hurd_port_locked_set (port, newport);
HURD_CRITICAL_END;
}
+# endif
+#endif
#endif /* hurd/port.h */
diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h
index 96f42d5064..aad9ac44ce 100644
--- a/hurd/hurd/signal.h
+++ b/hurd/hurd/signal.h
@@ -40,7 +40,6 @@
#include <cthreads.h> /* For `struct mutex'. */
#include <setjmp.h> /* For `jmp_buf'. */
#include <spin-lock.h>
-#include <hurd/threadvar.h> /* We cache sigstate in a threadvar. */
struct hurd_signal_preemptor; /* <hurd/sigpreempt.h> */
@@ -64,12 +63,20 @@ struct hurd_sigstate
spin_lock_t lock; /* Locks most of the rest of the structure. */
+ /* The signal state holds a reference on the thread port. */
thread_t thread;
+
struct hurd_sigstate *next; /* Linked-list of thread sigstates. */
sigset_t blocked; /* What signals are blocked. */
sigset_t pending; /* Pending signals, possibly blocked. */
+
+ /* Signal handlers. ACTIONS[0] is used to mark the threads with POSIX
+ semantics: if sa_handler is SIG_IGN instead of SIG_DFL, this thread
+ will receive global signals and use the process-wide action vector
+ instead of this one. */
struct sigaction actions[NSIG];
+
struct sigaltstack sigaltstack;
/* Chain of thread-local signal preemptors; see <hurd/sigpreempt.h>.
@@ -112,7 +119,9 @@ extern struct hurd_sigstate *_hurd_sigstates;
extern struct mutex _hurd_siglock; /* Locks _hurd_sigstates. */
-/* Get the sigstate of a given thread, taking its lock. */
+/* Get the sigstate of a given thread. If there was no sigstate for
+ the thread, one is created, and the thread gains a reference. If
+ the given thread is MACH_PORT_NULL, return the global sigstate. */
extern struct hurd_sigstate *_hurd_thread_sigstate (thread_t);
@@ -125,19 +134,46 @@ extern struct hurd_sigstate *_hurd_self_sigstate (void)
by different threads. */
__attribute__ ((__const__));
+/* Process-wide signal state. */
+
+extern struct hurd_sigstate *_hurd_global_sigstate;
+
+/* Mark the given thread as a process-wide signal receiver. */
+
+extern void _hurd_sigstate_set_global_rcv (struct hurd_sigstate *ss);
+
+/* A thread can either use its own action vector and pending signal set
+ or use the global ones, depending on wether it has been marked as a
+ global receiver. The accessors below take that into account. */
+
+extern void _hurd_sigstate_lock (struct hurd_sigstate *ss);
+extern struct sigaction *_hurd_sigstate_actions (struct hurd_sigstate *ss);
+extern sigset_t _hurd_sigstate_pending (const struct hurd_sigstate *ss);
+extern void _hurd_sigstate_unlock (struct hurd_sigstate *ss);
+
+/* Used by libpthread to remove stale sigstate structures. */
+extern void _hurd_sigstate_delete (thread_t thread);
+
#ifndef _HURD_SIGNAL_H_EXTERN_INLINE
#define _HURD_SIGNAL_H_EXTERN_INLINE __extern_inline
#endif
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
_HURD_SIGNAL_H_EXTERN_INLINE struct hurd_sigstate *
_hurd_self_sigstate (void)
{
- struct hurd_sigstate **location = (struct hurd_sigstate **)
- (void *) __hurd_threadvar_location (_HURD_THREADVAR_SIGSTATE);
+ struct hurd_sigstate **location = &THREAD_SELF->_hurd_sigstate;
if (*location == NULL)
- *location = _hurd_thread_sigstate (__mach_thread_self ());
+ {
+ thread_t self = __mach_thread_self ();
+ *location = _hurd_thread_sigstate (self);
+ __mach_port_deallocate (__mach_task_self (), self);
+ }
return *location;
}
+# endif
+#endif
/* Thread listening on our message port; also called the "signal thread". */
@@ -148,12 +184,6 @@ extern thread_t _hurd_msgport_thread;
extern mach_port_t _hurd_msgport;
-
-/* Thread to receive process-global signals. */
-
-extern thread_t _hurd_sigthread;
-
-
/* Resource limit on core file size. Enforced by hurdsig.c. */
extern int _hurd_core_limit;
@@ -164,19 +194,34 @@ extern int _hurd_core_limit;
interrupted lest the signal handler try to take the same lock and
deadlock result. */
+void *_hurd_critical_section_lock (void);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
_HURD_SIGNAL_H_EXTERN_INLINE void *
_hurd_critical_section_lock (void)
{
- struct hurd_sigstate **location = (struct hurd_sigstate **)
- (void *) __hurd_threadvar_location (_HURD_THREADVAR_SIGSTATE);
- struct hurd_sigstate *ss = *location;
+ struct hurd_sigstate **location;
+ struct hurd_sigstate *ss;
+
+#ifdef __LIBC_NO_TLS
+ if (__LIBC_NO_TLS())
+ /* TLS is currently initializing, no need to enter critical section. */
+ return NULL;
+#endif
+
+ location = &THREAD_SELF->_hurd_sigstate;
+ ss = *location;
if (ss == NULL)
{
+ thread_t self = __mach_thread_self ();
+
/* The thread variable is unset; this must be the first time we've
asked for it. In this case, the critical section flag cannot
possible already be set. Look up our sigstate structure the slow
way. */
- ss = *location = _hurd_thread_sigstate (__mach_thread_self ());
+ ss = *location = _hurd_thread_sigstate (self);
+ __mach_port_deallocate (__mach_task_self (), self);
}
if (! __spin_try_lock (&ss->critical_section_lock))
@@ -188,7 +233,13 @@ _hurd_critical_section_lock (void)
_hurd_critical_section_unlock to unlock it. */
return ss;
}
+# endif
+#endif
+
+void _hurd_critical_section_unlock (void *our_lock);
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
_HURD_SIGNAL_H_EXTERN_INLINE void
_hurd_critical_section_unlock (void *our_lock)
{
@@ -200,10 +251,10 @@ _hurd_critical_section_unlock (void *our_lock)
/* It was us who acquired the critical section lock. Unlock it. */
struct hurd_sigstate *ss = (struct hurd_sigstate *) our_lock;
sigset_t pending;
- __spin_lock (&ss->lock);
+ _hurd_sigstate_lock (ss);
__spin_unlock (&ss->critical_section_lock);
- pending = ss->pending & ~ss->blocked;
- __spin_unlock (&ss->lock);
+ pending = _hurd_sigstate_pending(ss) & ~ss->blocked;
+ _hurd_sigstate_unlock (ss);
if (! __sigisemptyset (&pending))
/* There are unblocked signals pending, which weren't
delivered because we were in the critical section.
@@ -211,6 +262,8 @@ _hurd_critical_section_unlock (void *our_lock)
__msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
}
}
+# endif
+#endif
/* Convenient macros for simple uses of critical sections.
These two must be used as a pair at the same C scoping level. */
@@ -241,6 +294,11 @@ extern int _hurd_raise_signal (struct hurd_sigstate *ss, int signo,
extern void _hurd_exception2signal (struct hurd_signal_detail *detail,
int *signo);
+/* Translate a Mach exception into a signal with a legacy sigcode. */
+
+extern void _hurd_exception2signal_legacy (struct hurd_signal_detail *detail,
+ int *signo);
+
/* Make the thread described by SS take the signal described by SIGNO and
DETAIL. If the process is traced, this will in fact stop with a SIGNO
diff --git a/hurd/hurd/sigpreempt.h b/hurd/hurd/sigpreempt.h
index 3a1eaf2e9f..75dcd59e00 100644
--- a/hurd/hurd/sigpreempt.h
+++ b/hurd/hurd/sigpreempt.h
@@ -46,9 +46,9 @@ struct hurd_signal_preemptor
struct hurd_signal_preemptor *next; /* List structure. */
};
-#define HURD_PREEMPT_SIGNAL_P(preemptor, signo, sigcode) \
+#define HURD_PREEMPT_SIGNAL_P(preemptor, signo, address) \
(((preemptor)->signals & sigmask (signo)) && \
- (sigcode) >= (preemptor)->first && (sigcode) <= (preemptor)->last)
+ (address) >= (preemptor)->first && (address) <= (preemptor)->last)
/* Signal preemptors applying to all threads; locked by _hurd_siglock. */
diff --git a/hurd/hurd/threadvar.h b/hurd/hurd/threadvar.h
index b7b2a041ef..ff43598d2c 100644
--- a/hurd/hurd/threadvar.h
+++ b/hurd/hurd/threadvar.h
@@ -20,97 +20,22 @@
#define _HURD_THREADVAR_H
#include <features.h>
+#include <tls.h>
-/* The per-thread variables are found by ANDing this mask
- with the value of the stack pointer and then adding this offset.
-
- In the multi-threaded case, cthreads initialization sets
- __hurd_threadvar_stack_mask to ~(cthread_stack_size - 1), a mask which
- finds the base of the fixed-size cthreads stack; and
- __hurd_threadvar_stack_offset to a small offset that skips the data
- cthreads itself maintains at the base of each thread's stack.
-
- In the single-threaded case, __hurd_threadvar_stack_mask is zero, so the
- stack pointer is ignored; and __hurd_threadvar_stack_offset gives the
- address of a small allocated region which contains the variables for the
- single thread. */
-
-extern unsigned long int __hurd_threadvar_stack_mask;
-extern unsigned long int __hurd_threadvar_stack_offset;
-
-/* A special case must always be made for the signal thread. Even when there
- is only one user thread and an allocated region can be used for the user
- thread's variables, the signal thread needs to have its own location for
- per-thread variables. The variables __hurd_sigthread_stack_base and
+/* The variables __hurd_sigthread_stack_base and
__hurd_sigthread_stack_end define the bounds of the stack used by the
signal thread, so that thread can always be specifically identified. */
extern unsigned long int __hurd_sigthread_stack_base;
extern unsigned long int __hurd_sigthread_stack_end;
-extern unsigned long int *__hurd_sigthread_variables;
-/* At the location described by the two variables above,
- there are __hurd_threadvar_max `unsigned long int's of per-thread data. */
+/* We do not use threadvars any more, this is kept as zero for compatibility with cthreads */
+extern unsigned long int __hurd_threadvar_stack_mask;
+extern unsigned long int __hurd_threadvar_stack_offset;
extern unsigned int __hurd_threadvar_max;
-/* These values are the indices for the standard per-thread variables. */
-enum __hurd_threadvar_index
- {
- _HURD_THREADVAR_MIG_REPLY, /* Reply port for MiG user stub functions. */
- _HURD_THREADVAR_ERRNO, /* `errno' value for this thread. */
- _HURD_THREADVAR_SIGSTATE, /* This thread's `struct hurd_sigstate'. */
- _HURD_THREADVAR_DYNAMIC_USER, /* Dynamically-assigned user variables. */
- _HURD_THREADVAR_MALLOC, /* For use of malloc. */
- _HURD_THREADVAR_DL_ERROR, /* For use of -ldl and dynamic linker. */
- _HURD_THREADVAR_RPC_VARS, /* For state of RPC functions. */
- _HURD_THREADVAR_LOCALE, /* For thread-local locale setting. */
- _HURD_THREADVAR_CTYPE_B, /* Cache of thread-local locale data. */
- _HURD_THREADVAR_CTYPE_TOLOWER, /* Cache of thread-local locale data. */
- _HURD_THREADVAR_CTYPE_TOUPPER, /* Cache of thread-local locale data. */
- _HURD_THREADVAR_MAX /* Default value for __hurd_threadvar_max. */
- };
-
-
-#ifndef _HURD_THREADVAR_H_EXTERN_INLINE
-#define _HURD_THREADVAR_H_EXTERN_INLINE __extern_inline
-#endif
-
-/* Return the location of the value for the per-thread variable with index
- INDEX used by the thread whose stack pointer is SP. */
-
-extern unsigned long int *__hurd_threadvar_location_from_sp
- (enum __hurd_threadvar_index __index, void *__sp);
-_HURD_THREADVAR_H_EXTERN_INLINE unsigned long int *
-__hurd_threadvar_location_from_sp (enum __hurd_threadvar_index __index,
- void *__sp)
-{
- unsigned long int __stack = (unsigned long int) __sp;
- return &((__stack >= __hurd_sigthread_stack_base &&
- __stack < __hurd_sigthread_stack_end)
- ? __hurd_sigthread_variables
- : (unsigned long int *) ((__stack & __hurd_threadvar_stack_mask) +
- __hurd_threadvar_stack_offset))[__index];
-}
-
-#include <machine-sp.h> /* Define __thread_stack_pointer. */
-
-/* Return the location of the current thread's value for the
- per-thread variable with index INDEX. */
-
-extern unsigned long int *
-__hurd_threadvar_location (enum __hurd_threadvar_index __index) __THROW
- /* This declaration tells the compiler that the value is constant
- given the same argument. We assume this won't be called twice from
- the same stack frame by different threads. */
- __attribute__ ((__const__));
-
-_HURD_THREADVAR_H_EXTERN_INLINE unsigned long int *
-__hurd_threadvar_location (enum __hurd_threadvar_index __index)
-{
- return __hurd_threadvar_location_from_sp (__index,
- __thread_stack_pointer ());
-}
-
+extern mach_port_t __hurd_reply_port0;
+#define __hurd_local_reply_port (*(__LIBC_NO_TLS() ? &__hurd_reply_port0 : &THREAD_SELF->reply_port))
#endif /* hurd/threadvar.h */
diff --git a/hurd/hurd/userlink.h b/hurd/hurd/userlink.h
index 275ce0cdd8..d2610d7561 100644
--- a/hurd/hurd/userlink.h
+++ b/hurd/hurd/userlink.h
@@ -76,6 +76,12 @@ struct hurd_userlink
/* Attach LINK to the chain of users at *CHAINP. */
+void
+_hurd_userlink_link (struct hurd_userlink **chainp,
+ struct hurd_userlink *link);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
_HURD_USERLINK_H_EXTERN_INLINE void
_hurd_userlink_link (struct hurd_userlink **chainp,
struct hurd_userlink *link)
@@ -96,11 +102,17 @@ _hurd_userlink_link (struct hurd_userlink **chainp,
link->thread.prevp = thread_chainp;
*thread_chainp = link;
}
+# endif
+#endif
/* Detach LINK from its chain. Returns nonzero iff this was the
last user of the resource and it should be deallocated. */
+int _hurd_userlink_unlink (struct hurd_userlink *link);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
_HURD_USERLINK_H_EXTERN_INLINE int
_hurd_userlink_unlink (struct hurd_userlink *link)
{
@@ -123,6 +135,8 @@ _hurd_userlink_unlink (struct hurd_userlink *link)
return dealloc;
}
+# endif
+#endif
/* Clear all users from *CHAINP. Call this when the resource *CHAINP
@@ -131,6 +145,10 @@ _hurd_userlink_unlink (struct hurd_userlink *link)
value is zero, someone is still using the resource and they will
deallocate it when they are finished. */
+int _hurd_userlink_clear (struct hurd_userlink **chainp);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+# if IS_IN (libc)
_HURD_USERLINK_H_EXTERN_INLINE int
_hurd_userlink_clear (struct hurd_userlink **chainp)
{
@@ -143,5 +161,7 @@ _hurd_userlink_clear (struct hurd_userlink **chainp)
*chainp = NULL;
return 0;
}
+# endif
+#endif
#endif /* hurd/userlink.h */
diff --git a/hurd/hurdauth.c b/hurd/hurdauth.c
index 7ecba39c8d..695e3abbbb 100644
--- a/hurd/hurdauth.c
+++ b/hurd/hurdauth.c
@@ -223,6 +223,7 @@ _S_msg_del_auth (mach_port_t me,
}
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ /* TODO: handle EINTR */
if (err)
return err;
diff --git a/hurd/hurdexec.c b/hurd/hurdexec.c
index 9978607be6..7f1df34101 100644
--- a/hurd/hurdexec.c
+++ b/hurd/hurdexec.c
@@ -104,15 +104,15 @@ _hurd_exec (task_t task, file_t file,
ss = _hurd_self_sigstate ();
- assert (! __spin_lock_locked (&ss->critical_section_lock));
__spin_lock (&ss->critical_section_lock);
- __spin_lock (&ss->lock);
+ _hurd_sigstate_lock (ss);
+ struct sigaction *actions = _hurd_sigstate_actions (ss);
ints[INIT_SIGMASK] = ss->blocked;
- ints[INIT_SIGPENDING] = ss->pending;
+ ints[INIT_SIGPENDING] = _hurd_sigstate_pending (ss);
ints[INIT_SIGIGN] = 0;
for (i = 1; i < NSIG; ++i)
- if (ss->actions[i].sa_handler == SIG_IGN)
+ if (actions[i].sa_handler == SIG_IGN)
ints[INIT_SIGIGN] |= __sigmask (i);
/* We hold the sigstate lock until the exec has failed so that no signal
@@ -123,7 +123,7 @@ _hurd_exec (task_t task, file_t file,
critical section flag avoids anything we call trying to acquire the
sigstate lock. */
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
/* Pack up the descriptor table to give the new program. */
__mutex_lock (&_hurd_dtable_lock);
@@ -394,6 +394,7 @@ _hurd_exec (task_t task, file_t file,
/* Safe to let signals happen now. */
_hurd_critical_section_unlock (ss);
+ /* FIXME: handle EINTR */
outargs:
free (args);
diff --git a/hurd/hurdfault.c b/hurd/hurdfault.c
index 9016227fc9..1618692231 100644
--- a/hurd/hurdfault.c
+++ b/hurd/hurdfault.c
@@ -70,7 +70,7 @@ _hurdsig_fault_catch_exception_raise (mach_port_t port,
codes into a signal number and subcode. */
_hurd_exception2signal (&d, &signo);
- return HURD_PREEMPT_SIGNAL_P (&_hurdsig_fault_preemptor, signo, d.code)
+ return HURD_PREEMPT_SIGNAL_P (&_hurdsig_fault_preemptor, signo, d.exc_subcode)
? 0 : EGREGIOUS;
}
@@ -204,6 +204,8 @@ _hurdsig_fault_init (void)
/* This state will be restored when we fault.
It runs the function above. */
memset (&state, 0, sizeof state);
+
+ MACHINE_THREAD_STATE_FIX_NEW (&state);
MACHINE_THREAD_STATE_SET_PC (&state, faulted);
MACHINE_THREAD_STATE_SET_SP (&state, faultstack, sizeof faultstack);
diff --git a/hurd/hurdfchdir.c b/hurd/hurdfchdir.c
index d771667345..027da108c5 100644
--- a/hurd/hurdfchdir.c
+++ b/hurd/hurdfchdir.c
@@ -53,6 +53,7 @@ _hurd_change_directory_port_from_fd (struct hurd_port *portcell, int fd)
}));
HURD_CRITICAL_END;
+ /* TODO:handle EINTR */
return ret;
}
diff --git a/hurd/hurdinit.c b/hurd/hurdinit.c
index 02d0134519..a310404f68 100644
--- a/hurd/hurdinit.c
+++ b/hurd/hurdinit.c
@@ -174,7 +174,7 @@ _hurd_new_proc_init (char **argv,
/* This process is "traced", meaning it should stop on signals or exec.
We are all set up now to handle signals. Stop ourselves, to inform
our parent (presumably a debugger) that the exec has completed. */
- __msg_sig_post (_hurd_msgport, SIGTRAP, 0, __mach_task_self ());
+ __msg_sig_post (_hurd_msgport, SIGTRAP, TRAP_TRACE, __mach_task_self ());
}
#include <shlib-compat.h>
diff --git a/hurd/hurdioctl.c b/hurd/hurdioctl.c
index 974787ed8b..c36dd613cf 100644
--- a/hurd/hurdioctl.c
+++ b/hurd/hurdioctl.c
@@ -211,6 +211,7 @@ install_ctty (mach_port_t cttyid)
__mutex_lock (&_hurd_dtable_lock);
_hurd_locked_install_cttyid (cttyid);
HURD_CRITICAL_END;
+ /* TODO: handle EINTR! */
}
diff --git a/hurd/hurdlock.c b/hurd/hurdlock.c
new file mode 100644
index 0000000000..4059b7926c
--- /dev/null
+++ b/hurd/hurdlock.c
@@ -0,0 +1,247 @@
+/* Copyright (C) 1999-2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "hurdlock.h"
+#include <hurd.h>
+#include <time.h>
+#include <errno.h>
+
+int lll_xwait (void *ptr, int lo, int hi, int flags)
+{
+ return (__gsync_wait (__mach_task_self (),
+ (vm_offset_t)ptr, lo, hi, 0, flags | GSYNC_QUAD));
+}
+
+int lll_timed_wait (void *ptr, int val, int mlsec, int flags)
+{
+ return (__gsync_wait (__mach_task_self (),
+ (vm_offset_t)ptr, val, 0, mlsec, flags | GSYNC_TIMED));
+}
+
+int lll_timed_xwait (void *ptr, int lo,
+ int hi, int mlsec, int flags)
+{
+ return (__gsync_wait (__mach_task_self (), (vm_offset_t)ptr,
+ lo, hi, mlsec, flags | GSYNC_TIMED | GSYNC_QUAD));
+}
+
+/* Convert an absolute timeout in nanoseconds to a relative
+ * timeout in milliseconds. */
+static inline int __attribute__ ((gnu_inline))
+compute_reltime (const struct timespec *abstime, clockid_t clk)
+{
+ struct timespec ts;
+ __clock_gettime (clk, &ts);
+
+ ts.tv_sec = abstime->tv_sec - ts.tv_sec;
+ ts.tv_nsec = abstime->tv_nsec - ts.tv_nsec;
+
+ if (ts.tv_nsec < 0)
+ {
+ --ts.tv_sec;
+ ts.tv_nsec += 1000000000;
+ }
+
+ return (ts.tv_sec < 0 ? -1 :
+ (int)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000));
+}
+
+int __lll_abstimed_wait (void *ptr, int val,
+ const struct timespec *tsp, int flags, int clk)
+{
+ int mlsec = compute_reltime (tsp, clk);
+ return (mlsec < 0 ? KERN_TIMEDOUT :
+ lll_timed_wait (ptr, val, mlsec, flags));
+}
+
+int __lll_abstimed_xwait (void *ptr, int lo, int hi,
+ const struct timespec *tsp, int flags, int clk)
+{
+ int mlsec = compute_reltime (tsp, clk);
+ return (mlsec < 0 ? KERN_TIMEDOUT :
+ lll_timed_xwait (ptr, lo, hi, mlsec, flags));
+}
+
+int __lll_abstimed_lock (void *ptr,
+ const struct timespec *tsp, int flags, int clk)
+{
+ if (lll_trylock (ptr) == 0)
+ return (0);
+
+ while (1)
+ {
+ if (atomic_exchange_acq ((int *)ptr, 2) == 0)
+ return (0);
+ else if (tsp->tv_nsec < 0 || tsp->tv_nsec >= 1000000000)
+ return (EINVAL);
+
+ int mlsec = compute_reltime (tsp, clk);
+ if (mlsec < 0 || lll_timed_wait (ptr,
+ 2, mlsec, flags) == KERN_TIMEDOUT)
+ return (ETIMEDOUT);
+ }
+}
+
+void lll_set_wake (void *ptr, int val, int flags)
+{
+ __gsync_wake (__mach_task_self (),
+ (vm_offset_t)ptr, val, flags | GSYNC_MUTATE);
+}
+
+void lll_requeue (void *src, void *dst, int wake_one, int flags)
+{
+ __gsync_requeue (__mach_task_self (), (vm_offset_t)src,
+ (vm_offset_t)dst, (boolean_t)wake_one, flags);
+}
+
+/* Robust locks. */
+
+extern int __getpid (void) __attribute__ ((const));
+extern task_t __pid2task (int);
+
+/* Test if a given process id is still valid. */
+static inline int valid_pid (int pid)
+{
+ task_t task = __pid2task (pid);
+ if (task == MACH_PORT_NULL)
+ return (0);
+
+ __mach_port_deallocate (__mach_task_self (), task);
+ return (1);
+}
+
+/* Robust locks have currently no support from the kernel; they
+ * are simply implemented with periodic polling. When sleeping, the
+ * maximum blocking time is determined by this constant. */
+#define MAX_WAIT_TIME 1500
+
+int lll_robust_lock (void *ptr, int flags)
+{
+ int *iptr = (int *)ptr;
+ int id = __getpid ();
+ int wait_time = 25;
+ unsigned int val;
+
+ /* Try to set the lock word to our PID if it's clear. Otherwise,
+ * mark it as having waiters. */
+ while (1)
+ {
+ val = *iptr;
+ if (!val && atomic_compare_and_exchange_bool_acq (iptr, id, 0) == 0)
+ return (0);
+ else if (atomic_compare_and_exchange_bool_acq (iptr,
+ val | LLL_WAITERS, val) == 0)
+ break;
+ }
+
+ for (id |= LLL_WAITERS ; ; )
+ {
+ val = *iptr;
+ if (!val && atomic_compare_and_exchange_bool_acq (iptr, id, 0) == 0)
+ return (0);
+ else if (val && !valid_pid (val & LLL_OWNER_MASK))
+ {
+ if (atomic_compare_and_exchange_bool_acq (iptr, id, val) == 0)
+ return (EOWNERDEAD);
+ }
+ else
+ {
+ lll_timed_wait (iptr, val, wait_time, flags);
+ if (wait_time < MAX_WAIT_TIME)
+ wait_time <<= 1;
+ }
+ }
+}
+
+int __lll_robust_abstimed_lock (void *ptr,
+ const struct timespec *tsp, int flags, int clk)
+{
+ int *iptr = (int *)ptr;
+ int id = __getpid ();
+ int wait_time = 25;
+ unsigned int val;
+
+ while (1)
+ {
+ val = *iptr;
+ if (!val && atomic_compare_and_exchange_bool_acq (iptr, id, 0) == 0)
+ return (0);
+ else if (atomic_compare_and_exchange_bool_acq (iptr,
+ val | LLL_WAITERS, val) == 0)
+ break;
+ }
+
+ for (id |= LLL_WAITERS ; ; )
+ {
+ val = *iptr;
+ if (!val && atomic_compare_and_exchange_bool_acq (iptr, id, 0) == 0)
+ return (0);
+ else if (val && !valid_pid (val & LLL_OWNER_MASK))
+ {
+ if (atomic_compare_and_exchange_bool_acq (iptr, id, val) == 0)
+ return (EOWNERDEAD);
+ }
+ else
+ {
+ int mlsec = compute_reltime (tsp, clk);
+ if (mlsec < 0)
+ return (ETIMEDOUT);
+ else if (mlsec > wait_time)
+ mlsec = wait_time;
+
+ int res = lll_timed_wait (iptr, val, mlsec, flags);
+ if (res == KERN_TIMEDOUT)
+ return (ETIMEDOUT);
+ else if (wait_time < MAX_WAIT_TIME)
+ wait_time <<= 1;
+ }
+ }
+}
+
+int lll_robust_trylock (void *ptr)
+{
+ int *iptr = (int *)ptr;
+ int id = __getpid ();
+ unsigned int val = *iptr;
+
+ if (!val)
+ {
+ if (atomic_compare_and_exchange_bool_acq (iptr, id, 0) == 0)
+ return (0);
+ }
+ else if (!valid_pid (val & LLL_OWNER_MASK) &&
+ atomic_compare_and_exchange_bool_acq (iptr, id, val) == 0)
+ return (EOWNERDEAD);
+
+ return (EBUSY);
+}
+
+void lll_robust_unlock (void *ptr, int flags)
+{
+ unsigned int val = atomic_load_relaxed((unsigned int *)ptr);
+ while (1)
+ {
+ if (val & LLL_WAITERS)
+ {
+ lll_set_wake (ptr, 0, flags);
+ break;
+ }
+ else if (atomic_compare_exchange_weak_release ((unsigned int *)ptr, &val, 0))
+ break;
+ }
+}
+
diff --git a/hurd/hurdlock.h b/hurd/hurdlock.h
new file mode 100644
index 0000000000..405ffaf5f9
--- /dev/null
+++ b/hurd/hurdlock.h
@@ -0,0 +1,117 @@
+/* Copyright (C) 1999-2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _HURD_LOCK_H
+#define _HURD_LOCK_H 1
+
+#include <mach/lowlevellock.h>
+
+struct timespec;
+
+/* Flags for robust locks. */
+#define LLL_WAITERS (1U << 31)
+#define LLL_DEAD_OWNER (1U << 30)
+
+#define LLL_OWNER_MASK ~(LLL_WAITERS | LLL_DEAD_OWNER)
+
+/* Wait on 64-bit address PTR, without blocking if its contents
+ * are different from the pair <LO, HI>. */
+extern int lll_xwait (void *__ptr, int __lo,
+ int __hi, int __flags);
+
+/* Same as 'lll_wait', but only block for MLSEC milliseconds. */
+extern int lll_timed_wait (void *__ptr, int __val,
+ int __mlsec, int __flags);
+
+/* Same as 'lll_xwait', but only block for MLSEC milliseconds. */
+extern int lll_timed_xwait (void *__ptr, int __lo,
+ int __hi, int __mlsec, int __flags);
+
+/* Same as 'lll_wait', but only block until TSP elapses,
+ * using clock CLK. */
+extern int __lll_abstimed_wait (void *__ptr, int __val,
+ const struct timespec *__tsp, int __flags, int __clk);
+
+/* Same as 'lll_xwait', but only block until TSP elapses,
+ * using clock CLK. */
+extern int __lll_abstimed_xwait (void *__ptr, int __lo, int __hi,
+ const struct timespec *__tsp, int __flags, int __clk);
+
+/* Same as 'lll_lock', but return with an error if TSP elapses,
+ * using clock CLK. */
+extern int __lll_abstimed_lock (void *__ptr,
+ const struct timespec *__tsp, int __flags, int __clk);
+
+/* Acquire the lock at PTR, but return with an error if
+ * the process containing the owner thread dies. */
+extern int lll_robust_lock (void *__ptr, int __flags);
+
+/* Same as 'lll_robust_lock', but only block until TSP
+ * elapses, using clock CLK. */
+extern int __lll_robust_abstimed_lock (void *__ptr,
+ const struct timespec *__tsp, int __flags, int __clk);
+
+/* Same as 'lll_robust_lock', but return with an error
+ * if the lock cannot be acquired without blocking. */
+extern int lll_robust_trylock (void *__ptr);
+
+/* Wake one or more threads waiting on address PTR,
+ * setting its value to VAL before doing so. */
+extern void lll_set_wake (void *__ptr, int __val, int __flags);
+
+/* Release the robust lock at PTR. */
+extern void lll_robust_unlock (void *__ptr, int __flags);
+
+/* Rearrange threads waiting on address SRC to instead wait on
+ * DST, waking one of them if WAIT_ONE is non-zero. */
+extern void lll_requeue (void *__src, void *__dst,
+ int __wake_one, int __flags);
+
+/* The following are hacks that allow us to simulate optional
+ * parameters in C, to avoid having to pass the clock id for
+ * every one of these calls, defaulting to CLOCK_REALTIME if
+ * no argument is passed. */
+
+#define lll_abstimed_wait(ptr, val, tsp, flags, ...) \
+ ({ \
+ const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ }; \
+ __lll_abstimed_wait ((ptr), (val), (tsp), (flags), \
+ __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]); \
+ })
+
+#define lll_abstimed_xwait(ptr, lo, hi, tsp, flags, ...) \
+ ({ \
+ const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ }; \
+ __lll_abstimed_xwait ((ptr), (lo), (hi), (tsp), (flags), \
+ __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]); \
+ })
+
+#define lll_abstimed_lock(ptr, tsp, flags, ...) \
+ ({ \
+ const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ }; \
+ __lll_abstimed_lock ((ptr), (tsp), (flags), \
+ __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]); \
+ })
+
+#define lll_robust_abstimed_lock(ptr, tsp, flags, ...) \
+ ({ \
+ const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ }; \
+ __lll_robust_abstimed_lock ((ptr), (tsp), (flags), \
+ __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]); \
+ })
+
+#endif
diff --git a/hurd/hurdlookup.c b/hurd/hurdlookup.c
index dbff009539..bd720c27ec 100644
--- a/hurd/hurdlookup.c
+++ b/hurd/hurdlookup.c
@@ -72,7 +72,7 @@ __hurd_file_name_lookup (error_t (*use_init_port)
if (flags & O_NOFOLLOW) /* See lookup-retry.c about O_NOFOLLOW. */
flags |= O_NOTRANS;
- if (flags & O_DIRECTORY)
+ if (flags & O_DIRECTORY && !(flags & O_NOFOLLOW))
{
/* The caller wants to require that the file we look up is a directory.
We can do this without an extra RPC by appending a trailing slash
diff --git a/hurd/hurdmalloc.c b/hurd/hurdmalloc.c
index 58c29fa07d..65fb959d84 100644
--- a/hurd/hurdmalloc.c
+++ b/hurd/hurdmalloc.c
@@ -405,8 +405,8 @@ print_malloc_free_list (void)
}
#endif /* DEBUG */
-static void
-malloc_fork_prepare(void)
+void
+_hurd_malloc_fork_prepare(void)
/*
* Prepare the malloc module for a fork by insuring that no thread is in a
* malloc critical section.
@@ -419,8 +419,8 @@ malloc_fork_prepare(void)
}
}
-static void
-malloc_fork_parent(void)
+void
+_hurd_malloc_fork_parent(void)
/*
* Called in the parent process after a fork() to resume normal operation.
*/
@@ -432,8 +432,8 @@ malloc_fork_parent(void)
}
}
-static void
-malloc_fork_child(void)
+void
+_hurd_malloc_fork_child(void)
/*
* Called in the child process after a fork() to resume normal operation.
*/
@@ -446,7 +446,4 @@ malloc_fork_child(void)
}
-text_set_element (_hurd_fork_prepare_hook, malloc_fork_prepare);
-text_set_element (_hurd_fork_parent_hook, malloc_fork_parent);
-text_set_element (_hurd_fork_child_hook, malloc_fork_child);
text_set_element (_hurd_preinit_hook, malloc_init);
diff --git a/hurd/hurdmalloc.h b/hurd/hurdmalloc.h
index e11c208a8f..ab572e2814 100644
--- a/hurd/hurdmalloc.h
+++ b/hurd/hurdmalloc.h
@@ -12,6 +12,10 @@ extern void *_hurd_malloc (size_t);
extern void *_hurd_realloc (void *, size_t);
extern void _hurd_free (void *);
+extern void _hurd_malloc_fork_prepare(void);
+extern void _hurd_malloc_fork_parent(void);
+extern void _hurd_malloc_fork_child(void);
+
#define malloc _hurd_malloc
#define realloc _hurd_realloc
#define free _hurd_free
diff --git a/hurd/hurdmsg.c b/hurd/hurdmsg.c
index 65f6edb1fa..5204a82c2a 100644
--- a/hurd/hurdmsg.c
+++ b/hurd/hurdmsg.c
@@ -121,17 +121,9 @@ get_int (int which, int *value)
case INIT_UMASK:
*value = _hurd_umask;
return 0;
- case INIT_SIGMASK:
- {
- struct hurd_sigstate *ss = _hurd_thread_sigstate (_hurd_sigthread);
- __spin_lock (&ss->lock);
- *value = ss->blocked;
- __spin_unlock (&ss->lock);
- return 0;
- }
case INIT_SIGPENDING:
{
- struct hurd_sigstate *ss = _hurd_thread_sigstate (_hurd_sigthread);
+ struct hurd_sigstate *ss = _hurd_global_sigstate;
__spin_lock (&ss->lock);
*value = ss->pending;
__spin_unlock (&ss->lock);
@@ -139,7 +131,7 @@ get_int (int which, int *value)
}
case INIT_SIGIGN:
{
- struct hurd_sigstate *ss = _hurd_thread_sigstate (_hurd_sigthread);
+ struct hurd_sigstate *ss = _hurd_global_sigstate;
sigset_t ign;
int sig;
__spin_lock (&ss->lock);
@@ -207,17 +199,9 @@ set_int (int which, int value)
return 0;
/* These are pretty odd things to do. But you asked for it. */
- case INIT_SIGMASK:
- {
- struct hurd_sigstate *ss = _hurd_thread_sigstate (_hurd_sigthread);
- __spin_lock (&ss->lock);
- ss->blocked = value;
- __spin_unlock (&ss->lock);
- return 0;
- }
case INIT_SIGPENDING:
{
- struct hurd_sigstate *ss = _hurd_thread_sigstate (_hurd_sigthread);
+ struct hurd_sigstate *ss = _hurd_global_sigstate;
__spin_lock (&ss->lock);
ss->pending = value;
__spin_unlock (&ss->lock);
@@ -225,7 +209,7 @@ set_int (int which, int value)
}
case INIT_SIGIGN:
{
- struct hurd_sigstate *ss = _hurd_thread_sigstate (_hurd_sigthread);
+ struct hurd_sigstate *ss = _hurd_global_sigstate;
int sig;
const sigset_t ign = value;
__spin_lock (&ss->lock);
diff --git a/hurd/hurdpid.c b/hurd/hurdpid.c
index e5cda8c2f0..859a7744ad 100644
--- a/hurd/hurdpid.c
+++ b/hurd/hurdpid.c
@@ -16,6 +16,8 @@
<http://www.gnu.org/licenses/>. */
#include <hurd.h>
+#include <lowlevellock.h>
+
pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
int _hurd_orphaned;
@@ -66,6 +68,7 @@ _S_msg_proc_newids (mach_port_t me,
/* Notify any waiting user threads that the id change as been completed. */
++_hurd_pids_changed_stamp;
+ lll_wake (&_hurd_pids_changed_stamp, GSYNC_BROADCAST);
return 0;
}
diff --git a/hurd/hurdselect.c b/hurd/hurdselect.c
index d5ba826d16..9004a9050c 100644
--- a/hurd/hurdselect.c
+++ b/hurd/hurdselect.c
@@ -16,14 +16,17 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/poll.h>
#include <hurd.h>
#include <hurd/fd.h>
+#include <hurd/io_request.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdint.h>
+#include <limits.h>
/* All user select types. */
#define SELECT_ALL (SELECT_READ | SELECT_WRITE | SELECT_URG)
@@ -31,6 +34,7 @@
/* Used to record that a particular select rpc returned. Must be distinct
from SELECT_ALL (which better not have the high bit set). */
#define SELECT_RETURNED ((SELECT_ALL << 1) & ~SELECT_ALL)
+#define SELECT_ERROR (SELECT_RETURNED << 1)
/* Check the first NFDS descriptors either in POLLFDS (if nonnnull) or in
each of READFDS, WRITEFDS, EXCEPTFDS that is nonnull. If TIMEOUT is not
@@ -44,11 +48,13 @@ _hurd_select (int nfds,
{
int i;
mach_port_t portset;
- int got;
+ int got, ready;
error_t err;
fd_set rfds, wfds, xfds;
int firstfd, lastfd;
- mach_msg_timeout_t to = 0;
+ mach_msg_id_t reply_msgid;
+ mach_msg_timeout_t to;
+ struct timespec ts;
struct
{
struct hurd_userlink ulink;
@@ -56,6 +62,7 @@ _hurd_select (int nfds,
mach_port_t io_port;
int type;
mach_port_t reply_port;
+ int error;
} d[nfds];
sigset_t oset;
@@ -73,16 +80,39 @@ _hurd_select (int nfds,
return -1;
}
- if (timeout != NULL)
+#define IO_SELECT_REPLY_MSGID (21012 + 100) /* XXX */
+#define IO_SELECT_TIMEOUT_REPLY_MSGID (21031 + 100) /* XXX */
+
+ if (timeout == NULL)
+ reply_msgid = IO_SELECT_REPLY_MSGID;
+ else
{
- if (timeout->tv_sec < 0 || timeout->tv_nsec < 0)
+ struct timeval now;
+
+ if (timeout->tv_sec < 0 || timeout->tv_nsec < 0 ||
+ timeout->tv_nsec >= 1000000000)
{
errno = EINVAL;
return -1;
}
- to = (timeout->tv_sec * 1000 +
- (timeout->tv_nsec + 999999) / 1000000);
+ err = __gettimeofday(&now, NULL);
+ if (err)
+ return -1;
+
+ ts.tv_sec = now.tv_sec + timeout->tv_sec;
+ ts.tv_nsec = now.tv_usec * 1000 + timeout->tv_nsec;
+
+ if (ts.tv_nsec >= 1000000000)
+ {
+ ts.tv_sec++;
+ ts.tv_nsec -= 1000000000;
+ }
+
+ if (ts.tv_sec < 0)
+ ts.tv_sec = LONG_MAX; /* XXX */
+
+ reply_msgid = IO_SELECT_TIMEOUT_REPLY_MSGID;
}
if (sigmask && __sigprocmask (SIG_SETMASK, sigmask, &oset))
@@ -90,6 +120,7 @@ _hurd_select (int nfds,
if (pollfds)
{
+ int error = 0;
/* Collect interesting descriptors from the user's `pollfd' array.
We do a first pass that reads the user's array before taking
any locks. The second pass then only touches our own stack,
@@ -123,28 +154,47 @@ _hurd_select (int nfds,
if (fd < _hurd_dtablesize)
{
d[i].cell = _hurd_dtable[fd];
- d[i].io_port = _hurd_port_get (&d[i].cell->port, &d[i].ulink);
- if (d[i].io_port != MACH_PORT_NULL)
- continue;
+ if (d[i].cell != NULL)
+ {
+ d[i].io_port = _hurd_port_get (&d[i].cell->port,
+ &d[i].ulink);
+ if (d[i].io_port != MACH_PORT_NULL)
+ continue;
+ }
}
- /* If one descriptor is bogus, we fail completely. */
- while (i-- > 0)
- if (d[i].type != 0)
- _hurd_port_free (&d[i].cell->port,
- &d[i].ulink, d[i].io_port);
- break;
+ /* Bogus descriptor, make it EBADF already. */
+ d[i].error = EBADF;
+ d[i].type = SELECT_ERROR;
+ error = 1;
}
__mutex_unlock (&_hurd_dtable_lock);
HURD_CRITICAL_END;
- if (i < nfds)
+ if (error)
{
- if (sigmask)
- __sigprocmask (SIG_SETMASK, &oset, NULL);
- errno = EBADF;
- return -1;
+ /* Set timeout to 0. */
+ struct timeval now;
+ err = __gettimeofday(&now, NULL);
+ if (err)
+ {
+ /* Really bad luck. */
+ err = errno;
+ HURD_CRITICAL_BEGIN;
+ __mutex_lock (&_hurd_dtable_lock);
+ while (i-- > 0)
+ if (d[i].type & ~SELECT_ERROR != 0)
+ _hurd_port_free (&d[i].cell->port, &d[i].ulink,
+ d[i].io_port);
+ __mutex_unlock (&_hurd_dtable_lock);
+ HURD_CRITICAL_END;
+ errno = err;
+ return -1;
+ }
+ ts.tv_sec = now.tv_sec;
+ ts.tv_nsec = now.tv_usec * 1000;
+ reply_msgid = IO_SELECT_TIMEOUT_REPLY_MSGID;
}
lastfd = i - 1;
@@ -171,9 +221,6 @@ _hurd_select (int nfds,
HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_dtable_lock);
- if (nfds > _hurd_dtablesize)
- nfds = _hurd_dtablesize;
-
/* Collect the ports for interesting FDs. */
firstfd = lastfd = -1;
for (i = 0; i < nfds; ++i)
@@ -188,9 +235,15 @@ _hurd_select (int nfds,
d[i].type = type;
if (type)
{
- d[i].cell = _hurd_dtable[i];
- d[i].io_port = _hurd_port_get (&d[i].cell->port, &d[i].ulink);
- if (d[i].io_port == MACH_PORT_NULL)
+ if (i < _hurd_dtablesize)
+ {
+ d[i].cell = _hurd_dtable[i];
+ if (d[i].cell != NULL)
+ d[i].io_port = _hurd_port_get (&d[i].cell->port,
+ &d[i].ulink);
+ }
+ if (i >= _hurd_dtablesize || d[i].cell == NULL ||
+ d[i].io_port == MACH_PORT_NULL)
{
/* If one descriptor is bogus, we fail completely. */
while (i-- > 0)
@@ -215,6 +268,9 @@ _hurd_select (int nfds,
errno = EBADF;
return -1;
}
+
+ if (nfds > _hurd_dtablesize)
+ nfds = _hurd_dtablesize;
}
@@ -232,19 +288,19 @@ _hurd_select (int nfds,
portset = MACH_PORT_NULL;
for (i = firstfd; i <= lastfd; ++i)
- if (d[i].type)
+ if (!(d[i].type & ~SELECT_ERROR))
+ d[i].reply_port = MACH_PORT_NULL;
+ else
{
int type = d[i].type;
d[i].reply_port = __mach_reply_port ();
- err = __io_select (d[i].io_port, d[i].reply_port,
- /* Poll only if there's a single descriptor. */
- (firstfd == lastfd) ? to : 0,
- &type);
- switch (err)
+ if (timeout == NULL)
+ err = __io_select_request (d[i].io_port, d[i].reply_port, type);
+ else
+ err = __io_select_timeout_request (d[i].io_port, d[i].reply_port,
+ ts, type);
+ if (!err)
{
- case MACH_RCV_TIMED_OUT:
- /* No immediate response. This is normal. */
- err = 0;
if (firstfd == lastfd)
/* When there's a single descriptor, we don't need a
portset, so just pretend we have one, but really
@@ -265,32 +321,23 @@ _hurd_select (int nfds,
__mach_port_move_member (__mach_task_self (),
d[i].reply_port, portset);
}
- break;
-
- default:
- /* No other error should happen. Callers of select
- don't expect to see errors, so we simulate
- readiness of the erring object and the next call
- hopefully will get the error again. */
- type = SELECT_ALL;
- /* FALLTHROUGH */
-
- case 0:
- /* We got an answer. */
- if ((type & SELECT_ALL) == 0)
- /* Bogus answer; treat like an error, as a fake positive. */
- type = SELECT_ALL;
-
- /* This port is already ready already. */
- d[i].type &= type;
- d[i].type |= SELECT_RETURNED;
+ }
+ else
+ {
+ /* No error should happen, but record it for later
+ processing. */
+ d[i].error = err;
+ d[i].type |= SELECT_ERROR;
++got;
- break;
}
_hurd_port_free (&d[i].cell->port, &d[i].ulink, d[i].io_port);
}
}
+ /* GOT is the number of replies (or errors), while READY is the number of
+ replies with at least one type bit set. */
+ ready = 0;
+
/* Now wait for reply messages. */
if (!err && got == 0)
{
@@ -332,22 +379,35 @@ _hurd_select (int nfds,
} success;
#endif
} msg;
- mach_msg_option_t options = (timeout == NULL ? 0 : MACH_RCV_TIMEOUT);
+ mach_msg_option_t options;
error_t msgerr;
+
+ /* We rely on servers to implement the timeout, but when there are none,
+ do it on the client side. */
+ if (timeout != NULL && firstfd == -1)
+ {
+ options = MACH_RCV_TIMEOUT;
+ to = timeout->tv_sec * 1000 + (timeout->tv_nsec + 999999) / 1000000;
+ }
+ else
+ {
+ options = 0;
+ to = MACH_MSG_TIMEOUT_NONE;
+ }
+
while ((msgerr = __mach_msg (&msg.head,
MACH_RCV_MSG | MACH_RCV_INTERRUPT | options,
0, sizeof msg, portset, to,
MACH_PORT_NULL)) == MACH_MSG_SUCCESS)
{
/* We got a message. Decode it. */
-#define IO_SELECT_REPLY_MSGID (21012 + 100) /* XXX */
#ifdef MACH_MSG_TYPE_BIT
const union typeword inttype =
{ type:
{ MACH_MSG_TYPE_INTEGER_T, sizeof (integer_t) * 8, 1, 1, 0, 0 }
};
#endif
- if (msg.head.msgh_id == IO_SELECT_REPLY_MSGID &&
+ if (msg.head.msgh_id == reply_msgid &&
msg.head.msgh_size >= sizeof msg.error &&
!(msg.head.msgh_bits & MACH_MSGH_BITS_COMPLEX) &&
#ifdef MACH_MSG_TYPE_BIT
@@ -365,16 +425,18 @@ _hurd_select (int nfds,
err = EINTR;
goto poll;
}
+ /* Keep in mind msg.success.result can be 0 if a timeout
+ occurred. */
if (msg.error.err ||
- msg.head.msgh_size != sizeof msg.success ||
#ifdef MACH_MSG_TYPE_BIT
msg.success.result_type.word != inttype.word ||
#endif
- (msg.success.result & SELECT_ALL) == 0)
+ msg.head.msgh_size != sizeof msg.success)
{
- /* Error or bogus reply. Simulate readiness. */
+ /* Error or bogus reply. */
+ if (!msg.error.err)
+ msg.error.err = EIO;
__mach_msg_destroy (&msg.head);
- msg.success.result = SELECT_ALL;
}
/* Look up the respondent's reply port and record its
@@ -386,7 +448,19 @@ _hurd_select (int nfds,
if (d[i].type
&& d[i].reply_port == msg.head.msgh_local_port)
{
- d[i].type &= msg.success.result;
+ if (msg.error.err)
+ {
+ d[i].error = msg.error.err;
+ d[i].type = SELECT_ERROR;
+ ++ready;
+ }
+ else
+ {
+ d[i].type &= msg.success.result;
+ if (d[i].type)
+ ++ready;
+ }
+
d[i].type |= SELECT_RETURNED;
++got;
}
@@ -411,7 +485,7 @@ _hurd_select (int nfds,
/* Interruption on our side (e.g. signal reception). */
err = EINTR;
- if (got)
+ if (ready)
/* At least one descriptor is known to be ready now, so we will
return success. */
err = 0;
@@ -419,7 +493,7 @@ _hurd_select (int nfds,
if (firstfd != -1)
for (i = firstfd; i <= lastfd; ++i)
- if (d[i].type)
+ if (d[i].reply_port != MACH_PORT_NULL)
__mach_port_destroy (__mach_task_self (), d[i].reply_port);
if (firstfd == -1 || (firstfd != lastfd && portset != MACH_PORT_NULL))
/* Destroy PORTSET, but only if it's not actually the reply port for a
@@ -441,23 +515,37 @@ _hurd_select (int nfds,
int type = d[i].type;
int_fast16_t revents = 0;
- if (type & SELECT_RETURNED)
- {
- if (type & SELECT_READ)
- revents |= POLLIN;
- if (type & SELECT_WRITE)
- revents |= POLLOUT;
- if (type & SELECT_URG)
- revents |= POLLPRI;
- }
+ if (type & SELECT_ERROR)
+ switch (d[i].error)
+ {
+ case EPIPE:
+ revents = POLLHUP;
+ break;
+ case EBADF:
+ revents = POLLNVAL;
+ break;
+ default:
+ revents = POLLERR;
+ break;
+ }
+ else
+ if (type & SELECT_RETURNED)
+ {
+ if (type & SELECT_READ)
+ revents |= POLLIN;
+ if (type & SELECT_WRITE)
+ revents |= POLLOUT;
+ if (type & SELECT_URG)
+ revents |= POLLPRI;
+ }
pollfds[i].revents = revents;
}
else
{
- /* Below we recalculate GOT to include an increment for each operation
+ /* Below we recalculate READY to include an increment for each operation
allowed on each fd. */
- got = 0;
+ ready = 0;
/* Set the user bitarrays. We only ever have to clear bits, as all
desired ones are initially set. */
@@ -469,16 +557,30 @@ _hurd_select (int nfds,
if ((type & SELECT_RETURNED) == 0)
type = 0;
+ /* Callers of select don't expect to see errors, so we simulate
+ readiness of the erring object and the next call hopefully
+ will get the error again. */
+ if (type & SELECT_ERROR)
+ {
+ type = 0;
+ if (readfds != NULL && FD_ISSET (i, readfds))
+ type |= SELECT_READ;
+ if (writefds != NULL && FD_ISSET (i, writefds))
+ type |= SELECT_WRITE;
+ if (exceptfds != NULL && FD_ISSET (i, exceptfds))
+ type |= SELECT_URG;
+ }
+
if (type & SELECT_READ)
- got++;
+ ready++;
else if (readfds)
FD_CLR (i, readfds);
if (type & SELECT_WRITE)
- got++;
+ ready++;
else if (writefds)
FD_CLR (i, writefds);
if (type & SELECT_URG)
- got++;
+ ready++;
else if (exceptfds)
FD_CLR (i, exceptfds);
}
@@ -487,5 +589,5 @@ _hurd_select (int nfds,
if (sigmask && __sigprocmask (SIG_SETMASK, &oset, NULL))
return -1;
- return got;
+ return ready;
}
diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c
index fe2eeabfe5..fd787c6c1b 100644
--- a/hurd/hurdsig.c
+++ b/hurd/hurdsig.c
@@ -20,6 +20,7 @@
#include <string.h>
#include <cthreads.h> /* For `struct mutex'. */
+#include <pthread.h>
#include <mach.h>
#include <mach/thread_switch.h>
@@ -42,17 +43,16 @@ mach_port_t _hurd_msgport;
/* Thread listening on it. */
thread_t _hurd_msgport_thread;
-/* Thread which receives task-global signals. */
-thread_t _hurd_sigthread;
-
/* These are set up by _hurdsig_init. */
unsigned long int __hurd_sigthread_stack_base;
unsigned long int __hurd_sigthread_stack_end;
-unsigned long int *__hurd_sigthread_variables;
/* Linked-list of per-thread signal state. */
struct hurd_sigstate *_hurd_sigstates;
+/* Sigstate for the task-global signals. */
+struct hurd_sigstate *_hurd_global_sigstate;
+
/* Timeout for RPC's after interrupt_operation. */
mach_msg_timeout_t _hurd_interrupted_rpc_timeout = 3000;
@@ -81,7 +81,7 @@ _hurd_thread_sigstate (thread_t thread)
{
ss = malloc (sizeof (*ss));
if (ss == NULL)
- __libc_fatal ("hurd: Can't allocate thread sigstate\n");
+ __libc_fatal ("hurd: Can't allocate sigstate\n");
ss->thread = thread;
__spin_lock_init (&ss->lock);
@@ -94,16 +94,21 @@ _hurd_thread_sigstate (thread_t thread)
ss->intr_port = MACH_PORT_NULL;
ss->context = NULL;
- /* Initialize the sigaction vector from the default signal receiving
- thread's state, and its from the system defaults. */
- if (thread == _hurd_sigthread)
- default_sigaction (ss->actions);
+ if (thread == MACH_PORT_NULL)
+ {
+ /* Process-wide sigstate, use the system defaults. */
+ default_sigaction (ss->actions);
+
+ /* The global sigstate is not added to the _hurd_sigstates list.
+ It is created with _hurd_thread_sigstate (MACH_PORT_NULL)
+ but should be accessed through _hurd_global_sigstate. */
+ }
else
{
- struct hurd_sigstate *s;
- for (s = _hurd_sigstates; s != NULL; s = s->next)
- if (s->thread == _hurd_sigthread)
- break;
+ error_t err;
+
+ /* Use the global actions as a default for new threads. */
+ struct hurd_sigstate *s = _hurd_global_sigstate;
if (s)
{
__spin_lock (&s->lock);
@@ -112,14 +117,118 @@ _hurd_thread_sigstate (thread_t thread)
}
else
default_sigaction (ss->actions);
- }
- ss->next = _hurd_sigstates;
- _hurd_sigstates = ss;
+ ss->next = _hurd_sigstates;
+ _hurd_sigstates = ss;
+
+ err = __mach_port_mod_refs (__mach_task_self (), thread,
+ MACH_PORT_RIGHT_SEND, 1);
+ if (err)
+ __libc_fatal ("hurd: Can't add reference on Mach thread\n");
+ }
}
__mutex_unlock (&_hurd_siglock);
return ss;
}
+
+/* Destroy a sigstate structure. Called by libpthread just before the
+ * corresponding thread is terminated. */
+void
+_hurd_sigstate_delete (thread_t thread)
+{
+ struct hurd_sigstate **ssp, *ss;
+
+ __mutex_lock (&_hurd_siglock);
+ for (ssp = &_hurd_sigstates; *ssp; ssp = &(*ssp)->next)
+ if ((*ssp)->thread == thread)
+ break;
+
+ ss = *ssp;
+ if (ss)
+ *ssp = ss->next;
+
+ __mutex_unlock (&_hurd_siglock);
+ if (ss)
+ {
+ if (ss->thread != MACH_PORT_NULL)
+ __mach_port_deallocate (__mach_task_self (), ss->thread);
+
+ free (ss);
+ }
+}
+
+/* Make SS a global receiver, with pthread signal semantics. */
+void
+_hurd_sigstate_set_global_rcv (struct hurd_sigstate *ss)
+{
+ assert (ss->thread != MACH_PORT_NULL);
+ ss->actions[0].sa_handler = SIG_IGN;
+}
+
+/* Check whether SS is a global receiver. */
+static int
+sigstate_is_global_rcv (const struct hurd_sigstate *ss)
+{
+ return (_hurd_global_sigstate != NULL)
+ && (ss->actions[0].sa_handler == SIG_IGN);
+}
+
+/* Lock/unlock a hurd_sigstate structure. If the accessors below require
+ it, the global sigstate will be locked as well. */
+void
+_hurd_sigstate_lock (struct hurd_sigstate *ss)
+{
+ if (sigstate_is_global_rcv (ss))
+ __spin_lock (&_hurd_global_sigstate->lock);
+ __spin_lock (&ss->lock);
+}
+void
+_hurd_sigstate_unlock (struct hurd_sigstate *ss)
+{
+ __spin_unlock (&ss->lock);
+ if (sigstate_is_global_rcv (ss))
+ __spin_unlock (&_hurd_global_sigstate->lock);
+}
+
+/* Retreive a thread's full set of pending signals, including the global
+ ones if appropriate. SS must be locked. */
+sigset_t
+_hurd_sigstate_pending (const struct hurd_sigstate *ss)
+{
+ sigset_t pending = ss->pending;
+ if (sigstate_is_global_rcv (ss))
+ __sigorset (&pending, &pending, &_hurd_global_sigstate->pending);
+ return pending;
+}
+
+/* Clear a pending signal and return the associated detailed
+ signal information. SS must be locked, and must have signal SIGNO
+ pending, either directly or through the global sigstate. */
+static struct hurd_signal_detail
+sigstate_clear_pending (struct hurd_sigstate *ss, int signo)
+{
+ if (sigstate_is_global_rcv (ss)
+ && __sigismember (&_hurd_global_sigstate->pending, signo))
+ {
+ __sigdelset (&_hurd_global_sigstate->pending, signo);
+ return _hurd_global_sigstate->pending_data[signo];
+ }
+
+ assert (__sigismember (&ss->pending, signo));
+ __sigdelset (&ss->pending, signo);
+ return ss->pending_data[signo];
+}
+
+/* Retreive a thread's action vector. SS must be locked. */
+struct sigaction *
+_hurd_sigstate_actions (struct hurd_sigstate *ss)
+{
+ if (sigstate_is_global_rcv (ss))
+ return _hurd_global_sigstate->actions;
+ else
+ return ss->actions;
+}
+
/* Signal delivery itself is on this page. */
@@ -214,6 +323,8 @@ static void
abort_thread (struct hurd_sigstate *ss, struct machine_thread_all_state *state,
void (*reply) (void))
{
+ assert (ss->thread != MACH_PORT_NULL);
+
if (!(state->set & THREAD_ABORTED))
{
error_t err = __thread_abort (ss->thread);
@@ -234,14 +345,14 @@ abort_thread (struct hurd_sigstate *ss, struct machine_thread_all_state *state,
that this location can be set without faulting, or else return NULL. */
static mach_port_t *
-interrupted_reply_port_location (struct machine_thread_all_state *thread_state,
+interrupted_reply_port_location (thread_t thread,
+ struct machine_thread_all_state *thread_state,
int sigthread)
{
- mach_port_t *portloc = (mach_port_t *) __hurd_threadvar_location_from_sp
- (_HURD_THREADVAR_MIG_REPLY, (void *) thread_state->basic.SP);
+ mach_port_t *portloc = &THREAD_TCB(thread, thread_state)->reply_port;
if (sigthread && _hurdsig_catch_memory_fault (portloc))
- /* Faulted trying to read the stack. */
+ /* Faulted trying to read the TCB. */
return NULL;
/* Fault now if this pointer is bogus. */
@@ -323,7 +434,8 @@ _hurdsig_abort_rpcs (struct hurd_sigstate *ss, int signo, int sigthread,
our nonzero return tells the trampoline code to finish the message
receive operation before running the handler. */
- mach_port_t *reply = interrupted_reply_port_location (state,
+ mach_port_t *reply = interrupted_reply_port_location (ss->thread,
+ state,
sigthread);
error_t err = __interrupt_operation (intr_port, _hurdsig_interrupt_timeout);
@@ -353,7 +465,7 @@ _hurdsig_abort_rpcs (struct hurd_sigstate *ss, int signo, int sigthread,
call above will retry their RPCs unless we clear SS->intr_port.
So we clear it for the thread taking a signal when SA_RESTART is
clear, so that its call returns EINTR. */
- if (! signo || !(ss->actions[signo].sa_flags & SA_RESTART))
+ if (! signo || !(_hurd_sigstate_actions (ss) [signo].sa_flags & SA_RESTART))
ss->intr_port = MACH_PORT_NULL;
}
@@ -441,6 +553,30 @@ abort_all_rpcs (int signo, struct machine_thread_all_state *state, int live)
}
}
+/* Wake up any sigsuspend call that is blocking SS->thread. SS must be
+ locked. */
+static void
+wake_sigsuspend (struct hurd_sigstate *ss)
+{
+ error_t err;
+ mach_msg_header_t msg;
+
+ if (ss->suspended == MACH_PORT_NULL)
+ return;
+
+ /* There is a sigsuspend waiting. Tell it to wake up. */
+ msg.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_MAKE_SEND, 0);
+ msg.msgh_remote_port = ss->suspended;
+ msg.msgh_local_port = MACH_PORT_NULL;
+ /* These values do not matter. */
+ msg.msgh_id = 8675309; /* Jenny, Jenny. */
+ ss->suspended = MACH_PORT_NULL;
+ err = __mach_msg (&msg, MACH_SEND_MSG, sizeof msg, 0,
+ MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE,
+ MACH_PORT_NULL);
+ assert_perror (err);
+}
+
struct hurd_signal_preemptor *_hurdsig_preemptors = 0;
sigset_t _hurdsig_preempted_set;
@@ -451,35 +587,20 @@ weak_alias (_hurdsig_preemptors, _hurdsig_preempters)
#define STOPSIGS (sigmask (SIGTTIN) | sigmask (SIGTTOU) | \
sigmask (SIGSTOP) | sigmask (SIGTSTP))
-/* Deliver a signal. SS is not locked. */
-void
-_hurd_internal_post_signal (struct hurd_sigstate *ss,
- int signo, struct hurd_signal_detail *detail,
- mach_port_t reply_port,
- mach_msg_type_name_t reply_port_type,
- int untraced)
+/* Actual delivery of a single signal. Called with SS unlocked. When
+ the signal is delivered, return SS, locked (or, if SS was originally
+ _hurd_global_sigstate, the sigstate of the actual thread the signal
+ was delivered to). If the signal is being traced, return NULL with
+ SS unlocked. */
+static struct hurd_sigstate *
+post_signal (struct hurd_sigstate *ss,
+ int signo, struct hurd_signal_detail *detail,
+ int untraced, void (*reply) (void))
{
- error_t err;
struct machine_thread_all_state thread_state;
enum { stop, ignore, core, term, handle } act;
- sighandler_t handler;
- sigset_t pending;
int ss_suspended;
- /* Reply to this sig_post message. */
- __typeof (__msg_sig_post_reply) *reply_rpc
- = (untraced ? __msg_sig_post_untraced_reply : __msg_sig_post_reply);
- void reply (void)
- {
- error_t err;
- if (reply_port == MACH_PORT_NULL)
- return;
- err = (*reply_rpc) (reply_port, reply_port_type, 0);
- reply_port = MACH_PORT_NULL;
- if (err != MACH_SEND_INVALID_DEST) /* Ignore dead reply port. */
- assert_perror (err);
- }
-
/* Mark the signal as pending. */
void mark_pending (void)
{
@@ -524,8 +645,12 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
assert_perror (err);
for (i = 0; i < nthreads; ++i)
{
- if (threads[i] != _hurd_msgport_thread &&
- (act != handle || threads[i] != ss->thread))
+ if (act == handle && threads[i] == ss->thread)
+ {
+ /* The thread that will run the handler is kept suspended. */
+ ss_suspended = 1;
+ }
+ else if (threads[i] != _hurd_msgport_thread)
{
err = __thread_resume (threads[i]);
assert_perror (err);
@@ -538,27 +663,58 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
(vm_address_t) threads,
nthreads * sizeof *threads);
_hurd_stopped = 0;
- if (act == handle)
- /* The thread that will run the handler is already suspended. */
- ss_suspended = 1;
}
+ error_t err;
+ sighandler_t handler;
+
if (signo == 0)
{
if (untraced)
- /* This is PTRACE_CONTINUE. */
- resume ();
+ {
+ /* This is PTRACE_CONTINUE. */
+ act = ignore;
+ resume ();
+ }
/* This call is just to check for pending signals. */
- __spin_lock (&ss->lock);
- goto check_pending_signals;
+ _hurd_sigstate_lock (ss);
+ return ss;
}
- post_signal:
-
thread_state.set = 0; /* We know nothing. */
- __spin_lock (&ss->lock);
+ _hurd_sigstate_lock (ss);
+
+ /* If this is a global signal, try to find a thread ready to accept
+ it right away. This is especially important for untraced signals,
+ since going through the global pending mask would de-untrace them. */
+ if (ss->thread == MACH_PORT_NULL)
+ {
+ struct hurd_sigstate *rss;
+
+ __mutex_lock (&_hurd_siglock);
+ for (rss = _hurd_sigstates; rss != NULL; rss = rss->next)
+ {
+ if (! sigstate_is_global_rcv (rss))
+ continue;
+
+ /* The global sigstate is already locked. */
+ __spin_lock (&rss->lock);
+ if (! __sigismember (&rss->blocked, signo))
+ {
+ ss = rss;
+ break;
+ }
+ __spin_unlock (&rss->lock);
+ }
+ __mutex_unlock (&_hurd_siglock);
+ }
+
+ /* We want the preemptors to be able to update the blocking mask
+ without affecting the delivery of this signal, so we save the
+ current value to test against later. */
+ sigset_t blocked = ss->blocked;
/* Check for a preempted signal. Preempted signals can arrive during
critical sections. */
@@ -567,7 +723,7 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
{ /* PE cannot be null. */
do
{
- if (HURD_PREEMPT_SIGNAL_P (pe, signo, detail->code))
+ if (HURD_PREEMPT_SIGNAL_P (pe, signo, detail->exc_subcode))
{
if (pe->preemptor)
{
@@ -616,12 +772,12 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
mark_pending ();
else
suspend ();
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
reply ();
- return;
+ return NULL;
}
- handler = ss->actions[signo].sa_handler;
+ handler = _hurd_sigstate_actions (ss) [signo].sa_handler;
if (handler == SIG_DFL)
/* Figure out the default action for this signal. */
@@ -714,9 +870,7 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
}
/* Handle receipt of a blocked signal, or any signal while stopped. */
- if (act != ignore && /* Signals ignored now are forgotten now. */
- __sigismember (&ss->blocked, signo) ||
- (signo != SIGKILL && _hurd_stopped))
+ if (__sigismember (&blocked, signo) || (signo != SIGKILL && _hurd_stopped))
{
mark_pending ();
act = ignore;
@@ -751,6 +905,7 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
now's the time to set it going. */
if (ss_suspended)
{
+ assert (ss->thread != MACH_PORT_NULL);
err = __thread_resume (ss->thread);
assert_perror (err);
ss_suspended = 0;
@@ -795,6 +950,8 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
struct sigcontext *scp, ocontext;
int wait_for_reply, state_changed;
+ assert (ss->thread != MACH_PORT_NULL);
+
/* Stop the thread and abort its pending RPC operations. */
if (! ss_suspended)
{
@@ -835,7 +992,8 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
if (! machine_get_basic_state (ss->thread, &thread_state))
goto sigbomb;
- loc = interrupted_reply_port_location (&thread_state, 1);
+ loc = interrupted_reply_port_location (ss->thread,
+ &thread_state, 1);
if (loc && *loc != MACH_PORT_NULL)
/* This is the reply port for the context which called
sigreturn. Since we are abandoning that context entirely
@@ -861,7 +1019,7 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
as a unit. */
crit ? 0 : signo, 1,
&thread_state, &state_changed,
- &reply)
+ reply)
!= MACH_PORT_NULL);
if (crit)
@@ -901,7 +1059,8 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
{
/* Fetch the thread variable for the MiG reply port,
and set it to MACH_PORT_NULL. */
- mach_port_t *loc = interrupted_reply_port_location (&thread_state,
+ mach_port_t *loc = interrupted_reply_port_location (ss->thread,
+ &thread_state,
1);
if (loc)
{
@@ -929,23 +1088,28 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
}
}
+ struct sigaction *action = & _hurd_sigstate_actions (ss) [signo];
+
/* Backdoor extra argument to signal handler. */
scp->sc_error = detail->error;
/* Block requested signals while running the handler. */
scp->sc_mask = ss->blocked;
- __sigorset (&ss->blocked, &ss->blocked, &ss->actions[signo].sa_mask);
+ __sigorset (&ss->blocked, &ss->blocked, &action->sa_mask);
/* Also block SIGNO unless we're asked not to. */
- if (! (ss->actions[signo].sa_flags & (SA_RESETHAND | SA_NODEFER)))
+ if (! (action->sa_flags & (SA_RESETHAND | SA_NODEFER)))
__sigaddset (&ss->blocked, signo);
/* Reset to SIG_DFL if requested. SIGILL and SIGTRAP cannot
be automatically reset when delivered; the system silently
enforces this restriction. */
- if (ss->actions[signo].sa_flags & SA_RESETHAND
+ if (action->sa_flags & SA_RESETHAND
&& signo != SIGILL && signo != SIGTRAP)
- ss->actions[signo].sa_handler = SIG_DFL;
+ action->sa_handler = SIG_DFL;
+
+ /* Any sigsuspend call must return after the handler does. */
+ wake_sigsuspend (ss);
/* Start the thread running the handler (or possibly waiting for an
RPC reply before running the handler). */
@@ -960,95 +1124,134 @@ _hurd_internal_post_signal (struct hurd_sigstate *ss,
}
}
- /* The signal has either been ignored or is now being handled. We can
- consider it delivered and reply to the killer. */
- reply ();
+ return ss;
+}
- /* We get here unless the signal was fatal. We still hold SS->lock.
- Check for pending signals, and loop to post them. */
- {
- /* Return nonzero if SS has any signals pending we should worry about.
- We don't worry about any pending signals if we are stopped, nor if
- SS is in a critical section. We are guaranteed to get a sig_post
- message before any of them become deliverable: either the SIGCONT
- signal, or a sig_post with SIGNO==0 as an explicit poll when the
- thread finishes its critical section. */
- inline int signals_pending (void)
+/* Return the set of pending signals in SS which should be delivered. */
+static sigset_t
+pending_signals (struct hurd_sigstate *ss)
+{
+ /* We don't worry about any pending signals if we are stopped, nor if
+ SS is in a critical section. We are guaranteed to get a sig_post
+ message before any of them become deliverable: either the SIGCONT
+ signal, or a sig_post with SIGNO==0 as an explicit poll when the
+ thread finishes its critical section. */
+ if (_hurd_stopped || __spin_lock_locked (&ss->critical_section_lock))
+ return 0;
+
+ return _hurd_sigstate_pending (ss) & ~ss->blocked;
+}
+
+/* Post the specified pending signals in SS and return 1. If one of
+ them is traced, abort immediately and return 0. SS must be locked on
+ entry and will be unlocked in all cases. */
+static int
+post_pending (struct hurd_sigstate *ss, sigset_t pending, void (*reply) (void))
+{
+ int signo;
+ struct hurd_signal_detail detail;
+
+ /* Make sure SS corresponds to an actual thread, since we assume it won't
+ change in post_signal. */
+ assert (ss->thread != MACH_PORT_NULL);
+
+ for (signo = 1; signo < NSIG; ++signo)
+ if (__sigismember (&pending, signo))
{
- if (_hurd_stopped || __spin_lock_locked (&ss->critical_section_lock))
+ detail = sigstate_clear_pending (ss, signo);
+ _hurd_sigstate_unlock (ss);
+
+ /* Will reacquire the lock, except if the signal is traced. */
+ if (! post_signal (ss, signo, &detail, 0, reply))
return 0;
- return pending = ss->pending & ~ss->blocked;
}
- check_pending_signals:
- untraced = 0;
+ /* No more signals pending; SS->lock is still locked. */
+ _hurd_sigstate_unlock (ss);
- if (signals_pending ())
- {
- for (signo = 1; signo < NSIG; ++signo)
- if (__sigismember (&pending, signo))
- {
- deliver_pending:
- __sigdelset (&ss->pending, signo);
- *detail = ss->pending_data[signo];
- __spin_unlock (&ss->lock);
- goto post_signal;
- }
- }
+ return 1;
+}
- /* No pending signals left undelivered for this thread.
- If we were sent signal 0, we need to check for pending
- signals for all threads. */
- if (signo == 0)
- {
- __spin_unlock (&ss->lock);
- __mutex_lock (&_hurd_siglock);
- for (ss = _hurd_sigstates; ss != NULL; ss = ss->next)
- {
- __spin_lock (&ss->lock);
- for (signo = 1; signo < NSIG; ++signo)
- if (__sigismember (&ss->pending, signo)
- && (!__sigismember (&ss->blocked, signo)
- /* We "deliver" immediately pending blocked signals whose
- action might be to ignore, so that if ignored they are
- dropped right away. */
- || ss->actions[signo].sa_handler == SIG_IGN
- || ss->actions[signo].sa_handler == SIG_DFL))
- {
- mutex_unlock (&_hurd_siglock);
- goto deliver_pending;
- }
- __spin_unlock (&ss->lock);
- }
- __mutex_unlock (&_hurd_siglock);
- }
- else
- {
- /* No more signals pending; SS->lock is still locked.
- Wake up any sigsuspend call that is blocking SS->thread. */
- if (ss->suspended != MACH_PORT_NULL)
- {
- /* There is a sigsuspend waiting. Tell it to wake up. */
- error_t err;
- mach_msg_header_t msg;
- msg.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_MAKE_SEND, 0);
- msg.msgh_remote_port = ss->suspended;
- msg.msgh_local_port = MACH_PORT_NULL;
- /* These values do not matter. */
- msg.msgh_id = 8675309; /* Jenny, Jenny. */
- ss->suspended = MACH_PORT_NULL;
- err = __mach_msg (&msg, MACH_SEND_MSG, sizeof msg, 0,
- MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE,
- MACH_PORT_NULL);
- assert_perror (err);
- }
- __spin_unlock (&ss->lock);
- }
- }
+/* Post all the pending signals of all threads and return 1. If a traced
+ signal is encountered, abort immediately and return 0. */
+static int
+post_all_pending_signals (void (*reply) (void))
+{
+ struct hurd_sigstate *ss;
+ sigset_t pending = 0;
+
+ for (;;)
+ {
+ __mutex_lock (&_hurd_siglock);
+ for (ss = _hurd_sigstates; ss != NULL; ss = ss->next)
+ {
+ _hurd_sigstate_lock (ss);
+
+ pending = pending_signals (ss);
+ if (pending)
+ /* post_pending() below will unlock SS. */
+ break;
+
+ _hurd_sigstate_unlock (ss);
+ }
+ __mutex_unlock (&_hurd_siglock);
- /* All pending signals delivered to all threads.
- Now we can send the reply message even for signal 0. */
- reply ();
+ if (! pending)
+ return 1;
+ if (! post_pending (ss, pending, reply))
+ return 0;
+ }
+}
+
+/* Deliver a signal. SS is not locked. */
+void
+_hurd_internal_post_signal (struct hurd_sigstate *ss,
+ int signo, struct hurd_signal_detail *detail,
+ mach_port_t reply_port,
+ mach_msg_type_name_t reply_port_type,
+ int untraced)
+{
+ /* Reply to this sig_post message. */
+ __typeof (__msg_sig_post_reply) *reply_rpc
+ = (untraced ? __msg_sig_post_untraced_reply : __msg_sig_post_reply);
+ void reply (void)
+ {
+ error_t err;
+ if (reply_port == MACH_PORT_NULL)
+ return;
+ err = (*reply_rpc) (reply_port, reply_port_type, 0);
+ reply_port = MACH_PORT_NULL;
+ if (err != MACH_SEND_INVALID_DEST) /* Ignore dead reply port. */
+ assert_perror (err);
+ }
+
+ ss = post_signal (ss, signo, detail, untraced, reply);
+ if (! ss)
+ return;
+
+ /* The signal was neither fatal nor traced. We still hold SS->lock. */
+ if (signo != 0 && ss->thread != MACH_PORT_NULL)
+ {
+ /* The signal has either been ignored or is now being handled. We can
+ consider it delivered and reply to the killer. */
+ reply ();
+
+ /* Post any pending signals for this thread. */
+ if (! post_pending (ss, pending_signals (ss), reply))
+ return;
+ }
+ else
+ {
+ /* If this was a process-wide signal or a poll request, we need
+ to check for pending signals for all threads. */
+ _hurd_sigstate_unlock (ss);
+ if (! post_all_pending_signals (reply))
+ return;
+
+ /* All pending signals delivered to all threads.
+ Now we can send the reply message even for signal 0. */
+ reply ();
+ }
}
/* Decide whether REFPORT enables the sender to send us a SIGNO signal.
@@ -1167,9 +1370,10 @@ _S_msg_sig_post (mach_port_t me,
d.code = sigcode;
d.exc = 0;
- /* Post the signal to the designated signal-receiving thread. This will
- reply when the signal can be considered delivered. */
- _hurd_internal_post_signal (_hurd_thread_sigstate (_hurd_sigthread),
+ /* Post the signal to a global receiver thread (or mark it pending in
+ the global sigstate). This will reply when the signal can be
+ considered delivered. */
+ _hurd_internal_post_signal (_hurd_global_sigstate,
signo, &d, reply_port, reply_port_type,
0); /* Stop if traced. */
@@ -1197,7 +1401,7 @@ _S_msg_sig_post_untraced (mach_port_t me,
/* Post the signal to the designated signal-receiving thread. This will
reply when the signal can be considered delivered. */
- _hurd_internal_post_signal (_hurd_thread_sigstate (_hurd_sigthread),
+ _hurd_internal_post_signal (_hurd_global_sigstate,
signo, &d, reply_port, reply_port_type,
1); /* Untraced flag. */
@@ -1208,8 +1412,8 @@ extern void __mig_init (void *);
#include <mach/task_special_ports.h>
-/* Initialize the message port and _hurd_sigthread and start the signal
- thread. */
+/* Initialize the message port, _hurd_global_sigstate, and start the
+ signal thread. */
void
_hurdsig_init (const int *intarray, size_t intarraysize)
@@ -1232,30 +1436,41 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
MACH_MSG_TYPE_MAKE_SEND);
assert_perror (err);
+ /* Initialize the global signal state. */
+ _hurd_global_sigstate = _hurd_thread_sigstate (MACH_PORT_NULL);
+
+ /* We block all signals, and let actual threads pull them from the
+ pending mask. */
+ __sigfillset(& _hurd_global_sigstate->blocked);
+
/* Initialize the main thread's signal state. */
ss = _hurd_self_sigstate ();
- /* Copy inherited values from our parent (or pre-exec process state)
- into the signal settings of the main thread. */
+ /* Mark it as a process-wide signal receiver. Threads in this set use
+ the common action vector in _hurd_global_sigstate. */
+ _hurd_sigstate_set_global_rcv (ss);
+
+ /* Copy inherited signal settings from our parent (or pre-exec process
+ state) */
if (intarraysize > INIT_SIGMASK)
ss->blocked = intarray[INIT_SIGMASK];
if (intarraysize > INIT_SIGPENDING)
- ss->pending = intarray[INIT_SIGPENDING];
+ _hurd_global_sigstate->pending = intarray[INIT_SIGPENDING];
if (intarraysize > INIT_SIGIGN && intarray[INIT_SIGIGN] != 0)
{
int signo;
for (signo = 1; signo < NSIG; ++signo)
if (intarray[INIT_SIGIGN] & __sigmask(signo))
- ss->actions[signo].sa_handler = SIG_IGN;
+ _hurd_global_sigstate->actions[signo].sa_handler = SIG_IGN;
}
- /* Set the default thread to receive task-global signals
- to this one, the main (first) user thread. */
- _hurd_sigthread = ss->thread;
-
/* Start the signal thread listening on the message port. */
- if (__hurd_threadvar_stack_mask == 0)
+#pragma weak cthread_fork
+#pragma weak cthread_detach
+#pragma weak pthread_getattr_np
+#pragma weak pthread_attr_getstack
+ if (!cthread_fork)
{
err = __thread_create (__mach_task_self (), &_hurd_msgport_thread);
assert_perror (err);
@@ -1266,16 +1481,10 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
(vm_address_t *) &__hurd_sigthread_stack_base,
&stacksize);
assert_perror (err);
+ err = __mach_setup_tls (_hurd_msgport_thread);
+ assert_perror (err);
__hurd_sigthread_stack_end = __hurd_sigthread_stack_base + stacksize;
- __hurd_sigthread_variables =
- malloc (__hurd_threadvar_max * sizeof (unsigned long int));
- if (__hurd_sigthread_variables == NULL)
- __libc_fatal ("hurd: Can't allocate threadvars for signal thread\n");
- memset (__hurd_sigthread_variables, 0,
- __hurd_threadvar_max * sizeof (unsigned long int));
- __hurd_sigthread_variables[_HURD_THREADVAR_LOCALE]
- = (unsigned long int) &_nl_global_locale;
/* Reinitialize the MiG support routines so they will use a per-thread
variable for the cached reply port. */
@@ -1286,6 +1495,7 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
}
else
{
+ cthread_t thread;
/* When cthreads is being used, we need to make the signal thread a
proper cthread. Otherwise it cannot use mutex_lock et al, which
will be the cthreads versions. Various of the message port RPC
@@ -1295,9 +1505,20 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
we'll let the signal thread's per-thread variables be found as for
any normal cthread, and just leave the magic __hurd_sigthread_*
values all zero so they'll be ignored. */
-#pragma weak cthread_fork
-#pragma weak cthread_detach
- cthread_detach (cthread_fork ((cthread_fn_t) &_hurd_msgport_receive, 0));
+ cthread_detach (thread = cthread_fork ((cthread_fn_t) &_hurd_msgport_receive, 0));
+
+ if (pthread_getattr_np)
+ {
+ /* Record stack layout for fork() */
+ pthread_attr_t attr;
+ void *addr;
+ size_t size;
+
+ pthread_getattr_np ((pthread_t) thread, &attr);
+ pthread_attr_getstack (&attr, &addr, &size);
+ __hurd_sigthread_stack_base = (uintptr_t) addr;
+ __hurd_sigthread_stack_end = __hurd_sigthread_stack_base + size;
+ }
/* XXX We need the thread port for the signal thread further on
in this thread (see hurdfault.c:_hurdsigfault_init).
@@ -1342,6 +1563,7 @@ reauth_proc (mach_port_t new)
if (! HURD_PORT_USE (&_hurd_ports[INIT_PORT_PROC],
__proc_reauthenticate (port, ref,
MACH_MSG_TYPE_MAKE_SEND) ||
+ /* FIXME: handle EINTR */
__auth_user_authenticate (new, ref,
MACH_MSG_TYPE_MAKE_SEND,
&ignore))
@@ -1350,14 +1572,14 @@ reauth_proc (mach_port_t new)
__mach_port_destroy (__mach_task_self (), ref);
/* Set the owner of the process here too. */
- mutex_lock (&_hurd_id.lock);
+ __mutex_lock (&_hurd_id.lock);
if (!_hurd_check_ids ())
HURD_PORT_USE (&_hurd_ports[INIT_PORT_PROC],
__proc_setowner (port,
(_hurd_id.gen.nuids
? _hurd_id.gen.uids[0] : 0),
!_hurd_id.gen.nuids));
- mutex_unlock (&_hurd_id.lock);
+ __mutex_unlock (&_hurd_id.lock);
(void) &reauth_proc; /* Silence compiler warning. */
}
diff --git a/hurd/hurdsock.c b/hurd/hurdsock.c
index 1aaec27acd..03d45e78a1 100644
--- a/hurd/hurdsock.c
+++ b/hurd/hurdsock.c
@@ -52,6 +52,7 @@ _hurd_socket_server (int domain, int dead)
return MACH_PORT_NULL;
}
+retry:
HURD_CRITICAL_BEGIN;
__mutex_lock (&lock);
@@ -102,6 +103,10 @@ _hurd_socket_server (int domain, int dead)
__mutex_unlock (&lock);
HURD_CRITICAL_END;
+ if (!server && errno == EINTR)
+ /* Got a signal while inside an RPC of the critical section, retry again */
+ goto retry;
+
return server;
}
diff --git a/hurd/hurdstartup.c b/hurd/hurdstartup.c
index 9de8f2a898..edfd96fcbd 100644
--- a/hurd/hurdstartup.c
+++ b/hurd/hurdstartup.c
@@ -23,7 +23,6 @@
#include <hurd.h>
#include <hurd/exec_startup.h>
#include <sysdep.h>
-#include <hurd/threadvar.h>
#include <unistd.h>
#include <elf.h>
#include <set-hooks.h>
diff --git a/hurd/intern-fd.c b/hurd/intern-fd.c
index 239bb8a874..91158f25c0 100644
--- a/hurd/intern-fd.c
+++ b/hurd/intern-fd.c
@@ -37,6 +37,7 @@ _hurd_intern_fd (io_t port, int flags, int dealloc)
__spin_unlock (&d->port.lock);
}
HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
if (d == NULL)
{
diff --git a/hurd/lookup-at.c b/hurd/lookup-at.c
index 3528ba8ac3..5b03a4c9d0 100644
--- a/hurd/lookup-at.c
+++ b/hurd/lookup-at.c
@@ -29,16 +29,9 @@ __file_name_lookup_at (int fd, int at_flags,
error_t err;
file_t result;
- if ((at_flags & AT_SYMLINK_FOLLOW) && (at_flags & AT_SYMLINK_NOFOLLOW))
- return (__hurd_fail (EINVAL), MACH_PORT_NULL);
-
- flags |= (at_flags & AT_SYMLINK_NOFOLLOW) ? O_NOLINK : 0;
- at_flags &= ~AT_SYMLINK_NOFOLLOW;
- if (at_flags & AT_SYMLINK_FOLLOW)
- flags &= ~O_NOLINK;
- at_flags &= ~AT_SYMLINK_FOLLOW;
- if (at_flags != 0)
- return (__hurd_fail (EINVAL), MACH_PORT_NULL);
+ err = __hurd_at_flags (&at_flags, &flags);
+ if (err)
+ return (__hurd_fail (err), MACH_PORT_NULL);
if (fd == AT_FDCWD || file_name[0] == '/')
return __file_name_lookup (file_name, flags, mode);
diff --git a/hurd/lookup-retry.c b/hurd/lookup-retry.c
index aee2ba8f93..d37295972b 100644
--- a/hurd/lookup-retry.c
+++ b/hurd/lookup-retry.c
@@ -127,7 +127,7 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
{
/* In Linux, O_NOFOLLOW means to reject symlinks. If we
did an O_NOLINK lookup above and io_stat here to check
- for S_IFLNK, a translator like firmlink could easily
+ for S_IFLNK only, a translator like firmlink could easily
spoof this check by not showing S_IFLNK, but in fact
redirecting the lookup to some other name
(i.e. opening the very same holes a symlink would).
@@ -145,23 +145,29 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
one exception to our general translator-based rule. */
struct stat64 st;
err = __io_stat (*result, &st);
- if (!err
- && (st.st_mode & (S_IPTRANS|S_IATRANS)))
+ if (!err)
{
- if (st.st_uid != 0)
- err = ENOENT;
- else if (st.st_mode & S_IPTRANS)
+ if (flags & O_DIRECTORY && !S_ISDIR(st.st_mode))
+ err = ENOTDIR;
+ if (S_ISLNK(st.st_mode))
+ err = ELOOP;
+ else if (st.st_mode & (S_IPTRANS|S_IATRANS))
{
- char buf[1024];
- char *trans = buf;
- size_t translen = sizeof buf;
- err = __file_get_translator (*result,
- &trans, &translen);
- if (!err
- && translen > sizeof _HURD_SYMLINK
- && !memcmp (trans,
- _HURD_SYMLINK, sizeof _HURD_SYMLINK))
- err = ENOENT;
+ if (st.st_uid != 0)
+ err = ELOOP;
+ else if (st.st_mode & S_IPTRANS)
+ {
+ char buf[1024];
+ char *trans = buf;
+ size_t translen = sizeof buf;
+ err = __file_get_translator (*result,
+ &trans, &translen);
+ if (!err
+ && translen > sizeof _HURD_SYMLINK
+ && !memcmp (trans,
+ _HURD_SYMLINK, sizeof _HURD_SYMLINK))
+ err = ELOOP;
+ }
}
}
}
diff --git a/hurd/setauth.c b/hurd/setauth.c
index d38fdddd52..a8a625d65a 100644
--- a/hurd/setauth.c
+++ b/hurd/setauth.c
@@ -18,14 +18,13 @@
#include <hurd.h>
#include <hurd/port.h>
#include <hurd/id.h>
+#include <hurdlock.h>
#include "set-hooks.h"
/* Things in the library which want to be run when the auth port changes. */
DEFINE_HOOK (_hurd_reauth_hook, (auth_t new_auth));
-#include <cthreads.h>
-static struct mutex reauth_lock = MUTEX_INITIALIZER;
-
+static unsigned int reauth_lock = LLL_INITIALIZER;
/* Set the auth port to NEW, and reauthenticate
everything used by the library. */
@@ -108,6 +107,7 @@ _hurd_setauth (auth_t new)
__mutex_unlock (&reauth_lock);
HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
return 0;
}
diff --git a/hurd/seteuids.c b/hurd/seteuids.c
index 21e3431e2a..c09fb0eb4a 100644
--- a/hurd/seteuids.c
+++ b/hurd/seteuids.c
@@ -47,6 +47,7 @@ seteuids (int n, const uid_t *uids)
}
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
if (err)
return __hurd_fail (err);
diff --git a/hurd/sigunwind.c b/hurd/sigunwind.c
index 1f224621bb..a999173c50 100644
--- a/hurd/sigunwind.c
+++ b/hurd/sigunwind.c
@@ -18,6 +18,7 @@
#include <hurd.h>
#include <thread_state.h>
+#include <hurd/threadvar.h>
#include <jmpbuf-unwind.h>
#include <assert.h>
#include <stdint.h>
@@ -38,8 +39,7 @@ _hurdsig_longjmp_from_handler (void *data, jmp_buf env, int val)
{
/* Destroy the MiG reply port used by the signal handler, and restore
the reply port in use by the thread when interrupted. */
- mach_port_t *reply_port =
- (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY);
+ mach_port_t *reply_port = &__hurd_local_reply_port;
if (*reply_port)
{
mach_port_t port = *reply_port;
diff --git a/hurd/sysvshm.c b/hurd/sysvshm.c
new file mode 100644
index 0000000000..e049345135
--- /dev/null
+++ b/hurd/sysvshm.c
@@ -0,0 +1,98 @@
+/* SysV shared memory for Hurd.
+ Copyright (C) 2005-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/shm.h>
+#include <hurdlock.h>
+
+
+/* Description of an shm attachment. */
+struct sysvshm_attach
+{
+ /* Linked list. */
+ struct sysvshm_attach *next;
+
+ /* Map address. */
+ void *addr;
+
+ /* Map size. */
+ size_t size;
+};
+
+/* List of attachments. */
+static struct sysvshm_attach *sysvshm_list;
+
+/* A lock to protect the linked list of shared memory attachments. */
+static unsigned int sysvshm_lock = LLL_INITIALIZER;
+
+
+/* Adds a segment attachment. */
+error_t
+__sysvshm_add (void *addr, size_t size)
+{
+ struct sysvshm_attach *shm;
+
+ shm = malloc (sizeof (*shm));
+ if (shm == NULL)
+ return errno;
+
+ __mutex_lock (&sysvshm_lock);
+ shm->addr = addr;
+ shm->size = size;
+ shm->next = sysvshm_list;
+ sysvshm_list = shm;
+ __mutex_unlock (&sysvshm_lock);
+
+ return 0;
+}
+
+/* Removes a segment attachment. On success, returns 0 and sets *SIZE to its
+ size. Returns EINVAL if not found. */
+error_t
+__sysvshm_remove (void *addr, size_t *size)
+{
+ struct sysvshm_attach *shm;
+ struct sysvshm_attach **pshm = &sysvshm_list;
+
+ __mutex_lock (&sysvshm_lock);
+ shm = sysvshm_list;
+ while (shm != NULL)
+ {
+ shm = *pshm;
+ if (shm->addr == addr)
+ {
+ *pshm = shm->next;
+ *size = shm->size;
+ __mutex_unlock (&sysvshm_lock);
+ free (shm);
+ return 0;
+ }
+ pshm = &shm->next;
+ shm = shm->next;
+ }
+ __mutex_unlock (&sysvshm_lock);
+ return EINVAL;
+}
diff --git a/hurd/sysvshm.h b/hurd/sysvshm.h
new file mode 100644
index 0000000000..8b9c29ff46
--- /dev/null
+++ b/hurd/sysvshm.h
@@ -0,0 +1,52 @@
+/* SysV shared memory for Hurd.
+ Copyright (C) 2005-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _HURD_SYSVSHM_H
+#define _HURD_SYSVSHM_H
+
+#include <paths.h>
+#include <hurd.h>
+
+/* The area (from top to bottom) that is used for private keys. These
+ are all keys that have the second highest bit set. */
+#define SHM_PRIV_KEY_START INT_MAX
+#define SHM_PRIV_KEY_END ((INT_MAX / 2) + 1)
+
+#define SHM_PREFIX "sysvshm-"
+#define SHM_DIR _PATH_DEV "shm/"
+
+/* The maximum number of characters in a shared memory segment file name.
+ 32 is the max number of characters in a 128 bit number in hex. */
+#if __WORDSIZE > 128
+#error Need to increase SHM_NAMEMAX.
+#else
+#define SHM_NAMEMAX (sizeof (SHM_PREFIX) - 1 + 32 + 1)
+#endif
+
+/* Use this with printf and its variants. */
+#define SHM_NAMEPRI SHM_PREFIX "%0x"
+
+
+/* Adds a segment attachment. */
+error_t __sysvshm_add (void *addr, size_t size);
+
+/* Removes a segment attachment. On success, returns 0 and sets *SIZE to its
+ size. Returns EINVAL if not found. */
+error_t __sysvshm_remove (void *addr, size_t *size);
+
+#endif /* sysvshm.h */
diff --git a/hurd/thread-cancel.c b/hurd/thread-cancel.c
index 6cf5e752b7..ef2b8a028c 100644
--- a/hurd/thread-cancel.c
+++ b/hurd/thread-cancel.c
@@ -51,7 +51,6 @@ hurd_thread_cancel (thread_t thread)
return 0;
}
- assert (! __spin_lock_locked (&ss->critical_section_lock));
__spin_lock (&ss->critical_section_lock);
__spin_lock (&ss->lock);
err = __thread_suspend (thread);
@@ -80,6 +79,7 @@ hurd_thread_cancel (thread_t thread)
}
_hurd_critical_section_unlock (ss);
+ /* FIXME: handle EINTR */
return err;
}
@@ -91,7 +91,6 @@ hurd_check_cancel (void)
int cancel;
__spin_lock (&ss->lock);
- assert (! __spin_lock_locked (&ss->critical_section_lock));
cancel = ss->cancel;
ss->cancel = 0;
__spin_unlock (&ss->lock);
diff --git a/include/errno.h b/include/errno.h
index 7df41dfc31..1d542ec1d4 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -26,13 +26,15 @@ extern int rtld_errno attribute_hidden;
# include <tls.h>
-# undef errno
-# if IS_IN (libc)
-# define errno __libc_errno
-# else
-# define errno errno /* For #ifndef errno tests. */
-# endif
+# if !(defined(__GNU__) && IS_IN (rtld))
+# undef errno
+# if IS_IN (libc)
+# define errno __libc_errno
+# else
+# define errno errno /* For #ifndef errno tests. */
+# endif
extern __thread int errno attribute_tls_model_ie;
+# endif
# endif /* IS_IN_LIB */
diff --git a/include/fcntl.h b/include/fcntl.h
index 4168ee429f..3b2c887146 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -31,8 +31,7 @@ extern int __openat64_2 (int __fd, const char *__path, int __oflag);
#if IS_IN (rtld)
-extern __typeof (__open) __open attribute_hidden;
-extern __typeof (__fcntl) __fcntl attribute_hidden;
+# include <dl-fcntl.h>
#endif
/* Flag determining whether the *at system calls are available. */
diff --git a/include/unistd.h b/include/unistd.h
index 5152f64f91..d58e815263 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -26,6 +26,7 @@ libc_hidden_proto (readlinkat)
/* Now define the internal interfaces. */
extern int __access (const char *__name, int __type);
extern int __euidaccess (const char *__name, int __type);
+extern int __faccessat (int __fd, const char *__file, int __type, int __flag);
extern __off64_t __lseek64 (int __fd, __off64_t __offset, int __whence);
extern __off_t __lseek (int __fd, __off_t __offset, int __whence);
libc_hidden_proto (__lseek)
diff --git a/include/verify.h b/include/verify.h
new file mode 100644
index 0000000000..34705007d2
--- /dev/null
+++ b/include/verify.h
@@ -0,0 +1,140 @@
+/* Compile-time assert-like macros.
+
+ Copyright (C) 2005-2015 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
+
+#ifndef VERIFY_H
+# define VERIFY_H 1
+
+/* Each of these macros verifies that its argument R is nonzero. To
+ be portable, R should be an integer constant expression. Unlike
+ assert (R), there is no run-time overhead.
+
+ There are two macros, since no single macro can be used in all
+ contexts in C. verify_true (R) is for scalar contexts, including
+ integer constant expression contexts. verify (R) is for declaration
+ contexts, e.g., the top level.
+
+ Symbols ending in "__" are private to this header.
+
+ The code below uses several ideas.
+
+ * The first step is ((R) ? 1 : -1). Given an expression R, of
+ integral or boolean or floating-point type, this yields an
+ expression of integral type, whose value is later verified to be
+ constant and nonnegative.
+
+ * Next this expression W is wrapped in a type
+ struct verify_type__ { unsigned int verify_error_if_negative_size__: W; }.
+ If W is negative, this yields a compile-time error. No compiler can
+ deal with a bit-field of negative size.
+
+ One might think that an array size check would have the same
+ effect, that is, that the type struct { unsigned int dummy[W]; }
+ would work as well. However, inside a function, some compilers
+ (such as C++ compilers and GNU C) allow local parameters and
+ variables inside array size expressions. With these compilers,
+ an array size check would not properly diagnose this misuse of
+ the verify macro:
+
+ void function (int n) { verify (n < 0); }
+
+ * For the verify macro, the struct verify_type__ will need to
+ somehow be embedded into a declaration. To be portable, this
+ declaration must declare an object, a constant, a function, or a
+ typedef name. If the declared entity uses the type directly,
+ such as in
+
+ struct dummy {...};
+ typedef struct {...} dummy;
+ extern struct {...} *dummy;
+ extern void dummy (struct {...} *);
+ extern struct {...} *dummy (void);
+
+ two uses of the verify macro would yield colliding declarations
+ if the entity names are not disambiguated. A workaround is to
+ attach the current line number to the entity name:
+
+ #define GL_CONCAT0(x, y) x##y
+ #define GL_CONCAT(x, y) GL_CONCAT0 (x, y)
+ extern struct {...} * GL_CONCAT(dummy,__LINE__);
+
+ But this has the problem that two invocations of verify from
+ within the same macro would collide, since the __LINE__ value
+ would be the same for both invocations.
+
+ A solution is to use the sizeof operator. It yields a number,
+ getting rid of the identity of the type. Declarations like
+
+ extern int dummy [sizeof (struct {...})];
+ extern void dummy (int [sizeof (struct {...})]);
+ extern int (*dummy (void)) [sizeof (struct {...})];
+
+ can be repeated.
+
+ * Should the implementation use a named struct or an unnamed struct?
+ Which of the following alternatives can be used?
+
+ extern int dummy [sizeof (struct {...})];
+ extern int dummy [sizeof (struct verify_type__ {...})];
+ extern void dummy (int [sizeof (struct {...})]);
+ extern void dummy (int [sizeof (struct verify_type__ {...})]);
+ extern int (*dummy (void)) [sizeof (struct {...})];
+ extern int (*dummy (void)) [sizeof (struct verify_type__ {...})];
+
+ In the second and sixth case, the struct type is exported to the
+ outer scope; two such declarations therefore collide. GCC warns
+ about the first, third, and fourth cases. So the only remaining
+ possibility is the fifth case:
+
+ extern int (*dummy (void)) [sizeof (struct {...})];
+
+ * This implementation exploits the fact that GCC does not warn about
+ the last declaration mentioned above. If a future version of GCC
+ introduces a warning for this, the problem could be worked around
+ by using code specialized to GCC, e.g.,:
+
+ #if 4 <= __GNUC__
+ # define verify(R) \
+ extern int (* verify_function__ (void)) \
+ [__builtin_constant_p (R) && (R) ? 1 : -1]
+ #endif
+
+ * In C++, any struct definition inside sizeof is invalid.
+ Use a template type to work around the problem. */
+
+
+/* Verify requirement R at compile-time, as an integer constant expression.
+ Return 1. */
+
+# ifdef __cplusplus
+template <int w>
+ struct verify_type__ { unsigned int verify_error_if_negative_size__: w; };
+# define verify_true(R) \
+ (!!sizeof (verify_type__<(R) ? 1 : -1>))
+# else
+# define verify_true(R) \
+ (!!sizeof \
+ (struct { unsigned int verify_error_if_negative_size__: (R) ? 1 : -1; }))
+# endif
+
+/* Verify requirement R at compile-time, as a declaration without a
+ trailing ';'. */
+
+# define verify(R) extern int (* verify_function__ (void)) [verify_true (R)]
+
+#endif
diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
index fadc3bfd43..694d7ebf3e 100644
--- a/locale/programs/locarchive.c
+++ b/locale/programs/locarchive.c
@@ -453,7 +453,16 @@ enlarge_archive (struct locarhandle *ah, const struct locarhead *head)
}
/* Lock the new file. */
+#ifdef __GNU__
+ struct flock fl;
+ fl.l_whence = SEEK_SET;
+ fl.l_start = 0;
+ fl.l_len = 0;
+ fl.l_type = F_WRLCK;
+ if (fcntl(fd, F_SETLKW, &fl) != 0)
+#else
if (lockf64 (fd, F_LOCK, total) != 0)
+#endif
{
int errval = errno;
unlink (fname);
@@ -613,7 +622,16 @@ open_archive (struct locarhandle *ah, bool readonly)
error (EXIT_FAILURE, errno, _("cannot stat locale archive \"%s\""),
archivefname);
+#ifdef __GNU__
+ struct flock fl;
+ fl.l_whence = SEEK_SET;
+ fl.l_start = 0;
+ fl.l_len = 0;
+ fl.l_type = F_WRLCK;
+ if (!readonly && fcntl(fd, F_SETLKW, &fl) == -1)
+#else
if (!readonly && lockf64 (fd, F_LOCK, sizeof (struct locarhead)) == -1)
+#endif
{
close (fd);
diff --git a/mach/Makefile b/mach/Makefile
index 2a695a5f3a..918cdd1630 100644
--- a/mach/Makefile
+++ b/mach/Makefile
@@ -23,7 +23,7 @@ headers = mach_init.h mach.h mach_error.h mach-shortcuts.h mach/mach_traps.h \
$(interface-headers) mach/mach.h mach/mig_support.h mach/error.h \
$(lock-headers) machine-sp.h
lock = spin-solid spin-lock mutex-init mutex-solid
-lock-headers = lock-intern.h machine-lock.h spin-lock.h
+lock-headers = lock-intern.h spin-lock.h
routines = $(mach-syscalls) $(mach-shortcuts) \
mach_init mig_strncpy msg \
mig-alloc mig-dealloc mig-reply \
@@ -61,7 +61,7 @@ mach-machine = $(patsubst powerpc,ppc,$(base-machine))
ifndef inhibit_mach_syscalls
-include $(objpfx)mach-syscalls.mk
endif
-$(objpfx)mach-syscalls.mk: syscalls.awk Makefile
+$(objpfx)mach-syscalls.mk: syscalls.awk Makefile libc-modules.h
# Go kludges!!!
$(make-target-directory)
# We must use $(CFLAGS) to get -O flags that affect #if's in header files.
@@ -107,7 +107,7 @@ ifndef mach-shortcuts
# $(mach-shortcuts) will be set, and that will change how
# mach_interface.defs is processed: it will get the -D flags below.
user-interfaces := $(filter-out $(mach-interface-list:%=mach/%) \
- mach/mach_port mach/mach_host mach/mach4 \
+ mach/mach_port mach/mach_host mach/mach4 mach/gnumach \
device/device_request,\
$(user-interfaces))
endif
diff --git a/mach/Versions b/mach/Versions
index 0097aad59b..8ab9d68824 100644
--- a/mach/Versions
+++ b/mach/Versions
@@ -29,16 +29,17 @@ libc {
mach_msg_send; mach_msg_receive;
mach_msg_server; mach_msg_server_timeout;
mach_open_devstream;
- mach_port_allocate; mach_port_allocate_name; mach_port_deallocate;
- mach_port_insert_right; mach_reply_port;
+ mach_port_allocate; __mach_port_allocate;
+ mach_port_allocate_name; mach_port_deallocate;
+ mach_port_insert_right; __mach_port_insert_right; mach_reply_port;
mach_setup_thread;
mach_task_self;
mach_thread_self;
mig_allocate; mig_dealloc_reply_port; mig_deallocate;
- mig_get_reply_port; mig_init; mig_put_reply_port;
+ mig_get_reply_port; mig_init; __mig_init; mig_put_reply_port;
# v*
- vm_allocate; vm_deallocate; vm_map;
+ vm_allocate; __vm_allocate; vm_deallocate; __vm_deallocate; vm_map;
# s*
swtch; swtch_pri;
diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index 426628b9c2..f59a76f2dc 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -19,78 +19,117 @@
#define _LOCK_INTERN_H
#include <sys/cdefs.h>
-#include <machine-lock.h>
+
+/* The type of a spin lock variable. */
+typedef unsigned int __spin_lock_t;
+
+/* Static initializer for spinlocks. */
+#define __SPIN_LOCK_INITIALIZER LLL_INITIALIZER
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+#include <lowlevellock.h>
+#endif
#ifndef _EXTERN_INLINE
#define _EXTERN_INLINE __extern_inline
#endif
-
/* Initialize LOCK. */
+void __spin_lock_init (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
_EXTERN_INLINE void
__spin_lock_init (__spin_lock_t *__lock)
{
*__lock = __SPIN_LOCK_INITIALIZER;
}
+#endif
-/* Lock LOCK, blocking if we can't get it. */
-extern void __spin_lock_solid (__spin_lock_t *__lock);
-
/* Lock the spin lock LOCK. */
+void __spin_lock (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
_EXTERN_INLINE void
__spin_lock (__spin_lock_t *__lock)
{
- if (! __spin_try_lock (__lock))
- __spin_lock_solid (__lock);
+ lll_lock (__lock, 0);
}
-
-/* Name space-clean internal interface to mutex locks.
+#endif
- Code internal to the C library uses these functions to lock and unlock
- mutex locks. These locks are of type `struct mutex', defined in
- <cthreads.h>. The functions here are name space-clean. If the program
- is linked with the cthreads library, `__mutex_lock_solid' and
- `__mutex_unlock_solid' will invoke the corresponding cthreads functions
- to implement real mutex locks. If not, simple stub versions just use
- spin locks. */
+/* Unlock LOCK. */
+void __spin_unlock (__spin_lock_t *__lock);
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+_EXTERN_INLINE void
+__spin_unlock (__spin_lock_t *__lock)
+{
+ lll_unlock (__lock, 0);
+}
+#endif
-/* Initialize the newly allocated mutex lock LOCK for further use. */
-extern void __mutex_init (void *__lock);
+/* Try to lock LOCK; return nonzero if we locked it, zero if another has. */
+int __spin_try_lock (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+_EXTERN_INLINE int
+__spin_try_lock (__spin_lock_t *__lock)
+{
+ return (lll_trylock (__lock) == 0);
+}
+#endif
+
+/* Return nonzero if LOCK is locked. */
+int __spin_lock_locked (__spin_lock_t *__lock);
-/* Lock LOCK, blocking if we can't get it. */
-extern void __mutex_lock_solid (void *__lock);
+#if defined __USE_EXTERN_INLINES && defined _LIBC
+_EXTERN_INLINE int
+__spin_lock_locked (__spin_lock_t *__lock)
+{
+ return (*(volatile __spin_lock_t *)__lock != 0);
+}
+#endif
+
+/* Name space-clean internal interface to mutex locks. */
-/* Finish unlocking LOCK, after the spin lock LOCK->held has already been
- unlocked. This function will wake up any thread waiting on LOCK. */
-extern void __mutex_unlock_solid (void *__lock);
+/* Initialize the newly allocated mutex lock LOCK for further use. */
+extern void __mutex_init (void *__lock);
/* Lock the mutex lock LOCK. */
+void __mutex_lock (void *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
_EXTERN_INLINE void
__mutex_lock (void *__lock)
{
- if (! __spin_try_lock ((__spin_lock_t *) __lock))
- __mutex_lock_solid (__lock);
+ __spin_lock ((__spin_lock_t *)__lock);
}
+#endif
/* Unlock the mutex lock LOCK. */
+void __mutex_unlock (void *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
_EXTERN_INLINE void
__mutex_unlock (void *__lock)
{
- __spin_unlock ((__spin_lock_t *) __lock);
- __mutex_unlock_solid (__lock);
+ __spin_unlock ((__spin_lock_t *)__lock);
}
+#endif
+int __mutex_trylock (void *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
_EXTERN_INLINE int
__mutex_trylock (void *__lock)
{
- return __spin_try_lock ((__spin_lock_t *) __lock);
+ return (__spin_try_lock ((__spin_lock_t *)__lock));
}
+#endif
#endif /* lock-intern.h */
diff --git a/mach/lowlevellock.h b/mach/lowlevellock.h
new file mode 100644
index 0000000000..b6ce93927b
--- /dev/null
+++ b/mach/lowlevellock.h
@@ -0,0 +1,80 @@
+/* Copyright (C) 1994-2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef __MACH_LOWLEVELLOCK_H__
+#define __MACH_LOWLEVELLOCK_H__ 1
+
+#include <mach/gnumach.h>
+#include <atomic.h>
+
+/* Gsync flags. */
+#ifndef GSYNC_SHARED
+ #define GSYNC_SHARED 0x01
+ #define GSYNC_QUAD 0x02
+ #define GSYNC_TIMED 0x04
+ #define GSYNC_BROADCAST 0x08
+ #define GSYNC_MUTATE 0x10
+#endif
+
+/* Static initializer for low-level locks. */
+#define LLL_INITIALIZER 0
+
+/* Wait on address PTR, without blocking if its contents
+ * are different from VAL. */
+#define lll_wait(ptr, val, flags) \
+ __gsync_wait (__mach_task_self (), \
+ (vm_offset_t)(ptr), (val), 0, 0, (flags))
+
+/* Wake one or more threads waiting on address PTR. */
+#define lll_wake(ptr, flags) \
+ __gsync_wake (__mach_task_self (), (vm_offset_t)(ptr), 0, (flags))
+
+/* Acquire the lock at PTR. */
+#define lll_lock(ptr, flags) \
+ ({ \
+ int *__iptr = (int *)(ptr); \
+ int __flags = (flags); \
+ if (*__iptr != 0 || \
+ atomic_compare_and_exchange_bool_acq (__iptr, 1, 0) != 0) \
+ while (1) \
+ { \
+ if (atomic_exchange_acq (__iptr, 2) == 0) \
+ break; \
+ lll_wait (__iptr, 2, __flags); \
+ } \
+ (void)0; \
+ })
+
+/* Try to acquire the lock at PTR, without blocking.
+ * Evaluates to zero on success. */
+#define lll_trylock(ptr) \
+ ({ \
+ int *__iptr = (int *)(ptr); \
+ *__iptr == 0 && \
+ atomic_compare_and_exchange_bool_acq (__iptr, 1, 0) == 0 ? 0 : -1; \
+ })
+
+/* Release the lock at PTR. */
+#define lll_unlock(ptr, flags) \
+ ({ \
+ int *__iptr = (int *)(ptr); \
+ if (atomic_exchange_rel (__iptr, 0) == 2) \
+ lll_wake (__iptr, (flags)); \
+ (void)0; \
+ })
+
+#endif
diff --git a/mach/mach.h b/mach/mach.h
index c7e7c8ca9b..7ea8a64733 100644
--- a/mach/mach.h
+++ b/mach/mach.h
@@ -100,5 +100,8 @@ kern_return_t mach_setup_thread (task_t task, thread_t thread, void *pc,
vm_address_t *stack_base,
vm_size_t *stack_size);
+/* Give THREAD a TLS area. */
+kern_return_t __mach_setup_tls (thread_t thread);
+kern_return_t mach_setup_tls (thread_t thread);
#endif /* mach.h */
diff --git a/mach/mach/mig_support.h b/mach/mach/mig_support.h
index b83b1d0b5c..01c452a28d 100644
--- a/mach/mach/mig_support.h
+++ b/mach/mach/mig_support.h
@@ -66,6 +66,8 @@ extern void mig_reply_setup (const mach_msg_header_t *__request,
/* Idiocy support function. */
extern vm_size_t mig_strncpy (char *__dst, const char *__src, vm_size_t __len);
extern vm_size_t __mig_strncpy (char *__dst, const char *__src, vm_size_t);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
__extern_inline vm_size_t
__mig_strncpy (char *__dst, const char *__src, vm_size_t __len)
{
@@ -76,6 +78,7 @@ mig_strncpy (char *__dst, const char *__src, vm_size_t __len)
{
return __mig_strncpy (__dst, __src, __len);
}
+#endif
diff --git a/mach/mutex-init.c b/mach/mutex-init.c
index 16bf34f67c..9de79fabf6 100644
--- a/mach/mutex-init.c
+++ b/mach/mutex-init.c
@@ -17,13 +17,10 @@
<http://www.gnu.org/licenses/>. */
#include <lock-intern.h>
-#include <cthreads.h>
+#include <lowlevellock.h>
void
__mutex_init (void *lock)
{
- /* This happens to be name space-safe because it is a macro.
- It invokes only spin_lock_init, which is a macro for __spin_lock_init;
- and cthread_queue_init, which is a macro for some simple code. */
- mutex_init ((struct mutex *) lock);
+ *(int *)lock = LLL_INITIALIZER;
}
diff --git a/mach/setup-thread.c b/mach/setup-thread.c
index 6100a20493..3e3fbcf93c 100644
--- a/mach/setup-thread.c
+++ b/mach/setup-thread.c
@@ -19,6 +19,7 @@
#include <thread_state.h>
#include <string.h>
#include <mach/machine/vm_param.h>
+#include <ldsodefs.h>
#include "sysdep.h" /* Defines stack direction. */
#define STACK_SIZE (16 * 1024 * 1024) /* 16MB, arbitrary. */
@@ -72,8 +73,35 @@ __mach_setup_thread (task_t task, thread_t thread, void *pc,
if (error = __vm_protect (task, stack, __vm_page_size, 0, VM_PROT_NONE))
return error;
- return __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
+ return __thread_set_state (thread, MACHINE_NEW_THREAD_STATE_FLAVOR,
(natural_t *) &ts, tssize);
}
weak_alias (__mach_setup_thread, mach_setup_thread)
+
+/* Give THREAD a TLS area. */
+kern_return_t
+__mach_setup_tls (thread_t thread)
+{
+ kern_return_t error;
+ struct machine_thread_state ts;
+ mach_msg_type_number_t tssize = MACHINE_THREAD_STATE_COUNT;
+ tcbhead_t *tcb;
+
+ if (error = __thread_get_state (thread, MACHINE_THREAD_STATE_FLAVOR,
+ (natural_t *) &ts, &tssize))
+ return error;
+ assert (tssize == MACHINE_THREAD_STATE_COUNT);
+
+ tcb = _dl_allocate_tls (NULL);
+ if (tcb == NULL)
+ return KERN_RESOURCE_SHORTAGE;
+
+ _hurd_tls_new (thread, &ts, tcb);
+
+ error = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
+ (natural_t *) &ts, tssize);
+ return error;
+}
+
+weak_alias (__mach_setup_tls, mach_setup_tls)
diff --git a/mach/spin-lock.c b/mach/spin-lock.c
index aaebc55cf4..1b1e69c8d6 100644
--- a/mach/spin-lock.c
+++ b/mach/spin-lock.c
@@ -1,3 +1,4 @@
+#define __USE_EXTERN_INLINES 1
#define _EXTERN_INLINE /* Empty to define the real functions. */
#include "spin-lock.h"
diff --git a/malloc/Makefile b/malloc/Makefile
index 360288bef8..59d4264ae0 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -46,12 +46,9 @@ extra-libs-others = $(extra-libs)
libmemusage-routines = memusage
libmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))
-$(objpfx)tst-malloc-backtrace: $(common-objpfx)nptl/libpthread.so \
- $(common-objpfx)nptl/libpthread_nonshared.a
-$(objpfx)tst-malloc-thread-exit: $(common-objpfx)nptl/libpthread.so \
- $(common-objpfx)nptl/libpthread_nonshared.a
-$(objpfx)tst-malloc-thread-fail: $(common-objpfx)nptl/libpthread.so \
- $(common-objpfx)nptl/libpthread_nonshared.a
+$(objpfx)tst-malloc-backtrace: $(shared-thread-library)
+$(objpfx)tst-malloc-thread-exit: $(shared-thread-library)
+$(objpfx)tst-malloc-thread-fail: $(shared-thread-library)
# These should be removed by `make clean'.
extra-objs = mcheck-init.o libmcheck.a
diff --git a/manual/errno.texi b/manual/errno.texi
index 1068be3a50..5b400fe64b 100644
--- a/manual/errno.texi
+++ b/manual/errno.texi
@@ -993,6 +993,18 @@ the normal result is for the operations affected to complete with this
error; @pxref{Cancel AIO Operations}.
@end deftypevr
+@comment errno.h
+@comment GNU: Owner died
+@deftypevr Macro int EOWNERDEAD
+@comment errno 120
+@end deftypevr
+
+@comment errno.h
+@comment GNU: State not recoverable
+@deftypevr Macro int ENOTRECOVERABLE
+@comment errno 121
+@end deftypevr
+
@emph{The following error codes are defined by the Linux/i386 kernel.
They are not yet documented.}
diff --git a/misc/Makefile b/misc/Makefile
index d7bbc85f18..4bfc935fd8 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -99,6 +99,10 @@ CFLAGS-getusershell.c = -fexceptions
CFLAGS-err.c = -fexceptions
CFLAGS-tst-tsearch.c = $(stack-align-test-flags)
+tests += tst-sbrk tst-sbrk-pie tst-sbrk-static
+tests-pie += tst-sbrk-pie
+tests-static += tst-sbrk-static
+
include ../Rules
$(objpfx)libg.a: $(dep-dummy-lib); $(make-dummy-lib)
diff --git a/misc/getauxval.c b/misc/getauxval.c
index e48f40f66d..61113766da 100644
--- a/misc/getauxval.c
+++ b/misc/getauxval.c
@@ -30,9 +30,11 @@ __getauxval (unsigned long int type)
else if (type == AT_HWCAP2)
return GLRO(dl_hwcap2);
+#ifdef HAVE_AUX_VECTOR
for (p = GLRO(dl_auxv); p->a_type != AT_NULL; p++)
if (p->a_type == type)
return p->a_un.a_val;
+#endif
__set_errno (ENOENT);
return 0;
diff --git a/misc/sys/file.h b/misc/sys/file.h
index 133e969dfc..cd2a6410fc 100644
--- a/misc/sys/file.h
+++ b/misc/sys/file.h
@@ -40,6 +40,7 @@ __BEGIN_DECLS
#define LOCK_SH 1 /* Shared lock. */
#define LOCK_EX 2 /* Exclusive lock. */
#define LOCK_UN 8 /* Unlock. */
+#define __LOCK_ATOMIC 16 /* Atomic update. */
/* Can be OR'd in to one of the above. */
#define LOCK_NB 4 /* Don't block when locking. */
diff --git a/misc/tst-sbrk-pie.c b/misc/tst-sbrk-pie.c
new file mode 100644
index 0000000000..3896b9699e
--- /dev/null
+++ b/misc/tst-sbrk-pie.c
@@ -0,0 +1,3 @@
+/* Test sbrk with -pie. */
+
+#include <tst-sbrk.c>
diff --git a/misc/tst-sbrk-static.c b/misc/tst-sbrk-static.c
new file mode 100644
index 0000000000..fef52718cd
--- /dev/null
+++ b/misc/tst-sbrk-static.c
@@ -0,0 +1,3 @@
+/* Test sbrk with -static. */
+
+#include <tst-sbrk.c>
diff --git a/misc/tst-sbrk.c b/misc/tst-sbrk.c
new file mode 100644
index 0000000000..8db48ca2e9
--- /dev/null
+++ b/misc/tst-sbrk.c
@@ -0,0 +1,49 @@
+/* Test sbrk.
+
+ Copyright (C) 2013-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+static int
+do_test (void)
+{
+ /* Try to advance the program break by 1 MiB. */
+ void *one_mib = sbrk (1 * 1024 * 1024);
+ if (one_mib == (void *) -1)
+ {
+ if (errno != ENOMEM)
+ printf ("sbrk (1 MiB) failed, and with wrong errno: %m\n");
+ else
+ printf ("sbrk (1 MiB) failed\n");
+
+ return 1;
+ }
+ else
+ printf ("sbrk at %p\n", one_mib);
+
+ return 0;
+}
+
+/* TODO: fix rlimit bug. 64 MiB (test-skeleton.c's default) should be
+ enough. */
+#define TEST_DATA_LIMIT RLIM_INFINITY
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/nscd/Depend b/nscd/Depend
index 6c1aa44e6e..c29ffb5e96 100644
--- a/nscd/Depend
+++ b/nscd/Depend
@@ -1 +1,2 @@
nptl
+libpthread
diff --git a/po/fr.po b/po/fr.po
index 65f9a6a665..189771120b 100644
--- a/po/fr.po
+++ b/po/fr.po
@@ -6459,12 +6459,12 @@ msgstr " ?"
#. TRANS You did @strong{what}?
#: sysdeps/gnu/errlist.c:977
msgid "You really blew it this time"
-msgstr "Vous avez vraiment tout gâcher cette fois-ci"
+msgstr "Vous avez vraiment tout gâché cette fois-ci"
#. TRANS Go home and have a glass of warm, dairy-fresh milk.
#: sysdeps/gnu/errlist.c:986
msgid "Computer bought the farm"
-msgstr "L'ordinateur a acheté la ferme"
+msgstr "L'ordinateur a cassé sa pipe"
#. TRANS This error code has no purpose.
#: sysdeps/gnu/errlist.c:995
diff --git a/resolv/Depend b/resolv/Depend
index 6c1aa44e6e..c29ffb5e96 100644
--- a/resolv/Depend
+++ b/resolv/Depend
@@ -1 +1,2 @@
nptl
+libpthread
diff --git a/resolv/gai_sigqueue.c b/resolv/gai_sigqueue.c
index 4b0c08f6e5..40d2a68963 100644
--- a/resolv/gai_sigqueue.c
+++ b/resolv/gai_sigqueue.c
@@ -22,6 +22,7 @@
#include <gai_misc.h>
int
+internal_function
__gai_sigqueue (int sig, const union sigval val, pid_t caller_pid)
{
__set_errno (ENOSYS);
diff --git a/rt/Depend b/rt/Depend
index 6c1aa44e6e..c29ffb5e96 100644
--- a/rt/Depend
+++ b/rt/Depend
@@ -1 +1,2 @@
nptl
+libpthread
diff --git a/rt/aio_sigqueue.c b/rt/aio_sigqueue.c
index 0297eca0d7..33bb61b957 100644
--- a/rt/aio_sigqueue.c
+++ b/rt/aio_sigqueue.c
@@ -22,6 +22,7 @@
#include <aio_misc.h>
int
+attribute_hidden internal_function
__aio_sigqueue (int sig, const union sigval val, pid_t caller_pid)
{
__set_errno (ENOSYS);
diff --git a/scripts/check-local-headers.sh b/scripts/check-local-headers.sh
index 0670da16bc..0a967bb5ce 100755
--- a/scripts/check-local-headers.sh
+++ b/scripts/check-local-headers.sh
@@ -33,7 +33,7 @@ exec ${AWK} -v includedir="$includedir" '
BEGIN {
status = 0
exclude = "^" includedir \
- "/(.*-.*-.*/|)(asm[-/]|arch|linux/|selinux/|mach/|device/|hurd/(((hurd|ioctl)_types|paths)\\.h|ioctls\\.defs)|cthreads\\.h|gd|nss3/|c\\+\\+/|sys/(capability|sdt(|-config))\\.h|libaudit\\.h)"
+ "/(.*-.*-.*/|.*-.*/|)(asm[-/]|arch|linux/|selinux/|mach/|mach_debug/|device/|hurd/(((hurd|ioctl)_types|paths)\\.h|ioctls\\.defs|ihash\\.h)|cthreads\\.h|gd|nss3/|c\\+\\+/|sys/(capability|sdt(|-config))\\.h|libaudit\\.h)"
}
/^[^ ]/ && $1 ~ /.*:/ { obj = $1 }
{
diff --git a/sysdeps/mach/hurd/libc-tsd.h b/sysdeps/generic/dl-fcntl.h
index f523034fe7..ee3c49c203 100644
--- a/sysdeps/mach/hurd/libc-tsd.h
+++ b/sysdeps/generic/dl-fcntl.h
@@ -1,5 +1,6 @@
-/* libc-internal interface for thread-specific data. Hurd version.
- Copyright (C) 1998-2016 Free Software Foundation, Inc.
+/* Functions with hidden attribute internal to ld.so, which are declared
+ in include/fcntl.h. Generic version.
+ Copyright (C) 2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -16,19 +17,5 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#ifndef _LIBC_TSD_H
-#define _LIBC_TSD_H 1
-
-#include <hurd/threadvar.h>
-
-#define __libc_tsd_define(CLASS, TYPE, KEY) /* nothing, always have threadvars */
-
-#define __libc_tsd_address(TYPE, KEY) \
- ((TYPE *) __hurd_threadvar_location (_HURD_THREADVAR_##KEY))
-
-#define __libc_tsd_get(TYPE, KEY) \
- (*__libc_tsd_address (TYPE, KEY))
-#define __libc_tsd_set(TYPE, KEY, VALUE) \
- (*__libc_tsd_address (TYPE, KEY) = (VALUE))
-
-#endif /* libc-tsd.h */
+extern __typeof (__open) __open attribute_hidden;
+extern __typeof (__fcntl) __fcntl attribute_hidden;
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 2733ac8268..4e2123b3be 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -416,6 +416,7 @@ struct rtld_global
size_t count;
void *list[50];
} *_dl_scope_free_list;
+ EXTERN volatile int _dl_thread_gscope_count;
#ifdef SHARED
};
# define __rtld_global_attribute__
@@ -509,8 +510,10 @@ struct rtld_global_ro
/* Mask for important hardware capabilities we honour. */
EXTERN uint64_t _dl_hwcap_mask;
+#ifdef HAVE_AUX_VECTOR
/* Pointer to the auxv list supplied to the program at startup. */
EXTERN ElfW(auxv_t) *_dl_auxv;
+#endif
/* Get architecture specific definitions. */
#define PROCINFO_DECL
diff --git a/sysdeps/generic/machine-lock.h b/sysdeps/generic/machine-lock.h
index 8497a7273e..883b63bd48 100644
--- a/sysdeps/generic/machine-lock.h
+++ b/sysdeps/generic/machine-lock.h
@@ -34,14 +34,21 @@ typedef volatile int __spin_lock_t;
/* Unlock LOCK. */
+void __spin_unlock (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
_EXTERN_INLINE void
__spin_unlock (__spin_lock_t *__lock)
{
*__lock = 0;
}
+#endif
/* Try to lock LOCK; return nonzero if we locked it, zero if another has. */
+int __spin_try_lock (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
_EXTERN_INLINE int
__spin_try_lock (__spin_lock_t *__lock)
{
@@ -50,14 +57,19 @@ __spin_try_lock (__spin_lock_t *__lock)
*__lock = 1;
return 1;
}
+#endif
/* Return nonzero if LOCK is locked. */
+int __spin_lock_locked (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
_EXTERN_INLINE int
__spin_lock_locked (__spin_lock_t *__lock)
{
return *__lock != 0;
}
+#endif
#endif /* machine-lock.h */
diff --git a/sysdeps/generic/machine-sp.h b/sysdeps/generic/machine-sp.h
index f7d84492f1..f9beec4da5 100644
--- a/sysdeps/generic/machine-sp.h
+++ b/sysdeps/generic/machine-sp.h
@@ -25,11 +25,15 @@
#define _EXTERN_INLINE __extern_inline
#endif
+void * __thread_stack_pointer (void);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
_EXTERN_INLINE void *
__thread_stack_pointer (void)
{
register void *__sp__ ("{STACK-POINTER}");
return __sp__;
}
+#endif
#endif /* machine-sp.h */
diff --git a/sysdeps/generic/not-cancel.h b/sysdeps/generic/not-cancel.h
index d703bb228f..b3297107c7 100644
--- a/sysdeps/generic/not-cancel.h
+++ b/sysdeps/generic/not-cancel.h
@@ -18,10 +18,22 @@
<http://www.gnu.org/licenses/>. */
/* By default we have none. Map the name to the normal functions. */
-#define open_not_cancel(name, flags, mode) \
+
+/* Uncancelable open. */
+#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
+# define open_not_cancel(name, flags, mode) \
__libc_open (name, flags, mode)
-#define open_not_cancel_2(name, flags) \
+# define open_not_cancel_2(name, flags) \
__libc_open (name, flags)
+#else
+/* In this case, we can't use the libc_* internal functions. */
+# define open_not_cancel(name, flags, mode) \
+ __open (name, flags, mode)
+# define open_not_cancel_2(name, flags) \
+ __open (name, flags)
+#endif
+
+/* Uncancelable openat. */
#define openat_not_cancel(fd, name, flags, mode) \
__openat (fd, name, flags, mode)
#define openat_not_cancel_3(fd, name, flags) \
@@ -30,18 +42,30 @@
__openat64 (fd, name, flags, mode)
#define openat64_not_cancel_3(fd, name, flags) \
__openat64 (fd, name, flags, 0)
+
+/* Uncancelable close. */
#define close_not_cancel(fd) \
__close (fd)
#define close_not_cancel_no_status(fd) \
(void) __close (fd)
+
+/* Uncancelable read. */
#define read_not_cancel(fd, buf, n) \
__read (fd, buf, n)
+
+/* Uncancelable write. */
#define write_not_cancel(fd, buf, n) \
__write (fd, buf, n)
+
+/* Uncancelable writev. */
#define writev_not_cancel_no_status(fd, iov, n) \
(void) __writev (fd, iov, n)
+
+/* Uncancelable fcntl. */
#define fcntl_not_cancel(fd, cmd, val) \
__fcntl (fd, cmd, val)
+
+/* Uncancelable waitpid. */
# define waitpid_not_cancel(pid, stat_loc, options) \
__waitpid (pid, stat_loc, options)
#define pause_not_cancel() \
diff --git a/sysdeps/generic/symbol-hacks.h b/sysdeps/generic/symbol-hacks.h
index ce576c9fd2..137ff57d8a 100644
--- a/sysdeps/generic/symbol-hacks.h
+++ b/sysdeps/generic/symbol-hacks.h
@@ -1,7 +1,10 @@
/* Some compiler optimizations may transform loops into memset/memmove
calls and without proper declaration it may generate PLT calls. */
#if !defined __ASSEMBLER__ && IS_IN (libc) && defined SHARED
+#include <config.h>
+# if !defined NO_HIDDEN
asm ("memmove = __GI_memmove");
asm ("memset = __GI_memset");
asm ("memcpy = __GI_memcpy");
+# endif
#endif
diff --git a/sysdeps/generic/thread_state.h b/sysdeps/generic/thread_state.h
index 07ac112691..b168e20246 100644
--- a/sysdeps/generic/thread_state.h
+++ b/sysdeps/generic/thread_state.h
@@ -22,6 +22,7 @@
/* Replace <machine> with "i386" or "mips" or whatever. */
+#define MACHINE_NEW_THREAD_STATE_FLAVOR <machine>_NEW_THREAD_STATE
#define MACHINE_THREAD_STATE_FLAVOR <machine>_THREAD_STATE
#define MACHINE_THREAD_STATE_COUNT <machine>_THREAD_STATE_COUNT
diff --git a/sysdeps/i386/atomic-machine.h b/sysdeps/i386/atomic-machine.h
index ce62b335af..8df4e3302d 100644
--- a/sysdeps/i386/atomic-machine.h
+++ b/sysdeps/i386/atomic-machine.h
@@ -66,35 +66,26 @@ typedef uintmax_t uatomic_max_t;
#define __arch_c_compare_and_exchange_val_8_acq(mem, newval, oldval) \
({ __typeof (*mem) ret; \
- __asm __volatile ("cmpl $0, %%gs:%P5\n\t" \
- "je 0f\n\t" \
- "lock\n" \
- "0:\tcmpxchgb %b2, %1" \
+ __asm __volatile ("lock\n" \
+ "\tcmpxchgb %b2, %1" \
: "=a" (ret), "=m" (*mem) \
- : "q" (newval), "m" (*mem), "0" (oldval), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "q" (newval), "m" (*mem), "0" (oldval)); \
ret; })
#define __arch_c_compare_and_exchange_val_16_acq(mem, newval, oldval) \
({ __typeof (*mem) ret; \
- __asm __volatile ("cmpl $0, %%gs:%P5\n\t" \
- "je 0f\n\t" \
- "lock\n" \
- "0:\tcmpxchgw %w2, %1" \
+ __asm __volatile ("lock\n" \
+ "\tcmpxchgw %w2, %1" \
: "=a" (ret), "=m" (*mem) \
- : "r" (newval), "m" (*mem), "0" (oldval), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "r" (newval), "m" (*mem), "0" (oldval)); \
ret; })
#define __arch_c_compare_and_exchange_val_32_acq(mem, newval, oldval) \
({ __typeof (*mem) ret; \
- __asm __volatile ("cmpl $0, %%gs:%P5\n\t" \
- "je 0f\n\t" \
- "lock\n" \
- "0:\tcmpxchgl %2, %1" \
+ __asm __volatile ("lock\n" \
+ "\tcmpxchgl %2, %1" \
: "=a" (ret), "=m" (*mem) \
- : "r" (newval), "m" (*mem), "0" (oldval), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "r" (newval), "m" (*mem), "0" (oldval)); \
ret; })
/* XXX We do not really need 64-bit compare-and-exchange. At least
@@ -135,10 +126,8 @@ typedef uintmax_t uatomic_max_t;
# define __arch_c_compare_and_exchange_val_64_acq(mem, newval, oldval) \
({ __typeof (*mem) ret; \
__asm __volatile ("xchgl %2, %%ebx\n\t" \
- "cmpl $0, %%gs:%P7\n\t" \
- "je 0f\n\t" \
"lock\n" \
- "0:\tcmpxchg8b %1\n\t" \
+ "\tcmpxchg8b %1\n\t" \
"xchgl %2, %%ebx" \
: "=A" (ret), "=m" (*mem) \
: "DS" (((unsigned long long int) (newval)) \
@@ -146,8 +135,7 @@ typedef uintmax_t uatomic_max_t;
"c" (((unsigned long long int) (newval)) >> 32), \
"m" (*mem), "a" (((unsigned long long int) (oldval)) \
& 0xffffffff), \
- "d" (((unsigned long long int) (oldval)) >> 32), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ "d" (((unsigned long long int) (oldval)) >> 32)); \
ret; })
# else
# define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
@@ -164,18 +152,15 @@ typedef uintmax_t uatomic_max_t;
# define __arch_c_compare_and_exchange_val_64_acq(mem, newval, oldval) \
({ __typeof (*mem) ret; \
- __asm __volatile ("cmpl $0, %%gs:%P7\n\t" \
- "je 0f\n\t" \
- "lock\n" \
- "0:\tcmpxchg8b %1" \
+ __asm __volatile ("lock\n" \
+ "\tcmpxchg8b %1" \
: "=A" (ret), "=m" (*mem) \
: "b" (((unsigned long long int) (newval)) \
& 0xffffffff), \
"c" (((unsigned long long int) (newval)) >> 32), \
"m" (*mem), "a" (((unsigned long long int) (oldval)) \
& 0xffffffff), \
- "d" (((unsigned long long int) (oldval)) >> 32), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ "d" (((unsigned long long int) (oldval)) >> 32)); \
ret; })
# endif
#endif
@@ -210,18 +195,15 @@ typedef uintmax_t uatomic_max_t;
if (sizeof (*mem) == 1) \
__asm __volatile (lock "xaddb %b0, %1" \
: "=q" (__result), "=m" (*mem) \
- : "0" (__addval), "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "0" (__addval), "m" (*mem)); \
else if (sizeof (*mem) == 2) \
__asm __volatile (lock "xaddw %w0, %1" \
: "=r" (__result), "=m" (*mem) \
- : "0" (__addval), "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "0" (__addval), "m" (*mem)); \
else if (sizeof (*mem) == 4) \
__asm __volatile (lock "xaddl %0, %1" \
: "=r" (__result), "=m" (*mem) \
- : "0" (__addval), "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "0" (__addval), "m" (*mem)); \
else \
{ \
__typeof (mem) __memp = (mem); \
@@ -238,7 +220,7 @@ typedef uintmax_t uatomic_max_t;
__sync_fetch_and_add (mem, value)
#define __arch_exchange_and_add_cprefix \
- "cmpl $0, %%gs:%P4\n\tje 0f\n\tlock\n0:\t"
+ "lock\n\t"
#define catomic_exchange_and_add(mem, value) \
__arch_exchange_and_add_body (__arch_exchange_and_add_cprefix, __arch_c, \
@@ -254,18 +236,15 @@ typedef uintmax_t uatomic_max_t;
else if (sizeof (*mem) == 1) \
__asm __volatile (lock "addb %b1, %0" \
: "=m" (*mem) \
- : "iq" (value), "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "iq" (value), "m" (*mem)); \
else if (sizeof (*mem) == 2) \
__asm __volatile (lock "addw %w1, %0" \
: "=m" (*mem) \
- : "ir" (value), "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "ir" (value), "m" (*mem)); \
else if (sizeof (*mem) == 4) \
__asm __volatile (lock "addl %1, %0" \
: "=m" (*mem) \
- : "ir" (value), "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "ir" (value), "m" (*mem)); \
else \
{ \
__typeof (value) __addval = (value); \
@@ -283,7 +262,7 @@ typedef uintmax_t uatomic_max_t;
__arch_add_body (LOCK_PREFIX, __arch, mem, value)
#define __arch_add_cprefix \
- "cmpl $0, %%gs:%P3\n\tje 0f\n\tlock\n0:\t"
+ "lock\n\t"
#define catomic_add(mem, value) \
__arch_add_body (__arch_add_cprefix, __arch_c, mem, value)
@@ -332,18 +311,15 @@ typedef uintmax_t uatomic_max_t;
if (sizeof (*mem) == 1) \
__asm __volatile (lock "incb %b0" \
: "=m" (*mem) \
- : "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "m" (*mem)); \
else if (sizeof (*mem) == 2) \
__asm __volatile (lock "incw %w0" \
: "=m" (*mem) \
- : "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "m" (*mem)); \
else if (sizeof (*mem) == 4) \
__asm __volatile (lock "incl %0" \
: "=m" (*mem) \
- : "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "m" (*mem)); \
else \
{ \
__typeof (mem) __memp = (mem); \
@@ -359,7 +335,7 @@ typedef uintmax_t uatomic_max_t;
#define atomic_increment(mem) __arch_increment_body (LOCK_PREFIX, __arch, mem)
#define __arch_increment_cprefix \
- "cmpl $0, %%gs:%P2\n\tje 0f\n\tlock\n0:\t"
+ "lock\n\t"
#define catomic_increment(mem) \
__arch_increment_body (__arch_increment_cprefix, __arch_c, mem)
@@ -389,18 +365,15 @@ typedef uintmax_t uatomic_max_t;
if (sizeof (*mem) == 1) \
__asm __volatile (lock "decb %b0" \
: "=m" (*mem) \
- : "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "m" (*mem)); \
else if (sizeof (*mem) == 2) \
__asm __volatile (lock "decw %w0" \
: "=m" (*mem) \
- : "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "m" (*mem)); \
else if (sizeof (*mem) == 4) \
__asm __volatile (lock "decl %0" \
: "=m" (*mem) \
- : "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "m" (*mem)); \
else \
{ \
__typeof (mem) __memp = (mem); \
@@ -416,7 +389,7 @@ typedef uintmax_t uatomic_max_t;
#define atomic_decrement(mem) __arch_decrement_body (LOCK_PREFIX, __arch, mem)
#define __arch_decrement_cprefix \
- "cmpl $0, %%gs:%P2\n\tje 0f\n\tlock\n0:\t"
+ "lock\n\t"
#define catomic_decrement(mem) \
__arch_decrement_body (__arch_decrement_cprefix, __arch_c, mem)
@@ -487,24 +460,21 @@ typedef uintmax_t uatomic_max_t;
if (sizeof (*mem) == 1) \
__asm __volatile (lock "andb %b1, %0" \
: "=m" (*mem) \
- : "iq" (mask), "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "iq" (mask), "m" (*mem)); \
else if (sizeof (*mem) == 2) \
__asm __volatile (lock "andw %w1, %0" \
: "=m" (*mem) \
- : "ir" (mask), "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "ir" (mask), "m" (*mem)); \
else if (sizeof (*mem) == 4) \
__asm __volatile (lock "andl %1, %0" \
: "=m" (*mem) \
- : "ir" (mask), "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "ir" (mask), "m" (*mem)); \
else \
abort (); \
} while (0)
#define __arch_cprefix \
- "cmpl $0, %%gs:%P3\n\tje 0f\n\tlock\n0:\t"
+ "lock\n\t"
#define atomic_and(mem, mask) __arch_and_body (LOCK_PREFIX, mem, mask)
@@ -516,18 +486,15 @@ typedef uintmax_t uatomic_max_t;
if (sizeof (*mem) == 1) \
__asm __volatile (lock "orb %b1, %0" \
: "=m" (*mem) \
- : "iq" (mask), "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "iq" (mask), "m" (*mem)); \
else if (sizeof (*mem) == 2) \
__asm __volatile (lock "orw %w1, %0" \
: "=m" (*mem) \
- : "ir" (mask), "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "ir" (mask), "m" (*mem)); \
else if (sizeof (*mem) == 4) \
__asm __volatile (lock "orl %1, %0" \
: "=m" (*mem) \
- : "ir" (mask), "m" (*mem), \
- "i" (offsetof (tcbhead_t, multiple_threads))); \
+ : "ir" (mask), "m" (*mem)); \
else \
abort (); \
} while (0)
diff --git a/sysdeps/mach/Makefile b/sysdeps/mach/Makefile
index 7d8c67c316..dc21cf232d 100644
--- a/sysdeps/mach/Makefile
+++ b/sysdeps/mach/Makefile
@@ -35,7 +35,7 @@ endif
# because it's different in Darwin and the conditional crap is
# too much trouble. This should suffice for getting the mach/Makefile
# rules invoked when they need to be.
-mach-before-compile := $(mach-objpfx)mach-shortcuts.h \
+mach-before-compile := $(mach-objpfx)mach-shortcuts.h $(mach-objpfx)mach/mach_interface.h \
$(patsubst %,$(mach-objpfx)mach/mach_%.h,\
port host)
@@ -50,4 +50,23 @@ mach-before-compile:
before-compile += $(mach-before-compile)
endif
+ifeq (crypt,$(subdir))
+ LDLIBS-crypt.so += -lmachuser
+else ifeq (dlfcn,$(subdir))
+ LDLIBS-dl.so += -lmachuser
+else ifeq (nis,$(subdir))
+ LDLIBS-nsl.so += -lmachuser
+ LDLIBS-nss_nis.so += -lmachuser
+ LDLIBS-nss_nisplus.so += -lmachuser
+ LDLIBS-nss_compat.so += -lmachuser
+else ifeq (nss,$(subdir))
+ LDLIBS-nss.so += -lmachuser
+ LDLIBS-nss_files.so += -lmachuser
+ LDLIBS-nss_db.so += -lmachuser
+else ifeq (posix,$(subdir))
+ LDLIBS-tst-rfc3484 += -lmachuser
+ LDLIBS-tst-rfc3484-2 += -lmachuser
+ LDLIBS-tst-rfc3484-3 += -lmachuser
+endif
+
endif # in-Makerules
diff --git a/sysdeps/mach/configure b/sysdeps/mach/configure
index 632a9c9fa4..c6ea9be20b 100644
--- a/sysdeps/mach/configure
+++ b/sysdeps/mach/configure
@@ -282,7 +282,7 @@ if test $libc_cv_mach_task_creation_time = no; then
fi
mach_interface_list=
-for ifc in mach mach4 \
+for ifc in mach mach4 gnumach \
clock clock_priv host_priv host_security ledger lock_set \
processor processor_set task task_notify thread_act vm_map \
memory_object memory_object_default default_pager \
diff --git a/sysdeps/mach/configure.ac b/sysdeps/mach/configure.ac
index 3033fec946..cadecae884 100644
--- a/sysdeps/mach/configure.ac
+++ b/sysdeps/mach/configure.ac
@@ -59,7 +59,7 @@ dnl but we don't do a check for that here because in a bare
dnl environment the compile against those headers will fail.
dnl
mach_interface_list=
-for ifc in mach mach4 \
+for ifc in mach mach4 gnumach \
clock clock_priv host_priv host_security ledger lock_set \
processor processor_set task task_notify thread_act vm_map \
memory_object memory_object_default default_pager \
diff --git a/sysdeps/mach/hurd/Makefile b/sysdeps/mach/hurd/Makefile
index 3845c57c14..c1b34d1637 100644
--- a/sysdeps/mach/hurd/Makefile
+++ b/sysdeps/mach/hurd/Makefile
@@ -79,9 +79,11 @@ endef
# the headers we want to search for Mach error codes, listed above (and
# incidentally, all other headers those include).
-include $(common-objpfx)errnos.d
-$(common-objpfx)errnos.d: $(mach-errnos-deps) libc-modules.h
+$(common-objpfx)errnos.d: $(mach-errnos-deps)
$(mach-errno-h) | \
- $(CC) $(CFLAGS) $(CPPFLAGS) -M -x c - | \
+ $(CC) $(CFLAGS) \
+ $(subst -include $(common-objpfx)libc-modules.h,,$(CPPFLAGS)) \
+ -M -x c - | \
sed $(sed-remove-objpfx) -e 's,- *:,mach-errnos-deps :=,' \
-e 's, \.\./, $(..),g' > $@t
mv -f $@t $@
@@ -168,6 +170,10 @@ $(objpfx)librtld.map: $(rpcuserlibs:.so=_pic.a)
CFLAGS-dl-load.c = -DEXTERNAL_MAP_FROM_FD
endif
+ifeq ($(subdir),posix)
+CFLAGS-confstr.c += -DLIBPTHREAD_VERSION='"libpthread 0.3"'
+endif
+
# Override the generic Makeconfig values so we link against the RPC libs.
link-libc-static := -Wl,--start-group \
$(patsubst %,$(common-objpfx)%.a,\
@@ -192,6 +198,10 @@ ifeq (hurd, $(subdir))
sysdep_routines += cthreads
endif
+ifeq (io, $(subdir))
+sysdep_routines += f_setlk
+endif
+
ifeq ($(subdir),sunrpc)
sysdep_headers += nfs/nfs.h
endif
diff --git a/sysdeps/mach/hurd/Versions b/sysdeps/mach/hurd/Versions
index 89e19061af..7cab8e8551 100644
--- a/sysdeps/mach/hurd/Versions
+++ b/sysdeps/mach/hurd/Versions
@@ -6,6 +6,7 @@ libc {
GLIBC_PRIVATE {
# Functions shared with the dynamic linker
__libc_read; __libc_write; __libc_lseek64;
+ __libc_lock_self0;
_dl_init_first;
}
@@ -14,8 +15,6 @@ libc {
ld {
GLIBC_2.0 {
# variables that must be shared with libc
- __hurd_sigthread_stack_base; __hurd_sigthread_stack_end;
- __hurd_sigthread_variables;
__hurd_threadvar_stack_mask; __hurd_threadvar_stack_offset;
# functions that must be shared with libc
@@ -33,5 +32,6 @@ ld {
# functions that must be shared with libc
__libc_read; __libc_write; __libc_lseek64;
+ __libc_lock_self0;
}
}
diff --git a/sysdeps/mach/hurd/access.c b/sysdeps/mach/hurd/access.c
index c308340329..dc64183f96 100644
--- a/sysdeps/mach/hurd/access.c
+++ b/sysdeps/mach/hurd/access.c
@@ -16,131 +16,13 @@
<http://www.gnu.org/licenses/>. */
#include <unistd.h>
-#include <hurd.h>
-#include <hurd/port.h>
-#include <hurd/id.h>
-#include <hurd/lookup.h>
#include <fcntl.h>
/* Test for access to FILE by our real user and group IDs. */
int
__access (const char *file, int type)
{
- error_t err;
- file_t rcrdir, rcwdir, io;
- int flags, allowed;
-
- error_t reauthenticate (int which, file_t *result)
- {
- /* Get a port to our root directory, authenticated with the real IDs. */
- error_t err;
- mach_port_t ref;
- ref = __mach_reply_port ();
- err = HURD_PORT_USE
- (&_hurd_ports[which],
- ({
- err = __io_reauthenticate (port, ref, MACH_MSG_TYPE_MAKE_SEND);
- if (!err)
- err = __auth_user_authenticate (_hurd_id.rid_auth,
- ref, MACH_MSG_TYPE_MAKE_SEND,
- result);
- err;
- }));
- __mach_port_destroy (__mach_task_self (), ref);
- return err;
- }
-
- error_t init_port (int which, error_t (*operate) (mach_port_t))
- {
- switch (which)
- {
- case INIT_PORT_AUTH:
- return (*operate) (_hurd_id.rid_auth);
- case INIT_PORT_CRDIR:
- return (reauthenticate (INIT_PORT_CRDIR, &rcrdir) ?:
- (*operate) (rcrdir));
- case INIT_PORT_CWDIR:
- return (reauthenticate (INIT_PORT_CWDIR, &rcwdir) ?:
- (*operate) (rcwdir));
- default:
- return _hurd_ports_use (which, operate);
- }
- }
-
- rcrdir = rcwdir = MACH_PORT_NULL;
-
- HURD_CRITICAL_BEGIN;
-
- __mutex_lock (&_hurd_id.lock);
- /* Get _hurd_id up to date. */
- if (err = _hurd_check_ids ())
- goto lose;
-
- if (_hurd_id.rid_auth == MACH_PORT_NULL)
- {
- /* Set up _hurd_id.rid_auth. This is a special auth server port
- which uses the real uid and gid (the first aux uid and gid) as
- the only effective uid and gid. */
-
- if (_hurd_id.aux.nuids < 1 || _hurd_id.aux.ngids < 1)
- {
- /* We do not have a real UID and GID. Lose, lose, lose! */
- err = EGRATUITOUS;
- goto lose;
- }
-
- /* Create a new auth port using our real UID and GID (the first
- auxiliary UID and GID) as the only effective IDs. */
- if (err = __USEPORT (AUTH,
- __auth_makeauth (port,
- NULL, MACH_MSG_TYPE_COPY_SEND, 0,
- _hurd_id.aux.uids, 1,
- _hurd_id.aux.uids,
- _hurd_id.aux.nuids,
- _hurd_id.aux.gids, 1,
- _hurd_id.aux.gids,
- _hurd_id.aux.ngids,
- &_hurd_id.rid_auth)))
- goto lose;
- }
-
- if (!err)
- /* Look up the file name using the modified init ports. */
- err = __hurd_file_name_lookup (&init_port, &__getdport, 0,
- file, 0, 0, &io);
-
- /* We are done with _hurd_id.rid_auth now. */
- lose:
- __mutex_unlock (&_hurd_id.lock);
-
- HURD_CRITICAL_END;
-
- if (rcrdir != MACH_PORT_NULL)
- __mach_port_deallocate (__mach_task_self (), rcrdir);
- if (rcwdir != MACH_PORT_NULL)
- __mach_port_deallocate (__mach_task_self (), rcwdir);
- if (err)
- return __hurd_fail (err);
-
- /* Find out what types of access we are allowed to this file. */
- err = __file_check_access (io, &allowed);
- __mach_port_deallocate (__mach_task_self (), io);
- if (err)
- return __hurd_fail (err);
-
- flags = 0;
- if (type & R_OK)
- flags |= O_READ;
- if (type & W_OK)
- flags |= O_WRITE;
- if (type & X_OK)
- flags |= O_EXEC;
-
- if (flags & ~allowed)
- /* We are not allowed all the requested types of access. */
- return __hurd_fail (EACCES);
-
- return 0;
+ return __faccessat (AT_FDCWD, file, type, 0);
}
weak_alias (__access, access)
diff --git a/sysdeps/mach/hurd/bind.c b/sysdeps/mach/hurd/bind.c
index e605e31c5f..7cdfefda19 100644
--- a/sysdeps/mach/hurd/bind.c
+++ b/sysdeps/mach/hurd/bind.c
@@ -48,7 +48,7 @@ __bind (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len)
return -1;
/* Create a new, unlinked node in the target directory. */
- err = __dir_mkfile (dir, O_CREAT, 0666 & ~_hurd_umask, &node);
+ err = __dir_mkfile (dir, O_CREAT, 0666, &node);
if (! err)
{
@@ -76,11 +76,16 @@ __bind (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len)
err = EGRATUITOUS;
if (! err)
{
- /* Link the node, now a socket with proper mode, into the
- target directory. */
- err = __dir_link (dir, node, n, 1);
- if (err == EEXIST)
- err = EADDRINUSE;
+ /* Fix the access mode before showing the file. */
+ err = __file_chmod (node, 0666 & ~_hurd_umask);
+ if (! err)
+ {
+ /* Link the node, now a socket with proper mode, into the
+ target directory. */
+ err = __dir_link (dir, node, n, 1);
+ if (err == EEXIST)
+ err = EADDRINUSE;
+ }
if (err)
__mach_port_deallocate (__mach_task_self (), aport);
}
diff --git a/sysdeps/mach/hurd/bits/errno.h b/sysdeps/mach/hurd/bits/errno.h
index d20ffe654a..c5db66e04e 100644
--- a/sysdeps/mach/hurd/bits/errno.h
+++ b/sysdeps/mach/hurd/bits/errno.h
@@ -222,6 +222,10 @@ enum __error_t_codes
#define ETIME _HURD_ERRNO (117)/* Timer expired */
ECANCELED = _HURD_ERRNO (119),
#define ECANCELED _HURD_ERRNO (119)/* Operation canceled */
+ EOWNERDEAD = _HURD_ERRNO (120),
+#define EOWNERDEAD _HURD_ERRNO (120)/* Robust mutex owner died */
+ ENOTRECOVERABLE = _HURD_ERRNO (121),
+#define ENOTRECOVERABLE _HURD_ERRNO (121)/* Robust mutex irrecoverable */
/* Errors from <mach/message.h>. */
EMACH_SEND_IN_PROGRESS = 0x10000001,
@@ -278,6 +282,8 @@ enum __error_t_codes
EKERN_MEMORY_PRESENT = 23,
EKERN_WRITE_PROTECTION_FAILURE = 24,
EKERN_TERMINATED = 26,
+ EKERN_TIMEDOUT = 27,
+ EKERN_INTERRUPTED = 28,
/* Errors from <mach/mig_errors.h>. */
EMIG_TYPE_ERROR = -300 /* client type check failure */,
@@ -305,7 +311,7 @@ enum __error_t_codes
};
-#define _HURD_ERRNOS 120
+#define _HURD_ERRNOS 122
/* User-visible type of error codes. It is ok to use `int' or
`kern_return_t' for these, but with `error_t' the debugger prints
diff --git a/sysdeps/mach/hurd/bits/fcntl.h b/sysdeps/mach/hurd/bits/fcntl.h
index fbd0b0abae..3f5bb96df9 100644
--- a/sysdeps/mach/hurd/bits/fcntl.h
+++ b/sysdeps/mach/hurd/bits/fcntl.h
@@ -163,9 +163,18 @@
# define F_GETOWN 5 /* Get owner (receiver of SIGIO). */
# define F_SETOWN 6 /* Set owner (receiver of SIGIO). */
#endif
-#define F_GETLK 7 /* Get record locking info. */
-#define F_SETLK 8 /* Set record locking info (non-blocking). */
-#define F_SETLKW 9 /* Set record locking info (blocking). */
+#ifdef __USE_FILE_OFFSET64
+# define F_GETLK F_GETLK64
+# define F_SETLK F_SETLK64
+# define F_SETLKW F_SETLKW64
+#else
+# define F_GETLK 7 /* Get record locking info. */
+# define F_SETLK 8 /* Set record locking info (non-blocking). */
+# define F_SETLKW 9 /* Set record locking info (blocking). */
+#endif
+#define F_GETLK64 10 /* Get record locking info. */
+#define F_SETLK64 11 /* Set record locking info (non-blocking). */
+#define F_SETLKW64 12 /* Set record locking info (blocking). */
#ifdef __USE_XOPEN2K8
# define F_DUPFD_CLOEXEC 1030 /* Duplicate, set FD_CLOEXEC on new one. */
diff --git a/sysdeps/mach/hurd/bits/local_lim.h b/sysdeps/mach/hurd/bits/local_lim.h
index a7760eeb1d..6222374542 100644
--- a/sysdeps/mach/hurd/bits/local_lim.h
+++ b/sysdeps/mach/hurd/bits/local_lim.h
@@ -32,3 +32,12 @@
suitable, and `sysconf' will return a number at least as large. */
#define NGROUPS_MAX 256
+
+/* The number of data keys per process. */
+#define _POSIX_THREAD_KEYS_MAX 128
+
+/* Controlling the iterations of destructors for thread-specific data. */
+#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
+
+/* The number of threads per process. */
+#define _POSIX_THREAD_THREADS_MAX 64
diff --git a/sysdeps/mach/hurd/bits/posix_opt.h b/sysdeps/mach/hurd/bits/posix_opt.h
index 5a578f0c1f..c4631e04f1 100644
--- a/sysdeps/mach/hurd/bits/posix_opt.h
+++ b/sysdeps/mach/hurd/bits/posix_opt.h
@@ -68,27 +68,41 @@
/* X/Open thread realtime support is not supported. */
#undef _XOPEN_REALTIME_THREADS
-/* XPG4.2 shared memory is not supported. */
-#undef _XOPEN_SHM
+/* XPG4.2 shared memory is supported. */
+#define _XOPEN_SHM 1
-/* We do not have the POSIX threads interface. */
-#define _POSIX_THREADS -1
+/* Tell we have POSIX threads. */
+#define _POSIX_THREADS 200112L
/* We have the reentrant functions described in POSIX. */
#define _POSIX_REENTRANT_FUNCTIONS 1
#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L
-/* These are all things that won't be supported when _POSIX_THREADS is not. */
+/* We do not provide priority scheduling for threads. */
#define _POSIX_THREAD_PRIORITY_SCHEDULING -1
-#define _POSIX_THREAD_ATTR_STACKSIZE -1
-#define _POSIX_THREAD_ATTR_STACKADDR -1
+
+/* We support user-defined stack sizes. */
+#define _POSIX_THREAD_ATTR_STACKSIZE 200112L
+
+/* We support user-defined stacks. */
+#define _POSIX_THREAD_ATTR_STACKADDR 200112L
+
+/* We do not support priority inheritence. */
#define _POSIX_THREAD_PRIO_INHERIT -1
+
+/* We do not support priority protection. */
#define _POSIX_THREAD_PRIO_PROTECT -1
+
#ifdef __USE_XOPEN2K8
+/* We do not support priority inheritence for robust mutexes. */
# define _POSIX_THREAD_ROBUST_PRIO_INHERIT -1
+
+/* We do not support priority protection for robust mutexes. */
# define _POSIX_THREAD_ROBUST_PRIO_PROTECT -1
#endif
-#define _POSIX_SEMAPHORES -1
+
+/* We support POSIX.1b semaphores. */
+#define _POSIX_SEMAPHORES 200112L
/* Real-time signals are not yet supported. */
#define _POSIX_REALTIME_SIGNALS -1
@@ -121,17 +135,17 @@
/* GNU libc provides regular expression handling. */
#define _POSIX_REGEXP 1
-/* Reader/Writer locks are not available. */
-#define _POSIX_READER_WRITER_LOCKS -1
+/* Reader/Writer locks are available. */
+#define _POSIX_READER_WRITER_LOCKS 200112L
/* We have a POSIX shell. */
#define _POSIX_SHELL 1
-/* We cannot support the Timeouts option without _POSIX_THREADS. */
-#define _POSIX_TIMEOUTS -1
+/* We support the Timeouts option. */
+#define _POSIX_TIMEOUTS 200112L
-/* We do not support spinlocks. */
-#define _POSIX_SPIN_LOCKS -1
+/* We support spinlocks. */
+#define _POSIX_SPIN_LOCKS 200112L
/* The `spawn' function family is supported. */
#define _POSIX_SPAWN 200809L
@@ -139,8 +153,8 @@
/* We do not have POSIX timers, but could in future without ABI change. */
#define _POSIX_TIMERS 0
-/* The barrier functions are not available. */
-#define _POSIX_BARRIERS -1
+/* We support barrier functions. */
+#define _POSIX_BARRIERS 200112L
/* POSIX message queues could be available in future. */
#define _POSIX_MESSAGE_PASSING 0
diff --git a/sysdeps/mach/hurd/bits/sigaction.h b/sysdeps/mach/hurd/bits/sigaction.h
new file mode 100644
index 0000000000..7204fc6b86
--- /dev/null
+++ b/sysdeps/mach/hurd/bits/sigaction.h
@@ -0,0 +1,81 @@
+/* Copyright (C) 1991-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SIGNAL_H
+# error "Never include <bits/sigaction.h> directly; use <signal.h> instead."
+#endif
+
+/* These definitions match those used by the 4.4 BSD kernel.
+ If the operating system has a `sigaction' system call that correctly
+ implements the POSIX.1 behavior, there should be a system-dependent
+ version of this file that defines `struct sigaction' and the `SA_*'
+ constants appropriately. */
+
+/* Structure describing the action to be taken when a signal arrives. */
+struct sigaction
+ {
+ /* Signal handler. */
+#ifdef __USE_POSIX199309
+ union
+ {
+ /* Used if SA_SIGINFO is not set. */
+ __sighandler_t sa_handler;
+ /* Used if SA_SIGINFO is set. */
+ void (*sa_sigaction) (int, siginfo_t *, void *);
+ }
+ __sigaction_handler;
+# define sa_handler __sigaction_handler.sa_handler
+# define sa_sigaction __sigaction_handler.sa_sigaction
+#else
+ __sighandler_t sa_handler;
+#endif
+
+ /* Additional set of signals to be blocked. */
+ __sigset_t sa_mask;
+
+ /* Special flags. */
+ int sa_flags;
+ };
+
+/* Bits in `sa_flags'. */
+#if defined __USE_UNIX98 || defined __USE_MISC
+# define SA_ONSTACK 0x0001 /* Take signal on signal stack. */
+#endif
+#if defined __USE_UNIX98 || defined __USE_MISC || defined __USE_XOPEN2K8
+# define SA_RESTART 0x0002 /* Restart syscall on signal return. */
+# define SA_NODEFER 0x0010 /* Don't automatically block the signal when
+ its handler is being executed. */
+# define SA_RESETHAND 0x0004 /* Reset to SIG_DFL on entry to handler. */
+# define SA_SIGINFO 0x0040 /* Signal handler with SA_SIGINFO args */
+#endif
+#define SA_NOCLDSTOP 0x0008 /* Don't send SIGCHLD when children stop. */
+
+#ifdef __USE_MISC
+# define SA_INTERRUPT 0 /* Historical no-op ("not SA_RESTART"). */
+
+/* Some aliases for the SA_ constants. */
+# define SA_NOMASK SA_NODEFER
+# define SA_ONESHOT SA_RESETHAND
+# define SA_STACK SA_ONSTACK
+#endif
+
+
+/* Values for the HOW argument to `sigprocmask'. */
+#define SIG_BLOCK 1 /* Block signals. */
+#define SIG_UNBLOCK 2 /* Unblock signals. */
+#define SIG_SETMASK 3 /* Set the set of blocked signals. */
diff --git a/sysdeps/mach/hurd/brk.c b/sysdeps/mach/hurd/brk.c
index 972d6a9791..8d4307f9b7 100644
--- a/sysdeps/mach/hurd/brk.c
+++ b/sysdeps/mach/hurd/brk.c
@@ -143,8 +143,12 @@ init_brk (void)
/* If _hurd_brk is already set, don't change it. The assumption is that
it was set in a previous run before something like Emacs's unexec was
called and dumped all the data up to the break at that point. */
- if (_hurd_brk == 0)
+ if (_hurd_brk == 0) {
_hurd_brk = (vm_address_t) &_end;
+ if (_hurd_brk < 0x8000000)
+ /* XXX: PIE case, get out of library area */
+ _hurd_brk = 0x8000000;
+ }
pagend = round_page (_hurd_brk);
diff --git a/sysdeps/mach/hurd/cthreads.c b/sysdeps/mach/hurd/cthreads.c
index ca1cc0dd91..f223e00b12 100644
--- a/sysdeps/mach/hurd/cthreads.c
+++ b/sysdeps/mach/hurd/cthreads.c
@@ -19,6 +19,8 @@
#include <errno.h>
#include <stdlib.h>
+char __libc_lock_self0[0];
+
/* Placeholder for key creation routine from Hurd cthreads library. */
int
weak_function
diff --git a/sysdeps/mach/hurd/dl-fcntl.h b/sysdeps/mach/hurd/dl-fcntl.h
new file mode 100644
index 0000000000..c34bf12eb1
--- /dev/null
+++ b/sysdeps/mach/hurd/dl-fcntl.h
@@ -0,0 +1,22 @@
+/* Functions with hidden attribute internal to ld.so, which are declared
+ in include/fcntl.h. Hurd version.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* __open can't be hidden in ld.so on Hurd since it will be preempted by the
+ one in libc.so after bootstrap. */
+extern __typeof (__fcntl) __fcntl attribute_hidden;
diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index 76140cf093..c43e0c6ba1 100644
--- a/sysdeps/mach/hurd/dl-sysdep.c
+++ b/sysdeps/mach/hurd/dl-sysdep.c
@@ -62,28 +62,11 @@ rtld_hidden_data_def(__libc_stack_end)
hp_timing_t _dl_cpuclock_offset;
#endif
+/* TODO: this is never properly initialized in here. */
+void *_dl_random attribute_relro = NULL;
struct hurd_startup_data *_dl_hurd_data;
-/* This is used only within ld.so, via dl-minimal.c's __errno_location. */
-#undef errno
-int errno attribute_hidden;
-
-/* Defining these variables here avoids the inclusion of hurdsig.c. */
-unsigned long int __hurd_sigthread_stack_base;
-unsigned long int __hurd_sigthread_stack_end;
-unsigned long int *__hurd_sigthread_variables;
-
-/* Defining these variables here avoids the inclusion of init-first.c.
- We need to provide temporary storage for the per-thread variables
- of the main user thread here, since it is used for storing the
- `errno' variable. Note that this information is lost once we
- relocate the dynamic linker. */
-static unsigned long int threadvars[_HURD_THREADVAR_MAX];
-unsigned long int __hurd_threadvar_stack_offset
- = (unsigned long int) &threadvars;
-unsigned long int __hurd_threadvar_stack_mask;
-
#define FMH defined(__i386__)
#if ! FMH
# define fmh() ((void)0)
@@ -105,12 +88,28 @@ static void fmh(void) {
max=a; break;}
fmha=a+=fmhs;}
if (err) assert(err==KERN_NO_SPACE);
- if (!fmha)fmhs=0;else{
- fmhs=max-fmha;
- err = __vm_map (__mach_task_self (),
- &fmha, fmhs, 0, 0, MACH_PORT_NULL, 0, 1,
- VM_PROT_NONE, VM_PROT_NONE, VM_INHERIT_COPY);
- assert_perror(err);}
+ if (!fmha)
+ fmhs=0;
+ else
+ while (1) {
+ fmhs=max-fmha;
+ if (fmhs == 0)
+ break;
+ err = __vm_map (__mach_task_self (),
+ &fmha, fmhs, 0, 0, MACH_PORT_NULL, 0, 1,
+ VM_PROT_NONE, VM_PROT_NONE, VM_INHERIT_COPY);
+ if (!err)
+ break;
+ if (err != KERN_INVALID_ADDRESS && err != KERN_NO_SPACE)
+ assert_perror(err);
+ vm_address_t new_max = (max - 1) & 0xf0000000U;
+ if (new_max >= max) {
+ fmhs = 0;
+ fmha = 0;
+ break;
+ }
+ max = new_max;
+ }
}
/* XXX loser kludge for vm_map kernel bug */
#endif
diff --git a/sysdeps/mach/hurd/errno-loc.c b/sysdeps/mach/hurd/errno-loc.c
index 4dca6ddca7..7709cc98ca 100644
--- a/sysdeps/mach/hurd/errno-loc.c
+++ b/sysdeps/mach/hurd/errno-loc.c
@@ -16,13 +16,21 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <errno.h>
-#include <hurd/threadvar.h>
-
-int *
+#if IS_IN (rtld)
+/*
+ * rtld can not access TLS too early, thus rtld_errno.
+ *
+ * Instead of making __open/__close pass errno from TLS to rtld_errno, simply
+ * use a weak __errno_location using rtld_errno, which will be overriden by the
+ * libc definition.
+ */
+static int rtld_errno;
+int * weak_function
__errno_location (void)
{
- return (int *) __hurd_threadvar_location (_HURD_THREADVAR_ERRNO);
+ return &rtld_errno;
}
-strong_alias (__errno_location, __hurd_errno_location)
-libc_hidden_def (__errno_location)
+libc_hidden_weak (__errno_location)
+#else
+#include <../../../csu/errno-loc.c>
+#endif
diff --git a/sysdeps/mach/hurd/errno.c b/sysdeps/mach/hurd/errno.c
deleted file mode 100644
index a29091b5e2..0000000000
--- a/sysdeps/mach/hurd/errno.c
+++ /dev/null
@@ -1 +0,0 @@
-/* No definition of `errno' variable on the Hurd. */
diff --git a/sysdeps/mach/hurd/euidaccess.c b/sysdeps/mach/hurd/euidaccess.c
index ee512ff5e3..4949aa9365 100644
--- a/sysdeps/mach/hurd/euidaccess.c
+++ b/sysdeps/mach/hurd/euidaccess.c
@@ -16,42 +16,13 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <errno.h>
-#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>
-#include <hurd.h>
int
__euidaccess (const char *file, int type)
{
- error_t err;
- file_t port;
- int allowed, flags;
-
- port = __file_name_lookup (file, 0, 0);
- if (port == MACH_PORT_NULL)
- return -1;
-
- /* Find out what types of access we are allowed to this file. */
- err = __file_check_access (port, &allowed);
- __mach_port_deallocate (__mach_task_self (), port);
- if (err)
- return __hurd_fail (err);
-
- flags = 0;
- if (type & R_OK)
- flags |= O_READ;
- if (type & W_OK)
- flags |= O_WRITE;
- if (type & X_OK)
- flags |= O_EXEC;
-
- if (flags & ~allowed)
- /* We are not allowed all the requested types of access. */
- return __hurd_fail (EACCES);
-
- return 0;
+ return __faccessat (AT_FDCWD, file, type, AT_EACCESS);
}
weak_alias (__euidaccess, euidaccess)
weak_alias (__euidaccess, eaccess)
diff --git a/sysdeps/mach/hurd/f_setlk.c b/sysdeps/mach/hurd/f_setlk.c
new file mode 100644
index 0000000000..6e1b308756
--- /dev/null
+++ b/sysdeps/mach/hurd/f_setlk.c
@@ -0,0 +1,68 @@
+/* Copyright (C) 2014-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sys/types.h>
+#include <sys/file.h>
+#include <fcntl.h>
+#include <errno.h>
+
+/* XXX
+ We need new RPCs to support POSIX.1 fcntl file locking!!
+ For the time being we support the whole-file case only,
+ with all kinds of WRONG WRONG WRONG semantics,
+ by using flock. This is definitely the Wrong Thing,
+ but it might be better than nothing (?). */
+int
+__f_setlk (int fd, int type, int whence, __off64_t start, __off64_t len, int wait)
+{
+ int cmd = 0;
+
+ switch (type)
+ {
+ case F_RDLCK: cmd |= LOCK_SH | __LOCK_ATOMIC; break;
+ case F_WRLCK: cmd |= LOCK_EX | __LOCK_ATOMIC; break;
+ case F_UNLCK: cmd = LOCK_UN; break;
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (wait == 0)
+ cmd |= LOCK_NB;
+
+ switch (whence)
+ {
+ case SEEK_SET:
+ if (start == 0 && len == 0) /* Whole file request. */
+ break;
+ /* It seems to be common for applications to lock the first
+ byte of the file when they are really doing whole-file locking.
+ So, since it's so wrong already, might as well do that too. */
+ if (start == 0 && len == 1)
+ break;
+ /* FALLTHROUGH */
+ case SEEK_CUR:
+ case SEEK_END:
+ errno = ENOTSUP;
+ return -1;
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+
+ return __flock (fd, cmd);
+}
diff --git a/sysdeps/mach/hurd/faccessat.c b/sysdeps/mach/hurd/faccessat.c
index 0a57ab627c..7eda601509 100644
--- a/sysdeps/mach/hurd/faccessat.c
+++ b/sysdeps/mach/hurd/faccessat.c
@@ -23,29 +23,153 @@
#include <sys/types.h>
#include <hurd.h>
#include <hurd/fd.h>
+#include <hurd/port.h>
+#include <hurd/id.h>
+#include <hurd/lookup.h>
int
-faccessat (int fd, const char *file, int type, int flag)
+__faccessat (int fd, const char *file, int type, int at_flags)
{
error_t err;
- file_t port;
- int allowed, flags;
+ file_t rcrdir, rcwdir, io;
+ int flags, allowed;
- if ((flag & AT_EACCESS) == 0)
+ if ((at_flags & AT_EACCESS) == AT_EACCESS)
{
- if (fd == AT_FDCWD || file[0] == '/')
- return __access (file, type);
- __set_errno (ENOTSUP); /* XXX later */
- return -1;
+ /* Use effective permissions. */
+ io = __file_name_lookup_at (fd, at_flags &~ AT_EACCESS, file, 0, 0);
+ if (io == MACH_PORT_NULL)
+ return -1;
}
+ else
+ {
+ /* We have to use real permissions instead of the
+ usual effective permissions. */
+
+ int hurd_flags = 0;
+ __hurd_at_flags (&at_flags, &hurd_flags);
+
+ error_t reauthenticate_cwdir_at (file_t *result)
+ {
+ /* Get a port to the FD directory, authenticated with the real IDs. */
+ error_t err;
+ mach_port_t ref;
+ ref = __mach_reply_port ();
+ err = HURD_DPORT_USE
+ (fd,
+ ({
+ err = __io_reauthenticate (port, ref, MACH_MSG_TYPE_MAKE_SEND);
+ if (!err)
+ err = __auth_user_authenticate (_hurd_id.rid_auth,
+ ref, MACH_MSG_TYPE_MAKE_SEND,
+ result);
+ err;
+ }));
+ __mach_port_destroy (__mach_task_self (), ref);
+ return err;
+ }
+
+ error_t reauthenticate (int which, file_t *result)
+ {
+ /* Get a port to our root directory, authenticated with the real IDs. */
+ error_t err;
+ mach_port_t ref;
+ ref = __mach_reply_port ();
+ err = HURD_PORT_USE
+ (&_hurd_ports[which],
+ ({
+ err = __io_reauthenticate (port, ref, MACH_MSG_TYPE_MAKE_SEND);
+ if (!err)
+ err = __auth_user_authenticate (_hurd_id.rid_auth,
+ ref, MACH_MSG_TYPE_MAKE_SEND,
+ result);
+ err;
+ }));
+ __mach_port_destroy (__mach_task_self (), ref);
+ return err;
+ }
+
+ error_t init_port (int which, error_t (*operate) (mach_port_t))
+ {
+ switch (which)
+ {
+ case INIT_PORT_AUTH:
+ return (*operate) (_hurd_id.rid_auth);
+ case INIT_PORT_CRDIR:
+ return (reauthenticate (INIT_PORT_CRDIR, &rcrdir) ?:
+ (*operate) (rcrdir));
+ case INIT_PORT_CWDIR:
+ if (fd == AT_FDCWD || file[0] == '/')
+ return (reauthenticate (INIT_PORT_CWDIR, &rcwdir) ?:
+ (*operate) (rcwdir));
+ else
+ return (reauthenticate_cwdir_at (&rcwdir) ?:
+ (*operate) (rcwdir));
+ default:
+ return _hurd_ports_use (which, operate);
+ }
+ }
+
+ rcrdir = rcwdir = MACH_PORT_NULL;
+
+ HURD_CRITICAL_BEGIN;
+
+ __mutex_lock (&_hurd_id.lock);
+ /* Get _hurd_id up to date. */
+ if (err = _hurd_check_ids ())
+ goto lose;
- port = __file_name_lookup_at (fd, flag &~ AT_EACCESS, file, 0, 0);
- if (port == MACH_PORT_NULL)
- return -1;
+ if (_hurd_id.rid_auth == MACH_PORT_NULL)
+ {
+ /* Set up _hurd_id.rid_auth. This is a special auth server port
+ which uses the real uid and gid (the first aux uid and gid) as
+ the only effective uid and gid. */
+
+ if (_hurd_id.aux.nuids < 1 || _hurd_id.aux.ngids < 1)
+ {
+ /* We do not have a real UID and GID. Lose, lose, lose! */
+ err = EGRATUITOUS;
+ goto lose;
+ }
+
+ /* Create a new auth port using our real UID and GID (the first
+ auxiliary UID and GID) as the only effective IDs. */
+ if (err = __USEPORT (AUTH,
+ __auth_makeauth (port,
+ NULL, MACH_MSG_TYPE_COPY_SEND, 0,
+ _hurd_id.aux.uids, 1,
+ _hurd_id.aux.uids,
+ _hurd_id.aux.nuids,
+ _hurd_id.aux.gids, 1,
+ _hurd_id.aux.gids,
+ _hurd_id.aux.ngids,
+ &_hurd_id.rid_auth)))
+ goto lose;
+ }
+
+ if (!err)
+ /* Look up the file name using the modified init ports. */
+ err = __hurd_file_name_lookup (&init_port, &__getdport, 0,
+ file, hurd_flags, 0, &io);
+
+ /* We are done with _hurd_id.rid_auth now. */
+ lose:
+ __mutex_unlock (&_hurd_id.lock);
+
+ HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
+
+ if (rcrdir != MACH_PORT_NULL)
+ __mach_port_deallocate (__mach_task_self (), rcrdir);
+ if (rcwdir != MACH_PORT_NULL)
+ __mach_port_deallocate (__mach_task_self (), rcwdir);
+ if (err)
+ return __hurd_fail (err);
+ }
/* Find out what types of access we are allowed to this file. */
- err = __file_check_access (port, &allowed);
- __mach_port_deallocate (__mach_task_self (), port);
+ err = __file_check_access (io, &allowed);
+ __mach_port_deallocate (__mach_task_self (), io);
if (err)
return __hurd_fail (err);
@@ -63,3 +187,4 @@ faccessat (int fd, const char *file, int type, int flag)
return 0;
}
+weak_alias (__faccessat, faccessat)
diff --git a/sysdeps/mach/hurd/fcntl.c b/sysdeps/mach/hurd/fcntl.c
index 2898ebbb14..075b00f7b8 100644
--- a/sysdeps/mach/hurd/fcntl.c
+++ b/sysdeps/mach/hurd/fcntl.c
@@ -21,6 +21,7 @@
#include <hurd/fd.h>
#include <stdarg.h>
#include <sys/file.h> /* XXX for LOCK_* */
+#include "f_setlk.h"
/* Perform file control operations on FD. */
int
@@ -128,56 +129,48 @@ __libc_fcntl (int fd, int cmd, ...)
case F_SETLK:
case F_SETLKW:
{
- /* XXX
- We need new RPCs to support POSIX.1 fcntl file locking!!
- For the time being we support the whole-file case only,
- with all kinds of WRONG WRONG WRONG semantics,
- by using flock. This is definitely the Wrong Thing,
- but it might be better than nothing (?). */
struct flock *fl = va_arg (ap, struct flock *);
+ int wait = 0;
va_end (ap);
switch (cmd)
{
case F_GETLK:
errno = ENOSYS;
return -1;
+ case F_SETLKW:
+ wait = 1;
+ /* FALLTHROUGH */
case F_SETLK:
- cmd = LOCK_NB;
- break;
- default:
- cmd = 0;
- break;
- }
- switch (fl->l_type)
- {
- case F_RDLCK: cmd |= LOCK_SH; break;
- case F_WRLCK: cmd |= LOCK_EX; break;
- case F_UNLCK: cmd |= LOCK_UN; break;
+ return __f_setlk (fd, fl->l_type, fl->l_whence,
+ fl->l_start, fl->l_len, wait);
default:
errno = EINVAL;
return -1;
}
- switch (fl->l_whence)
+ }
+
+ case F_GETLK64:
+ case F_SETLK64:
+ case F_SETLKW64:
+ {
+ struct flock64 *fl = va_arg (ap, struct flock64 *);
+ int wait = 0;
+ va_end (ap);
+ switch (cmd)
{
- case SEEK_SET:
- if (fl->l_start == 0 && fl->l_len == 0) /* Whole file request. */
- break;
- /* It seems to be common for applications to lock the first
- byte of the file when they are really doing whole-file locking.
- So, since it's so wrong already, might as well do that too. */
- if (fl->l_start == 0 && fl->l_len == 1)
- break;
- /* FALLTHROUGH */
- case SEEK_CUR:
- case SEEK_END:
- errno = ENOTSUP;
+ case F_GETLK64:
+ errno = ENOSYS;
return -1;
+ case F_SETLKW64:
+ wait = 1;
+ /* FALLTHROUGH */
+ case F_SETLK64:
+ return __f_setlk (fd, fl->l_type, fl->l_whence,
+ fl->l_start, fl->l_len, wait);
default:
errno = EINVAL;
return -1;
}
-
- return __flock (fd, cmd);
}
case F_GETFL: /* Get per-open flags. */
diff --git a/sysdeps/mach/hurd/fork.c b/sysdeps/mach/hurd/fork.c
index ad09fd7c41..816d893373 100644
--- a/sysdeps/mach/hurd/fork.c
+++ b/sysdeps/mach/hurd/fork.c
@@ -19,6 +19,7 @@
#include <unistd.h>
#include <hurd.h>
#include <hurd/signal.h>
+#include <hurd/threadvar.h>
#include <setjmp.h>
#include <thread_state.h>
#include <sysdep.h> /* For stack growth direction. */
@@ -117,6 +118,12 @@ __fork (void)
}
__mutex_lock (&_hurd_siglock);
+ /* Acquire malloc locks. This needs to come last because fork
+ handlers may use malloc, and the libio list lock has an
+ indirect malloc dependency as well (via the getdelim
+ function). */
+ _hurd_malloc_fork_prepare ();
+
newtask = MACH_PORT_NULL;
thread = sigthread = MACH_PORT_NULL;
newproc = MACH_PORT_NULL;
@@ -464,6 +471,7 @@ __fork (void)
(err = __mach_port_insert_right (newtask, ss->thread,
thread, MACH_MSG_TYPE_COPY_SEND)))
LOSE;
+ /* XXX consumed? (_hurd_sigthread is no more) */
if (thread_refs > 1 &&
(err = __mach_port_mod_refs (newtask, ss->thread,
MACH_PORT_RIGHT_SEND,
@@ -504,19 +512,17 @@ __fork (void)
(natural_t *) &state, &statecount))
LOSE;
#ifdef STACK_GROWTH_UP
-#define THREADVAR_SPACE (__hurd_threadvar_max \
- * sizeof *__hurd_sightread_variables)
if (__hurd_sigthread_stack_base == 0)
{
state.SP &= __hurd_threadvar_stack_mask;
- state.SP += __hurd_threadvar_stack_offset + THREADVAR_SPACE;
+ state.SP += __hurd_threadvar_stack_offset;
}
else
state.SP = __hurd_sigthread_stack_base;
#else
if (__hurd_sigthread_stack_end == 0)
{
- /* The signal thread has a normal stack assigned by cthreads.
+ /* The signal thread has a stack assigned by cthreads.
The threadvar_stack variables conveniently tell us how
to get to the highest address in the stack, just below
the per-thread variables. */
@@ -528,6 +534,11 @@ __fork (void)
#endif
MACHINE_THREAD_STATE_SET_PC (&state,
(unsigned long int) _hurd_msgport_receive);
+
+ /* Do special thread setup for TLS if needed. */
+ if (err = _hurd_tls_fork (sigthread, _hurd_msgport_thread, &state))
+ LOSE;
+
if (err = __thread_set_state (sigthread, MACHINE_THREAD_STATE_FLAVOR,
(natural_t *) &state, statecount))
LOSE;
@@ -538,7 +549,7 @@ __fork (void)
_hurd_longjmp_thread_state (&state, env, 1);
/* Do special thread setup for TLS if needed. */
- if (err = _hurd_tls_fork (thread, &state))
+ if (err = _hurd_tls_fork (thread, ss->thread, &state))
LOSE;
if (err = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
@@ -604,6 +615,9 @@ __fork (void)
nthreads * sizeof (*threads));
}
+ /* Release malloc locks. */
+ _hurd_malloc_fork_parent ();
+
/* Run things that want to run in the parent to restore it to
normality. Usually prepare hooks and parent hooks are
symmetrical: the prepare hook arrests state in some way for the
@@ -621,10 +635,6 @@ __fork (void)
for (i = 0; i < _hurd_nports; ++i)
__spin_unlock (&_hurd_ports[i].lock);
- /* We are one of the (exactly) two threads in this new task, we
- will take the task-global signals. */
- _hurd_sigthread = ss->thread;
-
/* Claim our sigstate structure and unchain the rest: the
threads existed in the parent task but don't exist in this
task (the child process). Delay freeing them until later
@@ -644,6 +654,25 @@ __fork (void)
ss->next = NULL;
_hurd_sigstates = ss;
__mutex_unlock (&_hurd_siglock);
+ /* Earlier on, the global sigstate may have been tainted and now needs to
+ be reinitialized. Nobody is interested in its present state anymore:
+ we're not, the signal thread will be restarted, and there are no other
+ threads.
+
+ We can't simply allocate a fresh global sigstate here, as
+ _hurd_thread_sigstate will call malloc and that will deadlock trying
+ to determine the current thread's sigstate. */
+#if 0
+ _hurd_thread_sigstate_init (_hurd_global_sigstate, MACH_PORT_NULL);
+#else
+ /* Only reinitialize the lock -- otherwise we might have to do additional
+ setup as done in hurdsig.c:_hurdsig_init. */
+ __spin_lock_init (&_hurd_global_sigstate->lock);
+#endif
+
+ /* We are one of the (exactly) two threads in this new task, we
+ will take the task-global signals. */
+ _hurd_sigstate_set_global_rcv (ss);
/* Fetch our new process IDs from the proc server. No need to
refetch our pgrp; it is always inherited from the parent (so
@@ -652,8 +681,13 @@ __fork (void)
err = __USEPORT (PROC, __proc_getpids (port, &_hurd_pid, &_hurd_ppid,
&_hurd_orphaned));
- /* Forking clears the trace flag. */
+ /* Forking clears the trace flag and pending masks. */
__sigemptyset (&_hurdsig_traced);
+ __sigemptyset (&_hurd_global_sigstate->pending);
+ __sigemptyset (&ss->pending);
+
+ /* Release malloc locks. */
+ _hurd_malloc_fork_child ();
/* Run things that want to run in the child task to set up. */
RUN_HOOK (_hurd_fork_child_hook, ());
@@ -701,6 +735,7 @@ __fork (void)
}
_hurd_critical_section_unlock (ss);
+ /* FIXME: handle EINTR */
if (!err)
{
diff --git a/sysdeps/mach/hurd/ftok.c b/sysdeps/mach/hurd/ftok.c
new file mode 100644
index 0000000000..ddd69b0dac
--- /dev/null
+++ b/sysdeps/mach/hurd/ftok.c
@@ -0,0 +1,41 @@
+/* SysV ftok for Hurd.
+ Copyright (C) 1995-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sys/ipc.h>
+#include <sys/stat.h>
+
+
+/* In the Hurd, we use the second-to-most-significant bit as flag for
+ private keys. We use an order of the components different from the generic
+ code in sysvipc/ftok.c so that the biggest one--the inode number--is
+ affected by this. */
+
+key_t
+ftok (const char *pathname, int proj_id)
+{
+ struct stat64 st;
+ key_t key;
+
+ if (__xstat64 (_STAT_VER, pathname, &st) < 0)
+ return (key_t) -1;
+
+ key = ((st.st_dev & 0xff) | ((proj_id & 0xff) << 8)
+ | ((st.st_ino & 0x3fff) << 16));
+
+ return key;
+}
diff --git a/sysdeps/mach/hurd/futimens.c b/sysdeps/mach/hurd/futimens.c
new file mode 100644
index 0000000000..4f82f1e76b
--- /dev/null
+++ b/sysdeps/mach/hurd/futimens.c
@@ -0,0 +1,50 @@
+/* futimes -- change access and modification times of open file. Hurd version.
+ Copyright (C) 2002-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sys/time.h>
+#include <errno.h>
+#include <stddef.h>
+#include <hurd.h>
+#include <hurd/fd.h>
+
+/* Change the access time of FD to TSP[0] and
+ the modification time of FD to TSP[1]. */
+int
+__futimens (int fd, const struct timespec tsp[2])
+{
+ time_value_t atime, mtime;
+ error_t err;
+
+ if (tsp == NULL)
+ {
+ /* Setting the number of microseconds to `-1' tells the
+ underlying filesystems to use the current time. */
+ atime.microseconds = mtime.microseconds = -1;
+ }
+ else
+ {
+ atime.seconds = tsp[0].tv_sec;
+ atime.microseconds = tsp[0].tv_nsec / 1000;
+ mtime.seconds = tsp[1].tv_sec;
+ mtime.microseconds = tsp[1].tv_nsec / 1000;
+ }
+
+ err = HURD_DPORT_USE (fd, __file_utimes (port, atime, mtime));
+ return err ? __hurd_dfail (fd, err) : 0;
+}
+weak_alias (__futimens, futimens)
diff --git a/sysdeps/mach/hurd/gai_misc.h b/sysdeps/mach/hurd/gai_misc.h
new file mode 100644
index 0000000000..ee8117fa96
--- /dev/null
+++ b/sysdeps/mach/hurd/gai_misc.h
@@ -0,0 +1,44 @@
+#include <signal.h>
+#include <pthread.h>
+
+#define gai_start_notify_thread __gai_start_notify_thread
+#define gai_create_helper_thread __gai_create_helper_thread
+
+extern inline void
+__gai_start_notify_thread (void)
+{
+ sigset_t ss;
+ sigemptyset (&ss);
+ sigprocmask(SIG_SETMASK, &ss, NULL);
+}
+
+extern inline int
+__gai_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
+ void *arg)
+{
+ pthread_attr_t attr;
+
+ /* Make sure the thread is created detached. */
+ pthread_attr_init (&attr);
+ pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+
+ /* The helper thread needs only very little resources. */
+ (void) pthread_attr_setstacksize (&attr, 0x10000);
+
+ /* Block all signals in the helper thread. To do this thoroughly we
+ temporarily have to block all signals here. */
+ sigset_t ss;
+ sigset_t oss;
+ sigfillset (&ss);
+ sigprocmask(SIG_SETMASK, &ss, &oss);
+
+ int ret = pthread_create (threadp, &attr, tf, arg);
+
+ /* Restore the signal mask. */
+ sigprocmask(SIG_SETMASK, &oss, NULL);
+
+ (void) pthread_attr_destroy (&attr);
+ return ret;
+}
+
+#include_next <gai_misc.h>
diff --git a/sysdeps/mach/hurd/getcwd.c b/sysdeps/mach/hurd/getcwd.c
index a757dab965..d7827589d0 100644
--- a/sysdeps/mach/hurd/getcwd.c
+++ b/sysdeps/mach/hurd/getcwd.c
@@ -266,11 +266,6 @@ _hurd_canonicalize_directory_name_internal (file_t thisdir,
So the root is our current directory. */
*--file_namep = '/';
- if (thisid != rootid)
- /* We did not get to our root directory. The returned name should
- not begin with a slash. */
- ++file_namep;
-
memmove (file_name, file_namep, file_name + size - file_namep);
cleanup ();
return file_name;
@@ -308,13 +303,6 @@ __getcwd (char *buf, size_t size)
__USEPORT (CWDIR,
_hurd_canonicalize_directory_name_internal (port,
buf, size));
- if (cwd && cwd[0] != '/')
- {
- /* `cwd' is an unknown root directory. */
- if (buf == NULL)
- free (cwd);
- return __hurd_fail (EGRATUITOUS), NULL;
- }
return cwd;
}
weak_alias (__getcwd, getcwd)
diff --git a/sysdeps/mach/hurd/hp-timing.h b/sysdeps/mach/hurd/hp-timing.h
new file mode 100644
index 0000000000..1246e21958
--- /dev/null
+++ b/sysdeps/mach/hurd/hp-timing.h
@@ -0,0 +1,42 @@
+/* High precision, low overhead timing functions. Generic version.
+ Copyright (C) 1998-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _HP_TIMING_H
+#define _HP_TIMING_H 1
+
+/* We don't have support for high precision timing for now. */
+
+/* Provide dummy definitions. */
+#define HP_TIMING_AVAIL (0)
+#define HP_SMALL_TIMING_AVAIL (0)
+#define HP_TIMING_INLINE (0)
+typedef int hp_timing_t;
+#define HP_TIMING_ZERO(Var)
+#define HP_TIMING_NOW(var)
+#define HP_TIMING_DIFF_INIT()
+#define HP_TIMING_DIFF(Diff, Start, End)
+#define HP_TIMING_ACCUM(Sum, Diff)
+#define HP_TIMING_ACCUM_NT(Sum, Diff)
+#define HP_TIMING_PRINT(Buf, Len, Val)
+
+/* Since this implementation is not available we tell the user about it. */
+#define HP_TIMING_NONAVAIL 1
+
+#endif /* hp-timing.h */
diff --git a/sysdeps/mach/hurd/i386/Makefile b/sysdeps/mach/hurd/i386/Makefile
index 5f988097c2..9e1a978b6f 100644
--- a/sysdeps/mach/hurd/i386/Makefile
+++ b/sysdeps/mach/hurd/i386/Makefile
@@ -6,3 +6,8 @@ endif
ifeq ($(subdir),debug)
gen-as-const-headers += signal-defines.sym
endif
+
+ifeq ($(subdir),stdlib)
+gen-as-const-headers += ucontext_i.sym
+sysdep_routines += makecontext-helper
+endif
diff --git a/sysdeps/mach/hurd/i386/____longjmp_chk.S b/sysdeps/mach/hurd/i386/____longjmp_chk.S
index 4ddf6cd82e..dec8ea7778 100644
--- a/sysdeps/mach/hurd/i386/____longjmp_chk.S
+++ b/sysdeps/mach/hurd/i386/____longjmp_chk.S
@@ -66,7 +66,12 @@ ENTRY (____longjmp_chk)
/* TODO: need locking? */
/* struct hurd_sigstate * _hurd_self_sigstate (void) */
- call _hurd_self_sigstate
+#ifdef PIC
+ call 1f
+1: popl %ebx
+ addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
+#endif
+ call JUMPTARGET(_hurd_self_sigstate)
/* TODO: %eax and %eax->sigaltstack are always valid? */
testl $SS_ONSTACK, (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_FLAGS__OFFSET)(%eax)
diff --git a/sysdeps/mach/hurd/i386/bits/sigcontext.h b/sysdeps/mach/hurd/i386/bits/sigcontext.h
index 6d15b039ef..8b8586affe 100644
--- a/sysdeps/mach/hurd/i386/bits/sigcontext.h
+++ b/sysdeps/mach/hurd/i386/bits/sigcontext.h
@@ -95,6 +95,10 @@ struct sigcontext
#define sc_ps sc_efl
+/* The deprecated sigcode values below are passed as an extra, non-portable
+ argument to regular signal handlers. You should use SA_SIGINFO handlers
+ instead, which use the standard POSIX signal codes. */
+
/* Codes for SIGFPE. */
#define FPE_INTOVF_TRAP 0x1 /* integer overflow */
#define FPE_INTDIV_FAULT 0x2 /* integer divide by zero */
diff --git a/sysdeps/mach/hurd/i386/exc2signal.c b/sysdeps/mach/hurd/i386/exc2signal.c
index bf0ca2e367..feb9e2de1c 100644
--- a/sysdeps/mach/hurd/i386/exc2signal.c
+++ b/sysdeps/mach/hurd/i386/exc2signal.c
@@ -23,8 +23,8 @@
/* Translate the Mach exception codes, as received in an `exception_raise' RPC,
into a signal number and signal subcode. */
-void
-_hurd_exception2signal (struct hurd_signal_detail *detail, int *signo)
+static void
+exception2signal (struct hurd_signal_detail *detail, int *signo, int posix)
{
detail->error = 0;
@@ -36,44 +36,62 @@ _hurd_exception2signal (struct hurd_signal_detail *detail, int *signo)
break;
case EXC_BAD_ACCESS:
- if (detail->exc_code == KERN_INVALID_ADDRESS
- || detail->exc_code == KERN_PROTECTION_FAILURE
- || detail->exc_code == KERN_WRITE_PROTECTION_FAILURE)
- *signo = SIGSEGV;
- else
- *signo = SIGBUS;
- detail->code = detail->exc_subcode;
+ switch (detail->exc_code)
+ {
+ case KERN_INVALID_ADDRESS:
+ case KERN_MEMORY_FAILURE:
+ *signo = SIGSEGV;
+ detail->code = posix ? SEGV_MAPERR : detail->exc_subcode;
+ break;
+
+ case KERN_PROTECTION_FAILURE:
+ case KERN_WRITE_PROTECTION_FAILURE:
+ *signo = SIGSEGV;
+ detail->code = posix ? SEGV_ACCERR : detail->exc_subcode;
+ break;
+
+ default:
+ *signo = SIGBUS;
+ detail->code = posix ? BUS_ADRERR : detail->exc_subcode;
+ break;
+ }
detail->error = detail->exc_code;
break;
case EXC_BAD_INSTRUCTION:
*signo = SIGILL;
- if (detail->exc_code == EXC_I386_INVOP)
- detail->code = ILL_INVOPR_FAULT;
- else if (detail->exc_code == EXC_I386_STKFLT)
- detail->code = ILL_STACK_FAULT;
- else
- detail->code = 0;
+ switch (detail->exc_code)
+ {
+ case EXC_I386_INVOP:
+ detail->code = posix ? ILL_ILLOPC : ILL_INVOPR_FAULT;
+ break;
+
+ case EXC_I386_STKFLT:
+ detail->code = posix ? ILL_BADSTK : ILL_STACK_FAULT;
+ break;
+
+ default:
+ detail->code = 0;
+ break;
+ }
break;
case EXC_ARITHMETIC:
+ *signo = SIGFPE;
switch (detail->exc_code)
{
case EXC_I386_DIV: /* integer divide by zero */
- *signo = SIGFPE;
- detail->code = FPE_INTDIV_FAULT;
+ detail->code = posix ? FPE_INTDIV : FPE_INTDIV_FAULT;
break;
case EXC_I386_INTO: /* integer overflow */
- *signo = SIGFPE;
- detail->code = FPE_INTOVF_TRAP;
+ detail->code = posix ? FPE_INTOVF : FPE_INTOVF_TRAP;
break;
/* These aren't anywhere documented or used in Mach 3.0. */
case EXC_I386_NOEXT:
case EXC_I386_EXTOVR:
default:
- *signo = SIGFPE;
detail->code = 0;
break;
@@ -82,51 +100,43 @@ _hurd_exception2signal (struct hurd_signal_detail *detail, int *signo)
Give an error code corresponding to the first bit set. */
if (detail->exc_subcode & FPS_IE)
{
- *signo = SIGILL;
- detail->code = ILL_FPEOPR_FAULT;
+ /* NB: We used to send SIGILL here but we can't distinguish
+ POSIX vs. legacy with respect to what signal we send. */
+ detail->code = posix ? FPE_FLTINV : 0 /*ILL_FPEOPR_FAULT*/;
}
else if (detail->exc_subcode & FPS_DE)
{
- *signo = SIGFPE;
- detail->code = FPE_FLTDNR_FAULT;
+ detail->code = posix ? FPE_FLTUND : FPE_FLTDNR_FAULT;
}
else if (detail->exc_subcode & FPS_ZE)
{
- *signo = SIGFPE;
- detail->code = FPE_FLTDIV_FAULT;
+ detail->code = posix ? FPE_FLTDIV : FPE_FLTDIV_FAULT;
}
else if (detail->exc_subcode & FPS_OE)
{
- *signo = SIGFPE;
- detail->code = FPE_FLTOVF_FAULT;
+ detail->code = posix ? FPE_FLTOVF : FPE_FLTOVF_FAULT;
}
else if (detail->exc_subcode & FPS_UE)
{
- *signo = SIGFPE;
- detail->code = FPE_FLTUND_FAULT;
+ detail->code = posix ? FPE_FLTUND : FPE_FLTUND_FAULT;
}
else if (detail->exc_subcode & FPS_PE)
{
- *signo = SIGFPE;
- detail->code = FPE_FLTINX_FAULT;
+ detail->code = posix ? FPE_FLTRES : FPE_FLTINX_FAULT;
}
else
{
- *signo = SIGFPE;
detail->code = 0;
}
break;
/* These two can only be arithmetic exceptions if we
- are in V86 mode, which sounds like emulation to me.
- (See Mach 3.0 i386/trap.c.) */
+ are in V86 mode. (See Mach 3.0 i386/trap.c.) */
case EXC_I386_EMERR:
- *signo = SIGFPE;
- detail->code = FPE_EMERR_FAULT;
+ detail->code = posix ? 0 : FPE_EMERR_FAULT;
break;
case EXC_I386_BOUND:
- *signo = SIGFPE;
- detail->code = FPE_EMBND_FAULT;
+ detail->code = posix ? FPE_FLTSUB : FPE_EMBND_FAULT;
break;
}
break;
@@ -143,7 +153,7 @@ _hurd_exception2signal (struct hurd_signal_detail *detail, int *signo)
if (detail->exc_code == EXC_I386_BOUND)
{
*signo = SIGFPE;
- detail->code = FPE_SUBRNG_FAULT;
+ detail->code = posix ? FPE_FLTSUB : FPE_SUBRNG_FAULT;
}
else
{
@@ -154,12 +164,33 @@ _hurd_exception2signal (struct hurd_signal_detail *detail, int *signo)
case EXC_BREAKPOINT:
*signo = SIGTRAP;
- if (detail->exc_code == EXC_I386_SGL)
- detail->code = DBG_SINGLE_TRAP;
- else if (detail->exc_code == EXC_I386_BPT)
- detail->code = DBG_BRKPNT_FAULT;
- else
- detail->code = 0;
+ switch (detail->exc_code)
+ {
+ case EXC_I386_SGL:
+ detail->code = posix ? TRAP_BRKPT : DBG_SINGLE_TRAP;
+ break;
+
+ case EXC_I386_BPT:
+ detail->code = posix ? TRAP_BRKPT : DBG_BRKPNT_FAULT;
+ break;
+
+ default:
+ detail->code = 0;
+ break;
+ }
break;
}
}
+
+void
+_hurd_exception2signal (struct hurd_signal_detail *detail, int *signo)
+{
+ exception2signal (detail, signo, 1);
+}
+
+void
+_hurd_exception2signal_legacy (struct hurd_signal_detail *detail, int *signo)
+{
+ exception2signal (detail, signo, 0);
+}
+
diff --git a/sysdeps/mach/hurd/i386/getcontext.S b/sysdeps/mach/hurd/i386/getcontext.S
new file mode 100644
index 0000000000..8157ea420a
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/getcontext.S
@@ -0,0 +1,74 @@
+/* Save current context.
+ Copyright (C) 2001-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__getcontext)
+ /* Load address of the context data structure. */
+ movl 4(%esp), %eax
+
+ /* Return value of getcontext. EAX is the only register whose
+ value is not preserved. */
+ movl $0, oEAX(%eax)
+
+ /* Save the 32-bit register values and the return address. */
+ movl %ecx, oECX(%eax)
+ movl %edx, oEDX(%eax)
+ movl %edi, oEDI(%eax)
+ movl %esi, oESI(%eax)
+ movl %ebp, oEBP(%eax)
+ movl (%esp), %ecx
+ movl %ecx, oEIP(%eax)
+ leal 4(%esp), %ecx /* Exclude the return address. */
+ movl %ecx, oESP(%eax)
+ movl %ebx, oEBX(%eax)
+
+ /* Save the FS segment register. We don't touch the GS register
+ since it is used for threads. */
+ xorl %edx, %edx
+ movw %fs, %dx
+ movl %edx, oFS(%eax)
+
+ leal oFPREGS(%eax), %ecx
+ /* Save the floating-point context. */
+ fnstenv (%ecx)
+ /* And load it right back since the processor changes the mask.
+ Intel thought this opcode to be used in interrupt handlers which
+ would block all exceptions. */
+ fldenv (%ecx)
+
+ /* Save the current signal mask. */
+ subl $12, %esp
+ cfi_adjust_cfa_offset (12)
+ leal oSIGMASK(%eax), %eax
+ movl %eax, 8(%esp)
+ movl $0, 4(%esp)
+ movl $SIG_BLOCK, (%esp)
+ call JUMPTARGET (__sigprocmask)
+ addl $12, %esp
+ cfi_adjust_cfa_offset (-12)
+ /* Propagate %eax (and errno, in case). */
+
+ ret
+PSEUDO_END(__getcontext)
+
+weak_alias (__getcontext, getcontext)
diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
index 7a905c2435..ca2be13d4f 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/i386/init-first.c
@@ -117,32 +117,10 @@ init1 (int argc, char *arg0, ...)
then after the environment pointers there is no Hurd
data block; the argument strings start there. */
if ((void *) d == argv[0])
- {
-#ifndef SHARED
- /* With a new enough linker (binutils-2.23 or better),
- the magic __ehdr_start symbol will be available and
- __libc_start_main will have done this that way already. */
- if (_dl_phdr == NULL)
- {
- /* We may need to see our own phdrs, e.g. for TLS setup.
- Try the usual kludge to find the headers without help from
- the exec server. */
- extern const void __executable_start;
- const ElfW(Ehdr) *const ehdr = &__executable_start;
- _dl_phdr = (const void *) ehdr + ehdr->e_phoff;
- _dl_phnum = ehdr->e_phnum;
- assert (ehdr->e_phentsize == sizeof (ElfW(Phdr)));
- }
-#endif
- return;
- }
+ return;
#ifndef SHARED
__libc_enable_secure = d->flags & EXEC_SECURE;
-
- _dl_phdr = (ElfW(Phdr) *) d->phdr;
- _dl_phnum = d->phdrsz / sizeof (ElfW(Phdr));
- assert (d->phdrsz % sizeof (ElfW(Phdr)) == 0);
#endif
_hurd_init_dtable = d->dtable;
@@ -177,15 +155,6 @@ init (int *data)
char **argv = (void *) (data + 1);
char **envp = &argv[argc + 1];
struct hurd_startup_data *d;
- unsigned long int threadvars[_HURD_THREADVAR_MAX];
-
- /* Provide temporary storage for thread-specific variables on the
- startup stack so the cthreads initialization code can use them
- for malloc et al, or so we can use malloc below for the real
- threadvars array. */
- memset (threadvars, 0, sizeof threadvars);
- threadvars[_HURD_THREADVAR_LOCALE] = (unsigned long int) &_nl_global_locale;
- __hurd_threadvar_stack_offset = (unsigned long int) threadvars;
/* Since the cthreads initialization code uses malloc, and the
malloc initialization code needs to get at the environment, make
@@ -198,12 +167,38 @@ init (int *data)
++envp;
d = (void *) ++envp;
- /* The user might have defined a value for this, to get more variables.
- Otherwise it will be zero on startup. We must make sure it is set
- properly before before cthreads initialization, so cthreads can know
- how much space to leave for thread variables. */
- if (__hurd_threadvar_max < _HURD_THREADVAR_MAX)
- __hurd_threadvar_max = _HURD_THREADVAR_MAX;
+#ifndef SHARED
+ /* If we are the bootstrap task started by the kernel,
+ then after the environment pointers there is no Hurd
+ data block; the argument strings start there. */
+ if ((void *) d == argv[0] || !d->phdr)
+ {
+ /* With a new enough linker (binutils-2.23 or better),
+ the magic __ehdr_start symbol will be available and
+ __libc_start_main will have done this that way already. */
+ if (_dl_phdr == NULL)
+ {
+ /* We may need to see our own phdrs, e.g. for TLS setup.
+ Try the usual kludge to find the headers without help from
+ the exec server. */
+ extern const void __executable_start;
+ const ElfW(Ehdr) *const ehdr = &__executable_start;
+ _dl_phdr = (const void *) ehdr + ehdr->e_phoff;
+ _dl_phnum = ehdr->e_phnum;
+ assert (ehdr->e_phentsize == sizeof (ElfW(Phdr)));
+ }
+ }
+ else
+ {
+ _dl_phdr = (ElfW(Phdr) *) d->phdr;
+ _dl_phnum = d->phdrsz / sizeof (ElfW(Phdr));
+ assert (d->phdrsz % sizeof (ElfW(Phdr)) == 0);
+ }
+
+ /* We need to setup TLS before starting the signal thread. */
+ extern void __pthread_initialize_minimal (void);
+ __pthread_initialize_minimal ();
+#endif
/* After possibly switching stacks, call `init1' (above) with the user
@@ -220,11 +215,6 @@ init (int *data)
__libc_stack_end = newsp;
- /* Copy per-thread variables from that temporary
- area onto the new cthread stack. */
- memcpy (__hurd_threadvar_location_from_sp (0, newsp),
- threadvars, sizeof threadvars);
-
/* Copy the argdata from the old stack to the new one. */
newsp = memcpy (newsp - ((char *) &d[1] - (char *) data), data,
(char *) d - (char *) data);
@@ -265,25 +255,10 @@ init (int *data)
}
else
{
- /* We are not using cthreads, so we will have just a single allocated
- area for the per-thread variables of the main user thread. */
- unsigned long int *array;
- unsigned int i;
int usercode;
void call_init1 (void);
- array = malloc (__hurd_threadvar_max * sizeof (unsigned long int));
- if (array == NULL)
- __libc_fatal ("Can't allocate single-threaded thread variables.");
-
- /* Copy per-thread variables from the temporary array into the
- newly malloc'd space. */
- memcpy (array, threadvars, sizeof threadvars);
- __hurd_threadvar_stack_offset = (unsigned long int) array;
- for (i = _HURD_THREADVAR_MAX; i < __hurd_threadvar_max; ++i)
- array[i] = 0;
-
/* The argument data is just above the stack frame we will unwind by
returning. Mutate our own return address to run the code below. */
/* The following expression would typically be written as
diff --git a/sysdeps/mach/hurd/i386/makecontext-helper.c b/sysdeps/mach/hurd/i386/makecontext-helper.c
new file mode 100644
index 0000000000..e604488264
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/makecontext-helper.c
@@ -0,0 +1,71 @@
+/* Helper for makecontext: handle threadvars.
+ Copyright (C) 2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <hurd/threadvar.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ucontext.h>
+
+#if 0
+
+void
+__makecontext_helper (ucontext_t *ucp)
+{
+ if (__hurd_threadvar_stack_mask == 0)
+ {
+ /* We are not using threads, so per init-first.c:init, the threadvars
+ live in a malloced space, addressed relative to the base of the
+ virtual address space. Just keep using that one. */
+ }
+ else
+ {
+ /* The following is only prepared to work with libpthread, which only
+ keeps the threadvars at the bottom of the stack -- contrary to
+ libthreads, which also puts additional data there. */
+
+ void *s = ucp->uc_stack.ss_sp;
+ size_t s_size = ucp->uc_stack.ss_size;
+
+ /* Is the new stack suitable? Check that that the last threadvar
+ occupies the last storage unit within the bounds of the new stack.
+ Alignment according to (sp & __hurd_threadvar_stack_mask) == sp is not
+ actually a requirement (though, in practice it often will be). */
+ if (__hurd_threadvar_location_from_sp (_HURD_THREADVAR_MAX, s)
+ != s + s_size)
+ {
+ /* Instead of having makecontext return an error, we bail out the
+ hard way, as we can't expect its caller to be able to properly
+ react to this situation. */
+ fprintf (stderr,
+ "*** makecontext: a stack at %p with size %#x is not "
+ "usable with threadvars\n",
+ s, s_size);
+ abort ();
+ }
+
+ /* Copy the threadvars to the new stack. */
+ void *t_old = __hurd_threadvar_location (0);
+ void *t_new = __hurd_threadvar_location_from_sp (0, s);
+ size_t t_size = __hurd_threadvar_max * sizeof (unsigned long int);
+ memcpy (t_new, t_old, t_size);
+ /* Account for the space taken by the threadvars. */
+ ucp->uc_stack.ss_size -= t_size;
+ }
+}
+#endif
diff --git a/sysdeps/mach/hurd/i386/makecontext.S b/sysdeps/mach/hurd/i386/makecontext.S
new file mode 100644
index 0000000000..95ae3411a8
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/makecontext.S
@@ -0,0 +1,130 @@
+/* Create new context.
+ Copyright (C) 2001-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__makecontext)
+ movl 4(%esp), %eax
+ subl $4, %esp
+ cfi_adjust_cfa_offset (4)
+ movl %eax, (%esp)
+ /* call HIDDEN_JUMPTARGET (__makecontext_helper) */
+ addl $4, %esp
+ cfi_adjust_cfa_offset (-4)
+
+ movl 4(%esp), %eax
+
+ /* Load the address of the function we are supposed to run. */
+ movl 8(%esp), %ecx
+
+ /* Compute the address of the stack. The information comes from
+ to us_stack element. */
+ movl oSS_SP(%eax), %edx
+ movl %ecx, oEIP(%eax)
+ addl oSS_SIZE(%eax), %edx
+
+ /* Remember the number of parameters for the exit handler since
+ it has to remove them. We store the number in the EBX register
+ which the function we will call must preserve. */
+ movl 12(%esp), %ecx
+ movl %ecx, oEBX(%eax)
+
+ /* Make room on the new stack for the parameters.
+ Room for the arguments, return address (== L(exitcode)) and
+ oLINK pointer is needed. One of the pointer sizes is subtracted
+ after aligning the stack. */
+ negl %ecx
+ leal -4(%edx,%ecx,4), %edx
+ negl %ecx
+
+ /* Align the stack. */
+ andl $0xfffffff0, %edx
+ subl $4, %edx
+
+ /* Store the future stack pointer. */
+ movl %edx, oESP(%eax)
+
+ /* Put the next context on the new stack (from the uc_link
+ element). */
+ movl oLINK(%eax), %eax
+ movl %eax, 4(%edx,%ecx,4)
+
+ /* Copy all the parameters. */
+ jecxz 2f
+1: movl 12(%esp,%ecx,4), %eax
+ movl %eax, (%edx,%ecx,4)
+ decl %ecx
+ jnz 1b
+2:
+
+ /* If the function we call returns we must continue with the
+ context which is given in the uc_link element. To do this
+ set the return address for the function the user provides
+ to a little bit of helper code which does the magic (see
+ below). */
+#ifdef PIC
+ call 1f
+ cfi_adjust_cfa_offset (4)
+1: popl %ecx
+ cfi_adjust_cfa_offset (-4)
+ addl $L(exitcode)-1b, %ecx
+ movl %ecx, (%edx)
+#else
+ movl $L(exitcode), (%edx)
+#endif
+ /* 'makecontext' returns no value. */
+ ret
+
+ /* This is the helper code which gets called if a function which
+ is registered with 'makecontext' returns. In this case we
+ have to install the context listed in the uc_link element of
+ the context 'makecontext' manipulated at the time of the
+ 'makecontext' call. If the pointer is NULL the process must
+ terminate. */
+ cfi_endproc
+L(exitcode):
+ /* This removes the parameters passed to the function given to
+ 'makecontext' from the stack. EBX contains the number of
+ parameters (see above). */
+ leal (%esp,%ebx,4), %esp
+
+#ifdef PIC
+ call 1f
+1: popl %ebx
+ addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
+#endif
+ cmpl $0, (%esp) /* Check the next context. */
+ je 2f /* If it is zero exit. */
+
+ call JUMPTARGET(__setcontext)
+ /* If this returns (which can happen if the syscall fails) we'll
+ exit the program with the return error value (-1). */
+
+ movl %eax, (%esp)
+2: call HIDDEN_JUMPTARGET(exit)
+ /* The 'exit' call should never return. In case it does cause
+ the process to terminate. */
+ hlt
+ cfi_startproc
+END(__makecontext)
+
+weak_alias (__makecontext, makecontext)
diff --git a/sysdeps/mach/hurd/i386/setcontext.S b/sysdeps/mach/hurd/i386/setcontext.S
new file mode 100644
index 0000000000..8c09915dd3
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/setcontext.S
@@ -0,0 +1,92 @@
+/* Install given context.
+ Copyright (C) 2001-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__setcontext)
+ /* Load address of the context data structure. */
+ movl 4(%esp), %eax
+
+ /* Get the current signal mask. */
+ subl $12, %esp
+ cfi_adjust_cfa_offset (12)
+ movl $0, 8(%esp)
+ leal oSIGMASK(%eax), %eax
+ movl %eax, 4(%esp)
+ movl $SIG_SETMASK, (%esp)
+ call JUMPTARGET (__sigprocmask)
+ addl $12, %esp
+ cfi_adjust_cfa_offset (-12)
+ testl %eax, %eax
+ jne L(pseudo_end)
+
+ /* EAX was modified, reload it. */
+ movl 4(%esp), %eax
+
+ /* Restore the floating-point context. Not the registers, only the
+ rest. */
+ leal oFPREGS(%eax), %ecx
+ fldenv (%ecx)
+
+ /* Restore the FS segment register. We don't touch the GS register
+ since it is used for threads. */
+ movl oFS(%eax), %ecx
+ movw %cx, %fs
+
+ /* Fetch the address to return to. */
+ movl oEIP(%eax), %ecx
+
+ /* Load the new stack pointer. */
+ cfi_def_cfa (eax, 0)
+ cfi_offset (edi, oEDI)
+ cfi_offset (esi, oESI)
+ cfi_offset (ebp, oEBP)
+ cfi_offset (ebx, oEBX)
+ cfi_offset (edx, oEDX)
+ cfi_offset (ecx, oECX)
+ movl oESP(%eax), %esp
+
+ /* Push the return address on the new stack so we can return there. */
+ pushl %ecx
+
+ /* Load the values of all the 32-bit registers (except ESP).
+ Since we are loading from EAX, it must be last. */
+ movl oEDI(%eax), %edi
+ movl oESI(%eax), %esi
+ movl oEBP(%eax), %ebp
+ movl oEBX(%eax), %ebx
+ movl oEDX(%eax), %edx
+ movl oECX(%eax), %ecx
+ movl oEAX(%eax), %eax
+
+ /* End FDE here, we fall into another context. */
+ cfi_endproc
+ cfi_startproc
+
+ /* The following 'ret' will pop the address of the code and jump
+ to it. */
+
+L(pseudo_end):
+ ret
+PSEUDO_END(__setcontext)
+
+weak_alias (__setcontext, setcontext)
diff --git a/sysdeps/mach/hurd/i386/sigreturn.c b/sysdeps/mach/hurd/i386/sigreturn.c
index 8285f33556..204bd472d3 100644
--- a/sysdeps/mach/hurd/i386/sigreturn.c
+++ b/sysdeps/mach/hurd/i386/sigreturn.c
@@ -24,6 +24,36 @@ register int *sp asm ("%esp");
#include <stdlib.h>
#include <string.h>
+/* This is run on the thread stack after restoring it, to be able to
+ unlock SS off sigstack. */
+static void
+__sigreturn2 (int *usp)
+{
+ struct hurd_sigstate *ss = _hurd_self_sigstate ();
+ _hurd_sigstate_unlock (ss);
+
+ sp = usp;
+#define A(line) asm volatile (#line)
+ /* The members in the sigcontext are arranged in this order
+ so we can pop them easily. */
+
+ /* Pop the segment registers (except %cs and %ss, done last). */
+ A (popl %gs);
+ A (popl %fs);
+ A (popl %es);
+ A (popl %ds);
+ /* Pop the general registers. */
+ A (popa);
+ /* Pop the processor flags. */
+ A (popf);
+ /* Return to the saved PC. */
+ A (ret);
+
+ /* Firewall. */
+ A (hlt);
+#undef A
+}
+
int
__sigreturn (struct sigcontext *scp)
{
@@ -38,7 +68,7 @@ __sigreturn (struct sigcontext *scp)
}
ss = _hurd_self_sigstate ();
- __spin_lock (&ss->lock);
+ _hurd_sigstate_lock (ss);
/* Remove the link on the `active resources' chain added by
_hurd_setup_sighandler. Its purpose was to make sure
@@ -50,35 +80,28 @@ __sigreturn (struct sigcontext *scp)
ss->intr_port = scp->sc_intr_port;
/* Check for pending signals that were blocked by the old set. */
- if (ss->pending & ~ss->blocked)
+ if (_hurd_sigstate_pending (ss) & ~ss->blocked)
{
/* There are pending signals that just became unblocked. Wake up the
signal thread to deliver them. But first, squirrel away SCP where
the signal thread will notice it if it runs another handler, and
arrange to have us called over again in the new reality. */
ss->context = scp;
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
__msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ());
/* If a pending signal was handled, sig_post never returned.
If it did return, the pending signal didn't run a handler;
proceed as usual. */
- __spin_lock (&ss->lock);
+ _hurd_sigstate_lock (ss);
ss->context = NULL;
}
if (scp->sc_onstack)
- {
- ss->sigaltstack.ss_flags &= ~SS_ONSTACK; /* XXX threadvars */
- /* XXX cannot unlock until off sigstack */
- abort ();
- }
- else
- __spin_unlock (&ss->lock);
+ ss->sigaltstack.ss_flags &= ~SS_ONSTACK;
/* Destroy the MiG reply port used by the signal handler, and restore the
reply port in use by the thread when interrupted. */
- reply_port =
- (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY);
+ reply_port = &__hurd_local_reply_port;
if (*reply_port)
{
mach_port_t port = *reply_port;
@@ -109,27 +132,19 @@ __sigreturn (struct sigcontext *scp)
*--usp = scp->sc_efl;
memcpy (usp -= 12, &scp->sc_i386_thread_state, 12 * sizeof (int));
- sp = usp;
-
-#define A(line) asm volatile (#line)
- /* The members in the sigcontext are arranged in this order
- so we can pop them easily. */
-
- /* Pop the segment registers (except %cs and %ss, done last). */
- A (popl %gs);
- A (popl %fs);
- A (popl %es);
- A (popl %ds);
- /* Pop the general registers. */
- A (popa);
- /* Pop the processor flags. */
- A (popf);
- /* Return to the saved PC. */
- A (ret);
+ /* Pass usp to __sigreturn2 so it can unwind itself easily. */
+ *(usp-1) = (int) usp;
+ --usp;
+ /* Bogus return address for __sigreturn2 */
+ *--usp = 0;
+ *--usp = (int) __sigreturn2;
+ /* Restore thread stack */
+ sp = usp;
+ /* Return into __sigreturn2. */
+ asm volatile ("ret");
/* Firewall. */
- A (hlt);
-#undef A
+ asm volatile ("hlt");
}
/* NOTREACHED */
diff --git a/sysdeps/mach/hurd/i386/swapcontext.S b/sysdeps/mach/hurd/i386/swapcontext.S
new file mode 100644
index 0000000000..8780572afe
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/swapcontext.S
@@ -0,0 +1,110 @@
+/* Save current context and install the given one.
+ Copyright (C) 2001-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__swapcontext)
+ /* Load address of the context data structure we save in. */
+ movl 4(%esp), %eax
+
+ /* Return value of swapcontext. EAX is the only register whose
+ value is not preserved. */
+ movl $0, oEAX(%eax)
+
+ /* Save the 32-bit register values and the return address. */
+ movl %ecx, oECX(%eax)
+ movl %edx, oEDX(%eax)
+ movl %edi, oEDI(%eax)
+ movl %esi, oESI(%eax)
+ movl %ebp, oEBP(%eax)
+ movl (%esp), %ecx
+ movl %ecx, oEIP(%eax)
+ leal 4(%esp), %ecx
+ movl %ecx, oESP(%eax)
+ movl %ebx, oEBX(%eax)
+
+ /* Save the FS segment register. */
+ xorl %edx, %edx
+ movw %fs, %dx
+ movl %edx, oFS(%eax)
+
+ leal oFPREGS(%eax), %ecx
+ /* Save the floating-point context. */
+ fnstenv (%ecx)
+
+ /* Load address of the context data structure we have to load. */
+ movl 8(%esp), %ecx
+
+ /* Save the current signal mask and install the new one. */
+ subl $12, %esp
+ cfi_adjust_cfa_offset (12)
+ leal oSIGMASK(%eax), %eax
+ movl %eax, 8(%esp)
+ leal oSIGMASK(%ecx), %eax
+ movl %eax, 4(%esp)
+ movl $SIG_SETMASK, (%esp)
+ call JUMPTARGET (__sigprocmask)
+ addl $12, %esp
+ cfi_adjust_cfa_offset (-12)
+ testl %eax, %eax
+ jne L(pseudo_end)
+
+ /* EAX was modified, reload it. */
+ movl 8(%esp), %eax
+
+ /* Restore the floating-point context. Not the registers, only the
+ rest. */
+ leal oFPREGS(%eax), %ecx
+ fldenv (%ecx)
+
+ /* Restore the FS segment register. We don't touch the GS register
+ since it is used for threads. */
+ movl oFS(%eax), %edx
+ movw %dx, %fs
+
+ /* Fetch the address to return to. */
+ movl oEIP(%eax), %ecx
+
+ /* Load the new stack pointer. */
+ movl oESP(%eax), %esp
+
+ /* Push the return address on the new stack so we can return there. */
+ pushl %ecx
+
+ /* Load the values of all the 32-bit registers (except ESP).
+ Since we are loading from EAX, it must be last. */
+ movl oEDI(%eax), %edi
+ movl oESI(%eax), %esi
+ movl oEBP(%eax), %ebp
+ movl oEBX(%eax), %ebx
+ movl oEDX(%eax), %edx
+ movl oECX(%eax), %ecx
+ movl oEAX(%eax), %eax
+
+ /* The following 'ret' will pop the address of the code and jump
+ to it. */
+
+L(pseudo_end):
+ ret
+PSEUDO_END(__swapcontext)
+
+weak_alias (__swapcontext, swapcontext)
diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h
index 3ec5bb032b..379f22e972 100644
--- a/sysdeps/mach/hurd/i386/tls.h
+++ b/sysdeps/mach/hurd/i386/tls.h
@@ -53,6 +53,10 @@ typedef struct
void *__private_tm[4];
/* GCC split stack support. */
void *__private_ss;
+
+ /* Keep this field last */
+ mach_port_t reply_port; /* This thread's reply port. */
+ struct hurd_sigstate *_hurd_sigstate;
} tcbhead_t;
#endif
@@ -72,6 +76,8 @@ typedef struct
# define __i386_set_gdt(thr, sel, desc) ((void) (thr), (void) (sel), (void) (desc), MIG_BAD_ID)
# endif
+#define __i386_selector_is_ldt(sel) (!!((sel) & 4))
+
# include <errno.h>
# include <assert.h>
@@ -88,41 +94,57 @@ typedef struct
| (((unsigned int) (tcb)) & 0xff000000) /* base 24..31 */ \
}
+# define HURD_DESC_TLS(desc) \
+ ({ \
+ (tcbhead_t *) ( (desc->low_word >> 16) \
+ | ((desc->high_word & 0xff) << 16) \
+ | (desc->high_word & 0xff000000) \
+ );})
+
+#define __LIBC_NO_TLS() \
+ ({ unsigned short ds, gs; \
+ asm ("movw %%ds,%w0; movw %%gs,%w1" : "=q" (ds), "=q" (gs)); \
+ ds == gs; })
static inline const char * __attribute__ ((unused))
_hurd_tls_init (tcbhead_t *tcb)
{
HURD_TLS_DESC_DECL (desc, tcb);
+ thread_t self = __mach_thread_self ();
+ const char *msg = NULL;
/* This field is used by TLS accesses to get our "thread pointer"
from the TLS point of view. */
tcb->tcb = tcb;
- /* Cache our thread port. */
- tcb->self = __mach_thread_self ();
-
/* Get the first available selector. */
int sel = -1;
- error_t err = __i386_set_gdt (tcb->self, &sel, desc);
+ kern_return_t err = __i386_set_gdt (tcb->self, &sel, desc);
if (err == MIG_BAD_ID)
{
/* Old kernel, use a per-thread LDT. */
sel = 0x27;
- err = __i386_set_ldt (tcb->self, sel, &desc, 1);
+ err = __i386_set_ldt (self, sel, &desc, 1);
assert_perror (err);
if (err)
- return "i386_set_ldt failed";
+ {
+ msg = "i386_set_ldt failed";
+ goto out;
+ }
}
else if (err)
{
assert_perror (err); /* Separate from above with different line #. */
- return "i386_set_gdt failed";
+ msg = "i386_set_gdt failed";
+ goto out;
}
/* Now install the new selector. */
asm volatile ("mov %w0, %%gs" :: "q" (sel));
- return 0;
+out:
+ __mach_port_deallocate (__mach_task_self (), self);
+ return msg;
}
/* Code to initially initialize the thread pointer. This might need
@@ -138,6 +160,20 @@ _hurd_tls_init (tcbhead_t *tcb)
: "i" (offsetof (tcbhead_t, tcb))); \
__tcb;})
+/* Return the TCB address of a thread given its state. */
+# define THREAD_TCB(thread, thread_state) \
+ ({ int __sel = (thread_state)->basic.gs; \
+ struct descriptor __desc, *___desc = &__desc; \
+ unsigned int __count = 1; \
+ kern_return_t __err; \
+ if (__builtin_expect (__sel, 0x48) & 4) /* LDT selector */ \
+ __err = __i386_get_ldt ((thread), __sel, 1, &___desc, &__count); \
+ else \
+ __err = __i386_get_gdt ((thread), __sel, &__desc); \
+ assert_perror (__err); \
+ assert (__count == 1); \
+ HURD_DESC_TLS(___desc);})
+
/* Install new dtv for current thread. */
# define INSTALL_NEW_DTV(dtvp) \
({ asm volatile ("movl %0,%%gs:%P1" \
@@ -151,9 +187,40 @@ _hurd_tls_init (tcbhead_t *tcb)
# include <mach/machine/thread_status.h>
-/* Set up TLS in the new thread of a fork child, copying from our own. */
-static inline error_t __attribute__ ((unused))
-_hurd_tls_fork (thread_t child, struct i386_thread_state *state)
+/* Set up TLS in the new thread of a fork child, copying from the original. */
+static inline kern_return_t __attribute__ ((unused))
+_hurd_tls_fork (thread_t child, thread_t orig, struct i386_thread_state *state)
+{
+ /* Fetch the selector set by _hurd_tls_init. */
+ int sel;
+ asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0));
+ if (sel == state->ds) /* _hurd_tls_init was never called. */
+ return 0;
+
+ struct descriptor desc, *_desc = &desc;
+ kern_return_t err;
+ unsigned int count = 1;
+
+ if (__glibc_unlikely (__i386_selector_is_ldt(sel)))
+ err = __i386_get_ldt (orig, sel, 1, &_desc, &count);
+ else
+ err = __i386_get_gdt (orig, sel, &desc);
+
+ assert_perror (err);
+ if (err)
+ return err;
+
+ if (__glibc_unlikely (__i386_selector_is_ldt(sel)))
+ err = __i386_set_ldt (child, sel, &desc, 1);
+ else
+ err = __i386_set_gdt (child, &sel, desc);
+
+ state->gs = sel;
+ return err;
+}
+
+static inline kern_return_t __attribute__ ((unused))
+_hurd_tls_new (thread_t child, struct i386_thread_state *state, tcbhead_t *tcb)
{
/* Fetch the selector set by _hurd_tls_init. */
int sel;
@@ -161,11 +228,13 @@ _hurd_tls_fork (thread_t child, struct i386_thread_state *state)
if (sel == state->ds) /* _hurd_tls_init was never called. */
return 0;
- tcbhead_t *const tcb = THREAD_SELF;
HURD_TLS_DESC_DECL (desc, tcb);
- error_t err;
+ kern_return_t err;
+
+ tcb->tcb = tcb;
+ tcb->self = child;
- if (__builtin_expect (sel, 0x50) & 4) /* LDT selector */
+ if (__glibc_unlikely (__i386_selector_is_ldt(sel)))
err = __i386_set_ldt (child, sel, &desc, 1);
else
err = __i386_set_gdt (child, &sel, desc);
diff --git a/sysdeps/mach/hurd/i386/tlsdesc.sym b/sysdeps/mach/hurd/i386/tlsdesc.sym
new file mode 100644
index 0000000000..a358f7e325
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/tlsdesc.sym
@@ -0,0 +1,19 @@
+#include <stddef.h>
+#include <sysdep.h>
+#include <tls.h>
+#include <link.h>
+#include <dl-tlsdesc.h>
+
+--
+
+-- We have to override sysdeps/i386/tlsdesc.sym to adapt to our libpthread.
+
+-- Abuse tls.h macros to derive offsets relative to the thread register.
+
+DTV_OFFSET offsetof(tcbhead_t, dtv)
+
+TLSDESC_ARG offsetof(struct tlsdesc, arg)
+
+TLSDESC_GEN_COUNT offsetof(struct tlsdesc_dynamic_arg, gen_count)
+TLSDESC_MODID offsetof(struct tlsdesc_dynamic_arg, tlsinfo.ti_module)
+TLSDESC_MODOFF offsetof(struct tlsdesc_dynamic_arg, tlsinfo.ti_offset)
diff --git a/sysdeps/mach/hurd/i386/trampoline.c b/sysdeps/mach/hurd/i386/trampoline.c
index f9c5349eb2..2ff3c406c5 100644
--- a/sysdeps/mach/hurd/i386/trampoline.c
+++ b/sysdeps/mach/hurd/i386/trampoline.c
@@ -19,13 +19,66 @@
#include <hurd/signal.h>
#include <hurd/userlink.h>
#include <thread_state.h>
+#include <mach/exception.h>
#include <mach/machine/eflags.h>
#include <assert.h>
#include <errno.h>
#include "hurdfault.h"
#include <intr-msg.h>
+#include <sys/ucontext.h>
+/* Fill in a siginfo_t structure for SA_SIGINFO-enabled handlers. */
+static void fill_siginfo (siginfo_t *si, int signo,
+ const struct hurd_signal_detail *detail,
+ const struct machine_thread_all_state *state)
+{
+ si->si_signo = signo;
+ si->si_errno = detail->error;
+ si->si_code = detail->code;
+
+ /* XXX We would need a protocol change for sig_post to include
+ * this information. */
+ si->si_pid = -1;
+ si->si_uid = -1;
+
+ /* Address of the faulting instruction or memory access. */
+ if (detail->exc == EXC_BAD_ACCESS)
+ si->si_addr = (void *) detail->exc_subcode;
+ else
+ si->si_addr = (void *) state->basic.eip;
+
+ /* XXX On SIGCHLD, this should be the exit status of the child
+ * process. We would need a protocol change for the proc server
+ * to send this information along with the signal. */
+ si->si_status = 0;
+
+ si->si_band = 0; /* SIGPOLL is not supported yet. */
+ si->si_value.sival_int = 0; /* sigqueue() is not supported yet. */
+}
+
+/* Fill in a ucontext_t structure SA_SIGINFO-enabled handlers. */
+static void fill_ucontext (ucontext_t *uc, const struct sigcontext *sc)
+{
+ uc->uc_flags = 0;
+ uc->uc_link = NULL;
+ uc->uc_sigmask = sc->sc_mask;
+ uc->uc_stack.ss_sp = (__ptr_t) sc->sc_esp;
+ uc->uc_stack.ss_size = 0;
+ uc->uc_stack.ss_flags = 0;
+
+ /* Registers. */
+ memcpy (&uc->uc_mcontext.gregs[REG_GS], &sc->sc_gs,
+ (REG_TRAPNO - REG_GS) * sizeof (int));
+ uc->uc_mcontext.gregs[REG_TRAPNO] = 0;
+ uc->uc_mcontext.gregs[REG_ERR] = 0;
+ memcpy (&uc->uc_mcontext.gregs[REG_EIP], &sc->sc_eip,
+ (NGREG - REG_EIP) * sizeof (int));
+
+ /* XXX FPU state. */
+ memset (&uc->uc_mcontext.fpregs, 0, sizeof (fpregset_t));
+}
+
struct sigcontext *
_hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler,
int signo, struct hurd_signal_detail *detail,
@@ -37,20 +90,44 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler,
void firewall (void);
extern const void _hurd_intr_rpc_msg_cx_sp;
extern const void _hurd_intr_rpc_msg_sp_restored;
+ const struct sigaction *action;
void *volatile sigsp;
struct sigcontext *scp;
struct
{
int signo;
- long int sigcode;
- struct sigcontext *scp; /* Points to ctx, below. */
+ union
+ {
+ /* Extra arguments for traditional signal handlers */
+ struct
+ {
+ long int sigcode;
+ struct sigcontext *scp; /* Points to ctx, below. */
+ } legacy;
+
+ /* Extra arguments for SA_SIGINFO handlers */
+ struct
+ {
+ siginfo_t *siginfop; /* Points to siginfo, below. */
+ ucontext_t *uctxp; /* Points to uctx, below. */
+ } posix;
+ };
void *sigreturn_addr;
void *sigreturn_returns_here;
struct sigcontext *return_scp; /* Same; arg to sigreturn. */
+
+ /* NB: sigreturn assumes link is next to ctx. */
struct sigcontext ctx;
struct hurd_userlink link;
+ ucontext_t ucontext;
+ siginfo_t siginfo;
} *stackframe;
+ /* sigaction for preemptors */
+ static const struct sigaction legacy_sigaction = {
+ .sa_flags = SA_RESTART
+ };
+
if (ss->context)
{
/* We have a previous sigcontext that sigreturn was about
@@ -62,7 +139,7 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler,
sizeof (state->basic));
memcpy (&state->fpu, &ss->context->sc_i386_float_state,
sizeof (state->fpu));
- state->set |= (1 << i386_THREAD_STATE) | (1 << i386_FLOAT_STATE);
+ state->set |= (1 << i386_REGS_SEGS_STATE) | (1 << i386_FLOAT_STATE);
}
}
@@ -74,13 +151,19 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler,
interrupted RPC frame. */
state->basic.esp = state->basic.uesp;
- if ((ss->actions[signo].sa_flags & SA_ONSTACK) &&
+ action = & _hurd_sigstate_actions (ss) [signo];
+ if ( (action->sa_flags & SA_SIGINFO)
+ && handler != (__sighandler_t) action->sa_sigaction
+ || !(action->sa_flags & SA_SIGINFO)
+ && handler != action->sa_handler)
+ /* A signal preemptor took over, use legacy semantic. */
+ action = &legacy_sigaction;
+
+ if ((action->sa_flags & SA_ONSTACK) &&
!(ss->sigaltstack.ss_flags & (SS_DISABLE|SS_ONSTACK)))
{
sigsp = ss->sigaltstack.ss_sp + ss->sigaltstack.ss_size;
ss->sigaltstack.ss_flags |= SS_ONSTACK;
- /* XXX need to set up base of new stack for
- per-thread variables, cthreads. */
}
/* This code has intimate knowledge of the special mach_msg system call
done in intr-msg.c; that code does (see intr-msg.h):
@@ -136,15 +219,9 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler,
= &stackframe->link.thread.next;
ss->active_resources = &stackframe->link;
- /* Set up the arguments for the signal handler. */
- stackframe->signo = signo;
- stackframe->sigcode = detail->code;
- stackframe->scp = stackframe->return_scp = scp = &stackframe->ctx;
- stackframe->sigreturn_addr = &__sigreturn;
- stackframe->sigreturn_returns_here = firewall; /* Crash on return. */
-
/* Set up the sigcontext from the current state of the thread. */
+ scp = &stackframe->ctx;
scp->sc_onstack = ss->sigaltstack.ss_flags & SS_ONSTACK ? 1 : 0;
/* struct sigcontext is laid out so that starting at sc_gs mimics a
@@ -158,6 +235,35 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler,
&state->fpu, &scp->sc_i386_float_state,
sizeof (state->fpu));
+ /* Set up the arguments for the signal handler. */
+ stackframe->signo = signo;
+ if (action->sa_flags & SA_SIGINFO)
+ {
+ stackframe->posix.siginfop = &stackframe->siginfo;
+ stackframe->posix.uctxp = &stackframe->ucontext;
+ fill_siginfo (&stackframe->siginfo, signo, detail, state);
+ fill_ucontext (&stackframe->ucontext, scp);
+ }
+ else
+ {
+ if (detail->exc)
+ {
+ int nsigno;
+ _hurd_exception2signal_legacy (detail, &nsigno);
+ assert (nsigno == signo);
+ }
+ else
+ detail->code = 0;
+
+ stackframe->legacy.sigcode = detail->code;
+ stackframe->legacy.scp = &stackframe->ctx;
+ }
+
+ /* Set up the bottom of the stack. */
+ stackframe->sigreturn_addr = &__sigreturn;
+ stackframe->sigreturn_returns_here = firewall; /* Crash on return. */
+ stackframe->return_scp = &stackframe->ctx;
+
_hurdsig_end_catch_fault ();
if (! ok)
diff --git a/sysdeps/mach/hurd/i386/ucontext_i.sym b/sysdeps/mach/hurd/i386/ucontext_i.sym
new file mode 100644
index 0000000000..cc1cfd578d
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/ucontext_i.sym
@@ -0,0 +1,29 @@
+#include <stddef.h>
+#include <signal.h>
+#include <sys/ucontext.h>
+
+--
+
+SIG_BLOCK
+SIG_SETMASK
+
+#define ucontext(member) offsetof (ucontext_t, member)
+#define mcontext(member) ucontext (uc_mcontext.member)
+#define mreg(reg) mcontext (gregs[REG_##reg])
+
+oLINK ucontext (uc_link)
+oSS_SP ucontext (uc_stack.ss_sp)
+oSS_SIZE ucontext (uc_stack.ss_size)
+oGS mreg (GS)
+oFS mreg (FS)
+oEDI mreg (EDI)
+oESI mreg (ESI)
+oEBP mreg (EBP)
+oESP mreg (ESP)
+oEBX mreg (EBX)
+oEDX mreg (EDX)
+oECX mreg (ECX)
+oEAX mreg (EAX)
+oEIP mreg (EIP)
+oFPREGS mcontext (fpregs)
+oSIGMASK ucontext (uc_sigmask)
diff --git a/sysdeps/mach/hurd/ifaddrs.c b/sysdeps/mach/hurd/ifaddrs.c
new file mode 100644
index 0000000000..d2f8978673
--- /dev/null
+++ b/sysdeps/mach/hurd/ifaddrs.c
@@ -0,0 +1,306 @@
+/* getifaddrs -- get names and addresses of all network interfaces
+ Copyright (C) 2013-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ifaddrs.h>
+#include <net/if.h>
+#include <sys/socket.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <hurd.h>
+#include <hurd/paths.h>
+#include <hurd/lookup.h>
+#include <hurd/fs.h>
+
+/* Create a linked list of `struct ifaddrs' structures, one for each
+ network interface on the host machine. If successful, store the
+ list in *IFAP and return 0. On errors, return -1 and set `errno'. */
+int
+getifaddrs (struct ifaddrs **ifap)
+{
+ /* XXX: Hackish. This assumes pfinet parameter style, and that the same
+ pfinet is on /servers/socket/2 and /servers/socket/26.
+
+ To be replaced by something like a netlink protocol, or fix ifreq into
+ using sockaddr_storage (but break existing compiled programs using it). */
+
+ file_t node;
+ char *argz = 0, *cur;
+ size_t argz_len = 0;
+ unsigned naddrs;
+ const char *ifa_name = NULL;
+ char *addr, *cidr_a;
+ int cidr;
+
+ node = __file_name_lookup (_SERVERS_SOCKET "/2", 0, 0666);
+
+ if (node == MACH_PORT_NULL)
+ return -1;
+
+ __file_get_fs_options (node, &argz, &argz_len);
+
+ __mach_port_deallocate (__mach_task_self (), node);
+
+ /* XXX: Two hardcoded for lo */
+ naddrs = 2;
+
+ for (cur = argz; cur < argz + argz_len; cur = cur + strlen (cur) + 1)
+ {
+ if (!strncmp (cur, "--address=", 10))
+ naddrs++;
+ else if (!strncmp (cur, "--address6=", 11))
+ naddrs++;
+ }
+
+ {
+ struct
+ {
+ struct ifaddrs ia;
+ struct sockaddr_storage addr, netmask, broadaddr;
+ char name[IF_NAMESIZE];
+ } *storage;
+ int i;
+ struct sockaddr_in *sin;
+ struct sockaddr_in6 *sin6;
+
+ storage = malloc (naddrs * sizeof storage[0]);
+ if (storage == NULL)
+ {
+ __munmap (argz, argz_len);
+ return -1;
+ }
+
+ i = 0;
+
+ /* XXX: Hardcoded lo interface */
+ ifa_name = "lo";
+
+ /* 127.0.0.1/8 */
+ storage[i].ia.ifa_next = &storage[i + 1].ia;
+ storage[i].ia.ifa_name = strncpy (storage[i].name, ifa_name, sizeof (storage[i].name));
+
+ storage[i].ia.ifa_addr = (struct sockaddr *) &storage[i].addr;
+ sin = ((struct sockaddr_in *) &storage[i].addr);
+ sin->sin_family = AF_INET;
+ sin->sin_len = sizeof(*sin);
+ sin->sin_port = 0;
+ sin->sin_addr.s_addr = htonl (INADDR_LOOPBACK);
+
+ storage[i].ia.ifa_netmask = (struct sockaddr *) &storage[i].netmask;
+ sin = ((struct sockaddr_in *) &storage[i].netmask);
+ sin->sin_family = AF_INET;
+ sin->sin_len = sizeof(*sin);
+ sin->sin_port = 0;
+ sin->sin_addr.s_addr = htonl (IN_CLASSA_NET);
+
+ storage[i].ia.ifa_broadaddr = (struct sockaddr *) &storage[i].addr;
+
+ storage[i].ia.ifa_flags = IFF_UP | IFF_LOOPBACK | IFF_RUNNING;
+
+ storage[i].ia.ifa_data = NULL; /* Nothing here for now. */
+
+ i++;
+
+ /* ::1/128 */
+ storage[i].ia.ifa_next = &storage[i + 1].ia;
+ storage[i].ia.ifa_name = strncpy (storage[i].name, ifa_name, sizeof (storage[i].name));
+
+ storage[i].ia.ifa_addr = (struct sockaddr *) &storage[i].addr;
+ sin6 = ((struct sockaddr_in6 *) &storage[i].addr);
+ sin6->sin6_family = AF_INET6;
+ sin6->sin6_len = sizeof(*sin6);
+ sin6->sin6_port = 0;
+ sin6->sin6_flowinfo = 0;
+ inet_pton (AF_INET6, "::1", &sin6->sin6_addr);
+ sin6->sin6_scope_id = 0;
+
+ storage[i].ia.ifa_netmask = (struct sockaddr *) &storage[i].netmask;
+ sin6 = ((struct sockaddr_in6 *) &storage[i].netmask);
+ sin6->sin6_family = AF_INET6;
+ sin6->sin6_len = sizeof(*sin6);
+ sin6->sin6_port = 0;
+ sin6->sin6_flowinfo = 0;
+ inet_pton (AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", &sin6->sin6_addr);
+ sin6->sin6_scope_id = 0;
+
+ storage[i].ia.ifa_broadaddr = NULL;
+
+ storage[i].ia.ifa_flags = IFF_UP | IFF_LOOPBACK | IFF_RUNNING;
+
+ storage[i].ia.ifa_data = NULL; /* Nothing here for now. */
+
+ for (cur = argz; cur < argz + argz_len; cur = cur + strlen (cur) + 1)
+ {
+ if (!strncmp (cur, "--interface=", 12))
+ {
+ ifa_name = cur + 12;
+ continue;
+ }
+
+ else if (!strncmp (cur, "--address=", 10))
+ {
+ i++;
+ /* IPv4 address */
+ addr = cur + 10;
+
+ storage[i].ia.ifa_next = &storage[i + 1].ia;
+ storage[i].ia.ifa_name = strncpy (storage[i].name, ifa_name, sizeof (storage[i].name));
+
+ storage[i].ia.ifa_addr = (struct sockaddr *) &storage[i].addr;
+ sin = ((struct sockaddr_in *) &storage[i].addr);
+ sin->sin_family = AF_INET;
+ sin->sin_len = sizeof(*sin);
+ sin->sin_port = 0;
+ inet_pton (AF_INET, addr, &sin->sin_addr);
+
+ storage[i].ia.ifa_netmask = NULL;
+ storage[i].ia.ifa_broadaddr = NULL;
+
+ storage[i].ia.ifa_flags = IFF_UP | IFF_BROADCAST | IFF_RUNNING | IFF_MULTICAST;
+ storage[i].ia.ifa_data = NULL; /* Nothing here for now. */
+ }
+
+ else if (!strncmp (cur, "--netmask=", 10))
+ {
+ /* IPv4 netmask */
+ addr = cur + 10;
+
+ storage[i].ia.ifa_netmask = (struct sockaddr *) &storage[i].netmask;
+ sin = ((struct sockaddr_in *) &storage[i].netmask);
+ sin->sin_family = AF_INET;
+ sin->sin_len = sizeof(*sin);
+ sin->sin_port = 0;
+ inet_pton (AF_INET, addr, &sin->sin_addr);
+
+ storage[i].ia.ifa_broadaddr = (struct sockaddr *) &storage[i].broadaddr;
+ sin = ((struct sockaddr_in *) &storage[i].broadaddr);
+ sin->sin_family = AF_INET;
+ sin->sin_len = sizeof(*sin);
+ sin->sin_port = 0;
+ sin->sin_addr.s_addr =
+ ((struct sockaddr_in *) &storage[i].addr)->sin_addr.s_addr
+ | ~(((struct sockaddr_in *) &storage[i].netmask)->sin_addr.s_addr);
+ }
+
+ else if (!strncmp (cur, "--peer=", 7))
+ {
+ /* IPv4 peer */
+ addr = cur + 7;
+
+ storage[i].ia.ifa_dstaddr = (struct sockaddr *) &storage[i].broadaddr;
+ sin = ((struct sockaddr_in *) &storage[i].broadaddr);
+ sin->sin_family = AF_INET;
+ sin->sin_len = sizeof(*sin);
+ sin->sin_port = 0;
+ inet_pton (AF_INET, addr, &sin->sin_addr);
+
+ storage[i].ia.ifa_flags &= ~IFF_BROADCAST;
+ storage[i].ia.ifa_flags |= IFF_POINTOPOINT;
+ }
+
+ else if (!strncmp (cur, "--address6=", 11))
+ {
+ i++;
+ /* IPv6 address */
+ addr = cur + 11;
+ cidr_a = strchr (addr, '/');
+ if (!cidr_a)
+ {
+ /* No CIDR length?! Assume 64. */
+ addr = strdup (addr);
+ cidr = 64;
+ }
+ else
+ {
+ addr = strndup (addr, cidr_a - addr);
+ cidr = atoi (cidr_a + 1);
+ }
+
+ storage[i].ia.ifa_next = &storage[i + 1].ia;
+ storage[i].ia.ifa_name = strncpy (storage[i].name, ifa_name, sizeof (storage[i].name));
+
+ storage[i].ia.ifa_addr = (struct sockaddr *) &storage[i].addr;
+ sin6 = ((struct sockaddr_in6 *) &storage[i].addr);
+ sin6->sin6_family = AF_INET6;
+ sin6->sin6_len = sizeof(*sin6);
+ sin6->sin6_port = 0;
+ sin6->sin6_flowinfo = 0;
+ inet_pton (AF_INET6, addr, &sin6->sin6_addr);
+ sin6->sin6_scope_id = 0;
+
+ storage[i].ia.ifa_netmask = (struct sockaddr *) &storage[i].netmask;
+ sin6 = ((struct sockaddr_in6 *) &storage[i].netmask);
+ sin6->sin6_family = AF_INET6;
+ sin6->sin6_len = sizeof(*sin6);
+ sin6->sin6_port = 0;
+ sin6->sin6_flowinfo = 0;
+ sin6->sin6_addr.s6_addr32[0] = htonl (cidr >= 32 ? 0xffffffffUL : cidr <= 0 ? 0 : ~((1UL << ( 32 - cidr)) - 1));
+ sin6->sin6_addr.s6_addr32[1] = htonl (cidr >= 64 ? 0xffffffffUL : cidr <= 32 ? 0 : ~((1UL << ( 64 - cidr)) - 1));
+ sin6->sin6_addr.s6_addr32[2] = htonl (cidr >= 96 ? 0xffffffffUL : cidr <= 64 ? 0 : ~((1UL << ( 96 - cidr)) - 1));
+ sin6->sin6_addr.s6_addr32[3] = htonl (cidr >= 128 ? 0xffffffffUL : cidr <= 96 ? 0 : ~((1UL << (128 - cidr)) - 1));
+ sin6->sin6_scope_id = 0;
+
+ storage[i].ia.ifa_broadaddr = NULL;
+ storage[i].ia.ifa_flags = IFF_UP | IFF_BROADCAST | IFF_RUNNING | IFF_MULTICAST;
+ storage[i].ia.ifa_data = NULL; /* Nothing here for now. */
+ free (addr);
+ }
+
+ else if (!strncmp (cur, "--peer6=", 8))
+ {
+ /* IPv6 peer */
+ addr = cur + 8;
+
+ storage[i].ia.ifa_dstaddr = (struct sockaddr *) &storage[i].broadaddr;
+ sin6 = ((struct sockaddr_in6 *) &storage[i].broadaddr);
+ sin6->sin6_family = AF_INET6;
+ sin6->sin6_len = sizeof(*sin6);
+ sin6->sin6_port = 0;
+ sin6->sin6_flowinfo = 0;
+ inet_pton (AF_INET6, addr, &sin6->sin6_addr);
+ sin6->sin6_scope_id = 0;
+
+ storage[i].ia.ifa_flags &= ~IFF_BROADCAST;
+ storage[i].ia.ifa_flags |= IFF_POINTOPOINT;
+ }
+ }
+
+ storage[i].ia.ifa_next = NULL;
+
+ *ifap = &storage[0].ia;
+ }
+
+ __munmap (argz, argz_len);
+
+ return 0;
+}
+#ifndef getifaddrs
+libc_hidden_def (getifaddrs)
+#endif
+
+void
+freeifaddrs (struct ifaddrs *ifa)
+{
+ free (ifa);
+}
+libc_hidden_def (freeifaddrs)
diff --git a/sysdeps/mach/hurd/jmp-unwind.c b/sysdeps/mach/hurd/jmp-unwind.c
index f74124eea9..ea8b4b7082 100644
--- a/sysdeps/mach/hurd/jmp-unwind.c
+++ b/sysdeps/mach/hurd/jmp-unwind.c
@@ -49,9 +49,8 @@ _longjmp_unwind (jmp_buf env, int val)
/* All access to SS->active_resources must take place inside a critical
section where signal handlers cannot run. */
- __spin_lock (&ss->lock);
- assert (! __spin_lock_locked (&ss->critical_section_lock));
__spin_lock (&ss->critical_section_lock);
+ __spin_lock (&ss->lock);
/* Remove local signal preemptors being unwound past. */
while (ss->preemptors &&
diff --git a/sysdeps/mach/hurd/kernel-features.h b/sysdeps/mach/hurd/kernel-features.h
index 7de5c11b66..d5fdf3edf9 100644
--- a/sysdeps/mach/hurd/kernel-features.h
+++ b/sysdeps/mach/hurd/kernel-features.h
@@ -23,3 +23,5 @@
#define __ASSUME_O_CLOEXEC 1
#define __ASSUME_DUP3 1
#define __ASSUME_ACCEPT4 1
+#define __ASSUME_SOCK_CLOEXEC 1
+#define __ASSUME_PIPE2 1
diff --git a/sysdeps/mach/hurd/kill.c b/sysdeps/mach/hurd/kill.c
index 3c5c0e573d..b9a4e23935 100644
--- a/sysdeps/mach/hurd/kill.c
+++ b/sysdeps/mach/hurd/kill.c
@@ -64,7 +64,7 @@ __kill (pid_t pid, int sig)
{
if (msgport != MACH_PORT_NULL)
/* Send a signal message to his message port. */
- return __msg_sig_post (msgport, sig, 0, refport);
+ return __msg_sig_post (msgport, sig, SI_USER, refport);
/* The process has no message port. Perhaps try direct
frobnication of the task. */
diff --git a/sysdeps/mach/hurd/libc-lock.h b/sysdeps/mach/hurd/libc-lock.h
deleted file mode 100644
index f6cbe50fc2..0000000000
--- a/sysdeps/mach/hurd/libc-lock.h
+++ /dev/null
@@ -1,213 +0,0 @@
-/* libc-internal interface for mutex locks. Hurd version using Mach cthreads.
- Copyright (C) 1996-2016 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
-
-#ifndef _LIBC_LOCK_H
-#define _LIBC_LOCK_H 1
-
-#if (_LIBC - 0) || (_CTHREADS_ - 0)
-#include <cthreads.h>
-#include <hurd/threadvar.h>
-
-typedef struct mutex __libc_lock_t;
-typedef struct
-{
- struct mutex mutex;
- void *owner;
- int count;
-} __libc_lock_recursive_t;
-typedef __libc_lock_recursive_t __rtld_lock_recursive_t;
-
-#define __libc_lock_owner_self() ((void *) __hurd_threadvar_location (0))
-
-#else
-typedef struct __libc_lock_opaque__ __libc_lock_t;
-typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t;
-#endif
-
-/* Define a lock variable NAME with storage class CLASS. The lock must be
- initialized with __libc_lock_init before it can be used (or define it
- with __libc_lock_define_initialized, below). Use `extern' for CLASS to
- declare a lock defined in another module. In public structure
- definitions you must use a pointer to the lock structure (i.e., NAME
- begins with a `*'), because its storage size will not be known outside
- of libc. */
-#define __libc_lock_define(CLASS,NAME) \
- CLASS __libc_lock_t NAME;
-
-/* Define an initialized lock variable NAME with storage class CLASS. */
-#define _LIBC_LOCK_INITIALIZER MUTEX_INITIALIZER
-#define __libc_lock_define_initialized(CLASS,NAME) \
- CLASS __libc_lock_t NAME = _LIBC_LOCK_INITIALIZER;
-
-/* Initialize the named lock variable, leaving it in a consistent, unlocked
- state. */
-#define __libc_lock_init(NAME) __mutex_init (&(NAME))
-
-/* Finalize the named lock variable, which must be locked. It cannot be
- used again until __libc_lock_init is called again on it. This must be
- called on a lock variable before the containing storage is reused. */
-#define __libc_lock_fini(NAME) __mutex_unlock (&(NAME))
-#define __libc_lock_fini_recursive(NAME) __mutex_unlock (&(NAME).mutex)
-#define __rtld_lock_fini_recursive(NAME) __mutex_unlock (&(NAME).mutex)
-
-
-/* Lock the named lock variable. */
-#define __libc_lock_lock(NAME) __mutex_lock (&(NAME))
-
-/* Lock the named lock variable. */
-#define __libc_lock_trylock(NAME) (!__mutex_trylock (&(NAME)))
-
-/* Unlock the named lock variable. */
-#define __libc_lock_unlock(NAME) __mutex_unlock (&(NAME))
-
-
-#define __libc_lock_define_recursive(CLASS,NAME) \
- CLASS __libc_lock_recursive_t NAME;
-#define _LIBC_LOCK_RECURSIVE_INITIALIZER { MUTEX_INITIALIZER, 0, 0 }
-#define __libc_lock_define_initialized_recursive(CLASS,NAME) \
- CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
-
-#define __rtld_lock_define_recursive(CLASS,NAME) \
- __libc_lock_define_recursive (CLASS, NAME)
-#define _RTLD_LOCK_RECURSIVE_INITIALIZER \
- _LIBC_LOCK_RECURSIVE_INITIALIZER
-#define __rtld_lock_define_initialized_recursive(CLASS,NAME) \
- __libc_lock_define_initialized_recursive (CLASS, NAME)
-
-#define __libc_lock_init_recursive(NAME) \
- ({ __libc_lock_recursive_t *const __lock = &(NAME); \
- __lock->owner = 0; mutex_init (&__lock->mutex); })
-
-#define __libc_lock_trylock_recursive(NAME) \
- ({ __libc_lock_recursive_t *const __lock = &(NAME); \
- void *__self = __libc_lock_owner_self (); \
- __mutex_trylock (&__lock->mutex) \
- ? (__lock->owner = __self, __lock->count = 1, 0) \
- : __lock->owner == __self ? (++__lock->count, 0) : 1; })
-
-#define __libc_lock_lock_recursive(NAME) \
- ({ __libc_lock_recursive_t *const __lock = &(NAME); \
- void *__self = __libc_lock_owner_self (); \
- if (__mutex_trylock (&__lock->mutex) \
- || (__lock->owner != __self \
- && (__mutex_lock (&__lock->mutex), 1))) \
- __lock->owner = __self, __lock->count = 1; \
- else \
- ++__lock->count; \
- })
-#define __libc_lock_unlock_recursive(NAME) \
- ({ __libc_lock_recursive_t *const __lock = &(NAME); \
- if (--__lock->count == 0) \
- { \
- __lock->owner = 0; \
- __mutex_unlock (&__lock->mutex); \
- } \
- })
-
-
-#define __rtld_lock_initialize(NAME) \
- (void) ((NAME) = (__rtld_lock_recursive_t) _RTLD_LOCK_RECURSIVE_INITIALIZER)
-#define __rtld_lock_trylock_recursive(NAME) \
- __libc_lock_trylock_recursive (NAME)
-#define __rtld_lock_lock_recursive(NAME) \
- __libc_lock_lock_recursive(NAME)
-#define __rtld_lock_unlock_recursive(NAME) \
- __libc_lock_unlock_recursive (NAME)
-
-
-/* XXX for now */
-#define __libc_rwlock_define __libc_lock_define
-#define __libc_rwlock_define_initialized __libc_lock_define_initialized
-#define __libc_rwlock_init __libc_lock_init
-#define __libc_rwlock_fini __libc_lock_fini
-#define __libc_rwlock_rdlock __libc_lock_lock
-#define __libc_rwlock_wrlock __libc_lock_lock
-#define __libc_rwlock_tryrdlock __libc_lock_trylock
-#define __libc_rwlock_trywrlock __libc_lock_trylock
-#define __libc_rwlock_unlock __libc_lock_unlock
-
-
-/* Start a critical region with a cleanup function */
-#define __libc_cleanup_region_start(DOIT, FCT, ARG) \
-{ \
- typeof (***(FCT)) *__save_FCT = (DOIT) ? (FCT) : 0; \
- typeof (ARG) __save_ARG = ARG; \
- /* close brace is in __libc_cleanup_region_end below. */
-
-/* End a critical region started with __libc_cleanup_region_start. */
-#define __libc_cleanup_region_end(DOIT) \
- if ((DOIT) && __save_FCT != 0) \
- (*__save_FCT)(__save_ARG); \
-}
-
-/* Sometimes we have to exit the block in the middle. */
-#define __libc_cleanup_end(DOIT) \
- if ((DOIT) && __save_FCT != 0) \
- (*__save_FCT)(__save_ARG); \
-
-#define __libc_cleanup_push(fct, arg) __libc_cleanup_region_start (1, fct, arg)
-#define __libc_cleanup_pop(execute) __libc_cleanup_region_end (execute)
-
-#if (_CTHREADS_ - 0)
-
-/* Use mutexes as once control variables. */
-
-struct __libc_once
- {
- __libc_lock_t lock;
- int done;
- };
-
-#define __libc_once_define(CLASS,NAME) \
- CLASS struct __libc_once NAME = { MUTEX_INITIALIZER, 0 }
-
-/* Call handler iff the first call. */
-#define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \
- do { \
- __libc_lock_lock (ONCE_CONTROL.lock); \
- if (!ONCE_CONTROL.done) \
- (INIT_FUNCTION) (); \
- ONCE_CONTROL.done = 1; \
- __libc_lock_unlock (ONCE_CONTROL.lock); \
- } while (0)
-
-/* Get once control variable. */
-#define __libc_once_get(ONCE_CONTROL) ((ONCE_CONTROL).done != 0)
-
-#ifdef _LIBC
-/* We need portable names for some functions. E.g., when they are
- used as argument to __libc_cleanup_region_start. */
-#define __libc_mutex_unlock __mutex_unlock
-#endif
-
-/* Type for key of thread specific data. */
-typedef cthread_key_t __libc_key_t;
-
-#define __libc_key_create(KEY,DEST) cthread_keycreate (KEY)
-#define __libc_setspecific(KEY,VAL) cthread_setspecific (KEY, VAL)
-void *__libc_getspecific (__libc_key_t key);
-
-#endif /* _CTHREADS_ */
-
-/* Hide the definitions which are only supposed to be used inside libc in
- a separate file. This file is not present in the installation! */
-#ifdef _LIBC
-# include <libc-lockP.h>
-#endif
-
-#endif /* libc-lock.h */
diff --git a/sysdeps/mach/hurd/malloc-machine.h b/sysdeps/mach/hurd/malloc-machine.h
index 515f3ff151..d3580059a6 100644
--- a/sysdeps/mach/hurd/malloc-machine.h
+++ b/sysdeps/mach/hurd/malloc-machine.h
@@ -22,15 +22,14 @@
#undef thread_atfork_static
-#include <atomic.h>
#include <libc-lock.h>
+#include <mach/lock-intern.h>
-/* Assume hurd, with cthreads */
-
-/* Cthreads `mutex_t' is a pointer to a mutex, and malloc wants just the
- mutex itself. */
#undef mutex_t
-#define mutex_t struct mutex
+#define mutex_t unsigned int
+
+#undef MUTEX_INITIALIZER
+#define MUTEX_INITIALIZER LLL_INITIALIZER
#undef mutex_init
#define mutex_init(m) ({ __mutex_init(m); 0; })
diff --git a/sysdeps/mach/hurd/mig-reply.c b/sysdeps/mach/hurd/mig-reply.c
index 5471cf220d..5aa04a8389 100644
--- a/sysdeps/mach/hurd/mig-reply.c
+++ b/sysdeps/mach/hurd/mig-reply.c
@@ -18,26 +18,20 @@
#include <mach.h>
#include <hurd/threadvar.h>
-#define GETPORT \
- mach_port_t *portloc = \
- (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY)
-#define reply_port (*(use_threadvar ? portloc : &global_reply_port))
-
-static int use_threadvar;
-static mach_port_t global_reply_port;
-
/* These functions are called by MiG-generated code. */
+mach_port_t __hurd_reply_port0;
+
/* Called by MiG to get a reply port. */
mach_port_t
__mig_get_reply_port (void)
{
- GETPORT;
-
- if (reply_port == MACH_PORT_NULL)
- reply_port = __mach_reply_port ();
+ if (__hurd_local_reply_port == MACH_PORT_NULL ||
+ (&__hurd_local_reply_port != &__hurd_reply_port0
+ && __hurd_local_reply_port == __hurd_reply_port0))
+ __hurd_local_reply_port = __mach_reply_port ();
- return reply_port;
+ return __hurd_local_reply_port;
}
weak_alias (__mig_get_reply_port, mig_get_reply_port)
@@ -45,12 +39,8 @@ weak_alias (__mig_get_reply_port, mig_get_reply_port)
void
__mig_dealloc_reply_port (mach_port_t arg)
{
- mach_port_t port;
-
- GETPORT;
-
- port = reply_port;
- reply_port = MACH_PORT_NULL; /* So the mod_refs RPC won't use it. */
+ mach_port_t port = __hurd_local_reply_port;
+ __hurd_local_reply_port = MACH_PORT_NULL; /* So the mod_refs RPC won't use it. */
if (MACH_PORT_VALID (port))
__mach_port_mod_refs (__mach_task_self (), port,
@@ -73,15 +63,6 @@ weak_alias (__mig_put_reply_port, mig_put_reply_port)
void
__mig_init (void *stack)
{
- use_threadvar = stack != 0;
-
- if (use_threadvar)
- {
- /* Recycle the reply port used before multithreading was enabled. */
- mach_port_t *portloc = (mach_port_t *)
- __hurd_threadvar_location_from_sp (_HURD_THREADVAR_MIG_REPLY, stack);
- *portloc = global_reply_port;
- global_reply_port = MACH_PORT_NULL;
- }
+ /* Do nothing. */
}
weak_alias (__mig_init, mig_init)
diff --git a/sysdeps/mach/hurd/openat.c b/sysdeps/mach/hurd/openat.c
index 974ff3fa15..4bb6ae421a 100644
--- a/sysdeps/mach/hurd/openat.c
+++ b/sysdeps/mach/hurd/openat.c
@@ -29,7 +29,7 @@
the directory associated with FD. If O_CREAT or O_TMPFILE is in OFLAG, a
third argument is the file protection. */
int
-__openat (int fd, const char *file, int oflag)
+__openat (int fd, const char *file, int oflag, ...)
{
mode_t mode;
io_t port;
diff --git a/sysdeps/mach/hurd/pipe.c b/sysdeps/mach/hurd/pipe.c
index 364c856a59..d4194bbe62 100644
--- a/sysdeps/mach/hurd/pipe.c
+++ b/sysdeps/mach/hurd/pipe.c
@@ -15,9 +15,6 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <errno.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
#include <unistd.h>
/* Create a one-way communication channel (pipe).
@@ -28,23 +25,7 @@
int
__pipe (int fds[2])
{
- int save_errno = errno;
- int result;
-
- /* The magic S_IFIFO protocol tells the pflocal server to create
- sockets which report themselves as FIFOs, as POSIX requires for
- pipes. */
- result = __socketpair (PF_LOCAL, SOCK_STREAM, S_IFIFO, fds);
- if (result == -1 && errno == EPROTONOSUPPORT)
- {
- /* We contacted an "old" pflocal server that doesn't support the
- magic S_IFIFO protocol.
- FIXME: Remove this junk somewhere in the future. */
- __set_errno (save_errno);
- return __socketpair (PF_LOCAL, SOCK_STREAM, 0, fds);
- }
-
- return result;
+ return __pipe2 (fds, 0);
}
libc_hidden_def (__pipe)
weak_alias (__pipe, pipe)
diff --git a/sysdeps/mach/hurd/pipe2.c b/sysdeps/mach/hurd/pipe2.c
new file mode 100644
index 0000000000..8086d64724
--- /dev/null
+++ b/sysdeps/mach/hurd/pipe2.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 1992-2015 Free Software Foundation, Inc.
+
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <fcntl-internal.h>
+#include <hurd.h>
+
+/* Create a one-way communication channel (pipe).
+ Actually the channel is two-way on the Hurd.
+ If successful, two file descriptors are stored in FDS;
+ bytes written on FDS[1] can be read from FDS[0].
+ Apply FLAGS to the new file descriptors.
+ Returns 0 if successful, -1 if not. */
+int
+__pipe2 (int fds[2], int flags)
+{
+ int save_errno = errno;
+ int result;
+
+ if (flags & ~(O_CLOEXEC | O_NONBLOCK))
+ return __hurd_fail (EINVAL);
+
+ flags = o_to_sock_flags (flags);
+
+ /* The magic S_IFIFO protocol tells the pflocal server to create
+ sockets which report themselves as FIFOs, as POSIX requires for
+ pipes. */
+ result = __socketpair (PF_LOCAL, SOCK_STREAM | flags, S_IFIFO, fds);
+ if (result == -1 && errno == EPROTONOSUPPORT)
+ {
+ /* We contacted an "old" pflocal server that doesn't support the
+ magic S_IFIFO protocol.
+ FIXME: Remove this junk somewhere in the future. */
+ __set_errno (save_errno);
+ return __socketpair (PF_LOCAL, SOCK_STREAM | flags, 0, fds);
+ }
+
+ return result;
+}
+weak_alias (__pipe2, pipe2)
diff --git a/sysdeps/mach/hurd/profil.c b/sysdeps/mach/hurd/profil.c
index dd77cd3d53..ae79ae6cb8 100644
--- a/sysdeps/mach/hurd/profil.c
+++ b/sysdeps/mach/hurd/profil.c
@@ -68,6 +68,8 @@ update_waiter (u_short *sample_buffer, size_t size, size_t offset, u_int scale)
if (! err)
err = __mach_setup_thread (__mach_task_self (), profile_thread,
&profile_waiter, NULL, NULL);
+ if (! err)
+ err = __mach_setup_tls (profile_thread);
}
else
err = 0;
@@ -100,7 +102,7 @@ update_waiter (u_short *sample_buffer, size_t size, size_t offset, u_int scale)
int
__profile_frequency (void)
{
- return profile_tick;
+ return 1000000 / profile_tick;
}
libc_hidden_def (__profile_frequency)
@@ -137,7 +139,7 @@ __profil (u_short *sample_buffer, size_t size, size_t offset, u_int scale)
weak_alias (__profil, profil)
/* Fetch PC samples. This function must be very careful not to depend
- on Hurd threadvar variables. We arrange that by using a special
+ on Hurd TLS variables. We arrange that by using a special
stub arranged for at the end of this file. */
static void
fetch_samples (void)
@@ -173,7 +175,7 @@ fetch_samples (void)
}
-/* This function must be very careful not to depend on Hurd threadvar
+/* This function must be very careful not to depend on Hurd TLS
variables. We arrange that by using special stubs arranged for at the
end of this file. */
static void
@@ -265,7 +267,7 @@ text_set_element (_hurd_fork_child_hook, fork_profil_child);
are fatal in profile_waiter anyhow. */
#define __mig_put_reply_port(foo)
-/* Use our static variable instead of the usual threadvar mechanism for
+/* Use our static variable instead of the usual TLS mechanism for
this. */
#define __mig_get_reply_port() profil_reply_port
diff --git a/sysdeps/mach/hurd/ptsname.c b/sysdeps/mach/hurd/ptsname.c
index 2978394eb5..b3dd0d8479 100644
--- a/sysdeps/mach/hurd/ptsname.c
+++ b/sysdeps/mach/hurd/ptsname.c
@@ -18,6 +18,7 @@
#include <errno.h>
#include <string.h>
+#include <sys/stat.h>
#include <hurd.h>
#include <hurd/fd.h>
#include <hurd/term.h>
@@ -38,11 +39,10 @@ ptsname (int fd)
}
-/* Store at most BUFLEN characters of the pathname of the slave pseudo
- terminal associated with the master FD is open on in BUF.
- Return 0 on success, otherwise an error number. */
+/* We can't make use of STP, but do it that way for conformity with the Linux
+ version... */
int
-__ptsname_r (int fd, char *buf, size_t buflen)
+__ptsname_internal (int fd, char *buf, size_t buflen, struct stat64 *stp)
{
string_t peername;
size_t len;
@@ -61,4 +61,14 @@ __ptsname_r (int fd, char *buf, size_t buflen)
memcpy (buf, peername, len);
return 0;
}
+
+
+/* Store at most BUFLEN characters of the pathname of the slave pseudo
+ terminal associated with the master FD is open on in BUF.
+ Return 0 on success, otherwise an error number. */
+int
+__ptsname_r (int fd, char *buf, size_t buflen)
+{
+ return __ptsname_internal (fd, buf, buflen, NULL);
+}
weak_alias (__ptsname_r, ptsname_r)
diff --git a/sysdeps/mach/hurd/reboot.c b/sysdeps/mach/hurd/reboot.c
index 73d2ad7ad4..d3ff94a794 100644
--- a/sysdeps/mach/hurd/reboot.c
+++ b/sysdeps/mach/hurd/reboot.c
@@ -18,6 +18,7 @@
#include <errno.h>
#include <unistd.h>
#include <hurd.h>
+#include <hurd/paths.h>
#include <hurd/startup.h>
#include <sys/reboot.h>
@@ -33,8 +34,8 @@ reboot (int howto)
if (err)
return __hurd_fail (EPERM);
- err = __USEPORT (PROC, __proc_getmsgport (port, 1, &init));
- if (!err)
+ init = __file_name_lookup (_SERVERS_STARTUP, 0, 0);
+ if (init != MACH_PORT_NULL)
{
err = __startup_reboot (init, hostpriv, howto);
__mach_port_deallocate (__mach_task_self (), init);
diff --git a/sysdeps/mach/hurd/recvmsg.c b/sysdeps/mach/hurd/recvmsg.c
index 770a42e05e..a174794913 100644
--- a/sysdeps/mach/hurd/recvmsg.c
+++ b/sysdeps/mach/hurd/recvmsg.c
@@ -23,6 +23,123 @@
#include <hurd/fd.h>
#include <hurd/socket.h>
+static unsigned
+contains_uid (unsigned int n, __uid_t uids[n], __uid_t uid)
+{
+ unsigned i;
+
+ for (i = 0; i < n; i++)
+ if (uids[i] == uid)
+ return 1;
+ return 0;
+}
+
+static unsigned
+contains_gid (unsigned int n, __gid_t gids[n], __gid_t gid)
+{
+ unsigned i;
+
+ for (i = 0; i < n; i++)
+ if (gids[i] == gid)
+ return 1;
+ return 0;
+}
+
+/* Check the passed credentials. */
+static error_t
+check_auth (mach_port_t rendezvous,
+ __pid_t pid,
+ __uid_t uid, __uid_t euid,
+ __gid_t gid,
+ int ngroups, __gid_t groups[ngroups])
+{
+ error_t err;
+ size_t neuids = CMGROUP_MAX, nauids = CMGROUP_MAX;
+ size_t negids = CMGROUP_MAX, nagids = CMGROUP_MAX;
+ __uid_t euids_buf[neuids], auids_buf[nauids];
+ __gid_t egids_buf[negids], agids_buf[nagids];
+ __uid_t *euids = euids_buf, *auids = auids_buf;
+ __gid_t *egids = egids_buf, *agids = agids_buf;
+
+ struct procinfo *pi = NULL;
+ mach_msg_type_number_t pi_size = 0;
+ int flags = PI_FETCH_TASKINFO;
+ char *tw = NULL;
+ size_t tw_size = 0;
+ unsigned i;
+
+ err = mach_port_mod_refs (mach_task_self (), rendezvous,
+ MACH_PORT_RIGHT_SEND, 1);
+ if (err)
+ goto out;
+
+ do
+ err = __USEPORT
+ (AUTH, __auth_server_authenticate (port,
+ rendezvous, MACH_MSG_TYPE_COPY_SEND,
+ MACH_PORT_NULL, 0,
+ &euids, &neuids, &auids, &nauids,
+ &egids, &negids, &agids, &nagids));
+ while (err == EINTR);
+ if (err)
+ goto out;
+
+ /* Check whether this process indeed has these IDs */
+ if ( !contains_uid (neuids, euids, uid)
+ && !contains_uid (nauids, auids, uid)
+ || !contains_uid (neuids, euids, euid)
+ && !contains_uid (nauids, auids, euid)
+ || !contains_gid (negids, egids, gid)
+ && !contains_gid (nagids, agids, gid)
+ )
+ {
+ err = EIO;
+ goto out;
+ }
+
+ /* Check groups */
+ for (i = 0; i < ngroups; i++)
+ if ( !contains_gid (negids, egids, groups[i])
+ && !contains_gid (nagids, agids, groups[i]))
+ {
+ err = EIO;
+ goto out;
+ }
+
+ /* Check PID */
+ /* XXX: Using proc_getprocinfo until
+ proc_user_authenticate proc_server_authenticate is implemented
+ */
+ /* Get procinfo to check the owner. Maybe he faked the pid, but at least we
+ check the owner. */
+ err = __USEPORT (PROC, __proc_getprocinfo (port, pid, &flags,
+ (procinfo_t *)&pi,
+ &pi_size, &tw, &tw_size));
+ if (err)
+ goto out;
+
+ if ( !contains_uid (neuids, euids, pi->owner)
+ && !contains_uid (nauids, auids, pi->owner))
+ err = EIO;
+
+out:
+ mach_port_deallocate (mach_task_self (), rendezvous);
+ if (euids != euids_buf)
+ __vm_deallocate (__mach_task_self(), (vm_address_t) euids, neuids * sizeof(uid_t));
+ if (auids != auids_buf)
+ __vm_deallocate (__mach_task_self(), (vm_address_t) auids, nauids * sizeof(uid_t));
+ if (egids != egids_buf)
+ __vm_deallocate (__mach_task_self(), (vm_address_t) egids, negids * sizeof(uid_t));
+ if (agids != agids_buf)
+ __vm_deallocate (__mach_task_self(), (vm_address_t) agids, nagids * sizeof(uid_t));
+ if (tw_size)
+ __vm_deallocate (__mach_task_self(), (vm_address_t) tw, tw_size);
+ if (pi_size)
+ __vm_deallocate (__mach_task_self(), (vm_address_t) pi, pi_size);
+
+ return err;
+}
+
/* Receive a message as described by MESSAGE from socket FD.
Returns the number of bytes read or -1 for errors. */
ssize_t
@@ -32,13 +149,34 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags)
addr_port_t aport;
char *data = NULL;
mach_msg_type_number_t len = 0;
- mach_port_t *ports;
+ mach_port_t *ports, *newports = NULL;
mach_msg_type_number_t nports = 0;
+ struct cmsghdr *cmsg;
char *cdata = NULL;
mach_msg_type_number_t clen = 0;
size_t amount;
char *buf;
- int i;
+ int nfds, *opened_fds = NULL;
+ int i, ii, j;
+ int newfds;
+
+ error_t reauthenticate (mach_port_t port, mach_port_t *result)
+ {
+ error_t err;
+ mach_port_t ref;
+ ref = __mach_reply_port ();
+ do
+ err = __io_reauthenticate (port, ref, MACH_MSG_TYPE_MAKE_SEND);
+ while (err == EINTR);
+ if (!err)
+ do
+ err = __USEPORT (AUTH, __auth_user_authenticate (port,
+ ref, MACH_MSG_TYPE_MAKE_SEND,
+ result));
+ while (err == EINTR);
+ __mach_port_destroy (__mach_task_self (), ref);
+ return err;
+ }
/* Find the total number of bytes to be read. */
amount = 0;
@@ -135,9 +273,101 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags)
message->msg_controllen = clen;
memcpy (message->msg_control, cdata, message->msg_controllen);
+ if (nports > 0)
+ {
+ newports = __alloca (nports * sizeof (mach_port_t));
+ opened_fds = __alloca (nports * sizeof (int));
+ }
+
+ /* This counts how many ports we processed completely. */
+ i = 0;
+ /* This counts how many new fds we create. */
+ newfds = 0;
+
+ for (cmsg = CMSG_FIRSTHDR (message);
+ cmsg;
+ cmsg = CMSG_NXTHDR (message, cmsg))
+ {
+ if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
+ {
+ /* SCM_RIGHTS support. */
+ /* The fd's flags are passed in the control data. */
+ int *fds = (int *) CMSG_DATA (cmsg);
+ nfds = (cmsg->cmsg_len - CMSG_ALIGN (sizeof (struct cmsghdr)))
+ / sizeof (int);
+
+ for (j = 0; j < nfds; j++)
+ {
+ err = reauthenticate (ports[i], &newports[newfds]);
+ if (err)
+ goto cleanup;
+ fds[j] = opened_fds[newfds] = _hurd_intern_fd (newports[newfds],
+ fds[j], 0);
+ if (fds[j] == -1)
+ {
+ err = errno;
+ __mach_port_deallocate (__mach_task_self (), newports[newfds]);
+ goto cleanup;
+ }
+ i++;
+ newfds++;
+ }
+ }
+ else if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDS)
+ {
+ /* SCM_CREDS support. */
+ /* Check received credentials */
+ struct cmsgcred *ucredp = (struct cmsgcred *) CMSG_DATA(cmsg);
+
+ err = check_auth (ports[i],
+ ucredp->cmcred_pid,
+ ucredp->cmcred_uid, ucredp->cmcred_euid,
+ ucredp->cmcred_gid,
+ ucredp->cmcred_ngroups, ucredp->cmcred_groups);
+ if (err)
+ goto cleanup;
+ i++;
+ }
+ }
+
+ for (i = 0; i < nports; i++)
+ __mach_port_deallocate (mach_task_self (), ports[i]);
+
__vm_deallocate (__mach_task_self (), (vm_address_t) cdata, clen);
return (buf - data);
+
+cleanup:
+ /* Clean up all the file descriptors from port 0 to i-1. */
+ if (nports > 0)
+ {
+ ii = 0;
+ newfds = 0;
+ for (cmsg = CMSG_FIRSTHDR (message);
+ cmsg;
+ cmsg = CMSG_NXTHDR (message, cmsg))
+ {
+ if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
+ {
+ nfds = (cmsg->cmsg_len - CMSG_ALIGN (sizeof (struct cmsghdr)))
+ / sizeof (int);
+ for (j = 0; j < nfds && ii < i; j++, ii++, newfds++)
+ {
+ _hurd_fd_close (_hurd_fd_get (opened_fds[newfds]));
+ __mach_port_deallocate (__mach_task_self (), newports[newfds]);
+ __mach_port_deallocate (__mach_task_self (), ports[ii]);
+ }
+ }
+ else if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDS)
+ {
+ __mach_port_deallocate (__mach_task_self (), ports[ii]);
+ ii++;
+ }
+ }
+ }
+
+ __vm_deallocate (__mach_task_self (), (vm_address_t) cdata, clen);
+ return __hurd_fail (err);
}
weak_alias (__libc_recvmsg, recvmsg)
diff --git a/sysdeps/mach/hurd/sendmsg.c b/sysdeps/mach/hurd/sendmsg.c
index ce40764992..20db6048f2 100644
--- a/sysdeps/mach/hurd/sendmsg.c
+++ b/sysdeps/mach/hurd/sendmsg.c
@@ -19,11 +19,13 @@
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <unistd.h>
#include <hurd.h>
#include <hurd/fd.h>
#include <hurd/ifsock.h>
#include <hurd/socket.h>
+#include <hurd/auth_request.h>
#include "hurd/hurdsocket.h"
/* Send a message described MESSAGE on socket FD.
@@ -32,6 +34,10 @@ ssize_t
__libc_sendmsg (int fd, const struct msghdr *message, int flags)
{
error_t err = 0;
+ struct cmsghdr *cmsg;
+ mach_port_t *ports = NULL;
+ mach_msg_type_number_t nports = 0;
+ int *fds, nfds;
struct sockaddr_un *addr = message->msg_name;
socklen_t addr_len = message->msg_namelen;
addr_port_t aport = MACH_PORT_NULL;
@@ -44,6 +50,7 @@ __libc_sendmsg (int fd, const struct msghdr *message, int flags)
mach_msg_type_number_t len;
mach_msg_type_number_t amount;
int dealloc = 0;
+ int socketrpc = 0;
int i;
/* Find the total number of bytes to be written. */
@@ -101,6 +108,82 @@ __libc_sendmsg (int fd, const struct msghdr *message, int flags)
}
}
+ /* Allocate enough room for ports. */
+ cmsg = CMSG_FIRSTHDR (message);
+ for (; cmsg; cmsg = CMSG_NXTHDR (message, cmsg))
+ if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
+ nports += (cmsg->cmsg_len - CMSG_ALIGN (sizeof (struct cmsghdr)))
+ / sizeof (int);
+ else if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDS)
+ nports++;
+
+ if (nports)
+ ports = __alloca (nports * sizeof (mach_port_t));
+
+ nports = 0;
+ for (cmsg = CMSG_FIRSTHDR (message);
+ cmsg;
+ cmsg = CMSG_NXTHDR (message, cmsg))
+ {
+ if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
+ {
+ /* SCM_RIGHTS support: send FDs. */
+ fds = (int *) CMSG_DATA (cmsg);
+ nfds = (cmsg->cmsg_len - CMSG_ALIGN (sizeof (struct cmsghdr)))
+ / sizeof (int);
+
+ for (i = 0; i < nfds; i++)
+ {
+ err = HURD_DPORT_USE
+ (fds[i],
+ ({
+ err = __io_restrict_auth (port, &ports[nports],
+ 0, 0, 0, 0);
+ if (! err)
+ nports++;
+ /* We pass the flags in the control data. */
+ fds[i] = descriptor->flags;
+ err;
+ }));
+
+ if (err)
+ goto out;
+ }
+ }
+ else if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDS)
+ {
+ /* SCM_CREDS support: send credentials. */
+ mach_port_t rendezvous = __mach_reply_port (), reply;
+ struct cmsgcred *ucredp;
+
+ err = mach_port_insert_right (mach_task_self (), rendezvous,
+ rendezvous, MACH_MSG_TYPE_MAKE_SEND);
+ ports[nports++] = rendezvous;
+ if (err)
+ goto out;
+
+ ucredp = (struct cmsgcred *) CMSG_DATA(cmsg);
+ /* Fill in credentials data */
+ ucredp->cmcred_pid = __getpid();
+ ucredp->cmcred_uid = __getuid();
+ ucredp->cmcred_euid = __geteuid();
+ ucredp->cmcred_gid = __getgid();
+ ucredp->cmcred_ngroups =
+ __getgroups (sizeof (ucredp->cmcred_groups) / sizeof (gid_t),
+ ucredp->cmcred_groups);
+
+ /* And make auth server authenticate us. */
+ reply = __mach_reply_port();
+ err = __USEPORT
+ (AUTH, __auth_user_authenticate_request (port,
+ reply, MACH_MSG_TYPE_MAKE_SEND_ONCE,
+ rendezvous, MACH_MSG_TYPE_MAKE_SEND));
+ mach_port_deallocate (__mach_task_self (), reply);
+ if (err)
+ goto out;
+ }
+ }
+
if (addr)
{
if (addr->sun_family == AF_LOCAL)
@@ -111,9 +194,8 @@ __libc_sendmsg (int fd, const struct msghdr *message, int flags)
file_t file = __file_name_lookup (name, 0, 0);
if (file == MACH_PORT_NULL)
{
- if (dealloc)
- __vm_deallocate (__mach_task_self (), data.addr, len);
- return -1;
+ err = errno;
+ goto out;
}
err = __ifsock_getsockaddr (file, &aport);
__mach_port_deallocate (__mach_task_self (), file);
@@ -121,11 +203,7 @@ __libc_sendmsg (int fd, const struct msghdr *message, int flags)
/* The file did not grok the ifsock protocol. */
err = ENOTSOCK;
if (err)
- {
- if (dealloc)
- __vm_deallocate (__mach_task_self (), data.addr, len);
- return __hurd_fail (err);
- }
+ goto out;
}
else
err = EIEIO;
@@ -144,8 +222,9 @@ __libc_sendmsg (int fd, const struct msghdr *message, int flags)
/* Send the data. */
err = __socket_send (port, aport,
flags, data.ptr, len,
- NULL,
- MACH_MSG_TYPE_COPY_SEND, 0,
+ ports,
+ MACH_MSG_TYPE_COPY_SEND,
+ nports,
message->msg_control,
message->msg_controllen,
&amount);
@@ -154,11 +233,19 @@ __libc_sendmsg (int fd, const struct msghdr *message, int flags)
}
err;
}));
+ socketrpc = 1;
+
+ out:
+ for (i = 0; i < nports; i++)
+ __mach_port_deallocate (__mach_task_self (), ports[i]);
if (dealloc)
__vm_deallocate (__mach_task_self (), data.addr, len);
- return err ? __hurd_sockfail (fd, flags, err) : amount;
+ if (socketrpc)
+ return err ? __hurd_sockfail (fd, flags, err) : amount;
+ else
+ return __hurd_fail (err);
}
weak_alias (__libc_sendmsg, sendmsg)
diff --git a/sysdeps/mach/hurd/setegid.c b/sysdeps/mach/hurd/setegid.c
index 9057135222..dc97f86d3c 100644
--- a/sysdeps/mach/hurd/setegid.c
+++ b/sysdeps/mach/hurd/setegid.c
@@ -55,6 +55,7 @@ setegid (gid_t gid)
}
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
if (err)
return __hurd_fail (err);
diff --git a/sysdeps/mach/hurd/seteuid.c b/sysdeps/mach/hurd/seteuid.c
index 3e16aba175..d6d905e5e6 100644
--- a/sysdeps/mach/hurd/seteuid.c
+++ b/sysdeps/mach/hurd/seteuid.c
@@ -55,6 +55,7 @@ seteuid (uid_t uid)
}
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
if (err)
return __hurd_fail (err);
diff --git a/sysdeps/mach/hurd/setgid.c b/sysdeps/mach/hurd/setgid.c
index 3bd1ac9f0a..5a3202f874 100644
--- a/sysdeps/mach/hurd/setgid.c
+++ b/sysdeps/mach/hurd/setgid.c
@@ -81,6 +81,7 @@ __setgid (gid_t gid)
}
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
if (err)
return __hurd_fail (err);
diff --git a/sysdeps/mach/hurd/setgroups.c b/sysdeps/mach/hurd/setgroups.c
index 23ae4f570e..b0392c49c3 100644
--- a/sysdeps/mach/hurd/setgroups.c
+++ b/sysdeps/mach/hurd/setgroups.c
@@ -50,6 +50,7 @@ setgroups (size_t n, const gid_t *groups)
}
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
if (err)
return __hurd_fail (err);
diff --git a/sysdeps/mach/hurd/setitimer.c b/sysdeps/mach/hurd/setitimer.c
index 803b981931..2ce928abd4 100644
--- a/sysdeps/mach/hurd/setitimer.c
+++ b/sysdeps/mach/hurd/setitimer.c
@@ -103,7 +103,7 @@ timer_thread (void)
__msg_sig_post_request (_hurd_msgport,
_hurd_itimer_port,
MACH_MSG_TYPE_MAKE_SEND_ONCE,
- SIGALRM, 0, __mach_task_self ());
+ SIGALRM, SI_TIMER, __mach_task_self ());
break;
case MACH_RCV_INTERRUPTED:
@@ -128,7 +128,8 @@ timer_thread (void)
/* Forward declaration. */
static int setitimer_locked (const struct itimerval *new,
- struct itimerval *old, void *crit);
+ struct itimerval *old, void *crit,
+ int hurd_siglocked);
static sighandler_t
restart_itimer (struct hurd_signal_preemptor *preemptor,
@@ -142,7 +143,7 @@ restart_itimer (struct hurd_signal_preemptor *preemptor,
/* Either reload or disable the itimer. */
__spin_lock (&_hurd_itimer_lock);
it.it_value = it.it_interval = _hurd_itimerval.it_interval;
- setitimer_locked (&it, NULL, NULL);
+ setitimer_locked (&it, NULL, NULL, 1);
/* Continue with normal delivery (or hold, etc.) of SIGALRM. */
return SIG_ERR;
@@ -154,7 +155,7 @@ restart_itimer (struct hurd_signal_preemptor *preemptor,
static int
setitimer_locked (const struct itimerval *new, struct itimerval *old,
- void *crit)
+ void *crit, int hurd_siglocked)
{
struct itimerval newval;
struct timeval now, remaining, elapsed;
@@ -192,16 +193,19 @@ setitimer_locked (const struct itimerval *new, struct itimerval *old,
run `restart_itimer' each time a SIGALRM would arrive. */
static struct hurd_signal_preemptor preemptor =
{
- __sigmask (SIGALRM), 0, 0,
+ __sigmask (SIGALRM), SI_TIMER, SI_TIMER,
&restart_itimer,
};
- __mutex_lock (&_hurd_siglock);
+ if (!hurd_siglocked)
+ __mutex_lock (&_hurd_siglock);
if (! preemptor.next && _hurdsig_preemptors != &preemptor)
{
preemptor.next = _hurdsig_preemptors;
_hurdsig_preemptors = &preemptor;
+ _hurdsig_preempted_set |= preemptor.signals;
}
- __mutex_unlock (&_hurd_siglock);
+ if (!hurd_siglocked)
+ __mutex_unlock (&_hurd_siglock);
if (_hurd_itimer_port == MACH_PORT_NULL)
{
@@ -221,11 +225,12 @@ setitimer_locked (const struct itimerval *new, struct itimerval *old,
goto out;
_hurd_itimer_thread_stack_base = 0; /* Anywhere. */
_hurd_itimer_thread_stack_size = __vm_page_size; /* Small stack. */
- if (err = __mach_setup_thread (__mach_task_self (),
+ if ((err = __mach_setup_thread (__mach_task_self (),
_hurd_itimer_thread,
&timer_thread,
&_hurd_itimer_thread_stack_base,
&_hurd_itimer_thread_stack_size))
+ || (err = __mach_setup_tls (_hurd_itimer_thread)))
{
__thread_terminate (_hurd_itimer_thread);
_hurd_itimer_thread = MACH_PORT_NULL;
@@ -348,7 +353,7 @@ __setitimer (enum __itimer_which which, const struct itimerval *new,
crit = _hurd_critical_section_lock ();
__spin_lock (&_hurd_itimer_lock);
- return setitimer_locked (new, old, crit);
+ return setitimer_locked (new, old, crit, 0);
}
static void
@@ -363,7 +368,7 @@ fork_itimer (void)
it = _hurd_itimerval;
it.it_value = it.it_interval;
- setitimer_locked (&it, NULL, NULL);
+ setitimer_locked (&it, NULL, NULL, 0);
(void) &fork_itimer; /* Avoid gcc optimizing out the function. */
}
diff --git a/sysdeps/mach/hurd/setpgid.c b/sysdeps/mach/hurd/setpgid.c
index 8579efb9b1..8c2a29cbab 100644
--- a/sysdeps/mach/hurd/setpgid.c
+++ b/sysdeps/mach/hurd/setpgid.c
@@ -19,6 +19,7 @@
#include <unistd.h>
#include <hurd.h>
#include <hurd/port.h>
+#include <lowlevellock.h>
/* Set the process group ID of the process matching PID to PGID.
If PID is zero, the current process's process group ID is set.
@@ -38,14 +39,7 @@ __setpgid (pid_t pid, pid_t pgid)
/* Synchronize with the signal thread to make sure we have
received and processed proc_newids before returning to the user. */
while (_hurd_pids_changed_stamp == stamp)
- {
-#ifdef noteven
- /* XXX we have no need for a mutex, but cthreads demands one. */
- __condition_wait (&_hurd_pids_changed_sync, NULL);
-#else
- __swtch_pri(0);
-#endif
- }
+ lll_wait (&_hurd_pids_changed_stamp, stamp, 0);
return 0;
diff --git a/sysdeps/mach/hurd/setregid.c b/sysdeps/mach/hurd/setregid.c
index 24797f3968..7e27e31c93 100644
--- a/sysdeps/mach/hurd/setregid.c
+++ b/sysdeps/mach/hurd/setregid.c
@@ -82,6 +82,7 @@ __setregid (gid_t rgid, gid_t egid)
}
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
if (err)
return __hurd_fail (err);
diff --git a/sysdeps/mach/hurd/setresgid.c b/sysdeps/mach/hurd/setresgid.c
index 256fac4a20..8abda001ec 100644
--- a/sysdeps/mach/hurd/setresgid.c
+++ b/sysdeps/mach/hurd/setresgid.c
@@ -110,6 +110,7 @@ __setresgid (gid_t rgid, gid_t egid, gid_t sgid)
}
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
if (err)
return __hurd_fail (err);
diff --git a/sysdeps/mach/hurd/setresuid.c b/sysdeps/mach/hurd/setresuid.c
index 7d33e205ac..8296055430 100644
--- a/sysdeps/mach/hurd/setresuid.c
+++ b/sysdeps/mach/hurd/setresuid.c
@@ -111,6 +111,7 @@ __setresuid (uid_t ruid, uid_t euid, uid_t suid)
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
if (err)
return __hurd_fail (err);
diff --git a/sysdeps/mach/hurd/setreuid.c b/sysdeps/mach/hurd/setreuid.c
index e4e05f6e4c..84f1cf6762 100644
--- a/sysdeps/mach/hurd/setreuid.c
+++ b/sysdeps/mach/hurd/setreuid.c
@@ -82,6 +82,7 @@ __setreuid (uid_t ruid, uid_t euid)
}
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
if (err)
return __hurd_fail (err);
diff --git a/sysdeps/mach/hurd/setsid.c b/sysdeps/mach/hurd/setsid.c
index c66466686f..746af3cd71 100644
--- a/sysdeps/mach/hurd/setsid.c
+++ b/sysdeps/mach/hurd/setsid.c
@@ -21,6 +21,7 @@
#include <hurd/port.h>
#include <hurd/fd.h>
#include <hurd/ioctl.h>
+#include <lowlevellock.h>
/* Create a new session with the calling process as its leader.
The process group IDs of the session and the calling process
@@ -55,17 +56,11 @@ __setsid (void)
returned by `getpgrp ()' in other threads) has been updated before
we return. */
while (_hurd_pids_changed_stamp == stamp)
- {
-#ifdef noteven
- /* XXX we have no need for a mutex, but cthreads demands one. */
- __condition_wait (&_hurd_pids_changed_sync, NULL);
-#else
- __swtch_pri (0);
-#endif
- }
+ lll_wait (&_hurd_pids_changed_stamp, stamp, 0);
}
HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
return err ? __hurd_fail (err) : _hurd_pgrp;
}
diff --git a/sysdeps/mach/hurd/setuid.c b/sysdeps/mach/hurd/setuid.c
index 6fca89c288..c7e92a54c5 100644
--- a/sysdeps/mach/hurd/setuid.c
+++ b/sysdeps/mach/hurd/setuid.c
@@ -86,6 +86,7 @@ __setuid (uid_t uid)
}
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
+ /* FIXME: handle EINTR! */
if (err)
return __hurd_fail (err);
diff --git a/sysdeps/mach/hurd/shmat.c b/sysdeps/mach/hurd/shmat.c
new file mode 100644
index 0000000000..dd783da5d1
--- /dev/null
+++ b/sysdeps/mach/hurd/shmat.c
@@ -0,0 +1,82 @@
+/* SysV shmat for Hurd.
+ Copyright (C) 2005-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <utime.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/mman.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "sysvshm.h"
+
+/* Attach the shared memory segment associated with SHMID to the data
+ segment of the calling process. SHMADDR and SHMFLG determine how
+ and where the segment is attached. */
+void *
+__shmat (int shmid, const void *shmaddr, int shmflg)
+{
+ error_t err;
+ char filename[sizeof (SHM_DIR) - 1 + SHM_NAMEMAX];
+ int fd;
+ void *addr;
+ struct stat statbuf;
+ int res;
+
+ sprintf (filename, SHM_DIR SHM_NAMEPRI, shmid);
+ fd = __open (filename, (shmflg & SHM_RDONLY) ? O_RDONLY : O_RDWR);
+ if (fd < 0)
+ {
+ if (errno == ENOENT)
+ errno = EINVAL;
+ return (void *) -1;
+ }
+
+ res = __fstat (fd, &statbuf);
+ if (res < 0)
+ {
+ err = errno;
+ __close (fd);
+ errno = err;
+ return (void *) -1;
+ }
+
+ addr = __mmap ((void *) shmaddr, statbuf.st_size,
+ PROT_READ | ((shmflg & SHM_RDONLY) ? 0 : PROT_WRITE),
+ MAP_SHARED, fd, 0);
+ __close (fd);
+ if (addr == MAP_FAILED)
+ return (void *) -1;
+
+ err = __sysvshm_add (addr, statbuf.st_size);
+ if (err)
+ {
+ munmap (addr, statbuf.st_size);
+ errno = err;
+ return (void *) -1;
+ }
+
+ return addr;
+}
+
+weak_alias(__shmat, shmat)
diff --git a/sysdeps/mach/hurd/shmctl.c b/sysdeps/mach/hurd/shmctl.c
new file mode 100644
index 0000000000..a991a0c8de
--- /dev/null
+++ b/sysdeps/mach/hurd/shmctl.c
@@ -0,0 +1,132 @@
+/* SysV shmctl for Hurd.
+ Copyright (C) 2005-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "sysvshm.h"
+
+/* Provide operations to control shared memory segments. */
+int
+__shmctl (int id, int cmd, struct shmid_ds *buf)
+{
+ error_t err = 0;
+ int fd;
+ int res;
+ char filename[sizeof (SHM_DIR) - 1 + SHM_NAMEMAX];
+ struct stat statbuf;
+
+ sprintf (filename, SHM_DIR SHM_NAMEPRI, id);
+ /* SysV requires read access for IPC_STAT. */
+ fd = __open (filename, O_NORW);
+ if (fd < 0)
+ {
+ if (errno == ENOENT)
+ errno = EINVAL;
+ return -1;
+ }
+
+ res = __fstat (fd, &statbuf);
+ if (res < 0)
+ {
+ err = errno;
+ __close (fd);
+ errno = err;
+ return -1;
+ }
+
+ switch (cmd)
+ {
+ case IPC_STAT:
+
+ buf->shm_perm.__key = id;
+ buf->shm_perm.uid = statbuf.st_uid;
+ buf->shm_perm.gid = statbuf.st_gid;
+
+ /* We do not support the creator. */
+ buf->shm_perm.cuid = statbuf.st_uid;
+ buf->shm_perm.cgid = statbuf.st_gid;
+
+ /* We just want the protection bits. */
+ buf->shm_perm.mode = statbuf.st_mode & 0777;
+ /* Hopeless. We do not support a sequence number. */
+ buf->shm_perm.__seq = statbuf.st_ino;
+ buf->shm_segsz = statbuf.st_size;
+
+ /* Hopeless. We do not support any of these. */
+ buf->shm_atime = statbuf.st_atime;
+ buf->shm_dtime = statbuf.st_mtime;
+ /* Well, this comes at least close. */
+ buf->shm_ctime = statbuf.st_ctime;
+
+ /* We do not support the PID. */
+ buf->shm_cpid = 0;
+ buf->shm_lpid = 0;
+
+ if (statbuf.st_mode & S_IMMAP0)
+ buf->shm_nattch = 0;
+ else
+ /* 42 is the answer. Of course this is bogus, but for most
+ applications, this should be fine. */
+ buf->shm_nattch = 42;
+
+ break;
+
+ case IPC_SET:
+ if (statbuf.st_uid != buf->shm_perm.uid
+ || statbuf.st_gid != buf->shm_perm.gid)
+ {
+ res = __fchown (fd,
+ (statbuf.st_uid != buf->shm_perm.uid)
+ ? buf->shm_perm.uid : -1,
+ (statbuf.st_gid != buf->shm_perm.gid)
+ ? buf->shm_perm.gid : -1);
+ if (res < 0)
+ err = errno;
+ }
+
+ if (!err && statbuf.st_mode & 0777 != buf->shm_perm.mode & 0777)
+ {
+ res = __fchmod (fd, (statbuf.st_mode & ~0777)
+ | (buf->shm_perm.mode & 0777));
+ if (res < 0)
+ err = errno;
+ }
+ break;
+
+ case IPC_RMID:
+ res = __unlink (filename);
+ /* FIXME: Check error (mapping ENOENT to EINVAL). */
+ break;
+
+ default:
+ err = EINVAL;
+ }
+
+ __close (fd);
+ errno = err;
+ return err ? -1 : 0;
+}
+
+weak_alias(__shmctl, shmctl)
diff --git a/sysdeps/mach/hurd/shmdt.c b/sysdeps/mach/hurd/shmdt.c
new file mode 100644
index 0000000000..988fab8ee6
--- /dev/null
+++ b/sysdeps/mach/hurd/shmdt.c
@@ -0,0 +1,51 @@
+/* SysV shmdt for Hurd.
+ Copyright (C) 2005-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/mman.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+
+#include "sysvshm.h"
+
+/* Detach shared memory segment starting at address specified by
+ SHMADDR from the caller's data segment. */
+int
+__shmdt (const void *shmaddr)
+{
+ error_t err;
+ size_t size;
+
+ err = __sysvshm_remove ((void *) shmaddr, &size);
+ if (err)
+ {
+ errno = err;
+ return -1;
+ }
+
+ __munmap ((void *) shmaddr, size);
+ return 0;
+}
+
+weak_alias(__shmdt, shmdt)
diff --git a/sysdeps/mach/hurd/shmget.c b/sysdeps/mach/hurd/shmget.c
new file mode 100644
index 0000000000..2065b41989
--- /dev/null
+++ b/sysdeps/mach/hurd/shmget.c
@@ -0,0 +1,242 @@
+/* SysV shmget for Hurd.
+ Copyright (C) 2005-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/shm.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <limits.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <hurd/fd.h>
+
+#include "sysvshm.h"
+
+/* Create a new shared memory segment file without linking it into the
+ filesystem. Return the directory and file ports in R_DIR and R_FILE. */
+static error_t
+create_shm_file (size_t size, int flags, file_t *r_dir, file_t *r_file)
+{
+ error_t err;
+ file_t dir;
+ file_t file;
+
+ flags &= 0777;
+
+ /* Get a port to the directory that will contain the file. */
+ dir = __file_name_lookup (SHM_DIR, 0, 0);
+ if (dir == MACH_PORT_NULL)
+ return errno;
+
+ /* Create an unnamed file in the directory. */
+ err = __dir_mkfile (dir, O_RDWR, flags, &file);
+ if (err)
+ {
+ __mach_port_deallocate (__mach_task_self (), dir);
+ return err;
+ }
+
+ err = __file_set_size (file, size);
+ if (err)
+ {
+ __mach_port_deallocate (__mach_task_self (), file);
+ __mach_port_deallocate (__mach_task_self (), dir);
+
+ return err;
+ }
+
+ *r_dir = dir;
+ *r_file = file;
+
+ return 0;
+}
+
+
+/* Open the shared memory segment *R_KEY and return a file descriptor
+ to it in R_FD. If KEY is IPC_PRIVATE, use a private key and return
+ it in R_KEY. */
+static error_t
+get_exclusive (int shmflags, size_t size, key_t *r_key, int *r_fd)
+{
+ error_t err;
+ file_t dir;
+ file_t file;
+ char filename[SHM_NAMEMAX];
+ key_t key = *r_key;
+ bool is_private;
+
+ /* Create the shared memory segment. */
+ err = create_shm_file (size, shmflags, &dir, &file);
+ if (err)
+ return err;
+
+ if (key == IPC_PRIVATE)
+ {
+ is_private = true;
+ key = SHM_PRIV_KEY_START;
+
+ /* Try to link the shared memory segment into the filesystem
+ (exclusively). */
+ do
+ {
+ sprintf (filename, SHM_NAMEPRI, key);
+ err = __dir_link (dir, file, filename, 1);
+ if (!err)
+ {
+ /* We are done. */
+ *r_key = key;
+ break;
+ }
+ else if (err == EEXIST)
+ {
+ /* Check if we ran out of keys. If not, try again with new
+ key. */
+ if (key == SHM_PRIV_KEY_END)
+ err = ENOSPC;
+ else
+ err = 0;
+
+ key--;
+ }
+ }
+ while (!err);
+ }
+ else
+ {
+ /* Try to link the shared memory segment into the filesystem
+ (exclusively) under the given key. */
+ sprintf (filename, SHM_NAMEPRI, key);
+ err = __dir_link (dir, file, filename, 1);
+ }
+
+ __mach_port_deallocate (__mach_task_self (), dir);
+
+ if (!err)
+ {
+ int fd;
+
+ /* Get a file descriptor for that port. */
+ fd = _hurd_intern_fd (file, O_RDWR, 1); /* dealloc on error */
+ if (fd < 0)
+ err = errno;
+ else
+ *r_fd = fd;
+ }
+
+ return err;
+}
+
+
+/* Open the shared memory segment KEY (creating it if it doesn't yet
+ exist) and return a file descriptor to it in R_FD. */
+static error_t
+get_shared (int shmflags, size_t size, key_t key, int *r_fd)
+{
+ error_t err = 0;
+ char filename[sizeof (SHM_DIR) - 1 + SHM_NAMEMAX];
+ int fd = -1;
+ sprintf (filename, SHM_DIR SHM_NAMEPRI, key);
+
+ do
+ {
+ fd = __open (filename, O_NORW, shmflags & 0777);
+
+ if (fd < 0 && errno != ENOENT)
+ /* We give up. */
+ return errno;
+ else if (fd >= 0)
+ {
+ int res;
+ struct stat statbuf;
+
+ /* Check the size (we only need to do this if we did not
+ create the shared memory segment file ourselves). */
+ res = __fstat (fd, &statbuf);
+ if (res < 0)
+ {
+ err = errno;
+ __close (fd);
+ return err;
+ }
+
+ if (statbuf.st_size < size)
+ {
+ __close (fd);
+ return EINVAL;
+ }
+ }
+ else
+ {
+ /* The memory segment doesn't exist. */
+ if (shmflags & IPC_CREAT)
+ {
+ /* Try to create it exclusively. */
+ err = get_exclusive (shmflags, size, &key, &fd);
+ if (err == EEXIST)
+ /* If somebody created it in the meanwhile, just try again. */
+ err = 0;
+ }
+ else
+ err = ENOENT;
+ }
+ }
+ while (fd < 0 && !err);
+
+ if (!err)
+ *r_fd = fd;
+ else
+ *r_fd = -1;
+
+ return err;
+}
+
+/* Return an identifier for an shared memory segment of at least size
+ SIZE which is associated with KEY. */
+int
+__shmget (key_t key, size_t size, int shmflags)
+{
+ error_t err;
+ int fd;
+
+ if (key == IPC_PRIVATE || shmflags & IPC_EXCL)
+ /* An exclusive shared memory segment must be created. */
+ err = get_exclusive (shmflags, size, &key, &fd);
+ else
+ err = get_shared (shmflags, size, key, &fd);
+
+ if (err)
+ {
+ errno = err;
+ return -1;
+ }
+
+ /* From here, we can't fail. That's important, as otherwise we
+ would need to unlink the file if we created it (in that case, the
+ code above would have to be changed to pass a "created" flag down
+ to the caller). */
+
+ __close (fd);
+
+ return key;
+}
+
+weak_alias(__shmget, shmget)
diff --git a/sysdeps/mach/hurd/sigaction.c b/sysdeps/mach/hurd/sigaction.c
index 3ff9d183f0..a753082fa4 100644
--- a/sysdeps/mach/hurd/sigaction.c
+++ b/sysdeps/mach/hurd/sigaction.c
@@ -46,15 +46,15 @@ __sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
ss = _hurd_self_sigstate ();
__spin_lock (&ss->critical_section_lock);
- __spin_lock (&ss->lock);
- old = ss->actions[sig];
+ _hurd_sigstate_lock (ss);
+ old = _hurd_sigstate_actions (ss) [sig];
if (act != NULL)
- ss->actions[sig] = a;
+ _hurd_sigstate_actions (ss) [sig] = a;
if (act != NULL && sig == SIGCHLD &&
(a.sa_flags & SA_NOCLDSTOP) != (old.sa_flags & SA_NOCLDSTOP))
{
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
/* Inform the proc server whether or not it should send us SIGCHLD for
stopped children. We do this in a critical section so that no
@@ -62,8 +62,8 @@ __sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
__USEPORT (PROC,
__proc_mod_stopchild (port, !(a.sa_flags & SA_NOCLDSTOP)));
- __spin_lock (&ss->lock);
- pending = ss->pending & ~ss->blocked;
+ _hurd_sigstate_lock (ss);
+ pending = _hurd_sigstate_pending (ss) & ~ss->blocked;
}
else if (act != NULL && (a.sa_handler == SIG_IGN || a.sa_handler == SIG_DFL))
/* We are changing to an action that might be to ignore SIG signals.
@@ -72,11 +72,11 @@ __sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
back and then SIG is unblocked, the signal pending now should not
arrive. So wake up the signal thread to check the new state and do
the right thing. */
- pending = ss->pending & __sigmask (sig);
+ pending = _hurd_sigstate_pending (ss) & __sigmask (sig);
else
pending = 0;
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
__spin_unlock (&ss->critical_section_lock);
if (pending)
diff --git a/sysdeps/mach/hurd/sigpending.c b/sysdeps/mach/hurd/sigpending.c
index ef855329c6..23aca3c681 100644
--- a/sysdeps/mach/hurd/sigpending.c
+++ b/sysdeps/mach/hurd/sigpending.c
@@ -36,9 +36,9 @@ sigpending (sigset_t *set)
}
ss = _hurd_self_sigstate ();
- __spin_lock (&ss->lock);
- pending = ss->pending;
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_lock (ss);
+ pending = _hurd_sigstate_pending (ss);
+ _hurd_sigstate_unlock (ss);
*set = pending;
return 0;
diff --git a/sysdeps/mach/hurd/sigprocmask.c b/sysdeps/mach/hurd/sigprocmask.c
index 9168224b0c..b5f2eba72d 100644
--- a/sysdeps/mach/hurd/sigprocmask.c
+++ b/sysdeps/mach/hurd/sigprocmask.c
@@ -36,7 +36,7 @@ __sigprocmask (int how, const sigset_t *set, sigset_t *oset)
ss = _hurd_self_sigstate ();
- __spin_lock (&ss->lock);
+ _hurd_sigstate_lock (ss);
old = ss->blocked;
@@ -57,7 +57,7 @@ __sigprocmask (int how, const sigset_t *set, sigset_t *oset)
break;
default:
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
errno = EINVAL;
return -1;
}
@@ -65,9 +65,9 @@ __sigprocmask (int how, const sigset_t *set, sigset_t *oset)
ss->blocked &= ~_SIG_CANT_MASK;
}
- pending = ss->pending & ~ss->blocked;
+ pending = _hurd_sigstate_pending (ss) & ~ss->blocked;
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
if (oset != NULL)
*oset = old;
diff --git a/sysdeps/mach/hurd/sigsuspend.c b/sysdeps/mach/hurd/sigsuspend.c
index bafac7e94d..770007c0d8 100644
--- a/sysdeps/mach/hurd/sigsuspend.c
+++ b/sysdeps/mach/hurd/sigsuspend.c
@@ -40,7 +40,7 @@ __sigsuspend (const sigset_t *set)
ss = _hurd_self_sigstate ();
- __spin_lock (&ss->lock);
+ _hurd_sigstate_lock (ss);
oldmask = ss->blocked;
if (set != NULL)
@@ -48,11 +48,11 @@ __sigsuspend (const sigset_t *set)
ss->blocked = newmask & ~_SIG_CANT_MASK;
/* Notice if any pending signals just became unblocked. */
- pending = ss->pending & ~ss->blocked;
+ pending = _hurd_sigstate_pending (ss) & ~ss->blocked;
/* Tell the signal thread to message us when a signal arrives. */
ss->suspended = wait;
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
if (pending)
/* Tell the signal thread to check for pending signals. */
@@ -63,10 +63,11 @@ __sigsuspend (const sigset_t *set)
MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
__mach_port_destroy (__mach_task_self (), wait);
- __spin_lock (&ss->lock);
- ss->blocked = oldmask; /* Restore the old mask. */
- pending = ss->pending & ~ss->blocked; /* Again check for pending signals. */
- __spin_unlock (&ss->lock);
+ /* Restore the old mask and check for pending signals again. */
+ _hurd_sigstate_lock (ss);
+ ss->blocked = oldmask;
+ pending = _hurd_sigstate_pending(ss) & ~ss->blocked;
+ _hurd_sigstate_unlock (ss);
if (pending)
/* Tell the signal thread to check for pending signals. */
diff --git a/sysdeps/mach/hurd/sigwait.c b/sysdeps/mach/hurd/sigwait.c
index ab10913f3a..d277edd3f1 100644
--- a/sysdeps/mach/hurd/sigwait.c
+++ b/sysdeps/mach/hurd/sigwait.c
@@ -27,7 +27,7 @@ int
__sigwait (const sigset_t *set, int *sig)
{
struct hurd_sigstate *ss;
- sigset_t mask, ready;
+ sigset_t mask, ready, blocked;
int signo = 0;
struct hurd_signal_preemptor preemptor;
jmp_buf buf;
@@ -49,8 +49,8 @@ __sigwait (const sigset_t *set, int *sig)
/* Make sure this is all kosher */
assert (__sigismember (&mask, signo));
- /* Make sure this signal is unblocked */
- __sigdelset (&ss->blocked, signo);
+ /* Restore the blocking mask. */
+ ss->blocked = blocked;
return pe->handler;
}
@@ -71,10 +71,11 @@ __sigwait (const sigset_t *set, int *sig)
__sigemptyset (&mask);
ss = _hurd_self_sigstate ();
- __spin_lock (&ss->lock);
+ _hurd_sigstate_lock (ss);
/* See if one of these signals is currently pending. */
- __sigandset (&ready, &ss->pending, &mask);
+ sigset_t pending = _hurd_sigstate_pending (ss);
+ __sigandset (&ready, &pending, &mask);
if (! __sigisemptyset (&ready))
{
for (signo = 1; signo < NSIG; signo++)
@@ -102,7 +103,11 @@ __sigwait (const sigset_t *set, int *sig)
preemptor.next = ss->preemptors;
ss->preemptors = &preemptor;
- __spin_unlock (&ss->lock);
+ /* Unblock the expected signals */
+ blocked = ss->blocked;
+ ss->blocked &= ~mask;
+
+ _hurd_sigstate_unlock (ss);
/* Wait. */
__mach_msg (&msg, MACH_RCV_MSG, 0, sizeof (msg), wait,
@@ -113,7 +118,7 @@ __sigwait (const sigset_t *set, int *sig)
{
assert (signo);
- __spin_lock (&ss->lock);
+ _hurd_sigstate_lock (ss);
/* Delete our preemptor. */
assert (ss->preemptors == &preemptor);
@@ -122,7 +127,7 @@ __sigwait (const sigset_t *set, int *sig)
all_done:
- spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
__mach_port_destroy (__mach_task_self (), wait);
*sig = signo;
diff --git a/sysdeps/mach/hurd/socket.c b/sysdeps/mach/hurd/socket.c
index 34c66a8481..1e1221431e 100644
--- a/sysdeps/mach/hurd/socket.c
+++ b/sysdeps/mach/hurd/socket.c
@@ -21,6 +21,7 @@
#include <hurd/socket.h>
#include <hurd/fd.h>
#include <fcntl.h>
+#include <fcntl-internal.h>
/* Create a new socket of type TYPE in domain DOMAIN, using
protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.
@@ -30,6 +31,11 @@ __socket (int domain, int type, int protocol)
{
error_t err;
socket_t sock, server;
+ int flags = sock_to_o_flags (type & ~SOCK_TYPE_MASK);
+ type &= SOCK_TYPE_MASK;
+
+ if (flags & ~(O_CLOEXEC | O_NONBLOCK))
+ return __hurd_fail (EINVAL);
/* Find the socket server for DOMAIN. */
server = _hurd_socket_server (domain, 0);
@@ -55,10 +61,17 @@ __socket (int domain, int type, int protocol)
|| err == MIG_BAD_ID || err == EOPNOTSUPP)
err = EAFNOSUPPORT;
+ if (! err)
+ {
+ if (flags & O_NONBLOCK)
+ err = __io_set_some_openmodes (sock, O_NONBLOCK);
+ /* TODO: do we need special ERR massaging after the previous call? */
+ }
+
if (err)
return __hurd_fail (err);
- return _hurd_intern_fd (sock, O_IGNORE_CTTY, 1);
+ return _hurd_intern_fd (sock, O_IGNORE_CTTY | flags, 1);
}
libc_hidden_def (__socket)
diff --git a/sysdeps/mach/hurd/socketpair.c b/sysdeps/mach/hurd/socketpair.c
index 0b0d4e9417..60b6218336 100644
--- a/sysdeps/mach/hurd/socketpair.c
+++ b/sysdeps/mach/hurd/socketpair.c
@@ -17,6 +17,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <fcntl-internal.h>
#include <sys/socket.h>
#include <unistd.h>
@@ -34,6 +35,11 @@ __socketpair (int domain, int type, int protocol, int fds[2])
error_t err;
socket_t server, sock1, sock2;
int d1, d2;
+ int flags = sock_to_o_flags (type & ~SOCK_TYPE_MASK);
+ type &= SOCK_TYPE_MASK;
+
+ if (flags & ~(O_CLOEXEC | O_NONBLOCK))
+ return __hurd_fail (EINVAL);
if (fds == NULL)
return __hurd_fail (EINVAL);
@@ -56,6 +62,14 @@ __socketpair (int domain, int type, int protocol, int fds[2])
return -1;
err = __socket_create (server, type, protocol, &sock1);
}
+ /* TODO: do we need special ERR massaging here, like it is done in
+ __socket? */
+ if (! err)
+ {
+ if (flags & O_NONBLOCK)
+ err = __io_set_some_openmodes (sock1, O_NONBLOCK);
+ /* TODO: do we need special ERR massaging after the previous call? */
+ }
if (err)
return __hurd_fail (err);
if (err = __socket_create (server, type, protocol, &sock2))
@@ -63,7 +77,12 @@ __socketpair (int domain, int type, int protocol, int fds[2])
__mach_port_deallocate (__mach_task_self (), sock1);
return __hurd_fail (err);
}
- if (err = __socket_connect2 (sock1, sock2))
+ if (flags & O_NONBLOCK)
+ err = __io_set_some_openmodes (sock2, O_NONBLOCK);
+ /* TODO: do we need special ERR massaging after the previous call? */
+ if (! err)
+ err = __socket_connect2 (sock1, sock2);
+ if (err)
{
__mach_port_deallocate (__mach_task_self (), sock1);
__mach_port_deallocate (__mach_task_self (), sock2);
@@ -72,13 +91,13 @@ __socketpair (int domain, int type, int protocol, int fds[2])
/* Put the sockets into file descriptors. */
- d1 = _hurd_intern_fd (sock1, O_IGNORE_CTTY, 1);
+ d1 = _hurd_intern_fd (sock1, O_IGNORE_CTTY | flags, 1);
if (d1 < 0)
{
__mach_port_deallocate (__mach_task_self (), sock2);
return -1;
}
- d2 = _hurd_intern_fd (sock2, O_IGNORE_CTTY, 1);
+ d2 = _hurd_intern_fd (sock2, O_IGNORE_CTTY | flags, 1);
if (d2 < 0)
{
err = errno;
diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c
index 328a4bb13f..1d2dcb2c7b 100644
--- a/sysdeps/mach/hurd/spawni.c
+++ b/sysdeps/mach/hurd/spawni.c
@@ -235,29 +235,31 @@ __spawni (pid_t *pid, const char *file,
ss = _hurd_self_sigstate ();
- assert (! __spin_lock_locked (&ss->critical_section_lock));
__spin_lock (&ss->critical_section_lock);
- __spin_lock (&ss->lock);
+ _hurd_sigstate_lock (ss);
ints[INIT_SIGMASK] = ss->blocked;
- ints[INIT_SIGPENDING] = ss->pending;
+ ints[INIT_SIGPENDING] = 0;
ints[INIT_SIGIGN] = 0;
/* Unless we were asked to reset all handlers to SIG_DFL,
pass down the set of signals that were set to SIG_IGN. */
- if ((flags & POSIX_SPAWN_SETSIGDEF) == 0)
- for (i = 1; i < NSIG; ++i)
- if (ss->actions[i].sa_handler == SIG_IGN)
- ints[INIT_SIGIGN] |= __sigmask (i);
-
- /* We hold the sigstate lock until the exec has failed so that no signal
- can arrive between when we pack the blocked and ignored signals, and
- when the exec actually happens. A signal handler could change what
+ {
+ struct sigaction *actions = _hurd_sigstate_actions (ss);
+ if ((flags & POSIX_SPAWN_SETSIGDEF) == 0)
+ for (i = 1; i < NSIG; ++i)
+ if (actions[i].sa_handler == SIG_IGN)
+ ints[INIT_SIGIGN] |= __sigmask (i);
+ }
+
+ /* We hold the critical section lock until the exec has failed so that no
+ signal can arrive between when we pack the blocked and ignored signals,
+ and when the exec actually happens. A signal handler could change what
signals are blocked and ignored. Either the change will be reflected
in the exec, or the signal will never be delivered. Setting the
critical section flag avoids anything we call trying to acquire the
sigstate lock. */
- __spin_unlock (&ss->lock);
+ _hurd_sigstate_unlock (ss);
/* Set signal mask. */
if ((flags & POSIX_SPAWN_SETSIGMASK) != 0)
@@ -363,6 +365,7 @@ __spawni (pid_t *pid, const char *file,
/* Safe to let signals happen now. */
_hurd_critical_section_unlock (ss);
+ /* FIXME: handle EINTR */
/* Execute the file actions. */
if (file_actions != NULL)
diff --git a/sysdeps/mach/hurd/sysdep-cancel.h b/sysdeps/mach/hurd/sysdep-cancel.h
new file mode 100644
index 0000000000..ec55c7330f
--- /dev/null
+++ b/sysdeps/mach/hurd/sysdep-cancel.h
@@ -0,0 +1,9 @@
+#include <sysdep.h>
+
+/* Always multi-thread (since there's at least the sig handler), but no
+ handling enabled. */
+#define SINGLE_THREAD_P (0)
+#define RTLD_SINGLE_THREAD_P (0)
+#define LIBC_CANCEL_ASYNC() 0 /* Just a dummy value. */
+#define LIBC_CANCEL_RESET(val) ((void)(val)) /* Nothing, but evaluate it. */
+#define LIBC_CANCEL_HANDLED() /* Nothing. */
diff --git a/sysdeps/mach/hurd/tls.h b/sysdeps/mach/hurd/tls.h
index 67ed17d00d..9f4d685b9d 100644
--- a/sysdeps/mach/hurd/tls.h
+++ b/sysdeps/mach/hurd/tls.h
@@ -53,5 +53,18 @@
#endif /* !ASSEMBLER */
+#ifndef __ASSEMBLER__
+#include <mach/mach_traps.h>
+#include <atomic.h>
+/* Temporary poor-man's global scope switch support: just busy-waits */
+#define THREAD_GSCOPE_SET_FLAG() \
+ asm volatile ("lock incl %0":"=m"(GL(dl_thread_gscope_count)))
+#define THREAD_GSCOPE_RESET_FLAG() \
+ asm volatile ("lock decl %0":"=m"(GL(dl_thread_gscope_count)))
+#define THREAD_GSCOPE_WAIT() \
+ while (GL(dl_thread_gscope_count)) { \
+ __swtch_pri (0); \
+ }
+#endif
#endif /* tls.h */
diff --git a/sysdeps/mach/i386/machine-lock.h b/sysdeps/mach/i386/machine-lock.h
index 966f128396..12f06b5cb2 100644
--- a/sysdeps/mach/i386/machine-lock.h
+++ b/sysdeps/mach/i386/machine-lock.h
@@ -34,6 +34,9 @@ typedef volatile int __spin_lock_t;
/* Unlock LOCK. */
+void __spin_unlock (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
_EXTERN_INLINE void
__spin_unlock (__spin_lock_t *__lock)
{
@@ -42,9 +45,13 @@ __spin_unlock (__spin_lock_t *__lock)
: "=&r" (__unlocked), "=m" (*__lock) : "0" (0)
: "memory");
}
+#endif
/* Try to lock LOCK; return nonzero if we locked it, zero if another has. */
+int __spin_try_lock (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
_EXTERN_INLINE int
__spin_try_lock (__spin_lock_t *__lock)
{
@@ -54,14 +61,19 @@ __spin_try_lock (__spin_lock_t *__lock)
: "memory");
return !__locked;
}
+#endif
/* Return nonzero if LOCK is locked. */
+int __spin_lock_locked (__spin_lock_t *__lock);
+
+#if defined __USE_EXTERN_INLINES && defined _LIBC
_EXTERN_INLINE int
__spin_lock_locked (__spin_lock_t *__lock)
{
return *__lock != 0;
}
+#endif
#endif /* machine-lock.h */
diff --git a/sysdeps/mach/i386/thread_state.h b/sysdeps/mach/i386/thread_state.h
index abb5ffe8b1..2e081405e3 100644
--- a/sysdeps/mach/i386/thread_state.h
+++ b/sysdeps/mach/i386/thread_state.h
@@ -21,7 +21,8 @@
#include <mach/machine/thread_status.h>
-#define MACHINE_THREAD_STATE_FLAVOR i386_THREAD_STATE
+#define MACHINE_NEW_THREAD_STATE_FLAVOR i386_THREAD_STATE
+#define MACHINE_THREAD_STATE_FLAVOR i386_REGS_SEGS_STATE
#define MACHINE_THREAD_STATE_COUNT i386_THREAD_STATE_COUNT
#define machine_thread_state i386_thread_state
@@ -30,6 +31,14 @@
#define SP uesp
#define SYSRETURN eax
+#define MACHINE_THREAD_STATE_FIX_NEW(ts) do { \
+ asm ("mov %%cs, %w0" : "=q" ((ts)->cs)); \
+ asm ("mov %%ds, %w0" : "=q" ((ts)->ds)); \
+ asm ("mov %%es, %w0" : "=q" ((ts)->es)); \
+ asm ("mov %%fs, %w0" : "=q" ((ts)->fs)); \
+ asm ("mov %%gs, %w0" : "=q" ((ts)->gs)); \
+} while(0)
+
struct machine_thread_all_state
{
int set; /* Mask of bits (1 << FLAVOR). */
diff --git a/sysdeps/mach/libc-lock.h b/sysdeps/mach/libc-lock.h
index 6acc78abd8..f9f57a0a65 100644
--- a/sysdeps/mach/libc-lock.h
+++ b/sysdeps/mach/libc-lock.h
@@ -20,10 +20,31 @@
#define _LIBC_LOCK_H 1
#ifdef _LIBC
+
+#include <tls.h>
#include <cthreads.h>
-#define __libc_lock_t struct mutex
+#include <lowlevellock.h>
+
+/* The locking here is very inexpensive, even for inlining. */
+#define _IO_lock_inexpensive 1
+
+typedef unsigned int __libc_lock_t;
+typedef struct
+{
+ __libc_lock_t lock;
+ int cnt;
+ void *owner;
+} __libc_lock_recursive_t;
+
+typedef __libc_lock_recursive_t __rtld_lock_recursive_t;
+
+extern char __libc_lock_self0[0];
+#define __libc_lock_owner_self() \
+ (__LIBC_NO_TLS() ? (void *)&__libc_lock_self0 : THREAD_SELF)
+
#else
typedef struct __libc_lock_opaque__ __libc_lock_t;
+typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t;
#endif
/* Type for key of thread specific data. */
@@ -40,58 +61,138 @@ typedef cthread_key_t __libc_key_t;
CLASS __libc_lock_t NAME;
/* Define an initialized lock variable NAME with storage class CLASS. */
+#define _LIBC_LOCK_INITIALIZER LLL_INITIALIZER
#define __libc_lock_define_initialized(CLASS,NAME) \
- CLASS __libc_lock_t NAME = MUTEX_INITIALIZER;
+ CLASS __libc_lock_t NAME = LLL_INITIALIZER;
/* Initialize the named lock variable, leaving it in a consistent, unlocked
state. */
-#define __libc_lock_init(NAME) __mutex_init (&(NAME))
+#define __libc_lock_init(NAME) (NAME) = LLL_INITIALIZER
/* Finalize the named lock variable, which must be locked. It cannot be
used again until __libc_lock_init is called again on it. This must be
called on a lock variable before the containing storage is reused. */
-#define __libc_lock_fini(NAME) __mutex_unlock (&(NAME))
+#define __libc_lock_fini __libc_lock_unlock
+#define __libc_lock_fini_recursive __libc_lock_unlock_recursive
+#define __rtld_lock_fini_recursive __rtld_lock_unlock_recursive
/* Lock the named lock variable. */
-#define __libc_lock_lock(NAME) __mutex_lock (&(NAME))
+#define __libc_lock_lock(NAME) \
+ ({ lll_lock (&(NAME), 0); 0; })
/* Lock the named lock variable. */
-#define __libc_lock_trylock(NAME) (!__mutex_trylock (&(NAME)))
+#define __libc_lock_trylock(NAME) lll_trylock (&(NAME))
/* Unlock the named lock variable. */
-#define __libc_lock_unlock(NAME) __mutex_unlock (&(NAME))
-
+#define __libc_lock_unlock(NAME) \
+ ({ lll_unlock (&(NAME), 0); 0; })
+
+#define __libc_lock_define_recursive(CLASS,NAME) \
+ CLASS __libc_lock_recursive_t NAME;
+
+#define _LIBC_LOCK_RECURSIVE_INITIALIZER { LLL_INITIALIZER, 0, 0 }
+
+#define __libc_lock_define_initialized_recursive(CLASS,NAME) \
+ CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
+
+#define __rtld_lock_define_recursive(CLASS,NAME) \
+ __libc_lock_define_recursive (CLASS, NAME)
+#define _RTLD_LOCK_RECURSIVE_INITIALIZER \
+ _LIBC_LOCK_RECURSIVE_INITIALIZER
+#define __rtld_lock_define_initialized_recursive(CLASS,NAME) \
+ __libc_lock_define_initialized_recursive (CLASS, NAME)
+
+#define __libc_lock_init_recursive(NAME) \
+ ((NAME) = (__libc_lock_recursive_t)_LIBC_LOCK_RECURSIVE_INITIALIZER, 0)
+
+#define __libc_lock_trylock_recursive(NAME) \
+ ({ \
+ __libc_lock_recursive_t *const __lock = &(NAME); \
+ void *__self = __libc_lock_owner_self (); \
+ int __r = 0; \
+ if (__self == __lock->owner) \
+ ++__lock->cnt; \
+ else if ((__r = lll_trylock (&__lock->lock)) == 0) \
+ __lock->owner = __self, __lock->cnt = 1; \
+ __r; \
+ })
+
+#define __libc_lock_lock_recursive(NAME) \
+ ({ \
+ __libc_lock_recursive_t *const __lock = &(NAME); \
+ void *__self = __libc_lock_owner_self (); \
+ if (__self != __lock->owner) \
+ { \
+ lll_lock (&__lock->lock, 0); \
+ __lock->owner = __self; \
+ } \
+ ++__lock->cnt; \
+ (void)0; \
+ })
+
+#define __libc_lock_unlock_recursive(NAME) \
+ ({ \
+ __libc_lock_recursive_t *const __lock = &(NAME); \
+ if (--__lock->cnt == 0) \
+ { \
+ __lock->owner = 0; \
+ lll_unlock (&__lock->lock, 0); \
+ } \
+ })
+
+
+#define __rtld_lock_initialize(NAME) \
+ (void) ((NAME) = (__rtld_lock_recursive_t) _RTLD_LOCK_RECURSIVE_INITIALIZER)
+#define __rtld_lock_trylock_recursive(NAME) \
+ __libc_lock_trylock_recursive (NAME)
+#define __rtld_lock_lock_recursive(NAME) \
+ __libc_lock_lock_recursive(NAME)
+#define __rtld_lock_unlock_recursive(NAME) \
+ __libc_lock_unlock_recursive (NAME)
/* XXX for now */
-#define __libc_rwlock_define __libc_lock_define
-#define __libc_rwlock_define_initialized __libc_lock_define_initialized
-#define __libc_rwlock_init __libc_lock_init
-#define __libc_rwlock_fini __libc_lock_fini
-#define __libc_rwlock_rdlock __libc_lock_lock
-#define __libc_rwlock_wrlock __libc_lock_lock
-#define __libc_rwlock_tryrdlock __libc_lock_trylock
-#define __libc_rwlock_trywrlock __libc_lock_trylock
-#define __libc_rwlock_unlock __libc_lock_unlock
-
+#define __libc_rwlock_define __libc_lock_define_recursive
+#define __libc_rwlock_define_initialized __libc_lock_define_initialized_recursive
+#define __libc_rwlock_init __libc_lock_init_recursive
+#define __libc_rwlock_fini __libc_lock_fini_recursive
+#define __libc_rwlock_rdlock __libc_lock_lock_recursive
+#define __libc_rwlock_wrlock __libc_lock_lock_recursive
+#define __libc_rwlock_tryrdlock __libc_lock_trylock_recursive
+#define __libc_rwlock_trywrlock __libc_lock_trylock_recursive
+#define __libc_rwlock_unlock __libc_lock_unlock_recursive
+
+struct __libc_cleanup_frame
+{
+ void (*__fct) (void *);
+ void *__argp;
+ int __doit;
+};
+
+__extern_inline void
+__libc_cleanup_fct (struct __libc_cleanup_frame *framep)
+{
+ if (framep->__doit)
+ framep->__fct (framep->__argp);
+}
/* Start a critical region with a cleanup function */
-#define __libc_cleanup_region_start(DOIT, FCT, ARG) \
-{ \
- typeof (***(FCT)) *__save_FCT = (DOIT) ? (FCT) : 0; \
- typeof (ARG) __save_ARG = ARG; \
- /* close brace is in __libc_cleanup_region_end below. */
-
-/* End a critical region started with __libc_cleanup_region_start. */
-#define __libc_cleanup_region_end(DOIT) \
- if ((DOIT) && __save_FCT != 0) \
- (*__save_FCT)(__save_ARG); \
-}
+#define __libc_cleanup_region_start(DOIT, FCT, ARG) \
+ do \
+ { \
+ struct __libc_cleanup_frame __cleanup \
+ __attribute__ ((__cleanup__ (__libc_cleanup_fct))) = \
+ { .__fct = (FCT), .__argp = (ARG), .__doit = (DOIT) };
+
+/* This one closes the brace above. */
+#define __libc_cleanup_region_end(DOIT) \
+ __cleanup.__doit = (DOIT); \
+ } \
+ while (0)
-/* Sometimes we have to exit the block in the middle. */
-#define __libc_cleanup_end(DOIT) \
- if ((DOIT) && __save_FCT != 0) \
- (*__save_FCT)(__save_ARG); \
+#define __libc_cleanup_end(DOIT) __cleanup.__doit = (DOIT);
+#define __libc_cleanup_push(fct, arg) __libc_cleanup_region_start (1, fct, arg)
+#define __libc_cleanup_pop(execute) __libc_cleanup_region_end (execute)
/* Use mutexes as once control variables. */
@@ -102,8 +203,7 @@ struct __libc_once
};
#define __libc_once_define(CLASS,NAME) \
- CLASS struct __libc_once NAME = { MUTEX_INITIALIZER, 0 }
-
+ CLASS struct __libc_once NAME = { _LIBC_LOCK_INITIALIZER, 0 }
/* Call handler iff the first call. */
#define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \
@@ -121,25 +221,15 @@ struct __libc_once
#ifdef _LIBC
/* We need portable names for some functions. E.g., when they are
used as argument to __libc_cleanup_region_start. */
-#define __libc_mutex_unlock __mutex_unlock
-#endif
+#define __libc_mutex_unlock __libc_lock_unlock
#define __libc_key_create(KEY,DEST) cthread_keycreate (KEY)
#define __libc_setspecific(KEY,VAL) cthread_setspecific (KEY, VAL)
void *__libc_getspecific (__libc_key_t key);
-/* XXX until cthreads supports recursive locks */
-#define __libc_lock_define_initialized_recursive __libc_lock_define_initialized
-#define __libc_lock_init_recursive __libc_lock_init
-#define __libc_lock_fini_recursive __libc_lock_fini
-#define __libc_lock_trylock_recursive __libc_lock_trylock
-#define __libc_lock_unlock_recursive __libc_lock_unlock
-#define __libc_lock_lock_recursive __libc_lock_lock
-
-#define __rtld_lock_define_initialized_recursive __libc_lock_define_initialized
-#define __rtld_lock_fini_recursive __libc_lock_fini
-#define __rtld_lock_trylock_recursive __libc_lock_trylock
-#define __rtld_lock_unlock_recursive __libc_lock_unlock
-#define __rtld_lock_lock_recursive __libc_lock_lock
+/* Hide the definitions which are only supposed to be used inside libc in
+ a separate file. This file is not present in the installation! */
+# include <libc-lockP.h>
+#endif
#endif /* libc-lock.h */
diff --git a/sysdeps/mach/pagecopy.h b/sysdeps/mach/pagecopy.h
index cda1ef90c6..3bf83ed6f4 100644
--- a/sysdeps/mach/pagecopy.h
+++ b/sysdeps/mach/pagecopy.h
@@ -20,7 +20,10 @@
/* Threshold at which vm_copy is more efficient than well-optimized copying
by words. This parameter should be tuned as necessary. */
-#define PAGE_THRESHOLD (2 * PAGE_SIZE) /* XXX ? */
+#define PAGE_THRESHOLD (16384) /* XXX Tune this. */
+#if 0
+#define PAGE_COPY_THRESHOLD (16384) /* XXX Tune this. */
+#endif
#define PAGE_SIZE __vm_page_size
#define PAGE_COPY_FWD(dstp, srcp, nbytes_left, nbytes) \
diff --git a/sysdeps/mach/thread_state.h b/sysdeps/mach/thread_state.h
index 33f293bf21..c382eb995a 100644
--- a/sysdeps/mach/thread_state.h
+++ b/sysdeps/mach/thread_state.h
@@ -37,6 +37,9 @@
((ts)->SP = (unsigned long int) (stack) + (size))
#endif
#endif
+#ifndef MACHINE_THREAD_STATE_FIX_NEW
+# define MACHINE_THREAD_STATE_FIX_NEW(ts)
+#endif
/* These functions are of use in machine-dependent signal trampoline
implementations. */
diff --git a/sysdeps/pthread/allocalim.h b/sysdeps/pthread/allocalim.h
index 076889463b..1653f9ece2 100644
--- a/sysdeps/pthread/allocalim.h
+++ b/sysdeps/pthread/allocalim.h
@@ -24,6 +24,9 @@ extern __always_inline
int
__libc_use_alloca (size_t size)
{
- return (__builtin_expect (size <= PTHREAD_STACK_MIN / 4, 1)
- || __builtin_expect (__libc_alloca_cutoff (size), 1));
+ return (
+#ifdef PTHREAD_STACK_MIN
+ __builtin_expect (size <= PTHREAD_STACK_MIN / 4, 1) ||
+#endif
+ __builtin_expect (__libc_alloca_cutoff (size), 1));
}
diff --git a/sysdeps/pthread/timer_routines.c b/sysdeps/pthread/timer_routines.c
index 7aa4437a61..52787de157 100644
--- a/sysdeps/pthread/timer_routines.c
+++ b/sysdeps/pthread/timer_routines.c
@@ -29,7 +29,7 @@
#include <sys/syscall.h>
#include "posix-timer.h"
-#include <nptl/pthreadP.h>
+//#include <nptl/pthreadP.h>
/* Number of threads used. */
@@ -395,6 +395,9 @@ thread_func (void *arg)
{
timespec_add (&timer->expirytime, &timer->expirytime,
&timer->value.it_interval);
+#ifndef DELAYTIMER_MAX
+#define DELAYTIMER_MAX INT_MAX
+#endif
if (timer->overrun_count < DELAYTIMER_MAX)
++timer->overrun_count;
}
@@ -481,7 +484,7 @@ __timer_thread_wakeup (struct thread_node *thread)
pthread_cond_broadcast (&thread->cond);
}
-
+#if 0
/* Compare two pthread_attr_t thread attributes for exact equality.
Returns 1 if they are equal, otherwise zero if they are not equal
or contain illegal values. This version is NPTL-specific for
@@ -506,6 +509,7 @@ thread_attr_compare (const pthread_attr_t *left, const pthread_attr_t *right)
&& memcmp (ileft->cpuset, iright->cpuset,
ileft->cpusetsize) == 0)));
}
+#endif
/* Search the list of active threads and find one which has matching
@@ -514,6 +518,7 @@ struct thread_node *
__timer_thread_find_matching (const pthread_attr_t *desired_attr,
clockid_t desired_clock_id)
{
+#if 0
struct list_head *iter = list_first (&thread_active_list);
while (iter != list_null (&thread_active_list))
@@ -526,6 +531,7 @@ __timer_thread_find_matching (const pthread_attr_t *desired_attr,
iter = list_next (iter);
}
+#endif
return NULL;
}
diff --git a/sysdeps/unix/bsd/unlockpt.c b/sysdeps/unix/bsd/unlockpt.c
index 436d8a2c0e..0d87086ec0 100644
--- a/sysdeps/unix/bsd/unlockpt.c
+++ b/sysdeps/unix/bsd/unlockpt.c
@@ -27,7 +27,7 @@
int
unlockpt (int fd)
{
- char buf[sizeof (_PATH_TTY) + 2];
+ char buf[1024]; /* XXX */
/* BSD doesn't have a lock, but it does have `revoke'. */
if (__ptsname_r (fd, buf, sizeof (buf)))
diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c
index a3fd267e9d..f850fd6eb8 100644
--- a/sysdeps/unix/clock_settime.c
+++ b/sysdeps/unix/clock_settime.c
@@ -21,6 +21,9 @@
#include <libc-internal.h>
#include <ldsodefs.h>
+/* TODO */
+#include <sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h>
+
#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
/* Clock frequency of the processor. We make it a 64-bit variable