Date: Sat, 3 Jan 2015 18:38:47 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r276630 - in head: contrib/jemalloc/include/jemalloc/internal contrib/jemalloc/src lib/libc lib/libc/compat-43 lib/libc/gen lib/libc/include lib/libc/stdlib lib/libc/stdlib/jemalloc lib... Message-ID: <201501031838.t03Iclot097606@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Sat Jan 3 18:38:46 2015 New Revision: 276630 URL: https://svnweb.freebsd.org/changeset/base/276630 Log: Fix known issues which blow up the process after dlopen("libthr.so") (or loading a dso linked to libthr.so into process which was not linked against threading library). - Remove libthr interposers of the libc functions, including __error(). Instead, functions calls are indirected through the interposing table, similar to how pthread stubs in libc are already done. Libc by default points either to syscall trampolines or to existing libc implementations. On libthr load, libthr rewrites the pointers to the cancellable implementations already in libthr. The interposition table is separate from pthreads stubs indirection table to not pull pthreads stubs into static binaries. - Postpone the malloc(3) internal mutexes initialization until libthr is loaded. This avoids recursion between calloc(3) and static pthread_mutex_t initialization. - Reinstall signal handlers with wrapper on libthr load. The _rtld_is_dlopened(3) is used to avoid useless calls to sigaction(2) when libthr is statically referenced from the main binary. In the process, fix openat(2), swapcontext(2) and setcontext(2) interposing. The libc symbols were exported at different versions than libthr interposers. Export both libc and libthr versions from libc now, with default set to the higher version from libthr. Remove unused and disconnected swapcontext(3) userspace implementation from libc/gen. No objections from: deischen Tested by: pho, antoine (exp-run) (previous versions) Sponsored by: The FreeBSD Foundation MFC after: 1 week Added: head/lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c (contents, props changed) head/lib/libc/sys/accept.c (contents, props changed) head/lib/libc/sys/accept4.c (contents, props changed) head/lib/libc/sys/aio_suspend.c (contents, props changed) head/lib/libc/sys/close.c (contents, props changed) head/lib/libc/sys/connect.c (contents, props changed) head/lib/libc/sys/fork.c (contents, props changed) head/lib/libc/sys/fsync.c (contents, props changed) head/lib/libc/sys/interposing_table.c (contents, props changed) head/lib/libc/sys/msync.c (contents, props changed) head/lib/libc/sys/nanosleep.c (contents, props changed) head/lib/libc/sys/open.c (contents, props changed) head/lib/libc/sys/openat.c (contents, props changed) head/lib/libc/sys/poll.c (contents, props changed) head/lib/libc/sys/pselect.c (contents, props changed) head/lib/libc/sys/read.c (contents, props changed) head/lib/libc/sys/readv.c (contents, props changed) head/lib/libc/sys/recvfrom.c (contents, props changed) head/lib/libc/sys/recvmsg.c (contents, props changed) head/lib/libc/sys/select.c (contents, props changed) head/lib/libc/sys/sendmsg.c (contents, props changed) head/lib/libc/sys/sendto.c (contents, props changed) head/lib/libc/sys/setcontext.c (contents, props changed) head/lib/libc/sys/sigaction.c (contents, props changed) head/lib/libc/sys/sigprocmask.c (contents, props changed) head/lib/libc/sys/sigsuspend.c (contents, props changed) head/lib/libc/sys/sigtimedwait.c (contents, props changed) head/lib/libc/sys/sigwaitinfo.c (contents, props changed) head/lib/libc/sys/swapcontext.c - copied, changed from r276627, head/lib/libc/gen/swapcontext.c head/lib/libc/sys/wait4.c (contents, props changed) head/lib/libc/sys/write.c (contents, props changed) head/lib/libc/sys/writev.c (contents, props changed) Deleted: head/lib/libc/gen/swapcontext.c Modified: head/contrib/jemalloc/include/jemalloc/internal/mutex.h head/contrib/jemalloc/src/jemalloc.c head/contrib/jemalloc/src/mutex.c head/lib/libc/Makefile head/lib/libc/compat-43/Symbol.map head/lib/libc/compat-43/creat.c head/lib/libc/gen/Makefile.inc head/lib/libc/gen/Symbol.map head/lib/libc/gen/pause.c head/lib/libc/gen/raise.c head/lib/libc/gen/sleep.c head/lib/libc/gen/termios.c head/lib/libc/gen/usleep.c head/lib/libc/gen/wait.c head/lib/libc/gen/wait3.c head/lib/libc/gen/waitpid.c head/lib/libc/include/libc_private.h head/lib/libc/stdlib/Symbol.map head/lib/libc/stdlib/jemalloc/Symbol.map head/lib/libc/stdlib/system.c head/lib/libc/sys/Makefile.inc head/lib/libc/sys/Symbol.map head/lib/libc/sys/__error.c head/lib/libc/sys/fcntl.c head/lib/libc/sys/sigwait.c head/lib/libthr/Makefile head/lib/libthr/pthread.map head/lib/libthr/sys/thr_error.c head/lib/libthr/thread/thr_create.c head/lib/libthr/thread/thr_fork.c head/lib/libthr/thread/thr_init.c head/lib/libthr/thread/thr_printf.c head/lib/libthr/thread/thr_private.h head/lib/libthr/thread/thr_sig.c head/lib/libthr/thread/thr_syscalls.c Modified: head/contrib/jemalloc/include/jemalloc/internal/mutex.h ============================================================================== --- head/contrib/jemalloc/include/jemalloc/internal/mutex.h Sat Jan 3 18:35:29 2015 (r276629) +++ head/contrib/jemalloc/include/jemalloc/internal/mutex.h Sat Jan 3 18:38:46 2015 (r276630) @@ -49,6 +49,7 @@ bool malloc_mutex_init(malloc_mutex_t *m void malloc_mutex_prefork(malloc_mutex_t *mutex); void malloc_mutex_postfork_parent(malloc_mutex_t *mutex); void malloc_mutex_postfork_child(malloc_mutex_t *mutex); +bool malloc_mutex_first_thread(void); bool mutex_boot(void); #endif /* JEMALLOC_H_EXTERNS */ Modified: head/contrib/jemalloc/src/jemalloc.c ============================================================================== --- head/contrib/jemalloc/src/jemalloc.c Sat Jan 3 18:35:29 2015 (r276629) +++ head/contrib/jemalloc/src/jemalloc.c Sat Jan 3 18:38:46 2015 (r276630) @@ -2061,6 +2061,13 @@ jemalloc_postfork_child(void) ctl_postfork_child(); } +void +_malloc_first_thread(void) +{ + + (void)malloc_mutex_first_thread(); +} + /******************************************************************************/ /* * The following functions are used for TLS allocation/deallocation in static Modified: head/contrib/jemalloc/src/mutex.c ============================================================================== --- head/contrib/jemalloc/src/mutex.c Sat Jan 3 18:35:29 2015 (r276629) +++ head/contrib/jemalloc/src/mutex.c Sat Jan 3 18:38:46 2015 (r276630) @@ -67,15 +67,15 @@ pthread_create(pthread_t *__restrict thr JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, void *(calloc_cb)(size_t, size_t)); -__weak_reference(_pthread_mutex_init_calloc_cb_stub, - _pthread_mutex_init_calloc_cb); - +#pragma weak _pthread_mutex_init_calloc_cb int -_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex, +_pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex, void *(calloc_cb)(size_t, size_t)) { - return (0); + return (((int (*)(pthread_mutex_t *, void *(*)(size_t, size_t))) + __libc_interposing[INTERPOS__pthread_mutex_init_calloc_cb])( + mutex, calloc_cb)); } #endif @@ -144,7 +144,7 @@ malloc_mutex_postfork_child(malloc_mutex } bool -mutex_boot(void) +malloc_mutex_first_thread(void) { #ifdef JEMALLOC_MUTEX_INIT_CB @@ -158,3 +158,14 @@ mutex_boot(void) #endif return (false); } + +bool +mutex_boot(void) +{ + +#ifndef JEMALLOC_MUTEX_INIT_CB + return (malloc_mutex_first_thread()); +#else + return (false); +#endif +} Modified: head/lib/libc/Makefile ============================================================================== --- head/lib/libc/Makefile Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/Makefile Sat Jan 3 18:38:46 2015 (r276630) @@ -156,6 +156,10 @@ libkern.${LIBC_ARCH}:: ${KMSRCS} cp -fp ${.ALLSRC} ${DESTDIR}/sys/libkern/${LIBC_ARCH} .endif +.if ${MK_SYSCALL_COMPAT} != "no" +CFLAGS+=-DSYSCALL_COMPAT +.endif + .include <bsd.arch.inc.mk> .include <bsd.lib.mk> Modified: head/lib/libc/compat-43/Symbol.map ============================================================================== --- head/lib/libc/compat-43/Symbol.map Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/compat-43/Symbol.map Sat Jan 3 18:38:46 2015 (r276630) @@ -28,4 +28,5 @@ FBSD_1.2 { FBSDprivate_1.0 { __creat; _creat; + __libc_creat; }; Modified: head/lib/libc/compat-43/creat.c ============================================================================== --- head/lib/libc/compat-43/creat.c Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/compat-43/creat.c Sat Jan 3 18:38:46 2015 (r276630) @@ -36,11 +36,23 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include <fcntl.h> #include "un-namespace.h" +#include "libc_private.h" +__weak_reference(__libc_creat, __creat); +__weak_reference(__libc_creat, _creat); + +#pragma weak creat int -__creat(const char *path, mode_t mode) +creat(const char *path, mode_t mode) { - return(_open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)); + + return (((int (*)(const char *, mode_t)) + __libc_interposing[INTERPOS_creat])(path, mode)); +} + +int +__libc_creat(const char *path, mode_t mode) +{ + + return(__sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode)); } -__weak_reference(__creat, creat); -__weak_reference(__creat, _creat); Modified: head/lib/libc/gen/Makefile.inc ============================================================================== --- head/lib/libc/gen/Makefile.inc Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/gen/Makefile.inc Sat Jan 3 18:38:46 2015 (r276630) @@ -5,6 +5,7 @@ .PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/gen ${LIBC_SRCTOP}/gen SRCS+= __getosreldate.c \ + __pthread_mutex_init_calloc_cb_stub.c \ __xuname.c \ _once_stub.c \ _pthread_stubs.c \ Modified: head/lib/libc/gen/Symbol.map ============================================================================== --- head/lib/libc/gen/Symbol.map Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/gen/Symbol.map Sat Jan 3 18:38:46 2015 (r276630) @@ -533,6 +533,15 @@ FBSDprivate_1.0 { _libc_sem_post_compat; _libc_sem_getvalue_compat; + __libc_pause; + __libc_raise; + __libc_sleep; + __libc_tcdrain; + __libc_usleep; + __libc_wait; + __libc_wait3; + __libc_waitpid; + __elf_aux_vector; __pthread_map_stacks_exec; __fillcontextx; Added: head/lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c Sat Jan 3 18:38:46 2015 (r276630) @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2014 The FreeBSD Foundation. + * All rights reserved. + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <pthread.h> +#include "libc_private.h" + +int +_pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex, + void *(calloc_cb)(size_t, size_t)) +{ + + return (0); +} Modified: head/lib/libc/gen/pause.c ============================================================================== --- head/lib/libc/gen/pause.c Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/gen/pause.c Sat Jan 3 18:38:46 2015 (r276630) @@ -38,11 +38,13 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include "un-namespace.h" +#include "libc_private.h" + /* * Backwards compatible pause. */ int -__pause(void) +__libc_pause(void) { sigset_t oset; @@ -50,5 +52,15 @@ __pause(void) return (-1); return (_sigsuspend(&oset)); } -__weak_reference(__pause, pause); -__weak_reference(__pause, _pause); + +#pragma weak pause +int +pause(void) +{ + + return (((int (*)(void)) + __libc_interposing[INTERPOS_pause])()); +} + +__weak_reference(__libc_pause, __pause); +__weak_reference(__libc_pause, _pause); Modified: head/lib/libc/gen/raise.c ============================================================================== --- head/lib/libc/gen/raise.c Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/gen/raise.c Sat Jan 3 18:38:46 2015 (r276630) @@ -36,11 +36,23 @@ __FBSDID("$FreeBSD$"); #include <signal.h> #include <unistd.h> -__weak_reference(__raise, raise); -__weak_reference(__raise, _raise); +#include "libc_private.h" +__weak_reference(__libc_raise, __raise); +__weak_reference(__libc_raise, _raise); + +#pragma weak raise int -__raise(int s) +raise(int s) { - return(kill(getpid(), s)); + + return (((int (*)(int)) + __libc_interposing[INTERPOS_raise])(s)); +} + +int +__libc_raise(int s) +{ + + return (kill(getpid(), s)); } Modified: head/lib/libc/gen/sleep.c ============================================================================== --- head/lib/libc/gen/sleep.c Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/gen/sleep.c Sat Jan 3 18:38:46 2015 (r276630) @@ -40,8 +40,19 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include "un-namespace.h" +#include "libc_private.h" + +#pragma weak sleep +unsigned int +sleep(unsigned int seconds) +{ + + return (((unsigned int (*)(unsigned int)) + __libc_interposing[INTERPOS_sleep])(seconds)); +} + unsigned int -__sleep(unsigned int seconds) +__libc_sleep(unsigned int seconds) { struct timespec time_to_sleep; struct timespec time_remaining; @@ -51,7 +62,7 @@ __sleep(unsigned int seconds) * the maximum value for a time_t is >= INT_MAX. */ if (seconds > INT_MAX) - return (seconds - INT_MAX + __sleep(INT_MAX)); + return (seconds - INT_MAX + __libc_sleep(INT_MAX)); time_to_sleep.tv_sec = seconds; time_to_sleep.tv_nsec = 0; @@ -63,5 +74,5 @@ __sleep(unsigned int seconds) (time_remaining.tv_nsec != 0)); /* round up */ } -__weak_reference(__sleep, sleep); -__weak_reference(__sleep, _sleep); +__weak_reference(__libc_sleep, __sleep); +__weak_reference(__libc_sleep, _sleep); Modified: head/lib/libc/gen/termios.c ============================================================================== --- head/lib/libc/gen/termios.c Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/gen/termios.c Sat Jan 3 18:38:46 2015 (r276630) @@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include "un-namespace.h" +#include "libc_private.h" + int tcgetattr(int fd, struct termios *t) { @@ -208,13 +210,23 @@ tcsendbreak(int fd, int len __unused) } int -__tcdrain(int fd) +__libc_tcdrain(int fd) { + return (_ioctl(fd, TIOCDRAIN, 0)); } -__weak_reference(__tcdrain, tcdrain); -__weak_reference(__tcdrain, _tcdrain); +#pragma weak tcdrain +int +tcdrain(int fd) +{ + + return (((int (*)(int)) + __libc_interposing[INTERPOS_tcdrain])(fd)); +} + +__weak_reference(__libc_tcdrain, __tcdrain); +__weak_reference(__libc_tcdrain, _tcdrain); int tcflush(int fd, int which) Modified: head/lib/libc/gen/usleep.c ============================================================================== --- head/lib/libc/gen/usleep.c Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/gen/usleep.c Sat Jan 3 18:38:46 2015 (r276630) @@ -38,8 +38,19 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include "un-namespace.h" +#include "libc_private.h" + +#pragma weak usleep +int +usleep(useconds_t useconds) +{ + + return (((int (*)(useconds_t)) + __libc_interposing[INTERPOS_usleep])(useconds)); +} + int -__usleep(useconds_t useconds) +__libc_usleep(useconds_t useconds) { struct timespec time_to_sleep; @@ -48,5 +59,5 @@ __usleep(useconds_t useconds) return (_nanosleep(&time_to_sleep, NULL)); } -__weak_reference(__usleep, usleep); -__weak_reference(__usleep, _usleep); +__weak_reference(__libc_usleep, __usleep); +__weak_reference(__libc_usleep, _usleep); Modified: head/lib/libc/gen/wait.c ============================================================================== --- head/lib/libc/gen/wait.c Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/gen/wait.c Sat Jan 3 18:38:46 2015 (r276630) @@ -40,11 +40,23 @@ __FBSDID("$FreeBSD$"); #include <sys/resource.h> #include "un-namespace.h" +#include "libc_private.h" + +#pragma weak wait pid_t -__wait(int *istat) +wait(int *istat) { - return (_wait4(WAIT_ANY, istat, 0, (struct rusage *)0)); + + return (((pid_t (*)(int *)) + __libc_interposing[INTERPOS_wait])(istat)); +} + +pid_t +__libc_wait(int *istat) +{ + + return (__sys_wait4(WAIT_ANY, istat, 0, NULL)); } -__weak_reference(__wait, wait); -__weak_reference(__wait, _wait); +__weak_reference(__libc_wait, __wait); +__weak_reference(__libc_wait, _wait); Modified: head/lib/libc/gen/wait3.c ============================================================================== --- head/lib/libc/gen/wait3.c Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/gen/wait3.c Sat Jan 3 18:38:46 2015 (r276630) @@ -40,11 +40,22 @@ __FBSDID("$FreeBSD$"); #include <sys/resource.h> #include "un-namespace.h" +#include "libc_private.h" + +#pragma weak wait3 +pid_t +wait3(int *istat, int options, struct rusage *rup) +{ + + return (((pid_t (*)(int *, int, struct rusage *)) + __libc_interposing[INTERPOS_wait3])(istat, options, rup)); +} + +__weak_reference(__libc_wait3, __wait3); + pid_t -wait3(istat, options, rup) - int *istat; - int options; - struct rusage *rup; +__libc_wait3(int *istat, int options, struct rusage *rup) { - return (_wait4(WAIT_ANY, istat, options, rup)); + + return (__sys_wait4(WAIT_ANY, istat, options, rup)); } Modified: head/lib/libc/gen/waitpid.c ============================================================================== --- head/lib/libc/gen/waitpid.c Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/gen/waitpid.c Sat Jan 3 18:38:46 2015 (r276630) @@ -40,11 +40,23 @@ __FBSDID("$FreeBSD$"); #include <sys/resource.h> #include "un-namespace.h" +#include "libc_private.h" + +#pragma weak waitpid pid_t -__waitpid(pid_t pid, int *istat, int options) +waitpid(pid_t pid, int *istat, int options) { - return (_wait4(pid, istat, options, (struct rusage *)0)); + + return (((pid_t (*)(pid_t, int *, int)) + __libc_interposing[INTERPOS_waitpid])(pid, istat, options)); +} + +pid_t +__libc_waitpid(pid_t pid, int *istat, int options) +{ + + return (__sys_wait4(pid, istat, options, NULL)); } -__weak_reference(__waitpid, waitpid); -__weak_reference(__waitpid, _waitpid); +__weak_reference(__libc_waitpid, __waitpid); +__weak_reference(__libc_waitpid, _waitpid); Modified: head/lib/libc/include/libc_private.h ============================================================================== --- head/lib/libc/include/libc_private.h Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/include/libc_private.h Sat Jan 3 18:38:46 2015 (r276630) @@ -173,6 +173,61 @@ typedef pthread_func_t pthread_func_entr extern pthread_func_entry_t __thr_jtable[]; +extern int *(*__error_selector)(void); +int _pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex, + void *(calloc_cb)(__size_t, __size_t)); + +typedef int (*interpos_func_t)(void); +interpos_func_t *__libc_interposing_slot(int interposno); +extern interpos_func_t __libc_interposing[]; + +enum { + INTERPOS_accept, + INTERPOS_accept4, + INTERPOS_aio_suspend, + INTERPOS_close, + INTERPOS_connect, + INTERPOS_creat, + INTERPOS_fcntl, + INTERPOS_fsync, + INTERPOS_fork, + INTERPOS_msync, + INTERPOS_nanosleep, + INTERPOS_open, + INTERPOS_openat, + INTERPOS_poll, + INTERPOS_pselect, + INTERPOS_raise, + INTERPOS_recvfrom, + INTERPOS_recvmsg, + INTERPOS_select, + INTERPOS_sendmsg, + INTERPOS_sendto, + INTERPOS_setcontext, + INTERPOS_sigaction, + INTERPOS_sigprocmask, + INTERPOS_sigsuspend, + INTERPOS_sigwait, + INTERPOS_sigtimedwait, + INTERPOS_sigwaitinfo, + INTERPOS_swapcontext, + INTERPOS_system, + INTERPOS_sleep, + INTERPOS_tcdrain, + INTERPOS_usleep, + INTERPOS_pause, + INTERPOS_read, + INTERPOS_readv, + INTERPOS_wait, + INTERPOS_wait3, + INTERPOS_wait4, + INTERPOS_waitpid, + INTERPOS_write, + INTERPOS_writev, + INTERPOS__pthread_mutex_init_calloc_cb, + INTERPOS_MAX +}; + /* * yplib internal interfaces */ @@ -215,42 +270,107 @@ void _malloc_thread_cleanup(void); void _malloc_prefork(void); void _malloc_postfork(void); +void _malloc_first_thread(void); + /* * Function to clean up streams, called from abort() and exit(). */ -extern void (*__cleanup)(void) __hidden; +void (*__cleanup)(void) __hidden; /* * Get kern.osreldate to detect ABI revisions. Explicitly * ignores value of $OSVERSION and caches result. Prototypes * for the wrapped "new" pad-less syscalls are here for now. */ -extern int __getosreldate(void); +int __getosreldate(void); #include <sys/_types.h> -/* Without pad */ -extern __off_t __sys_lseek(int, __off_t, int); -extern int __sys_ftruncate(int, __off_t); -extern int __sys_truncate(const char *, __off_t); -extern __ssize_t __sys_pread(int, void *, __size_t, __off_t); -extern __ssize_t __sys_pwrite(int, const void *, __size_t, __off_t); -extern void * __sys_mmap(void *, __size_t, int, int, int, __off_t); +#include <sys/_sigset.h> /* With pad */ -extern __off_t __sys_freebsd6_lseek(int, int, __off_t, int); -extern int __sys_freebsd6_ftruncate(int, int, __off_t); -extern int __sys_freebsd6_truncate(const char *, int, __off_t); -extern __ssize_t __sys_freebsd6_pread(int, void *, __size_t, int, __off_t); -extern __ssize_t __sys_freebsd6_pwrite(int, const void *, __size_t, int, __off_t); -extern void * __sys_freebsd6_mmap(void *, __size_t, int, int, int, int, __off_t); - -/* Without back-compat translation */ -extern int __sys_fcntl(int, int, ...); - +__off_t __sys_freebsd6_lseek(int, int, __off_t, int); +int __sys_freebsd6_ftruncate(int, int, __off_t); +int __sys_freebsd6_truncate(const char *, int, __off_t); +__ssize_t __sys_freebsd6_pread(int, void *, __size_t, int, __off_t); +__ssize_t __sys_freebsd6_pwrite(int, const void *, __size_t, int, __off_t); +void * __sys_freebsd6_mmap(void *, __size_t, int, int, int, int, __off_t); + +struct aiocb; +struct fd_set; +struct iovec; +struct msghdr; +struct pollfd; +struct rusage; +struct sigaction; +struct sockaddr; struct timespec; struct timeval; struct timezone; -int __sys_gettimeofday(struct timeval *, struct timezone *); -int __sys_clock_gettime(__clockid_t, struct timespec *ts); +struct __siginfo; +struct __ucontext; +int __sys_aio_suspend(const struct aiocb * const[], int, + const struct timespec *); +int __sys_accept(int, struct sockaddr *, __socklen_t *); +int __sys_accept4(int, struct sockaddr *, __socklen_t *, int); +int __sys_clock_gettime(__clockid_t, struct timespec *ts); +int __sys_close(int); +int __sys_connect(int, const struct sockaddr *, __socklen_t); +int __sys_fcntl(int, int, ...); +int __sys_fsync(int); +__pid_t __sys_fork(void); +int __sys_ftruncate(int, __off_t); +int __sys_gettimeofday(struct timeval *, struct timezone *); +__off_t __sys_lseek(int, __off_t, int); +void *__sys_mmap(void *, __size_t, int, int, int, __off_t); +int __sys_msync(void *, __size_t, int); +int __sys_nanosleep(const struct timespec *, struct timespec *); +int __sys_open(const char *, int, ...); +int __sys_openat(int, const char *, int, ...); +int __sys_pselect(int, struct fd_set *, struct fd_set *, + struct fd_set *, const struct timespec *, + const __sigset_t *); +int __sys_poll(struct pollfd *, unsigned, int); +__ssize_t __sys_pread(int, void *, __size_t, __off_t); +__ssize_t __sys_pwrite(int, const void *, __size_t, __off_t); +__ssize_t __sys_read(int, void *, __size_t); +__ssize_t __sys_readv(int, const struct iovec *, int); +__ssize_t __sys_recv(int, void *, __size_t, int); +__ssize_t __sys_recvfrom(int, void *, __size_t, int, struct sockaddr *, + __socklen_t *); +__ssize_t __sys_recvmsg(int, struct msghdr *, int); +int __sys_select(int, struct fd_set *, struct fd_set *, + struct fd_set *, struct timeval *); +__ssize_t __sys_sendmsg(int, const struct msghdr *, int); +__ssize_t __sys_sendto(int, const void *, __size_t, int, + const struct sockaddr *, __socklen_t); +int __sys_setcontext(const struct __ucontext *); +int __sys_sigaction(int, const struct sigaction *, + struct sigaction *); +int __sys_sigprocmask(int, const __sigset_t *, __sigset_t *); +int __sys_sigsuspend(const __sigset_t *); +int __sys_sigtimedwait(const __sigset_t *, struct __siginfo *, + const struct timespec *); +int __sys_sigwait(const __sigset_t *, int *); +int __sys_sigwaitinfo(const __sigset_t *, struct __siginfo *); +int __sys_swapcontext(struct __ucontext *, + const struct __ucontext *); +int __sys_truncate(const char *, __off_t); +__pid_t __sys_wait4(__pid_t, int *, int, struct rusage *); +__ssize_t __sys_write(int, const void *, __size_t); +__ssize_t __sys_writev(int, const struct iovec *, int); + +int __libc_creat(const char *path, __mode_t mode); +int __libc_pause(void); +int __libc_raise(int); +int __libc_sigwait(const __sigset_t * __restrict, + int * restrict sig); +int __libc_system(const char *); +unsigned int __libc_sleep(unsigned int); +int __libc_tcdrain(int); +int __libc_usleep(__useconds_t); +__pid_t __libc_wait(int *); +__pid_t __libc_wait3(int *, int, struct rusage *); +__pid_t __libc_waitpid(__pid_t, int *, int); +int __fcntl_compat(int fd, int cmd, ...); /* execve() with PATH processing to implement posix_spawnp() */ int _execvpe(const char *, char * const *, char * const *); Modified: head/lib/libc/stdlib/Symbol.map ============================================================================== --- head/lib/libc/stdlib/Symbol.map Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/stdlib/Symbol.map Sat Jan 3 18:38:46 2015 (r276630) @@ -118,4 +118,5 @@ FBSD_1.4 { FBSDprivate_1.0 { __system; _system; + __libc_system; }; Modified: head/lib/libc/stdlib/jemalloc/Symbol.map ============================================================================== --- head/lib/libc/stdlib/jemalloc/Symbol.map Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/stdlib/jemalloc/Symbol.map Sat Jan 3 18:38:46 2015 (r276630) @@ -55,4 +55,5 @@ FBSDprivate_1.0 { _malloc_thread_cleanup; _malloc_prefork; _malloc_postfork; + _malloc_first_thread; }; Modified: head/lib/libc/stdlib/system.c ============================================================================== --- head/lib/libc/stdlib/system.c Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/stdlib/system.c Sat Jan 3 18:38:46 2015 (r276630) @@ -46,8 +46,17 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" #include "libc_private.h" +#pragma weak system int -__system(const char *command) +system(const char *command) +{ + + return (((int (*)(const char *)) + __libc_interposing[INTERPOS_system])(command)); +} + +int +__libc_system(const char *command) { pid_t pid, savedpid; int pstat; @@ -95,5 +104,5 @@ __system(const char *command) return(pid == -1 ? -1 : pstat); } -__weak_reference(__system, system); -__weak_reference(__system, _system); +__weak_reference(__libc_system, __system); +__weak_reference(__libc_system, _system); Modified: head/lib/libc/sys/Makefile.inc ============================================================================== --- head/lib/libc/sys/Makefile.inc Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/sys/Makefile.inc Sat Jan 3 18:38:46 2015 (r276630) @@ -20,17 +20,61 @@ NOASM+= clock_gettime.o gettimeofday.o PSEUDO+= _clock_gettime.o _gettimeofday.o # Sources common to both syscall interfaces: -SRCS+= stack_protector.c stack_protector_compat.c __error.c +SRCS+= \ + stack_protector.c \ + stack_protector_compat.c \ + __error.c \ + interposing_table.c + .if ${MK_SYSCALL_COMPAT} != "no" -SYSCALL_COMPAT_SRCS= fcntl.c ftruncate.c lseek.c mmap.c pread.c \ - pwrite.c truncate.c +SYSCALL_COMPAT_SRCS= \ + ftruncate.c \ + lseek.c \ + mmap.c \ + pread.c \ + pwrite.c \ + truncate.c SRCS+= ${SYSCALL_COMPAT_SRCS} NOASM+= ${SYSCALL_COMPAT_SRCS:S/.c/.o/} -PSEUDO+= _fcntl.o .endif -SRCS+= sigwait.c -NOASM+= sigwait.o -PSEUDO+= _sigwait.o + +INTERPOSED = \ + accept \ + accept4 \ + aio_suspend \ + close \ + connect \ + fcntl \ + fsync \ + fork \ + msync \ + nanosleep \ + open \ + openat \ + poll \ + pselect \ + read \ + readv \ + recvfrom \ + recvmsg \ + select \ + sendmsg \ + sendto \ + setcontext \ + sigaction \ + sigprocmask \ + sigsuspend \ + sigtimedwait \ + sigwait \ + sigwaitinfo \ + swapcontext \ + wait4 \ + write \ + writev + +SRCS+= ${INTERPOSED:S/$/.c/} +NOASM+= ${INTERPOSED:S/$/.o/} +PSEUDO+= ${INTERPOSED:C/^.*$/_&.o/} # Add machine dependent asm sources: SRCS+=${MDASM} Modified: head/lib/libc/sys/Symbol.map ============================================================================== --- head/lib/libc/sys/Symbol.map Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/sys/Symbol.map Sat Jan 3 18:38:46 2015 (r276630) @@ -245,7 +245,6 @@ FBSD_1.0 { setaudit; setaudit_addr; setauid; - setcontext; setegid; seteuid; setgid; @@ -286,7 +285,6 @@ FBSD_1.0 { __stack_chk_guard; stat; statfs; - swapcontext; swapoff; swapon; symlink; @@ -351,7 +349,6 @@ FBSD_1.1 { mkfifoat; mknodat; msgctl; - openat; readlinkat; renameat; setfib; @@ -1049,6 +1046,9 @@ FBSDprivate_1.0 { _writev; __sys_writev; __error_unthreaded; + __error_selector; nlm_syscall; gssd_syscall; + __libc_interposing_slot; + __libc_sigwait; }; Modified: head/lib/libc/sys/__error.c ============================================================================== --- head/lib/libc/sys/__error.c Sat Jan 3 18:35:29 2015 (r276629) +++ head/lib/libc/sys/__error.c Sat Jan 3 18:38:46 2015 (r276630) @@ -32,14 +32,17 @@ __FBSDID("$FreeBSD$"); extern int errno; -/* - * Declare a weak reference in case the application is not linked - * with libpthread. - */ -__weak_reference(__error_unthreaded, __error); - int * __error_unthreaded(void) { return(&errno); } + +int *(*__error_selector)(void) = __error_unthreaded; + +int * +__error(void) +{ + + return (__error_selector()); +} Added: head/lib/libc/sys/accept.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/sys/accept.c Sat Jan 3 18:38:46 2015 (r276630) @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014 The FreeBSD Foundation. + * All rights reserved. + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> +#include <sys/syscall.h> +#include <sys/socket.h> +#include "libc_private.h" + +__weak_reference(__sys_accept, __accept); + +#pragma weak accept +int +accept(int s, struct sockaddr *addr, socklen_t *addrlen) +{ + + return (((int (*)(int, struct sockaddr *, socklen_t *)) + __libc_interposing[INTERPOS_accept])(s, addr, addrlen)); +} Added: head/lib/libc/sys/accept4.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/sys/accept4.c Sat Jan 3 18:38:46 2015 (r276630) @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014 The FreeBSD Foundation. + * All rights reserved. + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> +#include <sys/syscall.h> +#include <sys/socket.h> +#include "libc_private.h" + +__weak_reference(__sys_accept4, __accept4); + +#pragma weak accept4 +int +accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) +{ + + return (((int (*)(int, struct sockaddr *, socklen_t *, int)) + __libc_interposing[INTERPOS_accept4])(s, addr, addrlen, flags)); +} Added: head/lib/libc/sys/aio_suspend.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/sys/aio_suspend.c Sat Jan 3 18:38:46 2015 (r276630) @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2014 The FreeBSD Foundation. + * All rights reserved. + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> +#include <sys/aio.h> +#include "libc_private.h" + +__weak_reference(__sys_aio_suspend, __aio_suspend); + +#pragma weak aio_suspend +int +aio_suspend(const struct aiocb * const iocbs[], int niocb, + const struct timespec *timeout) +{ + + return (((int (*)(const struct aiocb * const[], int, + const struct timespec *)) + __libc_interposing[INTERPOS_aio_suspend])(iocbs, niocb, timeout)); +} Added: head/lib/libc/sys/close.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/sys/close.c Sat Jan 3 18:38:46 2015 (r276630) @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2014 The FreeBSD Foundation. *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201501031838.t03Iclot097606>