diff options
96 files changed, 4586 insertions, 178 deletions
@@ -1,22 +1,15 @@ 2008-08-12 Neal H. Walfield <neal@gnu.org> - * sysdeps/generic/pt-mutex-unlock.c (__pthread_mutex_unlock): - Remove dead code. + Merge in Samuel Thibault's changes from the main line. -2008-08-11 Neal H. Walfield <neal@gnu.org> + * Makefile.am (libpthread_a_SOURCES): Add pt-getattr.c. + * headers.m4: Link libpthread/include/pthread/pthreadtypes.h to + sysroot/include/pthread/pthreadtypes.h and + libpthread/sysdeps/${arch}/bits/spin-lock-inline.h. to + sysroot/include/bits/spin-lock-inline.h. - * sysdeps/l4/pt-docancel.c: Remove file. - * sysdeps/l4/pt-thread-alloc.c: Likewise. - * sysdeps/l4/pt-wakeup.c: Likewise. - * sysdeps/l4/pt-thread-halt.c: Likewise. - * sysdeps/l4/pt-start.c: Likewise. - * sysdeps/l4/pt-stack-alloc.c: Likewise. - * sysdeps/l4/pt-thread-start.c: Likewise. - * sysdeps/l4/pt-block.c: Likewise. - * sysdeps/l4/hurd/pt-sysdep.h: Likewise. - * sysdeps/l4/hurd/pt-sysdep.c: Likewise. - * sysdeps/l4/hurd/i386/pt-setup.c: Likewise. - * sysdeps/l4/hurd/i386/pt-machdep.c: Likewise. + * include/pthread/pthread.h: Include <sys/cdefs.h>. + (__extern_inline): If not defined, define appropriately. 2008-08-04 Samuel Thibault <samuel.thibault@ens-lyon.org> @@ -26,35 +19,26 @@ 2008-08-03 Samuel Thibault <samuel.thibault@ens-lyon.org> * Makefile (sysdeps_headers): Add spin-lock-inline.h. - (SYSDEP_PATH): Move sysdeps/i386 right after - sysdeps/$(MICROKERNEL)/i386. + (SYSDEP_PATH): Move sysdeps/ia32 right after + sysdeps/$(MICROKERNEL)/ia32. * include/pthread/pthread.h: Include <bits/spin-lock-inline.h>. - * sysdeps/i386/bits/spin-lock.h: Move inlines to... - * sysdeps/i386/bits/spin-lock-inline.h: ... new file. - * sysdeps/mach/bits/spin-lock.h: Move inlines to... - * sysdeps/mach/bits/spin-lock-inline.h: ... new file. + * sysdeps/ia32/bits/spin-lock.h: Move inlines to... + * sysdeps/ia32/bits/spin-lock-inline.h: ... new file. 2008-08-02 Samuel Thibault <samuel.thibault@ens-lyon.org> * sysdeps/generic/bits/mutex.h: Do not include <errno.h> and <stddef.h> - * sysdeps/i386/bits/memory.h (__memory_barrier): Add memory clobber. - * sysdeps/i386/bits/spin-lock.h (__pthread_spin_trylock, + * sysdeps/ia32/bits/memory.h (__memory_barrier): Add memory clobber. + * sysdeps/ia32/bits/spin-lock.h (__pthread_spin_trylock, __pthread_spin_unlock): Add memory clobbers. - * sysdeps/mach/hurd/i386/pt-setup.c (stack_setup): Fix cast from - thread to integer. Fix reservation of stack room for initial frame. - * sysdeps/l4/hurd/i386/pt-setup.c (stack_setup): Fix reservation of + * sysdeps/l4/hurd/ia32/pt-setup.c (stack_setup): Fix reservation of stack room for initial frame. 2008-07-18 Samuel Thibault <samuel.thibault@ens-lyon.org> * Makefile (sysdeps_headers): add pthread/pthreadtypes.h -2008-06-29 Samuel Thibault <samuel.thibault@ens-lyon.org> - - * sysdeps/generic/pt-mutex-unlock.c (__pthread_mutex_unlock): - Do not use assertx and threadid. - 2008-06-27 Samuel Thibault <samuel.thibault@ens-lyon.org> * include/pthread/pthread.h: Do not define __need_clockid_t, include @@ -94,16 +78,39 @@ * sysdeps/generic/bits/thread-barrier.h: Remove unused file. +2008-05-17 Samuel Thibault <samuel.thibault@ens-lyon.org> + + * include/pthread/pthread.h (pthread_getattr_np): New declaration. + * pthread/pt-getattr.c: New file. + * Makefile (SRCS): Add pt-getattr.c. + +2008-03-16 Samuel Thibault <samuel.thibault@ens-lyon.org> + + * include/libc-symbols.h (HAVE_ASM_PREVIOUS_DIRECTIVE): Define. + +2008-02-29 Samuel Thibault <samuel.thibault@ens-lyon.org> + + * sysdeps/l4/hurd/ia32/pt-setup.c (stack_setup): Align stack on 0x10 + for MMX operations. + +2008-01-01 Samuel Thibault <samuel.thibault@ens-lyon.org> + + * include/pthread/pthread.h (pthread_spin_destroy, pthread_spin_init, + pthread_spin_lock, pthread_spin_trylock, pthread_spin_unlock): Use + __extern_inline macro instead of extern __inline. + * sysdeps/ia32/bits/spin-lock.h (__PT_SPIN_INLINE, + __pthread_spin_lock): Likewise + * sysdeps/generic/bits/pthread.h (pthread_equal): Declare ; only + provide inline when __USE_EXTERN_INLINES is defined. Use __extern_inline + macro instead of extern __inline. + * sysdeps/ia32/bits/memory.h (__memory_barrier): Add static to inline. + 2008-06-22 Neal H. Walfield <neal@gnu.org> * sysdeps/generic/pt-mutex-timedlock.c - (__pthread_mutex_timedlock_internal) [! NDEBUG]: Set MUTEX->OWNER - appropriately and assert that it is consistent. - * sysdeps/generic/pt-mutex-unlock.c (__pthread_mutex_unlock) [! - NDEBUG]: Set MUTEX->OWNER appropriately and assert that it is - consistent. - * sysdeps/generic/pt-mutex-trylock.c (__pthread_mutex_trylock) [! - NDEBUG]: Set MUTEX->OWNER. + (__pthread_mutex_timedlock_internal): Don't set MUTEX->OWNER here. + * sysdeps/generic/pt-mutex-unlock.c (__pthread_mutex_unlock): Set + it here to WAKEUP. 2008-06-07 Neal H. Walfield <neal@gnu.org> @@ -111,47 +118,365 @@ true. (__pthread_dequeuing_iterate): Likewise. +2008-06-05 Neal H. Walfield <neal@gnu.org> + + * sysdeps/l4/hurd/pt-thread-alloc.c (__pthread_thread_alloc): + Replace use of as_slot_ensure with as_ensure. + +2008-06-01 Neal H. Walfield <neal@gnu.org> + + * include/pthread/pthread.h (PTHREAD_MUTEX_RECURSIVE_INITIALIZER_NP): + New definition. + * sysdeps/generic/bits/mutex.h + (__PTHREAD_MUTEX_RECURSIVE_INITIALIZER): New definition. + * sysdeps/generic/bits/mutex-attr.h (__pthread_recursive_mutexattr): + New definition. + * sysdeps/generic/pt-mutexattr.c (__pthread_recursive_mutexattr): + New declaration. + * sysdeps/generic/pt-mutex-init.c (_pthread_mutex_init): If ATTR + is &__PTHREAD_RECURSIVE_MUTEXATTR, don't allocate a copy, just + save in MUTEX->ATTR. + * sysdeps/generic/pt-mutex-destroy.c (_pthread_mutex_destroy): If + MUTEX->ATTR is &__PTHREAD_RECURSIVE_MUTEXATTR, don't free it. + +2008-05-29 Thomas Schwinge <tschwinge@gnu.org> + + * headers.m4: Link files into `sysroot/include/' instead of `include/'. + Create symbolic link to package's library in `sysroot/lib/'. + * Makefile.am [ENABLE_TESTS]: Don't build package's library. + + * sysdeps/generic/sem-timedwait.c: Don't include <error.h>. + +2008-05-29 Neal H. Walfield <neal@gnu.org> + + * sysdeps/l4/hurd/pt-sysdep.h Include <hurd/exceptions.h>. + (EXCEPTION_AREA_SIZE): Define. + (EXCEPTION_AREA_SIZE_LOG2): Likewise. + (EXCEPTION_PAGE): Likewise. + (PTHREAD_SYSDEP_MEMBERS): Change object's type to an addr_t. + Update users. Remove field exception_page, replace with + exception_area. Add field exception_area_va. + * sysdeps/l4/hurd/pt-thread-alloc.c: Include <hurd/as.h> and + <hurd/addr.h>. + (__pthread_thread_alloc): Allocate EXCEPTION_AREA_SIZE bytes of + address space. Save it in THREAD->EXCEPTION_AREA_VA. Allocate a + page for each page in that area. Save them in + THREAD->EXCEPTION_AREA. + * sysdeps/l4/hurd/ia32/pt-setup.c (__pthread_setup): Set + EXCEPTION_PAGE->EXCEPTION_HANDLER_SP to the end of + EXCEPTION_PAGE->EXCEPTION_HANDLER_SP minus one word, in which we + save the address of the exception page. + * sysdeps/l4/hurd/pt-thread-start.c (__pthread_thread_start): Set + IN.EXCEPTION_PAGE to the first page in THREAD->EXCEPTION_AREA_VA. + * sysdeps/l4/hurd/pt-thread-halt.c: Include <hurd/mutex.h>, + <hurd/as.h> and <hurd/addr.h>. + (saved_object_lock): New variable. + (__pthread_thread_halt): Lock SAVED_OBJECT_LOCK when accessing + SAVED_OBJECT. Free the address space used by the exception + area (THREAD->EXCEPTION_AREA_VA) and its associated + storage (THREAD->EXCEPTION_AREA). + 2008-05-27 Neal H. Walfield <neal@gnu.org> * pthread/pt-internal.h (__pthread_queue_iterate): Before returning the current element, save its next pointer. (__pthread_dequeuing_iterate): Likewise. -2008-05-27 Neal H. Walfield <neal@gnu.org> + * sysdeps/l4/hurd/pt-wakeup.c (__pthread_wakeup): Loop until we + successfully wake THREAD. + +2008-05-21 Neal H. Walfield <neal@gnu.org> + + * sysdeps/l4/hurd/bits/pthread-np.h: New file. + * headers.m4: Don't link include/bits/pthread-np.h to + libpthread/sysdeps/l4/bits/pthread-np.h but to + libpthread/sysdeps/l4/hurd/bits/pthread-np.h. + * include/pthread/pthread.h: Include <bits/pthread-np.h>. + * sysdeps/l4/hurd/pt-setactivity-np.c (pthread_setactivity_np): + New file. + * Makefile.am (libpthread_a_SOURCES): Add pt-setactivity-np.c. + +2008-04-06 Neal H. Walfield <neal@gnu.org> + + * sysdeps/l4/hurd/pt-kill.c: Just include "../generic/pt-kill.c". + +2008-03-01 Neal H. Walfield <neal@gnu.org> + + Add signal implementation. + * Makefile.am (SYSDEP_PATH): Add $(srcdir)/signal. + (libpthread_a_SOURCES): Add pt-mutex-transfer-np.c, kill.c, + killpg.c, pt-kill-siginfo-np.c, raise.c, sigaction.c, sigaddset.c, + sigaltstack.c, sigdelset.c, sigemptyset.c, sigfillset.c, + sig-internal.c, sig-internal.h, siginterrupt.c, sigismember.c, + signal.c, signal-dispatch.c, signal.h, sigpending.c, + sigprocmask.c, sigsuspend.c, sigtimedwait.c, sigwait.c, + sigwaiter.c, sigwaitinfo.c, signal-dispatch-lowlevel.c, and + sigprocmask.c. + * headers.m4: Link libpthread/signal/signal.h into ../include. + * sysdeps/generic/pt-mutex-transfer-np.c: New file. + * signal/README: New file. + * signal/TODO: Likewise. + * signal/kill.c: Likewise. + * signal/pt-kill-siginfo-np.c: Likewise. + * signal/sig-internal.c: Likewise. + * signal/sig-internal.h: Likewise. + * signal/sigaction.c: Likewise. + * signal/sigaltstack.c: Likewise. + * signal/signal-dispatch.c: Likewise. + * signal/signal.h: Likewise. + * signal/sigpending.c: Likewise. + * signal/sigsuspend.c: Likewise. + * signal/sigtimedwait.c: Likewise. + * signal/sigwaiter.c: Likewise. + * signal/sigwaitinfo.c: Likewise. + * sysdeps/l4/hurd/sig-sysdep.h: Likewise. + * sysdeps/l4/hurd/sigprocmask.c: Likewise. + * sysdeps/generic/killpg.c: Likewise. + * sysdeps/generic/pt-kill.c: Likewise. + * sysdeps/generic/raise.c: Likewise. + * sysdeps/generic/sigaddset.c: Likewise. + * sysdeps/generic/sigdelset.c: Likewise. + * sysdeps/generic/sigemptyset.c: Likewise. + * sysdeps/generic/sigfillset.c: Likewise. + * sysdeps/generic/siginterrupt.c: Likewise. + * sysdeps/generic/sigismember.c: Likewise. + * sysdeps/generic/signal.c: Likewise. + * sysdeps/generic/sigwait.c: Likewise. + * sysdeps/l4/hurd/ia32/signal-dispatch-lowlevel.c: Likewise. + * sysdeps/l4/hurd/pt-sysdep.c (sigprocmask): Remove function. + * sysdeps/l4/hurd/pt-sigstate.c (__pthread_sigstate): Implement + it. + * sysdeps/l4/hurd/pt-sigstate-init.c: Include <sig-internal.h>. + (__pthread_sigstate_init): Initialize THREAD->SS. + * sysdeps/l4/hurd/pt-kill.c: Remove file. + * pthread/pt-internal.h: Include <sig-internal.h>. + (PTHREAD_SIGNAL_MEMBERS) [! PTHREAD_SIGNAL_MEMBERS]: Define. + (struct __pthread): Add PTHREAD_SIGNAL_MEMBERS. + * pthread/pt-self.c (pthread_self): Assert that SELF is not NULL. + +2008-02-21 Neal H. Walfield <neal@gnu.org> + + * Makefile.am (AM_CPPFLAGS): Replace use of includes with + $(USER_CPPFLAGS). + (AM_CFLAGS): New variable. + +2008-02-16 Neal H. Walfield <neal@gnu.org> + + * sysdeps/l4/hurd/ia32/pt-setup.c (stack_setup): Add correct casts + to elide gcc warnings. + (__pthread_setup): Likewise. + +2008-02-13 Neal H. Walfield <neal@gnu.org> + + * sysdeps/l4/hurd/pt-thread-alloc.c (__pthread_thread_alloc): + Update use of storage_alloc to be consistent with new API. + +2008-02-13 Neal H. Walfield <neal@gnu.org> + + * sysdeps/l4/hurd/pt-sysdep.c (_pthread_init_routine): Change + function signature to take a function pointer and an argument and + to not return. + (init_routine): Likewise. Pass entry and argument to + __pthread_create_internal. Instead of returning, jump to the + program counter and switch stacks. + +2008-02-11 Neal H. Walfield <neal@gnu.org> + + * sysdeps/l4/hurd/ia32/pt-setup.c (_pthread_entry_point): New + assembly function. + (stack_setup): Take additional argument entry_point. Push it on + the stack. + (__pthread_setup): Set thread->mcontext.pc to + &_pthread_entry_point. Pass ENTRY_POINT to stack_setup. + +2008-02-08 Neal H. Walfield <neal@gnu.org> + + * sysdeps/hurd/pt-setspecific.c (pthread_setspecific): Update use + of hurd_ihash_create to be consistent with API changes. + +2008-01-23 Neal H. Walfield <neal@gnu.org> + + * Makefile.am (AM_CPPFLAGS): Add -I$(LIBC)/include. + +2008-01-17 Neal H. Walfield <neal@gnu.org> + + * sysdeps/l4/hurd/pt-block.c: New file. + * sysdeps/l4/hurd/pt-wakeup.c: Likewise. + +2008-01-01 Neal H. Walfield <neal@gnu.org> - * sysdeps/mach/hurd/pt-docancel.c (__pthread_do_cancel): Fix - assert. + * sysdeps/generic/pt-mutex-timedlock.c + (__pthread_mutex_timedlock_internal): Add additional asserts. + [! NDEBUG]: Keep MUTEX->OWNER up to date. + * sysdeps/generic/pt-mutex-trylock.c (__pthread_mutex_trylock): + Add additional asserts. + [! NDEBUG]: Keep MUTEX->OWNER up to date. + * sysdeps/generic/pt-mutex-unlock.c (__pthread_mutex_unlock): Add + additional asserts. + [! NDEBUG]: Keep MUTEX->OWNER up to date. + +2007-12-23 Neal H. Walfield <neal@gnu.org> + + * Makefile.am (AM_CPPFLAGS): Add "-std=gnu99 -Wall -g -O3". + + * sysdeps/l4/pt-block.c (__pthread_block): Remove unused variable + err. + + * pthread/pt-join.c (pthread_join): Cast argument to + pthread_cleanup_push to avoid warning. + +2007-12-13 Neal H. Walfield <neal@gnu.org> + + * sysdeps/l4/hurd/pt-thread-halt.c: Include <hurd/exceptions.h>. + (__pthread_thread_halt): Call exception_page_cleanup. + +2007-12-12 Neal H. Walfield <neal@gnu.org> + + * sysdeps/l4/pt-block.c (__pthread_block): Clear the acceptor. + Improve debugging output. + * sysdeps/l4/pt-wakeup.c (__pthread_wakeup): Load an empty message. + Improve debugging output. + +2007-12-04 Neal H. Walfield <neal@gnu.org> + + Remove exception threads. Replace with support for activations. + * sysdeps/l4/hurd/pt-sysdep.h (PTHREAD_SYSDEP_MEMBERS): Remove + fields exception_handler_stack and exception_handler_sp. Add + field exception_page. + * sysdeps/l4/hurd/pt-thread-alloc.c (__pthread_thread_alloc): + Allocate a page for THREAD->EXCEPTION_PAGE, not + THREAD->EXCEPTION_HANDLER_STACK. + * sysdeps/l4/hurd/ia32/pt-setup.c: Include <hurd/thread.h> and + <hurd/exceptions.h>. + (__pthread_setup): Remove code dealing with the exception thread. + Set up the exception page. + * sysdeps/l4/hurd/pt-thread-start.c (__pthread_thread_start): + Remove code dealing with the exception thread. Update to use new + rm_thread_exregs interface. Also set the thread's exception page. + * sysdeps/l4/hurd/pt-thread-halt.c (__pthread_thread_halt): Remove + code to dealing with the exception thread. Free the + THREAD->EXCEPTION_PAGE. + +2007-11-23 Neal H. Walfield <neal@gnu.org> + + * pthread/pt-internal.h (__pthread_startup): Add declaration. + * pthread/pt-create.c (entry_point): Call __pthread_startup. + * sysdeps/l4/hurd/pt-sysdep.h: Include <hurd/storage.h> and + <sys/mman.h>. + (PTHREAD_SYSDEP_MEMBERS): Add fields object, + exception_handler_stack and exception_handler_sp. + (__attribute__): Call munmap. + * sysdeps/l4/hurd/ia32/pt-setup.c (__pthread_setup): Set up + thread->exception_handler_sp. Don't set the user define handle + here. + * sysdeps/l4/hurd/pt-startup.c: New file. Do it here. + * sysdeps/l4/hurd/pt-thread-alloc.c: New file. + * sysdeps/l4/hurd/pt-thread-halt.c: New file. + * sysdeps/l4/hurd/pt-thread-start.c: New file. + * Makefile.am (libpthread_a_SOURCES): Add pt-startup.c. -2008-05-17 Samuel Thibault <samuel.thibault@ens-lyon.org> + * sysdeps/l4/pt-block.c: Include <hurd/stddef.h>. + (__pthread_block): Detect IPC failure. Add debugging output. + * sysdeps/l4/pt-wakeup.c: Include <hurd/stddef.h>. + (__pthread_wakeup): Detect IPC failure. Add debugging output. - * include/pthread/pthread.h (pthread_getattr_np): New declaration. - * pthread/pt-getattr.c: New file. - * Makefile (SRCS): Add pt-getattr.c. +2007-11-20 Neal H. Walfield <neal@gnu.org> -2008-03-16 Samuel Thibault <samuel.thibault@ens-lyon.org> + * sysdeps/l4/pt-thread-dealloc.c: New file. + * Makefile.am (libpthread_a_SOURCES): Add pt-thread-dealloc.c. - * include/libc-symbols.h (HAVE_ASM_PREVIOUS_DIRECTIVE): Define. + * sysdeps/l4/hurd/pt-sysdep.h (PTHREAD_STACK_DEFAULT): Change to + 2MB. -2008-02-29 Samuel Thibault <samuel.thibault@ens-lyon.org> + * sysdeps/l4/hurd/pt-sysdep.c (sched_yield): New function. + (sigprocmask): Likewise. + (init_routine): Only call __pthread_initialize once. Update + comments. - * sysdeps/l4/hurd/i386/pt-setup.c (stack_setup): Align stack on 0x10 - for MMX operations. - * sysdeps/mach/hurd/i386/pt-setup.c (stack_setup): Likewise. +2007-11-20 Neal H. Walfield <neal@gnu.org> + + * Makefile.am (libpthread_a_SOURCES): Remove pt-create-np.c. + * sysdeps/l4/pt-create-np.c: Remove file. + * sysdeps/l4/pt-pool-np.c (pthread_pool_add_np): Change tid from + an _L4_thread_id_t to an l4_thread_id_t. + (pthread_pool_get_np): Return an l4_thread_id_t, not a + _L4_thread_id_t. + * sysdeps/l4/bits/pthread-np.h (pthread_create_from_l4_tid_np): + Remove declaration. + (pthread_pool_add_np): Change tid from an _L4_thread_id_t to an + l4_thread_id_t. + (pthread_pool_get_np): Return an l4_thread_id_t, not a + _L4_thread_id_t. + + * sysdeps/l4/pt-docancel.c (__pthread_do_cancel): Implement for + the case that the target thread is not the executing thread. + + * sysdeps/l4/pt-thread-alloc.c (__pthread_thread_alloc): Return + EAGAIN if pthread_pool_get_np does not return a thread. Update + comments. -2008-01-01 Samuel Thibault <samuel.thibault@ens-lyon.org> + * sysdeps/l4/pt-thread-start.c (__pthread_thread_start): Don't set + the thread's pager. Assert that if this is the first thread, then + THREAD->THREADID is designates the running thread. - * include/pthread/pthread.h (pthread_spin_destroy, pthread_spin_init, - pthread_spin_lock, pthread_spin_trylock, pthread_spin_unlock): Use - __extern_inline macro instead of extern __inline. - * sysdeps/i386/bits/spin-lock.h (__PT_SPIN_INLINE, - __pthread_spin_lock): Likewise - * sysdeps/mach/bits/spin-lock.h (__PT_SPIN_INLINE, - __pthread_spin_lock): Likewise - * sysdeps/generic/bits/pthread.h (pthread_equal): Declare ; only - provide inline when __USE_EXTERN_INLINES is defined. Use __extern_inline - macro instead of extern __inline. - * sysdeps/i386/bits/memory.h (__memory_barrier): Add static to inline. + * sysdeps/l4/pt-timedblock.c (__pthread_timedblock): Add warning + about incomplete implementation. + + * Makefile.am (libpthread_a_SOURCES): Remove pt-thread-init.c. + * sysdeps/l4/pt-thread-init.c: Remove dead file. + * sysdeps/l4/pt-start.c: Remove dead file. + +2007-11-20 Neal H. Walfield <neal@gnu.org> + + Also merge semaphore changes from mainline Hurd. + +2007-11-20 Neal H. Walfield <neal@gnu.org> + Merge changes from mainline Hurd. Update L4 bits to compile with + those changes. + + * sysdeps/l4/pt-block.c (__pthread_block): Call l4_receive, not + L4_Receive. + * sysdeps/l4/pt-create-np.c (pthread_create_from_l4_tid_np): Don't + pass TID to __pthread_create_internal. Emit a warning. + * sysdeps/l4/pt-stack-alloc.c (allocate_page): Remove function. + (__pthread_stack_alloc): Don't require that STACKSIZE is equal to + __pthread_stacksize. Call mmap. + * sysdeps/l4/pt-thread-halt.c (__pthread_thread_halt): Take + additional argument, need_dealloc. Call __pthread_dealloc. Stop + the thread. + * sysdeps/l4/hurd/pt-sysdep.c (init_routine): When calling + __pthread_create_internal, don't pass the tid. + * tests/test-1.c (main): Use pthread_mutex_init, not + PTHREAD_MUTEX_INITIALIZER. + + * pthread/pt-alloc.c: Don't include <bits/atomic.h>. Include + <atomic.h>. + (__pthread_free_threads): Make it an atomicptr_t, not an + __atomicptr_t. + (__pthread_alloc): Don't use __atomicptr_compare_and_swap, use + atomic_compare_and_exchange_val_acq. + * pthread/pt-create.c: Don't include <bits/atomic.h>. Include + <atomic.h>. + (__pthread_total): Make it an atomic_fast32_t, not an __atomic_t. + (__pthread_create_internal): Use atomic_increment and + atomic_decrement, not __atomic_inc and __atomic_dec. + * pthread/pt-dealloc.c: Don't include <bits/atomic.h>. Include + <atomic.h>. + (__pthread_free_threads): Make it an atomicptr_t, not an + __atomicptr_t. + (__pthread_dealloc): Use atomic_compare_and_exchange_val_acq, not + __atomicptr_compare_and_swap. + * pthread/pt-exit.c: Don't include <bits/atomic.h>. Include + <atomic.h>. + (pthread_exit): Use atomic_decrement_and_test, not + __atomic_dec_and_test. + * pthread/pt-internal.h: Don't include <bits/atomic.h>. Include + <atomic.h>. + (__pthread_total): Make it an atomic_fast32_t, not an __atomic_t. + * sysdeps/powerpc/bits/atomic.h: Remove file. + * sysdeps/ia32/bits/atomic.h: Likewise. + 2007-11-19 Thomas Schwinge <tschwinge@gnu.org> * Makefile (CFLAGS): Don't set and instead... @@ -208,6 +533,7 @@ * sysdeps/i386/machine-sp.h (thread_stack_pointer): Optimize esp read. + * i386/cthreads.h (cthread_sp): Likewise. * include/pthread/pthread.h: Add the restrict keyword where appropriate for full compliance. * pthread/pt-internal.h: Likewise. @@ -435,13 +761,101 @@ THREAD_SPECIFICS to hurd_ihash_t. * sysdeps/hurd/pt-setspecific.c (pthread_setspecific): Call hurd_ihash_create instead ihash_create, and hurd_ihash_add instead - ihash_add. - * sysdeps/hurd/pt-getspecific.c (pthread_getspecific): Call - hurd_ihash_find instead of ihash_find. - * sysdeps/hurd/pt-destroy-specific.c (__pthread_destroy_specific): - Call hurd_ihash_find instead of ihash_find, hurd_ihash_remove - instead of ihash_remove, and hurd_ihash_free instead of - ihash_free. + +2007-08-06 Neal H. Walfield <neal@gnu.org> + + * sysdeps/l4/bits/pthread-np.h (pthread_create_from_l4_tid_np): + Don't require the GNU interface: use _L4_thread_id_t, not + l4_thread_id_t. + (pthread_pool_add_np): Likewise. + (pthread_pool_get_np): Likewise. + * sysdeps/l4/pt-create-np.c (pthread_create_from_l4_tid_np): Likewise. + * sysdeps/l4/pt-pool-np.c (pool_list): Likewise. + (pthread_pool_add_np): Likewise. + (pthread_pool_get_np): Likewise. + +2005-02-08 Neal H. Walfield <neal@gnu.org> + + * sysdeps/posix/pt-spin.c (__pthread_spin_lock): Make a weak alias + to _pthread_spin_lock. + * sysdeps/l4/hurd/pt-sysdep.h (_pthread_self): Add + __always_inline__ attribute. + (__pthread_stack_dealloc): Likewise. + +2005-01-12 Neal H. Walfield <neal@gnu.org> + + * sysdeps/l4/pt-thread-alloc.c: Replace assert with a compile time + warning. + * sysdeps/l4/hurd/pt-sigstate.c (__pthread_sigstate): Don't return + EINVAL. Pretend to work so the generic code is happy. + +2004-11-02 Marcus Brinkmann <marcus@gnu.org> + + * sysdeps/generic/bits/condition.h (__PTHREAD_COND_INITIALIZER): + Remove compound statement. + * pthread/pt-alloc.c (initialize_pthread): Use compound statement. + * sysdeps/generic/pt-cond-init.c (pthread_cond_init): Likewise. + +2004-11-01 Marcus Brinkmann <marcus@gnu.org> + + * pthread/pt-create.c (__pthread_total): Change type to uatomic32_t. + * pthread/pt-internal.h (__pthread_total): Likewise in declaration. + + * pthread/pt-internal.h: Include <atomic.h>, not <bits/atomic.h>. + (__pthread_total): Change type of declaration to uatomic_max_t. + * pthread/pt-alloc.c: Include <atomic.h>, not <bits/atomic.h>. + (__pthread_free_threads): Change type to uatomicptr_t. + (__pthread_alloc): Call atomic_compare_and_exchange_val_acq + instead of __atomicptr_compare_and_swap. + * pthread/pt-create.c: Include <atomic.h>, not <bits/atomic.h>. + (__pthread_total): Change type to uatomic_max_t. + (__pthread_create_internal): Call atomic_increment, not + __atomic_inc and atomic_decrement, not __atomic_dec. + * pthread/pt-dealloc.c: Include <atomic.h>, not <bits/atomic.h>. + (__pthread_free_threads): Declare as uatomicptr_t. + (__pthread_dealloc): Call atomic_compare_and_exchange_val_acq + instead of __atomicptr_compare_and_swap. + * pthread/pt-exit.c: Include <atomic.h>, not <bits/atomic.h>. + (pthread_exit): Call atomic_decrement_and_test instead of + __atomic_dec_and_test. + * sysdeps/l4/pt-create-np.c: Do not include <bits/atomic.h>. + +2004-10-29 Marcus Brinkmann <marcus@gnu.org> + + * headers.am (AC_CONFIG_LINKS): Remove include/bits/atomic.h. + +2004-03-23 Marcus Brinkmann <marcus@gnu.org> + + * sysdeps/generic/bits/mutex.h (__PTHREAD_MUTEX_INITIALIZER): + Remove compound statement. + (pthread_mutex_init): Use compound statement with initializer. + * pthread/pt-alloc.c (initialize_pthread): Likewise. + * sysdeps/generic/pt-mutex-init.c (_pthread_mutex_init): Likewise. + +2004-03-19 Marcus Brinkmann <marcus@gnu.org> + + * sysdeps/l4/bits/pthread-np.h (pthread_pool_add_np, + pthread_pool_get_np): New prototypes. + * sysdeps/l4/pt-pool-np.c: New file. + * Makefile.am (libpthread_a_SOURCES): Add pt-pool-np.c. + * sysdeps/l4/pt-thread-alloc.c (__pthread_thread_alloc): Try to + allocate thread from pool. + * sysdeps/l4/pt-thread-halt.c (__pthread_thread_halt): Add thread + to pool after stopping it. + +2004-03-17 Marcus Brinkmann <marcus@gnu.org> + + * sysdeps/l4/pt-thread-start.c (__pthread_thread_start): Use L4 + convenience interface. + + * sysdeps/l4/pt-spin.c (_pthread_spin_lock): Implement using new + time period interface. + +2003-10-16 Johan Rydberg <jrydberg@night.trouble.net> + + Many changes throughout all files, converting L4 specific source + code to the GNU libl4 interface. Integration into the hurd-l4 + infrastructure. 2003-08-03 Marco Gerards <metgerards@student.han.nl> @@ -157,9 +157,9 @@ sysdeps_headers = \ bits/rwlock-attr.h \ bits/semaphore.h -SYSDEP_PATH = $(srcdir)/sysdeps/$(MICROKERNEL)/hurd/i386 \ - $(srcdir)/sysdeps/$(MICROKERNEL)/i386 \ - $(srcdir)/sysdeps/i386 \ +SYSDEP_PATH = $(srcdir)/sysdeps/$(MICROKERNEL)/hurd/ia32 \ + $(srcdir)/sysdeps/$(MICROKERNEL)/ia32 \ + $(srcdir)/sysdeps/ia32 \ $(srcdir)/sysdeps/$(MICROKERNEL)/hurd \ $(srcdir)/sysdeps/$(MICROKERNEL) \ $(srcdir)/sysdeps/hurd \ diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..e59c946 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,167 @@ +# Makefile.am - Makefile template for libpthread. +# Copyright (C) 2003, 2008 Free Software Foundation, Inc. +# +# This file is part of the GNU Hurd. +# +# The GNU Hurd 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 2 of the License, or +# (at your option) any later version. +# +# The GNU Hurd 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +if ARCH_IA32 + arch=ia32 +endif +if ARCH_POWERPC + arch=powerpc +endif + +# The source files are scattered over several directories. Add +# all these directories to the vpath. +SYSDEP_PATH = $(srcdir)/sysdeps/l4/hurd/${arch} \ + $(srcdir)/sysdeps/l4/${arch} \ + $(srcdir)/sysdeps/${arch} \ + $(srcdir)/sysdeps/l4/hurd \ + $(srcdir)/sysdeps/l4 \ + $(srcdir)/sysdeps/hurd \ + $(srcdir)/sysdeps/generic \ + $(srcdir)/sysdeps/posix \ + $(srcdir)/pthread \ + $(srcdir)/signal \ + $(srcdir)/include +vpath %.c $(SYSDEP_PATH) + +AM_CPPFLAGS = $(USER_CPPFLAGS) -I$(srcdir)/pthread \ + $(addprefix -I, $(SYSDEP_PATH)) -imacros $(srcdir)/include/libc-symbols.h +AM_CFLAGS = $(USER_CFLAGS) + +# Sources. +SYSDEPS := lockfile.c + +if ! ENABLE_TESTS +noinst_LIBRARIES = libpthread.a +endif + +libpthread_a_SOURCES = pt-attr.c pt-attr-destroy.c pt-attr-getdetachstate.c \ + pt-attr-getguardsize.c pt-attr-getinheritsched.c \ + pt-attr-getschedparam.c pt-attr-getschedpolicy.c pt-attr-getscope.c \ + pt-attr-getstack.c pt-attr-getstackaddr.c pt-attr-getstacksize.c \ + pt-attr-init.c pt-attr-setdetachstate.c pt-attr-setguardsize.c \ + pt-attr-setinheritsched.c pt-attr-setschedparam.c \ + pt-attr-setschedpolicy.c pt-attr-setscope.c pt-attr-setstack.c \ + pt-attr-setstackaddr.c pt-attr-setstacksize.c pt-attr.c \ + pt-barrier-destroy.c pt-barrier-init.c pt-barrier-wait.c \ + pt-barrier.c pt-barrierattr-destroy.c pt-barrierattr-init.c \ + pt-barrierattr-getpshared.c pt-barrierattr-setpshared.c \ + pt-destroy-specific.c pt-init-specific.c \ + pt-key-create.c pt-key-delete.c \ + pt-getspecific.c pt-setspecific.c \ + pt-once.c \ + pt-alloc.c \ + pt-create.c \ + pt-getattr.c \ + pt-pool-np.c \ + pt-equal.c \ + pt-dealloc.c \ + pt-detach.c \ + pt-exit.c \ + pt-initialize.c \ + pt-join.c \ + pt-self.c \ + pt-sigmask.c \ + pt-spin-inlines.c \ + pt-cleanup.c \ + pt-setcancelstate.c \ + pt-setcanceltype.c \ + pt-testcancel.c \ + pt-cancel.c \ + pt-mutexattr.c \ + pt-mutexattr-destroy.c pt-mutexattr-init.c \ + pt-mutexattr-getprioceiling.c pt-mutexattr-getprotocol.c \ + pt-mutexattr-getpshared.c pt-mutexattr-gettype.c \ + pt-mutexattr-setprioceiling.c pt-mutexattr-setprotocol.c \ + pt-mutexattr-setpshared.c pt-mutexattr-settype.c \ + pt-mutex-init.c pt-mutex-destroy.c \ + pt-mutex-lock.c pt-mutex-trylock.c pt-mutex-timedlock.c \ + pt-mutex-unlock.c \ + pt-mutex-transfer-np.c \ + pt-mutex-getprioceiling.c pt-mutex-setprioceiling.c \ + pt-rwlock-attr.c \ + pt-rwlockattr-init.c pt-rwlockattr-destroy.c \ + pt-rwlockattr-getpshared.c pt-rwlockattr-setpshared.c \ + pt-rwlock-init.c pt-rwlock-destroy.c \ + pt-rwlock-rdlock.c pt-rwlock-tryrdlock.c \ + pt-rwlock-trywrlock.c pt-rwlock-wrlock.c \ + pt-rwlock-timedrdlock.c pt-rwlock-timedwrlock.c \ + pt-rwlock-unlock.c \ + pt-cond.c \ + pt-condattr-init.c pt-condattr-destroy.c \ + pt-condattr-getclock.c pt-condattr-getpshared.c \ + pt-condattr-setclock.c pt-condattr-setpshared.c \ + pt-cond-destroy.c pt-cond-init.c \ + pt-cond-brdcast.c \ + pt-cond-signal.c \ + pt-cond-wait.c \ + pt-cond-timedwait.c \ + pt-stack-alloc.c \ + pt-thread-alloc.c \ + pt-thread-dealloc.c \ + pt-thread-start.c \ + pt-thread-halt.c \ + pt-startup.c \ + pt-getconcurrency.c pt-setconcurrency.c \ + pt-block.c \ + pt-timedblock.c \ + pt-wakeup.c \ + pt-docancel.c \ + pt-sysdep.c \ + pt-setup.c \ + pt-machdep.c \ + pt-spin.c \ + pt-sigstate-init.c \ + pt-sigstate-destroy.c \ + pt-sigstate.c \ + pt-atfork.c \ + pt-kill.c \ + pt-getcpuclockid.c \ + pt-getschedparam.c pt-setschedparam.c pt-setschedprio.c \ + sem-close.c sem-init.c sem-timedwait.c sem-wait.c \ + sem-destroy.c sem-open.c sem-trywait.c sem-getvalue.c \ + sem-post.c sem-unlink.c \ + \ + pt-setactivity-np.c \ + \ + kill.c \ + killpg.c \ + pt-kill-siginfo-np.c \ + raise.c \ + sigaction.c \ + sigaddset.c \ + sigaltstack.c \ + sigdelset.c \ + sigemptyset.c \ + sigfillset.c \ + sig-internal.c \ + sig-internal.h \ + siginterrupt.c \ + sigismember.c \ + signal.c \ + signal-dispatch.c \ + signal.h \ + sigpending.c \ + sigprocmask.c \ + sigsuspend.c \ + sigtimedwait.c \ + sigwait.c \ + sigwaiter.c \ + sigwaitinfo.c \ + signal-dispatch-lowlevel.c \ + sigprocmask.c diff --git a/headers.m4 b/headers.m4 new file mode 100644 index 0000000..5a58b9b --- /dev/null +++ b/headers.m4 @@ -0,0 +1,45 @@ +# headers.m4 - Autoconf snippets to install links for header files. +# Copyright 2003, 2008 Free Software Foundation, Inc. +# Written by Marcus Brinkmann <marcus@gnu.org>. +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This file is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +AC_CONFIG_LINKS([ + sysroot/include/pthread.h:libpthread/include/pthread.h + sysroot/include/pthread/pthread.h:libpthread/include/pthread/pthread.h + sysroot/include/pthread/pthreadtypes.h:libpthread/include/pthread/pthreadtypes.h + sysroot/include/bits/memory.h:libpthread/sysdeps/${arch}/bits/memory.h + sysroot/include/bits/spin-lock.h:libpthread/sysdeps/${arch}/bits/spin-lock.h + sysroot/include/bits/spin-lock-inline.h:libpthread/sysdeps/${arch}/bits/spin-lock-inline.h + sysroot/include/bits/pthreadtypes.h:libpthread/sysdeps/generic/bits/pthreadtypes.h + sysroot/include/bits/barrier-attr.h:libpthread/sysdeps/generic/bits/barrier-attr.h + sysroot/include/bits/barrier.h:libpthread/sysdeps/generic/bits/barrier.h + sysroot/include/bits/cancelation.h:libpthread/sysdeps/generic/bits/cancelation.h + sysroot/include/bits/condition-attr.h:libpthread/sysdeps/generic/bits/condition-attr.h + sysroot/include/bits/condition.h:libpthread/sysdeps/generic/bits/condition.h + sysroot/include/bits/mutex-attr.h:libpthread/sysdeps/generic/bits/mutex-attr.h + sysroot/include/bits/mutex.h:libpthread/sysdeps/generic/bits/mutex.h + sysroot/include/bits/once.h:libpthread/sysdeps/generic/bits/once.h + sysroot/include/bits/pthread.h:libpthread/sysdeps/generic/bits/pthread.h + sysroot/include/bits/rwlock-attr.h:libpthread/sysdeps/generic/bits/rwlock-attr.h + sysroot/include/bits/rwlock.h:libpthread/sysdeps/generic/bits/rwlock.h + sysroot/include/bits/thread-attr.h:libpthread/sysdeps/generic/bits/thread-attr.h + sysroot/include/bits/thread-barrier.h:libpthread/sysdeps/generic/bits/thread-barrier.h + sysroot/include/bits/thread-specific.h:libpthread/sysdeps/generic/bits/thread-specific.h + sysroot/include/bits/pthread-np.h:libpthread/sysdeps/l4/hurd/bits/pthread-np.h + sysroot/include/semaphore.h:libpthread/include/semaphore.h + sysroot/include/bits/semaphore.h:libpthread/sysdeps/generic/bits/semaphore.h + sysroot/include/signal.h:libpthread/signal/signal.h +]) + +AC_CONFIG_COMMANDS_POST([ + mkdir -p sysroot/lib libpthread && + ln -sf ../../libpthread/libpthread.a sysroot/lib/ && + touch libpthread/libpthread.a +]) diff --git a/include/pthread/pthread.h b/include/pthread/pthread.h index 76733e0..c6e056a 100644 --- a/include/pthread/pthread.h +++ b/include/pthread/pthread.h @@ -26,6 +26,27 @@ #include <features.h> +#include <sys/cdefs.h> +#ifndef __extern_inline +/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 + inline semantics, unless -fgnu89-inline is used. */ +# if !defined __cplusplus || __GNUC_PREREQ (4,3) +# if defined __GNUC_STDC_INLINE__ || defined __cplusplus +# define __extern_inline extern __inline __attribute__ ((__gnu_inline__)) +# if __GNUC_PREREQ (4,3) +# define __extern_always_inline \ + extern __always_inline __attribute__ ((__gnu_inline__, __artificial__)) +# else +# define __extern_always_inline \ + extern __always_inline __attribute__ ((__gnu_inline__)) +# endif +# else +# define __extern_inline extern __inline +# define __extern_always_inline extern __always_inline +# endif +# endif +#endif + #include <sched.h> __BEGIN_DECLS @@ -289,6 +310,9 @@ extern int pthread_mutexattr_settype(pthread_mutexattr_t *attr, #include <bits/mutex.h> #define PTHREAD_MUTEX_INITIALIZER __PTHREAD_MUTEX_INITIALIZER +/* Static initializer for recursive mutexes. */ +#define PTHREAD_MUTEX_RECURSIVE_INITIALIZER_NP \ + __PTHREAD_MUTEX_RECURSIVE_INITIALIZER /* Create a mutex with attributes given by ATTR and store it in *__MUTEX. */ @@ -313,6 +337,11 @@ extern int pthread_mutex_timedlock (struct __pthread_mutex *__restrict mutex, /* Unlock MUTEX. */ extern int pthread_mutex_unlock (pthread_mutex_t *__mutex); +/* Transfer ownership of the mutex MUTEX to the thread TID. The + caller must own the lock. */ +extern int __pthread_mutex_transfer_np (struct __pthread_mutex *mutex, + pthread_t tid); + #ifdef __USE_UNIX98 /* Return the priority ceiling of mutex *MUTEX in *PRIOCEILING. */ @@ -699,6 +728,11 @@ extern int pthread_setschedparam (pthread_t thread, int policy, /* Set thread THREAD's scheduling priority. */ extern int pthread_setschedprio (pthread_t thread, int prio); + + +/* Kernel-specific interfaces. */ + +#include <bits/pthread-np.h> __END_DECLS diff --git a/pthread/pt-alloc.c b/pthread/pt-alloc.c index 30dcede..6cf9106 100644 --- a/pthread/pt-alloc.c +++ b/pthread/pt-alloc.c @@ -1,5 +1,5 @@ /* Allocate a new thread structure. - Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 2000, 2002, 2005, 2007 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 @@ -25,7 +25,7 @@ #include <pt-internal.h> -#include <bits/atomic.h> +#include <atomic.h> /* This braindamage is necessary because the standard says that some of the threads functions "shall fail" if "No thread could be found @@ -46,7 +46,7 @@ pthread_rwlock_t __pthread_threads_lock; /* List of thread structures corresponding to free thread IDs. */ -__atomicptr_t __pthread_free_threads; +atomicptr_t __pthread_free_threads; static inline error_t initialize_pthread (struct __pthread *new, int recycling) @@ -97,8 +97,10 @@ __pthread_alloc (struct __pthread **pthread) /* Try to re-use a thread structure before creating a new one. */ while ((new = (struct __pthread *)__pthread_free_threads)) { - if (__atomicptr_compare_and_swap (&__pthread_free_threads, - new, new->next)) + if (atomic_compare_and_exchange_val_acq (&__pthread_free_threads, + (uintptr_t) new->next, + (uintptr_t) new) + == (uintptr_t) new) { /* Yes, we managed to get one. The thread number in the thread structure still refers to the correct slot. */ @@ -110,8 +112,10 @@ __pthread_alloc (struct __pthread **pthread) while (1) { new->next = (struct __pthread *)__pthread_free_threads; - if (__atomicptr_compare_and_swap (&__pthread_free_threads, - new->next, new)) + if (atomic_compare_and_exchange_val_acq + (&__pthread_free_threads, + (uintptr_t) new, (uintptr_t) new->next) + == (uintptr_t) new->next) break; } diff --git a/pthread/pt-create.c b/pthread/pt-create.c index bad5d83..5bb9f1f 100644 --- a/pthread/pt-create.c +++ b/pthread/pt-create.c @@ -1,5 +1,5 @@ /* Thread creation. - Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 2000, 2002, 2005, 2007 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 @@ -22,7 +22,7 @@ #include <pthread.h> #include <signal.h> -#include <bits/atomic.h> +#include <atomic.h> #include <pt-internal.h> @@ -33,7 +33,7 @@ /* The total number of pthreads currently active. This is defined here since it would be really stupid to have a threads-using program that doesn't call `pthread_create'. */ -__atomic_t __pthread_total; +atomic_fast32_t __pthread_total; /* The entry-point for new threads. */ @@ -45,6 +45,8 @@ entry_point (void *(*start_routine)(void *), void *arg) uselocale (LC_GLOBAL_LOCALE); #endif + __pthread_startup (); + pthread_exit (start_routine (arg)); } @@ -161,7 +163,7 @@ __pthread_create_internal (struct __pthread **thread, the number of threads from within the new thread isn't an option since this thread might return and call `pthread_exit' before the new thread runs. */ - __atomic_inc (&__pthread_total); + atomic_increment (&__pthread_total); /* Store a pointer to this thread in the thread ID lookup table. We could use __thread_setid, however, we only lock for reading as no @@ -188,7 +190,7 @@ __pthread_create_internal (struct __pthread **thread, failed_starting: __pthread_setid (pthread->thread, NULL); - __atomic_dec (&__pthread_total); + atomic_decrement (&__pthread_total); failed_sigstate: __pthread_sigstate_destroy (pthread); failed_setup: diff --git a/pthread/pt-dealloc.c b/pthread/pt-dealloc.c index 1fc7a7b..879608b 100644 --- a/pthread/pt-dealloc.c +++ b/pthread/pt-dealloc.c @@ -23,10 +23,10 @@ #include <pt-internal.h> -#include <bits/atomic.h> +#include <atomic.h> /* List of thread structures corresponding to free thread IDs. */ -extern __atomicptr_t __pthread_free_threads; +extern atomicptr_t __pthread_free_threads; /* Deallocate the thread structure for PTHREAD and the resources associated with it. */ @@ -54,9 +54,11 @@ __pthread_dealloc (struct __pthread *pthread) while (1) { pthread->next = (struct __pthread *)__pthread_free_threads; - if (__atomicptr_compare_and_swap (&__pthread_free_threads, - pthread->next, pthread)) - return; + if (atomic_compare_and_exchange_val_acq (&__pthread_free_threads, + (uintptr_t) pthread, + (uintptr_t) pthread->next) + == (uintptr_t) pthread->next) + break; } /* NOTREACHED */ diff --git a/pthread/pt-exit.c b/pthread/pt-exit.c index 7484ffd..a8f85b1 100644 --- a/pthread/pt-exit.c +++ b/pthread/pt-exit.c @@ -24,7 +24,7 @@ #include <pt-internal.h> -#include <bits/atomic.h> +#include <atomic.h> /* Terminate the current thread and make STATUS available to any @@ -57,7 +57,7 @@ pthread_exit (void *status) /* Decrease the number of threads. We use an atomic operation to make sure that only the last thread calls `exit'. */ - if (__atomic_dec_and_test (&__pthread_total)) + if (atomic_decrement_and_test (&__pthread_total)) /* We are the last thread. */ exit (0); diff --git a/pthread/pt-internal.h b/pthread/pt-internal.h index e7c85fd..9eb84ed 100644 --- a/pthread/pt-internal.h +++ b/pthread/pt-internal.h @@ -26,13 +26,15 @@ #include <signal.h> #include <assert.h> -#include <bits/atomic.h> +#include <atomic.h> #include <pt-key.h> #include <pt-sysdep.h> #include <pt-machdep.h> +#include <sig-internal.h> + /* Thread state. */ enum pthread_state { @@ -50,6 +52,10 @@ enum pthread_state # define PTHREAD_SYSDEP_MEMBERS #endif +#ifndef PTHREAD_SIGNAL_MEMBERS +# define PTHREAD_SIGNAL_MEMBERS +#endif + /* This structure describes a POSIX thread. */ struct __pthread { @@ -85,6 +91,8 @@ struct __pthread PTHREAD_SYSDEP_MEMBERS + PTHREAD_SIGNAL_MEMBERS + struct __pthread *next, **prevp; }; @@ -132,7 +140,7 @@ __pthread_dequeue (struct __pthread *thread) ) /* The total number of threads currently active. */ -extern __atomic_t __pthread_total; +extern atomic_fast32_t __pthread_total; /* The total number of thread IDs currently in use, or on the list of available thread IDs. */ @@ -225,6 +233,10 @@ extern void __pthread_thread_halt (struct __pthread *thread, int need_dealloc); +/* Called by a thread just before it calls the provided start + routine. */ +extern void __pthread_startup (void); + /* Block THREAD. */ extern void __pthread_block (struct __pthread *thread); diff --git a/pthread/pt-join.c b/pthread/pt-join.c index 698b6c9..06e9f1f 100644 --- a/pthread/pt-join.c +++ b/pthread/pt-join.c @@ -37,7 +37,8 @@ pthread_join (pthread_t thread, void **status) return ESRCH; __pthread_mutex_lock (&pthread->state_lock); - pthread_cleanup_push (__pthread_mutex_unlock, &pthread->state_lock); + pthread_cleanup_push ((void (*)(void *)) __pthread_mutex_unlock, + &pthread->state_lock); while (pthread->state == PTHREAD_JOINABLE) pthread_cond_wait (&pthread->state_cond, &pthread->state_lock); diff --git a/pthread/pt-self.c b/pthread/pt-self.c index e14fe1e..4976864 100644 --- a/pthread/pt-self.c +++ b/pthread/pt-self.c @@ -1,5 +1,5 @@ /* Get calling thread's ID. - Copyright (C) 2000 Free Software Foundation, Inc. + Copyright (C) 2000, 2008 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 @@ -25,5 +25,8 @@ pthread_t pthread_self (void) { - return _pthread_self()->thread; + struct __pthread *self = _pthread_self (); + assert (self); + + return self->thread; } diff --git a/signal/README b/signal/README new file mode 100644 index 0000000..5487e2e --- /dev/null +++ b/signal/README @@ -0,0 +1,4 @@ +This directory provides a signal implementation, which is appropriate +for operating systems where signals are managed at user-level. It is +up to the run-time to catch the signals and forward them to the +implementation via, e.g., the pthread_kill_info_np call. diff --git a/signal/TODO b/signal/TODO new file mode 100644 index 0000000..1148abb --- /dev/null +++ b/signal/TODO @@ -0,0 +1,29 @@ +Unimplemented Functionality +--------------------------- + +We don't support interruptible functions. That is, if a signal is +delivered when a thread is in e.g. the write system call, then the +write function should be interrupted and return EINTR when the signal +handler is finished. To realize this behavior, we could have a thread +local interruptible flag and a setjmp buffer. A function that is +interruptible would fill the jump buffer and set the interruptible +flag. If a signal comes in and the interruptible flag is set, rather +than resuming the thread, we longjmp to the buffer. + +If a signal action has set the SA_SIGINFO, the third argument must be +a pointer to a ucontext describing the thread's interrupted state; +this implementation passes NULL. This isn't as bad as it sounds as +the the ucontext family of functions are marked obsolete in SUSv3 with +the advisory that any use of them should be replaced by the use of +pthread functionality (cf. makecontext rationale). + +stop and continue signals are not implemented (as we need to stop all +threads, this requires being in bed with libpthread). + +Implementation is not yet cancellation-safe. + +There are not even stubs for sighold, sigingore, sigpause, sigrelse, +however, according to posix: "Use of any of these functions is +unspecified in a multi-threaded process." + +Implement sigtimedwait, sigqueue.
\ No newline at end of file diff --git a/signal/kill.c b/signal/kill.c new file mode 100644 index 0000000..27c9c32 --- /dev/null +++ b/signal/kill.c @@ -0,0 +1,70 @@ +/* kill.c - Generic kill implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +int +kill (pid_t pid, int signo) +{ + if (pid != getpid ()) + { + errno = EOPNOTSUPP; + return -1; + } + + /* "Signals generated for the process shall be delivered to exactly + one of those threads within the process which is in a call to a + sigwait() function selecting that signal or has not blocked + delivery of the signal. If there are no threads in a call to a + sigwait() function selecting that signal, and if all threads + within the process block delivery of the signal, the signal shall + remaing pending on the process" (2.4.1). */ + + /* First, see if there is a waiter, which is interested in this + signal. */ + pthread_mutex_lock (&sig_lock); + + struct sigwaiter *waiter; + for (waiter = sigwaiters; waiter; waiter = waiter->next) + if ((waiter->signals & sigmask (signo))) + /* Got a winner. */ + { + sigdelset (&process_pending, signo); + + pthread_mutex_lock (&waiter->ss->lock); + sigdelset (&waiter->ss->pending, signo); + + memset (&waiter->info, 0, sizeof (waiter->info)); + waiter->info.si_signo = signo; + + sigwaiter_unblock (waiter); + + return 0; + } + + pthread_mutex_unlock (&sig_lock); + + /* XXX: We just generate the signal for the current thread. If the + current thread has blocked the signal, the correct thing to do is + to iterate over all the other threads and find on that hasn't + blocked it. */ + return pthread_kill (pthread_self (), signo); +} + diff --git a/signal/pt-kill-siginfo-np.c b/signal/pt-kill-siginfo-np.c new file mode 100644 index 0000000..9bdf6cc --- /dev/null +++ b/signal/pt-kill-siginfo-np.c @@ -0,0 +1,88 @@ +/* pthread-kill-siginfo-np.c - Generic pthread_kill_siginfo_np implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "pt-internal.h" +#include "sig-internal.h" + +int +pthread_kill_siginfo_np (pthread_t tid, siginfo_t si) +{ + int sig = si.si_signo; + + if (sig < 0 || sig >= NSIG) + return EINVAL; + + if (sig == 0) + return 0; + + struct signal_state *ss = &__pthread_getid (tid)->ss; + + pthread_mutex_lock (&sig_lock); + pthread_mutex_lock (&ss->lock); + + if (ss->sigwaiter && (ss->sigwaiter->signals & sigmask (si.si_signo))) + /* The thread is in a call to sigwait. */ + { + ss->sigwaiter->info = si; + sigwaiter_unblock (ss->sigwaiter); + return 0; + } + + pthread_mutex_unlock (&sig_lock); + + if (ss->actions[sig - 1].sa_handler == (void *) SIG_IGN + || (ss->actions[sig - 1].sa_handler == (void *) SIG_DFL + && default_action (sig) == sig_ignore)) + /* It is unclear (to me) what is supposed to happen when a signal + is generated for a thread, which is blocking that signal and + ignoring it. POSIX does say that when the action associated + with a pending, blocked signal is set to SIG_IGN, the pending + signal is to be cleared. Thus, it makes sense that any signal + set to ignore is discarded at generation. */ + { + pthread_mutex_unlock (&ss->lock); + return 0; + } + + + if ((sigmask (sig) & ss->blocked)) + /* The signal is blocked. Mark it pending. */ + { + ss->pending |= sigmask (sig); + pthread_mutex_unlock (&ss->lock); + return 0; + } + + if (pthread_self () == tid + && (! (ss->actions[si.si_signo - 1].sa_flags & SA_ONSTACK) + || (ss->stack.ss_flags & SS_DISABLE) + || (ss->stack.ss_flags & SS_ONSTACK))) + /* We are sending a signal to ourself and we don't use an + alternate stack. */ + signal_dispatch (ss, &si); + else + signal_dispatch_lowlevel (ss, tid, si); + + /* Don't unlock ss: signal_dispatch and signal_dispatch_lowlevel + assume ownership of the lock. */ + + return 0; +} + diff --git a/signal/sig-internal.c b/signal/sig-internal.c new file mode 100644 index 0000000..f73f38b --- /dev/null +++ b/signal/sig-internal.c @@ -0,0 +1,26 @@ +/* sig-internal.c - Signal state functions. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +pthread_mutex_t sig_lock = PTHREAD_MUTEX_INITIALIZER; + +sigset_t process_pending; +siginfo_t process_pending_info[NSIG]; diff --git a/signal/sig-internal.h b/signal/sig-internal.h new file mode 100644 index 0000000..6c86c79 --- /dev/null +++ b/signal/sig-internal.h @@ -0,0 +1,177 @@ +/* sig-internal.h - Internal signal handling interface. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#ifndef SIG_INTERNAL_H +#define SIG_INTERNAL_H + +#include <signal.h> + +#include <sig-sysdep.h> + +#define sigmask(sig) (1ULL << (sig - 1)) +#define STOPSIGS (sigmask (SIGTTIN) | sigmask (SIGTTOU) | \ + sigmask (SIGSTOP) | sigmask (SIGTSTP)) + +/* General lock. Protects PROCESS_PENDING, PROCESS_PENDING_INFO, + SIGWAITERS. */ +extern pthread_mutex_t sig_lock; + +/* "Signals generated for the process shall be delivered to exactly + one of those threads within the process which is in a call to a + sigwait() function selecting that signal or has not blocked + delivery of the signal. If there are no threads in a call to a + sigwait() function selecting that signal, and if all threads within + the process block delivery of the signal, the signal shall remaing + pending on the process" (2.4.1). + + This variable is protected by SIG_LOCK. */ +extern sigset_t process_pending; +extern siginfo_t process_pending_info[NSIG]; + +struct sigwaiter; + +/* The per-thread signal state. */ +struct signal_state +{ + /* Protects the following fields. STACK.SA_FLAGS may be accessed + using atomic operations. */ + pthread_mutex_t lock; + + /* Pending signals. */ + sigset_t pending; + + /* Blocked signals (i.e., the signal mask). */ + sigset_t blocked; + + stack_t stack; + struct sigaction actions[NSIG]; + siginfo_t info[NSIG]; + + /* If the thread is blocked in a call to sigwait. */ + struct sigwaiter *sigwaiter; +}; + +#define PTHREAD_SIGNAL_MEMBERS struct signal_state ss; + +/* Arranges for thread TID to call signal_dispatch. Must not be + called if TID is the caller and an alternate stack is not required. + In this case, the caller should call signal_dispatch directly. */ +extern void signal_dispatch_lowlevel (struct signal_state *ss, + pthread_t tid, siginfo_t si); + +/* This is the signal handler entry point. A thread is forced into + this state when it receives a signal. We need to save the thread's + state and then invoke the high-level signal dispatcher. SS->LOCK + is locked by the caller. */ +extern void signal_dispatch (struct signal_state *ss, siginfo_t *si); + +#ifndef SIGNAL_DISPATCH_ENTRY +#define SIGNAL_DISPATCH_ENTRY +#endif + +#ifndef SIGNAL_DISPATCH_EXIT +#define SIGNAL_DISPATCH_EXIT +#endif + +/* When a thread calls sigwait and a requested signal is not pending, + it allocates the following structure, fills it in, adds it to + sigwaiters and sleeps. */ +struct sigwaiter +{ + struct sigwaiter *next; + struct sigwaiter *prev; + + /* Thread's signal state. */ + struct signal_state *ss; + + /* Signals this thread is waiting for. */ + sigset_t signals; + + /* The selected signal is returned here. The waiter also + futex_waits on this info.si_signo. */ + siginfo_t info; +}; + +/* This variable is protected by SIG_LOCK. */ +extern struct sigwaiter *sigwaiters; + +/* Block the caller waiting for a signal in set SET. SIG_LOCK and + SS->LOCK must be held and will be unlocked by this function before + blocking. */ +extern siginfo_t sigwaiter_block (struct signal_state *ss, + const sigset_t *restrict set); + +/* Unblock the waiter WAITER. SIG_LOCK and WAITER->SS->LOCK must be + held. Both will be dropped on return. */ +extern void sigwaiter_unblock (struct sigwaiter *waiter); + +enum sig_action { sig_core, sig_terminate, sig_ignore, sig_cont, sig_stop }; + +static inline enum sig_action +default_action (int signo) +{ + switch (signo) + { + case SIGABRT: + case SIGBUS: + case SIGFPE: + case SIGILL: + case SIGQUIT: + case SIGSEGV: + case SIGSTKFLT: + case SIGSYS: + case SIGTRAP: + case SIGXCPU: + case SIGXFSZ: + return sig_core; + + case SIGALRM: + case SIGHUP: + case SIGINT: + case SIGIO: /* Perhaps ignore? */ + case SIGKILL: + case SIGPIPE: + case SIGPROF: + case SIGTERM: + case SIGUSR1: + case SIGUSR2: + case SIGVTALRM: + return sig_terminate; + + case SIGCHLD: + case SIGPWR: + case SIGURG: + case SIGWINCH: + return sig_ignore; + + case SIGCONT: + return sig_cont; + + case SIGSTOP: + case SIGTSTP: + case SIGTTIN: + case SIGTTOU: + return sig_stop; + } + + panic ("Unknown signal number: %d", signo); +} + +#endif diff --git a/signal/sigaction.c b/signal/sigaction.c new file mode 100644 index 0000000..0126c99 --- /dev/null +++ b/signal/sigaction.c @@ -0,0 +1,72 @@ +/* sigaction.c - Generic sigaction implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" +#include "pt-internal.h" + +int +sigaction (int sig, const struct sigaction *restrict sa, + struct sigaction *restrict osa) +{ + if (sig <= 0 || sig >= NSIG) + { + errno = EINVAL; + return -1; + } + + struct signal_state *ss = &_pthread_self ()->ss; + + pthread_mutex_lock (&ss->lock); + + if (osa) + *osa = ss->actions[sig - 1]; + + if (sa) + { + ss->actions[sig - 1] = *sa; + + /* "The SIGKILL and SIGSTOP signals shall not be added to the + signal mask using this mechanism; this restriction shall be + enforced by the system without causing an error to be + indicated" (sigaction). */ + sigdelset (&ss->blocked, SIGKILL); + sigdelset (&ss->blocked, SIGSTOP); + + /* A "signal shall remain pending on the process until it is + unblocked, it is accepted when ..., or the action associated + with it is set to ignore the signal" (2.4.1). + + "Setting a signal action to SIG_DFL for a signal that is + pending, and whose default action is to ignore the signal, + ..., shall cause the pending signal to be discarded, whether + or not it is blocked" (2.4.3). */ + if (sa->sa_handler == SIG_IGN + || (sa->sa_handler == SIG_DFL && default_action (sig) == sig_ignore)) + { + sigdelset (&ss->pending, sig); + sigdelset (&process_pending, sig); + } + } + + pthread_mutex_unlock (&ss->lock); + + return 0; +} + diff --git a/signal/sigaltstack.c b/signal/sigaltstack.c new file mode 100644 index 0000000..8334811 --- /dev/null +++ b/signal/sigaltstack.c @@ -0,0 +1,69 @@ +/* sigaltstack.c - Generic sigaltstack implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" +#include "pt-internal.h" + +int +sigaltstack (const stack_t *restrict stack, stack_t *restrict old) +{ + int err = 0; + struct signal_state *ss = &_pthread_self ()->ss; + + pthread_mutex_lock (&ss->lock); + + if (old) + *old = ss->stack; + + if (stack) + { + if (stack->ss_size < MINSIGSTKSZ) + { + err = ENOMEM; + goto out; + } + + if ((stack->ss_flags & ~(SS_DISABLE))) + /* Flags contains a value other than SS_DISABLE. */ + { + err = EINVAL; + goto out; + } + + if ((ss->stack.ss_flags & SS_ONSTACK)) + /* Stack in use. */ + { + err = EPERM; + goto out; + } + + ss->stack = *stack; + } + + out: + pthread_mutex_unlock (&ss->lock); + + if (err) + { + errno = err; + return -1; + } + return 0; +} diff --git a/signal/signal-dispatch.c b/signal/signal-dispatch.c new file mode 100644 index 0000000..40440b7 --- /dev/null +++ b/signal/signal-dispatch.c @@ -0,0 +1,117 @@ +/* signal-dispatch.c - Signal dispatcher. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +/* This is the signal handler entry point. A thread is forced into + this state when it receives a signal. We need to save the thread's + state and then invoke the high-level signal dispatcher. SS->LOCK + is locked by the caller. */ +void +signal_dispatch (struct signal_state *ss, siginfo_t *si) +{ + SIGNAL_DISPATCH_ENTRY; + + int signo = si->si_signo; + + assert (signo > 0 && signo < NSIG); + assert (pthread_mutex_trylock (&ss->lock) == EBUSY); + + do + { + if ((sigmask (signo) & STOPSIGS)) + /* Stop signals clear a pending SIGCONT even if they + are handled or ignored (but not if preempted). */ + { + sigdelset (&ss->pending, SIGCONT); + sigdelset (&process_pending, SIGCONT); + } + else if ((signo == SIGCONT)) + /* Even if handled or ignored (but not preempted), SIGCONT + clears stop signals and resumes the process. */ + { + ss->pending &= ~STOPSIGS; + process_pending &= ~STOPSIGS; + } + + void (*handler)(int, siginfo_t *, void *) + = ss->actions[signo - 1].sa_sigaction; + + /* Reset to SIG_DFL if requested. SIGILL and SIGTRAP cannot + be automatically reset when delivered; the system silently + enforces this restriction (sigaction). */ + if (ss->actions[signo - 1].sa_flags & SA_RESETHAND + && signo != SIGILL && signo != SIGTRAP) + ss->actions[signo - 1].sa_handler = SIG_DFL; + + sigset_t orig_blocked = ss->blocked; + /* Block requested signals while running the handler. */ + ss->blocked |= ss->actions[signo - 1].sa_mask; + + /* Block SIGNO unless we're asked not to. */ + if (! (ss->actions[signo - 1].sa_flags & (SA_RESETHAND | SA_NODEFER))) + sigaddset (&ss->blocked, signo); + + sigdelset (&ss->pending, signo); + pthread_mutex_unlock (&ss->lock); + + pthread_mutex_lock (&sig_lock); + sigdelset (&process_pending, signo); + pthread_mutex_unlock (&sig_lock); + + if (handler == (void *) SIG_DFL) + { + enum sig_action action = default_action (signo); + + if (action == sig_terminate || action == sig_core) + _exit (128 + signo); + + if (action == sig_stop) + /* XXX: Implement me. */ + panic ("Stopping process unimplemented."); + + if (action == sig_cont) + /* XXX: Implement me. */; + panic ("Continuing process unimplemented."); + } + else if (handler == (void *) SIG_IGN) + ; + else + handler (signo, si, NULL); + + pthread_mutex_lock (&ss->lock); + + /* "When a thread's signal mask is changed in a signal-catching + function that is installed by sigaction(), the restoration of + the signal mask on return from the signal-catching function + overrides that change (see sigaction())" (sigprocmask). */ + ss->blocked = orig_blocked; + + sigset_t pending = ~ss->blocked & ss->pending; + if (! pending) + pending = ~ss->blocked & process_pending; + signo = l4_lsb64 (pending); + } + while (signo); + + pthread_mutex_unlock (&ss->lock); + + SIGNAL_DISPATCH_EXIT; +} diff --git a/signal/signal.h b/signal/signal.h new file mode 100644 index 0000000..a33d995 --- /dev/null +++ b/signal/signal.h @@ -0,0 +1,275 @@ +/* signal.h - Signal handling interface. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#ifndef _SIGNAL_H +#define _SIGNAL_H 1 + +#include <stdint.h> +#include <sys/types.h> + +typedef volatile int sig_atomic_t; + +typedef uint64_t sigset_t; + +int sigaddset (sigset_t *, int); +int sigdelset (sigset_t *, int); +int sigemptyset (sigset_t *); +int sigfillset (sigset_t *); +int sigismember (const sigset_t *, int); + +/* These values are consistent with Linux. */ +#define SIGRTMIN 34 +#define SIGRTMAX 64 + +enum + { + SIGHUP = 1, +#define SIGHUP SIGHUP + SIGINT, +#define SIGINT SIGINT + SIGQUIT, +#define SIGQUIT SIGQUIT + SIGILL, +#define SIGILL SIGILL + SIGTRAP, +#define SIGTRAP SIGTRAP + SIGABRT, +#define SIGABRT SIGABRT + SIGBUS, +#define SIGBUS SIGBUS + SIGFPE, +#define SIGFPE SIGFPE + SIGKILL, +#define SIGKILL SIGKILL + SIGUSR1, +#define SIGUSR1 SIGUSR1 + SIGSEGV, +#define SIGSEGV SIGSEGV + SIGUSR2, +#define SIGUSR2 SIGUSR2 + SIGPIPE, +#define SIGPIPE SIGPIPE + SIGALRM, +#define SIGALRM SIGALRM + SIGTERM, +#define SIGTERM SIGTERM + SIGSTKFLT, +#define SIGSTKFLT SIGSTKFLT + SIGCHLD, +#define SIGCHLD SIGCHLD + SIGCONT, +#define SIGCONT SIGCONT + SIGSTOP, +#define SIGSTOP SIGSTOP + SIGTSTP, +#define SIGTSTP SIGTSTP + SIGTTIN, +#define SIGTTIN SIGTTIN + SIGTTOU, +#define SIGTTOU SIGTTOU + SIGURG, +#define SIGURG SIGURG + SIGXCPU, +#define SIGXCPU SIGXCPU + SIGXFSZ, +#define SIGXFSZ SIGXFSZ + SIGVTALRM, +#define SIGVTALRM SIGVTALRM + SIGPROF, +#define SIGPROF SIGPROF + SIGWINCH, +#define SIGWINCH SIGWINCH + SIGIO, +#define SIGIO SIGIO + SIGPWR, +#define SIGPWR SIGPWR + SIGSYS, +#define SIGSYS SIGSYS + NSIG + }; + +/* The resulting set is the union of the current set and the signal + set pointed to by the argument set. */ +#define SIG_BLOCK 1 +/* The resulting set is the intersection of the current set and the + complement of the signal set pointed to by the argument set. */ +#define SIG_UNBLOCK 2 +/* The resulting set is the signal set pointed to by the argument + set. */ +#define SIG_SETMASK 3 + +int pthread_sigmask (int how, const sigset_t *mask, sigset_t *old); +int sigprocmask (int how, const sigset_t *restrict mask, + sigset_t *restrict old); + +/* Return set of pending signals. */ +int sigpending(sigset_t *set); + +union sigval +{ + int sival_int; + void *sival_ptr; +}; + +#define SIG_DFL ((void (*)(int)) (0)) +#define SIG_ERR ((void (*)(int)) (-1)) +#define SIG_IGN ((void (*)(int)) (1)) + +/* Causes signal delivery to occur on an alternate stack. */ +#define SA_ONSTACK (1 << 0) +/* Do not generate SIGCHLD when children stop or stopped children + continue. */ +#define SA_NOCLDSTOP (1 << 1) +/* Causes signal dispositions to be set to SIG_DFL on entry to signal + handlers. */ +#define SA_RESETHAND (1 << 2) +/* Causes certain functions to become restartable. */ +#define SA_RESTART (1 << 3) +/* Causes extra information to be passed to signal handlers at the + time of receipt of a signal. */ +#define SA_SIGINFO (1 << 4) +/* Causes implementations not to create zombie processes on child + death. */ +#define SA_NOCLDWAIT (1 << 5) +/* Causes signal not to be automatically blocked on entry to + signal handler. */ +#define SA_NODEFER (1 << 6) + +typedef struct +{ + int si_signo; + int si_code; + int si_errno; + pid_t si_pid; + uid_t si_uid; + void *si_addr; + int si_status; + long si_band; + union sigval si_value; +} siginfo_t; + +struct sigaction +{ + union + { + /* Pointer to a signal-catching function or one of the macros + SIG_IGN or SIG_DFL. */ + void (*sa_handler)(int); + + /* Pointer to a signal-catching function. */ + void (*sa_sigaction)(int, siginfo_t *, void *); + }; + + /* Set of signals to be blocked during execution of the signal + handling function. */ + sigset_t sa_mask; + + /* Special flags. */ + int sa_flags; +}; + +int sigaction (int signo, const struct sigaction *restrict newaction, + struct sigaction *restrict oldaction); + +void (*signal (int signo, void (*handler)(int)))(int); +void (*bsd_signal (int signo, void (*handler)(int)))(int); + +/* Process is executing on an alternate signal stack. */ +#define SS_ONSTACK (1 << 0) +/* Alternate signal stack is disabled. */ +#define SS_DISABLE (1 << 1) + +/* Minimum stack size for a signal handler. */ +#define MINSIGSTKSZ PAGESIZE +/* Default size in bytes for the alternate signal stack. */ +#define SIGSTKSZ (16 * PAGESIZE) + +typedef struct +{ + void *ss_sp; + size_t ss_size; + int ss_flags; +} stack_t; + +int sigaltstack(const stack_t *restrict stack, stack_t *restrict old); + +#include <pthread.h> + +/* Send SIGNO to the process PID. */ +int kill(pid_t pid, int signo); + +/* Send SIGNO to the process group PG. */ +int killpg(pid_t pg, int signo); + +/* Send SIGNO to thread TID. */ +int pthread_kill(pthread_t tid, int signo); + +/* Send a signal to thread TID using SIGINFO. */ +int pthread_kill_siginfo_np (pthread_t tid, siginfo_t siginfo); + +/* Send SIGNO to the calling thread. */ +int raise(int signo); + +typedef struct sigevent +{ + /* Notification type. */ + int sigev_notify; + + /* Signal number. */ + int sigev_signo; + + /* Signal value. */ + union sigval sigev_value; + + /* Notification function. */ + void (*sigev_notify_function) (union sigval); + + /* Notification attributes. */ + pthread_attr_t *sigev_notify_attributes; +} sigevent_t; + +enum + { + SIGEV_NONE = 0, +#define SIGEV_NONE SIGEV_NONE + SIGEV_SIGNAL, +#define SIGEV_SIGNAL SIGEV_SIGNAL + SIGEV_THREAD +#define SIGEV_THREAD SIGEV_THREAD + }; + +#define SIG_HOLD + +int sighold (int); +int sigignore (int); +int siginterrupt (int, int); +int sigpause (int); +int sigqueue (pid_t, int, const union sigval); +int sigrelse (int); +void (*sigset (int, void (*)(int)))(int); +int sigsuspend (const sigset_t *); + +/* Wait for a signal. */ +int sigwait (const sigset_t *restrict set, int *restrict signo); +int sigwaitinfo (const sigset_t *restrict set, siginfo_t *restrict info); +int sigtimedwait (const sigset_t *restrict set, siginfo_t *restrict info, + const struct timespec *restrict timespec); + +#endif diff --git a/signal/sigpending.c b/signal/sigpending.c new file mode 100644 index 0000000..609b55d --- /dev/null +++ b/signal/sigpending.c @@ -0,0 +1,38 @@ +/* sigpending.c - Generic sigpending implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <sig-internal.h> +#include <pt-internal.h> + +int +sigpending (sigset_t *set) +{ + struct signal_state *ss = &_pthread_self ()->ss; + + pthread_mutex_lock (&ss->lock); + + /* There is no need to lock SIG_LOCK for process_pending since we + just read it, which is atomic. */ + *set = (ss->pending | process_pending) & ss->blocked; + + pthread_mutex_unlock (&ss->lock); + + return 0; +} diff --git a/signal/sigsuspend.c b/signal/sigsuspend.c new file mode 100644 index 0000000..73cf12a --- /dev/null +++ b/signal/sigsuspend.c @@ -0,0 +1,29 @@ +/* sigsuspend.c - Generic sigsuspend implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +int +sigsuspend (const sigset_t *set) +{ + /* XXX: Implement me. */ + errno = EOPNOTSUPP; + return -1; +} diff --git a/signal/sigtimedwait.c b/signal/sigtimedwait.c new file mode 100644 index 0000000..52cd017 --- /dev/null +++ b/signal/sigtimedwait.c @@ -0,0 +1,30 @@ +/* sigtimedwait.c - Generic sigtimedwait implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +int +sigtimedwait (const sigset_t *restrict set, siginfo_t *restrict info, + const struct timespec *restrict timeout) +{ + errno = EOPNOTSUPP; + return -1; +} + diff --git a/signal/sigwaiter.c b/signal/sigwaiter.c new file mode 100644 index 0000000..8d041ac --- /dev/null +++ b/signal/sigwaiter.c @@ -0,0 +1,91 @@ +/* sigwaiter.c - Signal handling functions. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +#include <hurd/futex.h> + +struct sigwaiter *sigwaiters; + +siginfo_t +sigwaiter_block (struct signal_state *ss, const sigset_t *restrict set) +{ + assert (pthread_mutex_trylock (&sig_lock) == EBUSY); + assert (pthread_mutex_trylock (&ss->lock) == EBUSY); + + assert (! ss->sigwaiter); + + struct sigwaiter waiter; + + waiter.next = sigwaiters; + if (waiter.next) + { + assert (! waiter.next->prev); + waiter.next->prev = &waiter; + } + waiter.prev = 0; + sigwaiters = &waiter; + + waiter.ss = ss; + waiter.info.si_signo = 0; + waiter.signals = *set; + + ss->sigwaiter = &waiter; + + pthread_mutex_unlock (&ss->lock); + pthread_mutex_unlock (&sig_lock); + + futex_wait (&waiter.info.si_signo, 0); + +#ifndef NDEBUG + pthread_mutex_lock (&ss->lock); + ss->sigwaiter = 0; + pthread_mutex_unlock (&ss->lock); +#endif + + assert (waiter.info.si_signo); + return waiter.info; +} + +void +sigwaiter_unblock (struct sigwaiter *waiter) +{ + assert (pthread_mutex_trylock (&sig_lock) == EBUSY); + assert (pthread_mutex_trylock (&waiter->ss->lock) == EBUSY); + + struct sigwaiter *prev = waiter->prev; + struct sigwaiter *next = waiter->next; + + if (next) + next->prev = prev; + + if (prev) + prev->next = next; + else + sigwaiters = next; + + sigdelset (&process_pending, waiter->info.si_signo); + sigdelset (&waiter->ss->pending, waiter->info.si_signo); + + pthread_mutex_unlock (&waiter->ss->lock); + pthread_mutex_unlock (&sig_lock); + + futex_wake (&waiter->info.si_signo, 1); +} diff --git a/signal/sigwaitinfo.c b/signal/sigwaitinfo.c new file mode 100644 index 0000000..1b47079 --- /dev/null +++ b/signal/sigwaitinfo.c @@ -0,0 +1,74 @@ +/* sigwaitinfo.c - Generic sigwaitinfo implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <sig-internal.h> +#include <pt-internal.h> + +int +sigwaitinfo (const sigset_t *restrict set, siginfo_t *restrict info) +{ + pthread_mutex_lock (&sig_lock); + + struct signal_state *ss = &_pthread_self ()->ss; + + pthread_mutex_lock (&ss->lock); + + if ((process_pending & *set) || (ss->pending & *set)) + /* There is at least one signal pending. */ + { + bool local = true; + sigset_t extant = process_pending & *set; + if (! extant) + { + local = false; + extant = ss->pending & *set; + } + + assert (extant); + + int signo = l4_msb64 (extant); + + if (info) + { + if (local) + *info = ss->info[signo - 1]; + else + *info = process_pending_info[signo - 1]; + info->si_signo = signo; + } + + sigdelset (&process_pending, signo); + sigdelset (&ss->pending, signo); + + pthread_mutex_unlock (&ss->lock); + pthread_mutex_unlock (&sig_lock); + return 0; + } + + siginfo_t i = sigwaiter_block (ss, set); + assert (i.si_signo); + assert ((sigmask (i.si_signo) & *set)); + + if (info) + *info = i; + + return 0; +} + diff --git a/sysdeps/generic/bits/mutex-attr.h b/sysdeps/generic/bits/mutex-attr.h index 7a5c45c..9161cda 100644 --- a/sysdeps/generic/bits/mutex-attr.h +++ b/sysdeps/generic/bits/mutex-attr.h @@ -34,4 +34,7 @@ struct __pthread_mutexattr enum __pthread_mutex_type mutex_type; }; +/* Attributes for a recursive mutex. */ +extern const struct __pthread_mutexattr __pthread_recursive_mutexattr; + #endif /* bits/mutex-attr.h */ diff --git a/sysdeps/generic/bits/mutex.h b/sysdeps/generic/bits/mutex.h index 7c77a8d..f5f3fa9 100644 --- a/sysdeps/generic/bits/mutex.h +++ b/sysdeps/generic/bits/mutex.h @@ -57,6 +57,10 @@ struct __pthread_mutex # define __PTHREAD_MUTEX_INITIALIZER \ { __SPIN_LOCK_INITIALIZER, __SPIN_LOCK_INITIALIZER, 0, 0, 0, 0, 0, 0 } +# define __PTHREAD_MUTEX_RECURSIVE_INITIALIZER \ + { __SPIN_LOCK_INITIALIZER, __SPIN_LOCK_INITIALIZER, 0, 0, \ + (struct __pthread_mutexattr *) &__pthread_recursive_mutexattr, 0, 0, 0 } + # endif #endif /* Not __pthread_mutex_defined. */ diff --git a/sysdeps/generic/bits/pthreadtypes.h b/sysdeps/generic/bits/pthreadtypes.h new file mode 100644 index 0000000..e5cbfd2 --- /dev/null +++ b/sysdeps/generic/bits/pthreadtypes.h @@ -0,0 +1,29 @@ +/* + Copyright (C) 2000 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#if !defined _BITS_TYPES_H && !defined _PTHREAD_H +# error "Never include <bits/pthreadtypes.h> directly; use <sys/types.h> instead." +#endif + +#ifndef _BITS_PTHREADTYPES_H +#define _BITS_PTHREADTYPES_H 1 + +#include <pthread.h> + +#endif /* bits/pthreadtypes.h */ diff --git a/sysdeps/generic/killpg.c b/sysdeps/generic/killpg.c new file mode 100644 index 0000000..7f7ed87 --- /dev/null +++ b/sysdeps/generic/killpg.c @@ -0,0 +1,27 @@ +/* killpg.c - Generic killpg implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +int +killpg (pid_t pid, int sig) +{ + return kill (-pid, sig); +} diff --git a/sysdeps/generic/pt-kill.c b/sysdeps/generic/pt-kill.c new file mode 100644 index 0000000..0dfac34 --- /dev/null +++ b/sysdeps/generic/pt-kill.c @@ -0,0 +1,32 @@ +/* pthread-kill.c - Generic pthread-kill implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +int +pthread_kill (pthread_t tid, int signo) +{ + siginfo_t si; + memset (&si, 0, sizeof (si)); + si.si_signo = signo; + + return pthread_kill_siginfo_np (tid, si); +} + diff --git a/sysdeps/generic/pt-mutex-destroy.c b/sysdeps/generic/pt-mutex-destroy.c index 71fc692..b0ca00f 100644 --- a/sysdeps/generic/pt-mutex-destroy.c +++ b/sysdeps/generic/pt-mutex-destroy.c @@ -26,7 +26,10 @@ int _pthread_mutex_destroy (pthread_mutex_t *mutex) { - if (mutex->attr) + if (mutex->attr == &__pthread_recursive_mutexattr) + /* Static attributes. */ + ; + else free (mutex->attr); return 0; diff --git a/sysdeps/generic/pt-mutex-init.c b/sysdeps/generic/pt-mutex-init.c index 9407673..a818fe3 100644 --- a/sysdeps/generic/pt-mutex-init.c +++ b/sysdeps/generic/pt-mutex-init.c @@ -1,5 +1,5 @@ /* Initialize a mutex. Generic version. - Copyright (C) 2000, 2002, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2000, 2002, 2005, 2006, 2008 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 @@ -32,10 +32,15 @@ _pthread_mutex_init (pthread_mutex_t *mutex, if (! attr || memcmp (attr, &__pthread_default_mutexattr, sizeof (*attr) == 0)) - /* Use the default attributes. */ + /* The default attributes. */ return 0; - /* Non-default attributes. */ + if (attr == &__pthread_recursive_mutexattr) + /* Non-default but known attributes. */ + { + mutex->attr = attr; + return 0; + } mutex->attr = malloc (sizeof *attr); if (! mutex->attr) diff --git a/sysdeps/generic/pt-mutex-transfer-np.c b/sysdeps/generic/pt-mutex-transfer-np.c new file mode 100644 index 0000000..bcb809d --- /dev/null +++ b/sysdeps/generic/pt-mutex-transfer-np.c @@ -0,0 +1,54 @@ +/* Transfer ownership of a mutex. Generic version. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <pthread.h> +#include <assert.h> + +#include <pt-internal.h> + +int +__pthread_mutex_transfer_np (struct __pthread_mutex *mutex, pthread_t tid) +{ + assert (mutex->owner == _pthread_self ()); + + struct __pthread *thread = __pthread_getid (tid); + if (! thread) + return ESRCH; + + if (thread == _pthread_self ()) + return 0; + + if (mutex->attr && mutex->attr->mutex_type == PTHREAD_MUTEX_ERRORCHECK) + { + + if (mutex->owner != _pthread_self ()) + return EPERM; + + mutex->owner = thread; + } + +#ifndef NDEBUG + mutex->owner = thread; +#endif + + return 0; +} + +strong_alias (__pthread_mutex_transfer_np, pthread_mutex_transfer_np) diff --git a/sysdeps/generic/pt-mutex-trylock.c b/sysdeps/generic/pt-mutex-trylock.c index d523205..5264dc7 100644 --- a/sysdeps/generic/pt-mutex-trylock.c +++ b/sysdeps/generic/pt-mutex-trylock.c @@ -1,5 +1,5 @@ /* Try to Lock a mutex. Generic version. - Copyright (C) 2002, 2005, 2006, 2008 Free Software Foundation, Inc. + Copyright (C) 2002, 2005, 2008 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 diff --git a/sysdeps/generic/pt-mutex-unlock.c b/sysdeps/generic/pt-mutex-unlock.c index d1ef23a..d2a4257 100644 --- a/sysdeps/generic/pt-mutex-unlock.c +++ b/sysdeps/generic/pt-mutex-unlock.c @@ -1,5 +1,5 @@ /* Unlock a mutex. Generic version. - Copyright (C) 2000, 2002, 2006, 2008 Free Software Foundation, Inc. + Copyright (C) 2000, 2002, 2008 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 @@ -37,7 +37,12 @@ __pthread_mutex_unlock (pthread_mutex_t *mutex) if (_pthread_self ()) { assert (mutex->owner); - assert (mutex->owner == _pthread_self ()); + assertx (mutex->owner == _pthread_self (), + "%p(%x) != %p(%x)", + mutex->owner, + ((struct __pthread *) mutex->owner)->threadid, + _pthread_self (), + _pthread_self ()->threadid); mutex->owner = NULL; } #endif diff --git a/sysdeps/generic/pt-mutexattr.c b/sysdeps/generic/pt-mutexattr.c index 647db24..d80a7d7 100644 --- a/sysdeps/generic/pt-mutexattr.c +++ b/sysdeps/generic/pt-mutexattr.c @@ -1,5 +1,5 @@ /* Default mutex attributes. Generic version. - Copyright (C) 2000,02 Free Software Foundation, Inc. + Copyright (C) 2000, 2002, 2008 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 @@ -27,3 +27,11 @@ const struct __pthread_mutexattr __pthread_default_mutexattr = pshared: PTHREAD_PROCESS_PRIVATE, mutex_type: PTHREAD_MUTEX_DEFAULT }; + +const struct __pthread_mutexattr __pthread_recursive_mutexattr = +{ + prioceiling: 0, + protocol: PTHREAD_PRIO_NONE, + pshared: PTHREAD_PROCESS_PRIVATE, + mutex_type: PTHREAD_MUTEX_RECURSIVE +}; diff --git a/sysdeps/generic/raise.c b/sysdeps/generic/raise.c new file mode 100644 index 0000000..410f557 --- /dev/null +++ b/sysdeps/generic/raise.c @@ -0,0 +1,41 @@ +/* raise.c - Generic raise implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +int +raise (int signo) +{ + /* According to POSIX, if we implement threads (and we do), then + "the effect of the raise() function shall be equivalent to + calling: pthread_kill(pthread_self(), sig);" */ + +debug (0, ""); + int err = pthread_kill (pthread_self (), signo); +debug (0, ""); + if (err) + { + errno = err; + return -1; + } + + return 0; +} + diff --git a/sysdeps/generic/sem-timedwait.c b/sysdeps/generic/sem-timedwait.c index f904000..e34539a 100644 --- a/sysdeps/generic/sem-timedwait.c +++ b/sysdeps/generic/sem-timedwait.c @@ -1,5 +1,5 @@ /* Wait on a semaphore with a timeout. Generic version. - Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2005, 2006, 2008 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 @@ -18,7 +18,6 @@ Boston, MA 02111-1307, USA. */ #include <semaphore.h> -#include <error.h> #include <errno.h> #include <assert.h> diff --git a/sysdeps/generic/sigaddset.c b/sysdeps/generic/sigaddset.c new file mode 100644 index 0000000..14edb71 --- /dev/null +++ b/sysdeps/generic/sigaddset.c @@ -0,0 +1,35 @@ +/* sigaddset.c - Generic sigaddset implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +int +sigaddset (sigset_t *sigset, int signo) +{ + if (signo <= 0 || signo >= NSIG) + { + errno = EINVAL; + return -1; + } + + *sigset |= sigmask (signo); + return 0; +} + diff --git a/sysdeps/generic/sigdelset.c b/sysdeps/generic/sigdelset.c new file mode 100644 index 0000000..5456467 --- /dev/null +++ b/sysdeps/generic/sigdelset.c @@ -0,0 +1,35 @@ +/* sigdelset.c - Generic sigdelset implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +int +sigdelset (sigset_t *sigset, int signo) +{ + if (signo <= 0 || signo >= NSIG) + { + errno = EINVAL; + return -1; + } + + *sigset &= ~sigmask (signo); + return 0; +} + diff --git a/sysdeps/generic/sigemptyset.c b/sysdeps/generic/sigemptyset.c new file mode 100644 index 0000000..690c15b --- /dev/null +++ b/sysdeps/generic/sigemptyset.c @@ -0,0 +1,29 @@ +/* sigemptyset.c - Generic sigemptyset implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <signal.h> + +int +sigemptyset (sigset_t *sigset) +{ + *sigset = 0; + return 0; +} + diff --git a/sysdeps/generic/sigfillset.c b/sysdeps/generic/sigfillset.c new file mode 100644 index 0000000..f0ac078 --- /dev/null +++ b/sysdeps/generic/sigfillset.c @@ -0,0 +1,29 @@ +/* sigfillset.c - Generic sigfillset implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <signal.h> + +int +sigfillset (sigset_t *sigset) +{ + *sigset = (1ULL << (NSIG - 1)) - 1; + return 0; +} + diff --git a/sysdeps/generic/siginterrupt.c b/sysdeps/generic/siginterrupt.c new file mode 100644 index 0000000..0899efb --- /dev/null +++ b/sysdeps/generic/siginterrupt.c @@ -0,0 +1,36 @@ +/* siginterrupt.c - Generic siginterrupt implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +int +siginterrupt (int sig, int flag) +{ + int ret; + struct sigaction act; + + sigaction (sig, NULL, &act); + if (flag) + act.sa_flags &= ~SA_RESTART; + else + act.sa_flags |= SA_RESTART; + ret = sigaction(sig, &act, NULL); + return ret; +} diff --git a/sysdeps/generic/sigismember.c b/sysdeps/generic/sigismember.c new file mode 100644 index 0000000..b3d65c9 --- /dev/null +++ b/sysdeps/generic/sigismember.c @@ -0,0 +1,36 @@ +/* sigismember.c - Generic sigismember implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +int +sigismember (const sigset_t *sigset, int signo) +{ + if (signo <= 0 || signo >= NSIG) + { + errno = EINVAL; + return -1; + } + + if (*sigset & sigmask (signo)) + return 1; + else + return 0; +} diff --git a/sysdeps/generic/signal.c b/sysdeps/generic/signal.c new file mode 100644 index 0000000..7555d0a --- /dev/null +++ b/sysdeps/generic/signal.c @@ -0,0 +1,44 @@ +/* signal.c - Generic signal implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +void (*signal (int sig, void (*handler)(int)))(int) +{ + struct sigaction sa; + + sa.sa_handler = handler; + sa.sa_flags = SA_RESTART; + + if (sigemptyset (&sa.sa_mask) < 0 + || sigaddset (&sa.sa_mask, sig) < 0) + return SIG_ERR; + + struct sigaction osa; + if (sigaction (sig, &sa, &osa) < 0) + return SIG_ERR; + + return osa.sa_handler; +} + +void (*bsd_signal (int sig, void (*func)(int)))(int) +{ + return signal (sig, func); +} diff --git a/sysdeps/generic/sigwait.c b/sysdeps/generic/sigwait.c new file mode 100644 index 0000000..7d10bf8 --- /dev/null +++ b/sysdeps/generic/sigwait.c @@ -0,0 +1,34 @@ +/* sigwait.c - Generic sigwait implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include "sig-internal.h" + +int +sigwait (const sigset_t *restrict set, int *restrict signo) +{ + siginfo_t info; + + if (sigwaitinfo (set, &info) < 0) + return -1; + + *signo = info.si_signo; + return 0; +} + diff --git a/sysdeps/hurd/pt-setspecific.c b/sysdeps/hurd/pt-setspecific.c index 89ca4d7..d2d1157 100644 --- a/sysdeps/hurd/pt-setspecific.c +++ b/sysdeps/hurd/pt-setspecific.c @@ -1,5 +1,5 @@ /* pthread_setspecific. Generic version. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2008 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 @@ -30,7 +30,8 @@ pthread_setspecific (pthread_key_t key, const void *value) if (! self->thread_specifics) { - err = hurd_ihash_create (&self->thread_specifics, HURD_IHASH_NO_LOCP); + err = hurd_ihash_create (&self->thread_specifics, false, + HURD_IHASH_NO_LOCP); if (err) return ENOMEM; } diff --git a/sysdeps/i386/bits/atomic.h b/sysdeps/i386/bits/atomic.h deleted file mode 100644 index 0dfc1f6..0000000 --- a/sysdeps/i386/bits/atomic.h +++ /dev/null @@ -1,66 +0,0 @@ -/* Atomic operations. i386 version. - Copyright (C) 2000 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 Library General Public License as - published by the Free Software Foundation; either version 2 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef _BITS_ATOMIC_H -#define _BITS_ATOMIC_H 1 - -typedef __volatile int __atomic_t; - -static inline void -__atomic_inc (__atomic_t *__var) -{ - __asm__ __volatile ("lock; incl %0" : "=m" (*__var) : "m" (*__var)); -} - -static inline void -__atomic_dec (__atomic_t *__var) -{ - __asm__ __volatile ("lock; decl %0" : "=m" (*__var) : "m" (*__var)); -} - -static inline int -__atomic_dec_and_test (__atomic_t *__var) -{ - unsigned char __ret; - - __asm__ __volatile ("lock; decl %0; sete %1" - : "=m" (*__var), "=qm" (__ret) : "m" (*__var)); - return __ret != 0; -} - -/* We assume that an __atomicptr_t is only used for pointers to - word-aligned objects, and use the lowest bit for a simple lock. */ -typedef __volatile int * __atomicptr_t; - -/* Actually we don't implement that yet, and assume that we run on - something that has the i486 instruction set. */ -static inline int -__atomicptr_compare_and_swap (__atomicptr_t *__ptr, void *__oldval, - void * __newval) -{ - char __ret; - int __dummy; - - __asm__ __volatile ("lock; cmpxchgl %3, %1; sete %0" - : "=q" (__ret), "=m" (*__ptr), "=a" (__dummy) - : "r" (__newval), "m" (*__ptr), "a" (__oldval)); - return __ret; -} - -#endif diff --git a/sysdeps/i386/bits/memory.h b/sysdeps/ia32/bits/memory.h index 932c408..932c408 100644 --- a/sysdeps/i386/bits/memory.h +++ b/sysdeps/ia32/bits/memory.h diff --git a/sysdeps/i386/bits/spin-lock-inline.h b/sysdeps/ia32/bits/spin-lock-inline.h index 0f3ca58..0f3ca58 100644 --- a/sysdeps/i386/bits/spin-lock-inline.h +++ b/sysdeps/ia32/bits/spin-lock-inline.h diff --git a/sysdeps/i386/bits/spin-lock.h b/sysdeps/ia32/bits/spin-lock.h index 2662b6f..71af163 100644 --- a/sysdeps/i386/bits/spin-lock.h +++ b/sysdeps/ia32/bits/spin-lock.h @@ -32,7 +32,7 @@ __BEGIN_DECLS typedef __volatile int __pthread_spinlock_t; /* Initializer for a spin lock object. */ -# define __SPIN_LOCK_INITIALIZER (0) +# define __SPIN_LOCK_INITIALIZER ((__pthread_spinlock_t) 0) __END_DECLS diff --git a/sysdeps/i386/machine-sp.h b/sysdeps/ia32/machine-sp.h index cef6ab7..39a8b69 100644 --- a/sysdeps/i386/machine-sp.h +++ b/sysdeps/ia32/machine-sp.h @@ -23,7 +23,8 @@ /* Return the current stack pointer. */ #define __thread_stack_pointer() ({ \ - register void *__sp__ asm("esp"); \ + void *__sp__; \ + __asm__ ("movl %%esp, %0" : "=r" (__sp__)); \ __sp__; \ }) diff --git a/sysdeps/i386/pt-machdep.h b/sysdeps/ia32/pt-machdep.h index 6d45636..6d45636 100644 --- a/sysdeps/i386/pt-machdep.h +++ b/sysdeps/ia32/pt-machdep.h diff --git a/sysdeps/l4/bits/pthread-np.h b/sysdeps/l4/bits/pthread-np.h new file mode 100644 index 0000000..6a02bdc --- /dev/null +++ b/sysdeps/l4/bits/pthread-np.h @@ -0,0 +1,35 @@ +/* Non-portable functions. L4 version. + Copyright (C) 2003, 2007 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* + * Never include this file directly; use <pthread.h> or <cthreads.h> instead. + */ + +#ifndef _BITS_PTHREAD_NP_H +#define _BITS_PTHREAD_NP_H 1 + +#include <l4.h> + +/* Add the thread TID to the internal kernel thread pool. */ +extern int pthread_pool_add_np (l4_thread_id_t tid); + +/* Get the first thread from the pool. */ +extern l4_thread_id_t pthread_pool_get_np (void); + +#endif /* bits/pthread-np.h */ diff --git a/sysdeps/l4/hurd/bits/pthread-np.h b/sysdeps/l4/hurd/bits/pthread-np.h new file mode 100644 index 0000000..a90793d --- /dev/null +++ b/sysdeps/l4/hurd/bits/pthread-np.h @@ -0,0 +1,31 @@ +/* Non-portable functions. Viengoos version. + Copyright (C) 2008 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* + * Never include this file directly; use <pthread.h> or <cthreads.h> instead. + */ + +#ifndef _BITS_PTHREAD_NP_H +#define _BITS_PTHREAD_NP_H 1 + +#include <hurd/addr.h> + +int pthread_setactivity_np (addr_t activity); + +#endif /* bits/pthread-np.h */ diff --git a/sysdeps/l4/hurd/ia32/pt-machdep.c b/sysdeps/l4/hurd/ia32/pt-machdep.c new file mode 100644 index 0000000..dbf5cd7 --- /dev/null +++ b/sysdeps/l4/hurd/ia32/pt-machdep.c @@ -0,0 +1,20 @@ +/* Machine dependent pthreads code. Hurd/i386 version. + Copyright (C) 2000 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* Nothing to do. */ diff --git a/sysdeps/l4/hurd/ia32/pt-setup.c b/sysdeps/l4/hurd/ia32/pt-setup.c new file mode 100644 index 0000000..579905c --- /dev/null +++ b/sysdeps/l4/hurd/ia32/pt-setup.c @@ -0,0 +1,117 @@ +/* Setup thread stack. Viengoos/i386 version. + Copyright (C) 2000, 2002, 2008 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <l4.h> + +#include <pt-internal.h> +#include <hurd/thread.h> +#include <hurd/exceptions.h> + +/* The stack layout used on the i386 is: + + ----------------- + | ARG | + ----------------- + | START_ROUTINE | + ----------------- + | Return address | + ----------------- <- %ebp + | Frame pointer | + ----------------- + + We do the following: setup the stack to return to the entry routine. + + +*/ + +/* The stack contains: + + arg + start_routine + 0 <- fake return address + C entry_point +*/ +extern uintptr_t _pthread_entry_point; +__asm__ ("\n\ + .globl _pthread_entry_point, __pthread_entry_point\n\ +_pthread_entry_point:\n\ +__pthread_entry_point:\n\ + pushl $0\n\ + popf\n\ +\n\ + xor %ebp, %ebp\n\ + ret\n"); + +/* Set up the stack for THREAD, such that it appears as if + START_ROUTINE and ARG were passed to the new thread's entry-point. + Return the stack pointer for the new thread. We also take the + opportunity to install THREAD in our utcb. */ +static void * +stack_setup (struct __pthread *thread, + void *(*start_routine)(void *), void *arg, + void (*entry_point)(void *(*)(void *), void *)) +{ + uintptr_t *top; + + /* Calculate top of the new stack. */ + top = (uintptr_t *) ((uintptr_t) thread->stackaddr + thread->stacksize); + + /* Align on 0x10 for MMX operations. */ + top = (uintptr_t) top & ~0xf; + + if (start_routine) + { + /* Set up call frame. */ + *--top = (uintptr_t) arg; /* Argument to START_ROUTINE. */ + *--top = (uintptr_t) start_routine; + *--top = 0; /* Fake return address. */ + *--top = (uintptr_t) entry_point; + } + + return top; +} + +int +__pthread_setup (struct __pthread *thread, + void (*entry_point)(void *(*)(void *), void *), + void *(*start_routine)(void *), void *arg) +{ + thread->mcontext.pc = (void *) &_pthread_entry_point; + thread->mcontext.sp = (void *) stack_setup (thread, start_routine, arg, + entry_point); + + if (__pthread_num_threads == 1) + return 0; + + assert (! ADDR_IS_VOID (thread->exception_area[0])); + + struct exception_page *exception_page = thread->exception_area_va; + + /* SP is set to the end of the exception area minus one word, which + is the location of the exception page. */ + exception_page->exception_handler_sp + = (uintptr_t) thread->exception_area_va + EXCEPTION_AREA_SIZE; + exception_page->exception_handler_sp -= sizeof (void *); + * (void **) exception_page->exception_handler_sp = thread->exception_area_va; + + exception_page->exception_handler_ip = (uintptr_t) &exception_handler_entry; + exception_page->exception_handler_end = (uintptr_t) &exception_handler_end; + + return 0; +} diff --git a/sysdeps/l4/hurd/ia32/signal-dispatch-lowlevel.c b/sysdeps/l4/hurd/ia32/signal-dispatch-lowlevel.c new file mode 100644 index 0000000..37ef821 --- /dev/null +++ b/sysdeps/l4/hurd/ia32/signal-dispatch-lowlevel.c @@ -0,0 +1,213 @@ +/* signal-dispatch-lowlevel.c - ia32 specific signal handling functions. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <pt-internal.h> +#include <sig-internal.h> + +#include <hurd/thread.h> +#include <pthread.h> +#include <stdint.h> +#include <atomic.h> + +extern char _signal_dispatch_entry; +/* - 0(%esp) a pointer to the thread's struct signal_state. + - 4(%esp) a pointer to a siginfo_t. + - 8(%esp) is a pointer to the ss_flags field (or NULL). + - 12(%esp)+4 is the value of the sp when the thread was interrupted (intr_sp) + - 0(intr_sp) is the value of the ip when the thread was interrupted. + - 16(%esp) - 16 byte register save area +*/ +__asm__ ("\n\ + .globl _signal_dispatch_entry\n\ +_signal_dispatch_entry:\n\ + /* Save caller saved registers (16 bytes). */\n\ + mov %eax, 16(%esp)\n\ + mov %ecx, 16+4(%esp)\n\ + mov %edx, 16+8(%esp)\n\ + pushf\n\ + popl %eax\n\ + mov %eax, 16+12(%esp)\n\ +\n\ + /* Reset EFLAGS. */\n\ + cld\n\ + call signal_dispatch\n\ +\n\ + /* Get the original stack and begin restoration. */\n\ + mov 12(%esp), %edx\n\ +\n\ + /* Move the saved registers to the user stack. */\n\ + sub $16, %edx\n\ + /* eax. */\n\ + mov 16+0(%esp), %ecx\n\ + mov %ecx, 0(%edx)\n\ + /* ecx. */\n\ + mov 16+4(%esp), %ecx\n\ + mov %ecx, 4(%edx)\n\ + /* edx. */\n\ + mov 16+8(%esp), %ecx\n\ + mov %ecx, 8(%edx)\n\ + /* eflags. */\n\ + mov 16+12(%esp), %ecx\n\ + mov %ecx, 12(%edx)\n\ +\n\ + /* Get the pointer to the sigaltstack flags. */\n\ + mov 8(%esp), %ecx\n\ +\n\ + /* Restore the user stack. */\n\ + mov %edx, %esp\n\ +\n\ + /* Clear the SA_ONSTACK flag. */\n\ + and %ecx, %ecx\n\ + jz after_clear\n\ + lock; and $~1, 0(%ecx)\n\ +after_clear:\n\ +\n\ + /* Restore eflags, the scratch regs and the original sp and ip. */\n\ + popl %eax\n\ + popl %ecx\n\ + popl %edx\n\ + popf\n\ + ret\n"); + +extern char _signal_dispatch_entry_self; +/* - 0(%esp) is the return address (we ignore it) + - 4(%esp) is the sp to load + + Since we are returning to signal_dispatch_lowlevel's caller, we + also need to restore its frame pointer. */ +__asm__ ("\n\ + .globl _signal_dispatch_entry_self\n\ +_signal_dispatch_entry_self:\n\ + mov 0(%ebp), %ebp\n\ + mov 4(%esp), %esp\n\ + jmp _signal_dispatch_entry\n"); + +void +signal_dispatch_lowlevel (struct signal_state *ss, pthread_t tid, + siginfo_t si) +{ + assert (pthread_mutex_trylock (&ss->lock) == EBUSY); + + struct __pthread *thread = __pthread_getid (tid); + + bool self = tid == pthread_self (); + + uintptr_t intr_sp; + + if (self) + { + /* The return address is just before the first argument. */ + intr_sp = (uintptr_t) &ss - 4; + assert (* (void **) intr_sp == __builtin_return_address (0)); + } + else + { + struct hurd_thread_exregs_in in; + memset (&in, 0, sizeof (in)); + struct hurd_thread_exregs_out out; + + error_t err; + err = rm_thread_exregs (ADDR_VOID, thread->object, + HURD_EXREGS_STOP | HURD_EXREGS_ABORT_IPC + | HURD_EXREGS_GET_REGS, + in, &out); + if (err) + panic ("Failed to modify thread " ADDR_FMT, + ADDR_PRINTF (thread->object)); + + intr_sp = out.sp; + + /* Push the ip on the user stack. */ + intr_sp -= 4; + * (uintptr_t *) intr_sp = out.ip; + } + + bool altstack = false; + uintptr_t sp; + if (! (ss->actions[si.si_signo - 1].sa_flags & SA_ONSTACK) + || (ss->stack.ss_flags & SS_DISABLE) + || (ss->stack.ss_flags & SS_ONSTACK)) + { + assert (! self); + sp = intr_sp; + } + else + { + /* The stack grows down. */ + sp = (uintptr_t) ss->stack.ss_sp + ss->stack.ss_size; + + /* We know intimately that SS_ONSTACK is the least significant + bit. */ + assert (SS_ONSTACK == 1); + atomic_bit_set (&ss->stack.ss_flags, 0); + + altstack = true; + } + + /* Set up the call frame for a call to signal_dispatch_entry. */ + + /* Allocate a siginfo structure on the stack. */ + sp = sp - sizeof (siginfo_t); + siginfo_t *sip = (void *) sp; + /* Copy the user supplied values. */ + *sip = si; + + /* Add space for the 4 caller saved registers. */ + sp -= 4 * sizeof (uintptr_t); + + /* Save the interrupted sp. */ + sp -= 4; + * (uintptr_t *) sp = intr_sp; + + /* Address of the ss_flags. */ + sp -= 4; + if (altstack) + * (uintptr_t *) sp = (uintptr_t) &ss->stack.ss_flags; + else + * (uintptr_t *) sp = 0; + + /* Push the parameters to signal_dispatch. */ + + /* signal info structure. */ + sp -= 4; + * (uintptr_t *) sp = (uintptr_t) sip; + + /* The ss. */ + sp -= 4; + * (uintptr_t *) sp = (uintptr_t) ss; + + pthread_mutex_transfer_np (&ss->lock, tid); + + if (self) + ((void (*) (uintptr_t)) &_signal_dispatch_entry_self) ((uintptr_t) sp); + else + { + struct hurd_thread_exregs_in in; + struct hurd_thread_exregs_out out; + + in.sp = sp; + in.ip = (uintptr_t) &_signal_dispatch_entry; + + rm_thread_exregs (ADDR_VOID, thread->object, + HURD_EXREGS_SET_SP_IP + | HURD_EXREGS_START | HURD_EXREGS_ABORT_IPC, + in, &out); + } +} diff --git a/sysdeps/l4/hurd/powerpc/pt-machdep.c b/sysdeps/l4/hurd/powerpc/pt-machdep.c new file mode 100644 index 0000000..754d203 --- /dev/null +++ b/sysdeps/l4/hurd/powerpc/pt-machdep.c @@ -0,0 +1,20 @@ +/* Machine dependent pthreads code. Hurd/PowerPC version. + Copyright (C) 2003 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* Nothing to do. */ diff --git a/sysdeps/l4/hurd/powerpc/pt-setup.c b/sysdeps/l4/hurd/powerpc/pt-setup.c new file mode 100644 index 0000000..d3cf4ec --- /dev/null +++ b/sysdeps/l4/hurd/powerpc/pt-setup.c @@ -0,0 +1,93 @@ +/* Setup thread stack. Hurd/PowerPC version. + Copyright (C) 2003 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <l4.h> + +#include <pt-internal.h> + +/* Arguments is passed in registers on the PowerPC. But the + exchange registers syscall only allows us to set the PC and the + stack pointer so we put the entry point and start function on + the stack. */ +struct start_info +{ + void (*entry_point) (void *(*)(void *), void *); + void *(*start_routine) (void *); + void *arg; +}; + +void first_entry_1 (void); + +/* Stage 1 entry function. The start_info structure is inlined on the + stack. Put values into registers and call entry function. */ +asm (" ;\ +first_entry_1: ;\ + lwz 0, 0(1) ;\ + lwz 3, 4(1) ;\ + lwz 4, 8(1) ;\ + mtctr 0 ;\ + bctrl ;\ +"); + +/* Set up the stack for THREAD, such that it appears as if + START_ROUTINE and ARG were passed to the new thread's entry-point. + Return the stack pointer for the new thread. We also take the + opportunity to install THREAD in our utcb. */ +static void * +stack_setup (struct __pthread *thread, + void (*entry_point)(void *(*)(void *), void *), + void *(*start_routine)(void *), void *arg) +{ + l4_word_t *top; + + /* Calculate top of the new stack. */ + top = (l4_word_t *) ((l4_word_t) thread->stackaddr + thread->stacksize); + + /* Initial stack frame. */ + top[-4] = 0; + top = top - 4; + + if (start_routine) + { + struct start_info *info = ((struct start_info *) top) - 1; + + info->entry_point = entry_point; + info->start_routine = start_routine; + info->arg = arg; + return (void *) info; + } + return top; +} + +int +__pthread_setup (struct __pthread *thread, + void (*entry_point)(void *(*)(void *), void *), + void *(*start_routine)(void *), void *arg) +{ + thread->mcontext.pc = first_entry_1; + thread->mcontext.sp = stack_setup (thread, entry_point, + start_routine, arg); + + if (l4_same_threads (thread->threadid, l4_myself ())) + l4_set_user_defined_handle ((l4_word_t) thread); + else + l4_set_user_defined_handle_of (thread->threadid, + (l4_word_t) thread); + return 0; +} diff --git a/sysdeps/l4/hurd/pt-block.c b/sysdeps/l4/hurd/pt-block.c new file mode 100644 index 0000000..2315b1c --- /dev/null +++ b/sysdeps/l4/hurd/pt-block.c @@ -0,0 +1,30 @@ +/* Block a thread. Viengoos version. + Copyright (C) 2008 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <pt-internal.h> + +#include <hurd/stddef.h> +#include <hurd/futex.h> + +/* Block THREAD. */ +void +__pthread_block (struct __pthread *thread) +{ + futex_wait (&thread->threadid, thread->threadid); +} diff --git a/sysdeps/l4/hurd/pt-kill.c b/sysdeps/l4/hurd/pt-kill.c new file mode 100644 index 0000000..c72e82f --- /dev/null +++ b/sysdeps/l4/hurd/pt-kill.c @@ -0,0 +1,3 @@ +/* The generic version is good enough for us, however, the generic + Hurd on Mach version supplies a specialized version */ +#include "../generic/pt-kill.c" diff --git a/sysdeps/l4/hurd/pt-setactivity-np.c b/sysdeps/l4/hurd/pt-setactivity-np.c new file mode 100644 index 0000000..f2f0723 --- /dev/null +++ b/sysdeps/l4/hurd/pt-setactivity-np.c @@ -0,0 +1,39 @@ +/* Set a thread's activity activity. Viengoos version. + Copyright (C) 2008 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <pt-internal.h> + +#include <hurd/addr.h> +#include <hurd/thread.h> + +int +pthread_setactivity_np (addr_t activity) +{ + struct __pthread *self = _pthread_self (); + + struct hurd_thread_exregs_in in; + in.activity = activity; + + struct hurd_thread_exregs_out out; + int err = rm_thread_exregs (ADDR_VOID, self->object, + HURD_EXREGS_SET_ACTIVITY, + in, &out); + + return err; +} diff --git a/sysdeps/l4/hurd/pt-sigstate-destroy.c b/sysdeps/l4/hurd/pt-sigstate-destroy.c new file mode 100644 index 0000000..997a036 --- /dev/null +++ b/sysdeps/l4/hurd/pt-sigstate-destroy.c @@ -0,0 +1,28 @@ +/* Destroy the signal state. Hurd on L4 version. + Copyright (C) 2002 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <pthread.h> + +#include <pt-internal.h> + +void +__pthread_sigstate_destroy (struct __pthread *thread) +{ + /* Nothing to do. */ +} diff --git a/sysdeps/l4/hurd/pt-sigstate-init.c b/sysdeps/l4/hurd/pt-sigstate-init.c new file mode 100644 index 0000000..4c40fdb --- /dev/null +++ b/sysdeps/l4/hurd/pt-sigstate-init.c @@ -0,0 +1,44 @@ +/* Initialize the signal state. Hurd on L4 version. + Copyright (C) 2003, 2008 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <pthread.h> + +#include <pt-internal.h> +#include <sig-internal.h> + +error_t +__pthread_sigstate_init (struct __pthread *thread) +{ + struct signal_state *ss = &thread->ss; + + memset (ss, 0, sizeof (*ss)); + + ss->stack.ss_flags = SS_DISABLE; + + int signo; + for (signo = 1; signo < NSIG; ++signo) + { + sigemptyset (&ss->actions[signo - 1].sa_mask); + ss->actions[signo - 1].sa_flags = SA_RESTART; + ss->actions[signo - 1].sa_handler = SIG_DFL; + ss->lock = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER; + } + + return 0; +} diff --git a/sysdeps/l4/hurd/pt-sigstate.c b/sysdeps/l4/hurd/pt-sigstate.c new file mode 100644 index 0000000..66dd08c --- /dev/null +++ b/sysdeps/l4/hurd/pt-sigstate.c @@ -0,0 +1,81 @@ +/* Set a thread's signal state. Hurd on L4 version. + Copyright (C) 2002, 2005, 2008 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <pthread.h> +#include <assert.h> +#include <signal.h> + +#include <pt-internal.h> + +error_t +__pthread_sigstate (struct __pthread *thread, int how, + const sigset_t *set, sigset_t *oset, + int clear_pending) +{ + struct signal_state *ss = &thread->ss; + pthread_mutex_lock (&ss->lock); + + if (oset) + *oset = ss->blocked; + + if (set) + { + /* Mask out SIGKILL and SIGSTOP. */ + sigset_t s = *set; + sigdelset (&s, SIGKILL); + sigdelset (&s, SIGSTOP); + + switch (how) + { + case SIG_BLOCK: + ss->blocked |= s; + break; + case SIG_UNBLOCK: + ss->blocked &= ~s; + break; + case SIG_SETMASK: + ss->blocked = s; + break; + default: + errno = EINVAL; + pthread_mutex_unlock (&ss->lock); + return -1; + } + } + + if (clear_pending) + sigemptyset (&ss->pending); + + /* A "signal shall remain pending until it is unblocked" (2.4.1). + + "If there are any pending unblocked signals after the call to + sigprocmask(), at least one of those signals shall be delivered + before the call to sigprocmask() returns." + (pthread_sigmask). */ + sigset_t extant = ~ss->blocked & ss->pending; + if (! extant) + extant = ~ss->blocked & process_pending; + + pthread_mutex_unlock (&ss->lock); + + if (extant) + raise (l4_lsb64 (extant)); + + return 0; +} diff --git a/sysdeps/l4/hurd/pt-startup.c b/sysdeps/l4/hurd/pt-startup.c new file mode 100644 index 0000000..b6461de --- /dev/null +++ b/sysdeps/l4/hurd/pt-startup.c @@ -0,0 +1,30 @@ +/* Thread initialization. Hurd/L4 version. + Copyright (C) 2007 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <l4.h> +#include <pt-internal.h> + +#include <hurd/exceptions.h> + +void +__pthread_startup (void) +{ + struct __pthread *pthread = _pthread_self (); + pthread->threadid = l4_myself (); +} diff --git a/sysdeps/l4/hurd/pt-sysdep.c b/sysdeps/l4/hurd/pt-sysdep.c new file mode 100644 index 0000000..c23364c --- /dev/null +++ b/sysdeps/l4/hurd/pt-sysdep.c @@ -0,0 +1,61 @@ +/* System dependent pthreads code. Hurd version. + Copyright (C) 2000, 2008 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <assert.h> +#include <stddef.h> +#include <stdint.h> + +#include <pt-internal.h> + +int +sched_yield (void) +{ + l4_yield (); + return 0; +} + +/* Forward. */ +static void init_routine (void (*) (void *), void *) + __attribute__ ((noreturn)); + +/* OK, the name of this variable isn't really appropriate, but I don't + want to change it yet. */ +void (*_pthread_init_routine)(void (*) (void *), void *) = &init_routine; + +/* This function is called from the Hurd-specific startup code. It + should return a new stack pointer for the main thread. The caller + will switch to this new stack before doing anything serious. */ +static void +init_routine (void (*entry) (void *), void *arg) +{ + /* Initialize the library. */ + __pthread_initialize (); + + struct __pthread *thread; + int err; + + /* Create the pthread structure for the main thread (i.e. us). */ + err = __pthread_create_internal (&thread, 0, + (void *(*)(void *)) entry, arg); + assert_perror (err); + + /* Switch stacks. */ + l4_start_sp_ip (l4_myself (), thread->mcontext.sp, + thread->mcontext.pc); +} diff --git a/sysdeps/l4/hurd/pt-sysdep.h b/sysdeps/l4/hurd/pt-sysdep.h new file mode 100644 index 0000000..08bcd14 --- /dev/null +++ b/sysdeps/l4/hurd/pt-sysdep.h @@ -0,0 +1,61 @@ +/* Internal definitions for pthreads library. + Copyright (C) 2000, 2002, 2005, 2007, 2008 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _PT_SYSDEP_H +#define _PT_SYSDEP_H 1 + +#include <l4.h> +#include <hurd/storage.h> +#include <sys/mman.h> + +/* XXX */ +#define _POSIX_THREAD_THREADS_MAX 64 + +/* The default stack size: 2MB. */ +#define PTHREAD_STACK_DEFAULT (2 * 1024 * 1024) + +#include <hurd/exceptions.h> + +#define EXCEPTION_AREA_SIZE EXCEPTION_STACK_SIZE +#define EXCEPTION_AREA_SIZE_LOG2 EXCEPTION_STACK_SIZE_LOG2 +/* The exception page is the first object. */ +#define EXCEPTION_PAGE 0 + +#define PTHREAD_SYSDEP_MEMBERS \ + addr_t object; \ + l4_thread_id_t threadid; \ + addr_t exception_area[EXCEPTION_AREA_SIZE / PAGESIZE]; \ + void *exception_area_va; \ + l4_word_t my_errno; + +extern inline struct __pthread * +__attribute__((__always_inline__)) +_pthread_self (void) +{ + return (struct __pthread *) l4_user_defined_handle (); +} + +extern inline void +__attribute__((__always_inline__)) +__pthread_stack_dealloc (void *stackaddr, size_t stacksize) +{ + munmap (stackaddr, stacksize); +} + +#endif /* pt-sysdep.h */ diff --git a/sysdeps/l4/hurd/pt-thread-alloc.c b/sysdeps/l4/hurd/pt-thread-alloc.c new file mode 100644 index 0000000..ada7b3b --- /dev/null +++ b/sysdeps/l4/hurd/pt-thread-alloc.c @@ -0,0 +1,95 @@ +/* Allocate kernel thread. Viengoos version. + Copyright (C) 2007, 2008 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <assert.h> +#include <errno.h> +#include <string.h> + +#include <hurd/startup.h> +#include <hurd/storage.h> +#include <hurd/as.h> +#include <hurd/addr.h> + +#include <pt-internal.h> + +extern struct hurd_startup_data *__hurd_startup_data; + +extern addr_t meta_data_activity; + +int +__pthread_thread_alloc (struct __pthread *thread) +{ + /* The main thread is already running of course. */ + if (__pthread_num_threads == 1) + { + thread->object = __hurd_startup_data->thread; + thread->threadid = l4_myself (); + return 0; + } + else + { + addr_t exception_area = as_alloc (EXCEPTION_AREA_SIZE_LOG2, 1, true); + + thread->exception_area_va + = ADDR_TO_PTR (addr_extend (exception_area, + 0, EXCEPTION_AREA_SIZE_LOG2)); + + int i; + for (i = 0; i < EXCEPTION_AREA_SIZE / PAGESIZE; i ++) + { + addr_t slot = addr_chop (PTR_TO_ADDR (thread->exception_area_va + + i * PAGESIZE), + PAGESIZE_LOG2); + as_ensure (slot); + + struct storage storage = storage_alloc (ADDR_VOID, cap_page, + STORAGE_LONG_LIVED, + OBJECT_POLICY_DEFAULT, + slot); + if (ADDR_IS_VOID (storage.addr)) + { + int j; + for (j = 0; j < i; j ++) + storage_free (thread->exception_area[j], false); + as_free (exception_area, false); + return EAGAIN; + } + + thread->exception_area[i] = storage.addr; + } + + struct storage storage; + storage = storage_alloc (meta_data_activity, cap_thread, + /* Threads are rarely shortly lived. */ + STORAGE_MEDIUM_LIVED, OBJECT_POLICY_DEFAULT, + ADDR_VOID); + if (ADDR_IS_VOID (storage.addr)) + { + int j; + for (j = 0; j < EXCEPTION_AREA_SIZE / PAGESIZE; j ++) + storage_free (thread->exception_area[j], false); + as_free (exception_area, false); + return EAGAIN; + } + + thread->object = storage.addr; + } + + return 0; +} diff --git a/sysdeps/l4/hurd/pt-thread-halt.c b/sysdeps/l4/hurd/pt-thread-halt.c new file mode 100644 index 0000000..98fefaa --- /dev/null +++ b/sysdeps/l4/hurd/pt-thread-halt.c @@ -0,0 +1,104 @@ +/* Deallocate the kernel thread resources. Viengoos version. + Copyright (C) 2007, 2008 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <assert.h> +#include <errno.h> + +#include <pt-internal.h> + +#include <hurd/exceptions.h> +#include <hurd/mutex.h> +#include <hurd/as.h> +#include <hurd/addr.h> + +/* If we try to deallocate our self, we will end up causing a + deadlock. Thus, when a thread tries to free itself, we add it + here. The next thread to free a thread will free it. */ +ss_mutex_t saved_object_lock; +static addr_t saved_object; + +void +__pthread_thread_halt (struct __pthread *thread, int need_dealloc) +{ + /* We may deallocate THREAD. First save any data we need. */ + + addr_t exception_area[EXCEPTION_AREA_SIZE / PAGESIZE]; + memcpy (exception_area, thread->exception_area, + sizeof (thread->exception_area)); + memset (thread->exception_area, 0, sizeof (thread->exception_area)); + + void *va = thread->exception_area_va; + + addr_t object = thread->object; + l4_thread_id_t tid = thread->threadid; + + if (need_dealloc) + __pthread_dealloc (thread); + + /* The THREAD data structure is no longer valid. */ + thread = NULL; + + /* Deallocate any saved object. */ + ss_mutex_lock (&saved_object_lock); + if (! ADDR_IS_VOID (saved_object)) + { + storage_free (saved_object, false); + saved_object = ADDR_VOID; + } + ss_mutex_unlock (&saved_object_lock); + + /* Free the exception area. */ + + /* Clean up the exception page. */ + exception_page_cleanup + (ADDR_TO_PTR (addr_extend (exception_area[EXCEPTION_PAGE], + 0, PAGESIZE_LOG2))); + + /* Free the storage. */ + int i; + for (i = 0; i < EXCEPTION_AREA_SIZE / PAGESIZE; i ++) + { + assert (! ADDR_IS_VOID (exception_area[i])); + storage_free (exception_area[i], false); + } + + /* And the address space. */ + as_free (addr_chop (PTR_TO_ADDR (va), EXCEPTION_AREA_SIZE_LOG2), false); + + if (tid == l4_myself ()) + /* If we try to storage_free (storage.addr), we will freeze in the + middle. That's no good. We set SAVED_OBJECT to our thread + object and the next thread in will free us. */ + { + ss_mutex_lock (&saved_object_lock); + saved_object = object; + ss_mutex_unlock (&saved_object_lock); + } + else + storage_free (object, false); + + if (tid == l4_myself ()) + { + l4_send_timeout (l4_myself (), L4_NEVER); + panic ("Failed to stop thread %x.%x!", + l4_thread_no (l4_myself ()), l4_version (l4_myself ())); + } + else + thread_stop (object); +} diff --git a/sysdeps/l4/hurd/pt-thread-start.c b/sysdeps/l4/hurd/pt-thread-start.c new file mode 100644 index 0000000..9db399c --- /dev/null +++ b/sysdeps/l4/hurd/pt-thread-start.c @@ -0,0 +1,70 @@ +/* Start thread. L4 version. + Copyright (C) 2007 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <assert.h> +#include <errno.h> +#include <string.h> +#include <hurd/thread.h> +#include <hurd/exceptions.h> + +#include <pt-internal.h> + +int +__pthread_thread_start (struct __pthread *thread) +{ + error_t err; + + if (__pthread_num_threads == 1) + /* The main thread is already running of course. */ + { + assert (__pthread_total == 1); + assert (l4_is_thread_equal (l4_myself (), thread->threadid)); + l4_set_user_defined_handle ((l4_word_t) thread); + } + else + { + struct hurd_thread_exregs_in in; + struct hurd_thread_exregs_out out; + + in.aspace = ADDR (0, 0); + in.aspace_cap_properties = CAP_PROPERTIES_VOID; + in.aspace_cap_properties_flags = CAP_COPY_COPY_SOURCE_GUARD; + + in.activity = ADDR_VOID; + + in.exception_page = addr_chop (PTR_TO_ADDR (thread->exception_area_va), + PAGESIZE_LOG2); + + in.sp = (l4_word_t) thread->mcontext.sp; + in.ip = (l4_word_t) thread->mcontext.pc; + + in.user_handle = (l4_word_t) thread; + err = rm_thread_exregs (ADDR_VOID, thread->object, + HURD_EXREGS_SET_ASPACE + | HURD_EXREGS_SET_ACTIVITY + | HURD_EXREGS_SET_EXCEPTION_PAGE + | HURD_EXREGS_SET_SP_IP + | HURD_EXREGS_SET_USER_HANDLE + | HURD_EXREGS_START + | HURD_EXREGS_ABORT_IPC, + in, &out); + assert (err == 0); + } + return 0; +} diff --git a/sysdeps/l4/hurd/pt-wakeup.c b/sysdeps/l4/hurd/pt-wakeup.c new file mode 100644 index 0000000..e568a6f --- /dev/null +++ b/sysdeps/l4/hurd/pt-wakeup.c @@ -0,0 +1,46 @@ +/* Wakeup a thread. Viengoos version. + Copyright (C) 2008 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <pt-internal.h> + +#include <hurd/stddef.h> +#include <hurd/futex.h> +#include <stdint.h> + +/* Wakeup THREAD. */ +void +__pthread_wakeup (struct __pthread *thread) +{ + /* We need to loop here as the blocked thread may not yet be + blocked! Here's what happens when a thread blocks: it registers + itself as blocked, drops the relevant lock and then actually + blocks (via __pthread_block). This means that after dropping the + lock and before blocking, it may be interrupted and another + thread may try to wake it. */ + long ret; + do + { + ret = futex_wake (&thread->threadid, INT_MAX); + assertx (ret <= 1, "tid: %x, ret: %d", thread->threadid, ret); + + if (ret == 0) + l4_thread_switch (thread->threadid); + } + while (ret == 0); +} diff --git a/sysdeps/l4/hurd/sig-sysdep.h b/sysdeps/l4/hurd/sig-sysdep.h new file mode 100644 index 0000000..33e1385 --- /dev/null +++ b/sysdeps/l4/hurd/sig-sysdep.h @@ -0,0 +1,69 @@ +/* sig-sysdep.h - Hurd system specific header file. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <l4.h> +#include <string.h> + +struct utcb +{ + l4_word_t saved_sender; + l4_word_t saved_receiver; + l4_word_t saved_timeout; + l4_word_t saved_error_code; + l4_word_t saved_flags; + l4_word_t saved_br0; + l4_msg_t saved_message; +}; + +static inline void +utcb_state_save (struct utcb *buffer) +{ + l4_word_t *utcb = _L4_utcb (); + + buffer->saved_sender = utcb[_L4_UTCB_SENDER]; + buffer->saved_receiver = utcb[_L4_UTCB_RECEIVER]; + buffer->saved_timeout = utcb[_L4_UTCB_TIMEOUT]; + buffer->saved_error_code = utcb[_L4_UTCB_ERROR_CODE]; + buffer->saved_flags = utcb[_L4_UTCB_FLAGS]; + buffer->saved_br0 = utcb[_L4_UTCB_BR0]; + memcpy (&buffer->saved_message, + utcb, L4_NUM_MRS * sizeof (l4_word_t)); +} + +static inline void +utcb_state_restore (struct utcb *buffer) +{ + l4_word_t *utcb = _L4_utcb (); + + utcb[_L4_UTCB_SENDER] = buffer->saved_sender; + utcb[_L4_UTCB_RECEIVER] = buffer->saved_receiver; + utcb[_L4_UTCB_TIMEOUT] = buffer->saved_timeout; + utcb[_L4_UTCB_ERROR_CODE] = buffer->saved_error_code; + utcb[_L4_UTCB_FLAGS] = buffer->saved_flags; + utcb[_L4_UTCB_BR0] = buffer->saved_br0; + memcpy (utcb, &buffer->saved_message, + L4_NUM_MRS * sizeof (l4_word_t)); +} + +#define SIGNAL_DISPATCH_ENTRY \ + struct utcb buffer; utcb_state_save (&buffer); + +#define SIGNAL_DISPATCH_EXIT \ + utcb_state_restore (&buffer); diff --git a/sysdeps/l4/hurd/sigprocmask.c b/sysdeps/l4/hurd/sigprocmask.c new file mode 100644 index 0000000..a38b379 --- /dev/null +++ b/sysdeps/l4/hurd/sigprocmask.c @@ -0,0 +1,41 @@ +/* sigprocmask.c - Generic sigprocmask implementation. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Neal H. Walfield <neal@gnu.org>. + + This file is part of the GNU Hurd. + + The GNU Hurd 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 3 of + the License, or (at your option) any later version. + + The GNU Hurd 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 this program. If not, see + <http://www.gnu.org/licenses/>. */ + +#include <pt-internal.h> +#include <sig-internal.h> + +int +sigprocmask (int how, const sigset_t *restrict set, sigset_t *restrict old) +{ + struct __pthread *thread = _pthread_self (); + if (! thread) + /* Library is initializing. */ + { + assert (__pthread_num_threads == 1); + + /* We should get the default mask from the startup data structure. */ + if (old) + *old = 0; + + return 0; + } + + return pthread_sigmask (how, set, old); +} diff --git a/sysdeps/l4/pt-block.c b/sysdeps/l4/pt-block.c new file mode 100644 index 0000000..69e1d35 --- /dev/null +++ b/sysdeps/l4/pt-block.c @@ -0,0 +1,47 @@ +/* Block a thread. L4 version. + Copyright (C) 2002 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <l4.h> + +#include <pt-internal.h> + +#include <hurd/stddef.h> + +/* Block THREAD. */ +void +__pthread_block (struct __pthread *thread) +{ + debug (5, "%x.%x/%x blocking", + l4_thread_no (thread->threadid), l4_version (thread->threadid), + thread->threadid); + + l4_accept (L4_UNTYPED_WORDS_ACCEPTOR); + l4_msg_tag_t tag = l4_receive (l4_anythread); + if (l4_ipc_failed (tag)) + { + debug (1, "%x.%x failed to block: %d, offset: %x", + l4_thread_no (l4_myself ()), l4_version (l4_myself ()), + (l4_error_code () >> 1) & 0x7, + l4_error_code () >> 4); + assert (! l4_ipc_failed (tag)); + } + else + debug (5, "%x.%x unblocked", + l4_thread_no (thread->threadid), l4_version (thread->threadid)); +} diff --git a/sysdeps/l4/pt-docancel.c b/sysdeps/l4/pt-docancel.c new file mode 100644 index 0000000..a3965d0 --- /dev/null +++ b/sysdeps/l4/pt-docancel.c @@ -0,0 +1,42 @@ +/* Cancel a thread. + Copyright (C) 2002, 2007 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <pthread.h> + +#include <pt-internal.h> + +static void +call_exit (void) +{ + pthread_exit (0); +} + +int +__pthread_do_cancel (struct __pthread *p) +{ + assert (p->cancel_pending == 1); + assert (p->cancel_state == PTHREAD_CANCEL_ENABLE); + + if (l4_is_thread_equal (l4_myself (), p->threadid)) + call_exit (); + else + l4_start_sp_ip (p->threadid, (l4_word_t) p->mcontext.sp, + (l4_word_t) call_exit); + return 0; +} diff --git a/sysdeps/l4/pt-pool-np.c b/sysdeps/l4/pt-pool-np.c new file mode 100644 index 0000000..e83022b --- /dev/null +++ b/sysdeps/l4/pt-pool-np.c @@ -0,0 +1,54 @@ +/* Thread pool for L4 threads. + Copyright (C) 2004, 2007 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <pt-internal.h> +#include <l4/thread.h> + +static pthread_mutex_t pool_lock = PTHREAD_MUTEX_INITIALIZER; + +_L4_thread_id_t pool_list = l4_nilthread; + +/* Add the thread TID to the pthread kernel thread pool. */ +int +pthread_pool_add_np (l4_thread_id_t tid) +{ + __pthread_mutex_lock (&pool_lock); + /* FIXME: Do error checking. */ + l4_set_user_defined_handle_of (tid, pool_list); + pool_list = tid; + __pthread_mutex_unlock (&pool_lock); + + return 0; +} + + +/* Get the first thread from the pool. */ +l4_thread_id_t +pthread_pool_get_np (void) +{ + _L4_thread_id_t tid; + + __pthread_mutex_lock (&pool_lock); + /* FIXME: Do error checking. */ + tid = pool_list; + if (tid != l4_nilthread) + pool_list = l4_user_defined_handle_of (tid); + __pthread_mutex_unlock (&pool_lock); + return tid; +} diff --git a/sysdeps/l4/pt-spin.c b/sysdeps/l4/pt-spin.c new file mode 100644 index 0000000..b6978b0 --- /dev/null +++ b/sysdeps/l4/pt-spin.c @@ -0,0 +1,63 @@ +/* Spin locks. L4 version. + Copyright (C) 2000, 2004 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <l4.h> + +#include <pthread.h> +#include <sched.h> + +/* The default for single processor machines; don't spin, it's + pointless. */ +#ifndef __PTHREAD_SPIN_COUNT +# define __PTHREAD_SPIN_COUNT 1 +#endif + +/* The number of times to spin while trying to lock a spin lock object + before yielding the processor. */ +int __pthread_spin_count = __PTHREAD_SPIN_COUNT; + + +/* Lock the spin lock object LOCK. If the lock is held by another + thread spin until it becomes available. */ +int +_pthread_spin_lock (__pthread_spinlock_t *lock) +{ + l4_time_t timeout; + int i; + + /* Start with a small timeout of 2 microseconds, then back off + exponentially. */ + timeout = l4_time_period (2); + + while (1) + { + for (i = 0; i < __pthread_spin_count; i++) + { + if (__pthread_spin_trylock (lock) == 0) + return 0; + } + l4_sleep (timeout); + + timeout = l4_time_mul2 (timeout); + if (timeout == L4_NEVER) + timeout = L4_TIME_PERIOD_MAX; + } +} + +weak_alias (_pthread_spin_lock, pthread_spin_lock); diff --git a/sysdeps/l4/pt-stack-alloc.c b/sysdeps/l4/pt-stack-alloc.c new file mode 100644 index 0000000..b7ec12b --- /dev/null +++ b/sysdeps/l4/pt-stack-alloc.c @@ -0,0 +1,43 @@ +/* Allocate a new stack. L4 Hurd version. + Copyright (C) 2000, 2007 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <l4.h> +#include <errno.h> + +#include <pt-internal.h> + +#include <sys/mman.h> + +/* Allocate a new stack of size STACKSIZE. If successful, store the + address of the newly allocated stack in *STACKADDR and return 0. + Otherwise return an error code (EINVAL for an invalid stack size, + EAGAIN if the system lacked the necessary resources to allocate a + new stack). */ +int +__pthread_stack_alloc (void **stackaddr, size_t stacksize) +{ + void *buffer = mmap (0, stacksize, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (buffer == MAP_FAILED) + return EAGAIN; + + *stackaddr = buffer; + + return 0; +} diff --git a/sysdeps/l4/pt-thread-alloc.c b/sysdeps/l4/pt-thread-alloc.c new file mode 100644 index 0000000..ec69afb --- /dev/null +++ b/sysdeps/l4/pt-thread-alloc.c @@ -0,0 +1,43 @@ +/* Allocate kernel thread. L4 version. + Copyright (C) 2003, 2005 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <assert.h> +#include <errno.h> +#include <string.h> + +#include <pt-internal.h> + +int +__pthread_thread_alloc (struct __pthread *thread) +{ + error_t err; + + /* The main thread is already running of course. */ + if (__pthread_num_threads == 1) + thread->threadid = l4_myself (); + else + { + thread->threadid = pthread_pool_get_np (); + if (thread->threadid != l4_nilthread) + return 0; + + return EAGAIN; + } + return 0; +} diff --git a/sysdeps/l4/pt-thread-dealloc.c b/sysdeps/l4/pt-thread-dealloc.c new file mode 100644 index 0000000..c09e486 --- /dev/null +++ b/sysdeps/l4/pt-thread-dealloc.c @@ -0,0 +1,32 @@ +/* Deallocate the kernel thread resources. L4 version. + Copyright (C) 2005 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <assert.h> +#include <errno.h> +#include <l4.h> + +#include <pt-internal.h> + +/* Deallocate any kernel resources associated with THREAD except don't + halt the thread itself. On return, the thread will be marked as + dead and __pthread_halt will be called. */ +void +__pthread_thread_dealloc (struct __pthread *thread) +{ +} diff --git a/sysdeps/l4/pt-thread-halt.c b/sysdeps/l4/pt-thread-halt.c new file mode 100644 index 0000000..aa2bf43 --- /dev/null +++ b/sysdeps/l4/pt-thread-halt.c @@ -0,0 +1,45 @@ +/* Deallocate the kernel thread resources. L4version. + Copyright (C) 2000, 2002, 2004 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <assert.h> +#include <errno.h> + +#include <pt-internal.h> + +/* Deallocate the kernel thread resources associated with THREAD. */ +void +__pthread_thread_halt (struct __pthread *thread, int need_dealloc) +{ + l4_thread_id_t tid = thread->threadid; + + if (need_dealloc) + __pthread_dealloc (thread); + + /* There is potential race here: once if TID is the current thread, + then once we add TID to the pool, someone can reallocate it + before we call stop. However, to start the thread, the caller + atomically starts and sets the sp and ip, thus, if the stop has + not yet executed at that point, it won't. */ + + if (tid != l4_myself ()) + l4_stop (tid); + pthread_pool_add_np (tid); + if (tid == l4_myself ()) + l4_stop (tid); +} diff --git a/sysdeps/l4/pt-thread-start.c b/sysdeps/l4/pt-thread-start.c new file mode 100644 index 0000000..144c58b --- /dev/null +++ b/sysdeps/l4/pt-thread-start.c @@ -0,0 +1,40 @@ +/* Start thread. L4 version. + Copyright (C) 2003, 2004, 2007 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <assert.h> +#include <errno.h> +#include <string.h> + +#include <pt-internal.h> + +/* Start THREAD. Get the kernel thread scheduled and running. */ +int +__pthread_thread_start (struct __pthread *thread) +{ + if (__pthread_num_threads == 1) + /* The main thread is already running of course. */ + { + assert (__pthread_total == 1); + assert (l4_is_thread_equal (l4_myself (), thread->threadid)); + } + else + l4_start_sp_ip (thread->threadid, (l4_word_t) thread->mcontext.sp, + (l4_word_t) thread->mcontext.pc); + return 0; +} diff --git a/sysdeps/l4/pt-timedblock.c b/sysdeps/l4/pt-timedblock.c new file mode 100644 index 0000000..ce7972b --- /dev/null +++ b/sysdeps/l4/pt-timedblock.c @@ -0,0 +1,35 @@ +/* Block a thread with a timeout. L4 version. + Copyright (C) 2000,02 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <assert.h> +#include <errno.h> +#include <time.h> +#include <sys/time.h> + +#include <pt-internal.h> + +/* Block THREAD. */ +error_t +__pthread_timedblock (struct __pthread *thread, + const struct timespec *abstime) +{ +#warning Need gettimeofday to implement properly. + __pthread_block (thread); + return 0; +} diff --git a/sysdeps/l4/pt-wakeup.c b/sysdeps/l4/pt-wakeup.c new file mode 100644 index 0000000..de37846 --- /dev/null +++ b/sysdeps/l4/pt-wakeup.c @@ -0,0 +1,54 @@ +/* Wakeup a thread. L4 version. + Copyright (C) 2002 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <l4.h> + +#include <pt-internal.h> + +#include <hurd/stddef.h> + +/* Wakeup THREAD. */ +void +__pthread_wakeup (struct __pthread *thread) +{ + debug (5, "%x.%x/%x waking %x.%x/%x", + l4_thread_no (l4_myself ()), l4_version (l4_myself ()), l4_myself (), + l4_thread_no (thread->threadid), l4_version (thread->threadid), + thread->threadid); + + /* Signal the waiter. */ + l4_msg_t msg; + l4_msg_clear (msg); + l4_msg_set_untyped_words (msg, 0); + l4_msg_load (msg); + + l4_msg_tag_t tag = l4_send (thread->threadid); + if (l4_ipc_failed (tag)) + { + int err = l4_error_code (); + debug (1, "%x.%x failed to wake %x.%x: %s (%d)", + l4_thread_no (l4_myself ()), l4_version (l4_myself ()), + l4_thread_no (thread->threadid), l4_version (thread->threadid), + l4_strerror (err), err); + } + else + debug (5, "%x.%x woke %x.%x", + l4_thread_no (l4_myself ()), l4_version (l4_myself ()), + l4_thread_no (thread->threadid), l4_version (thread->threadid)); +} diff --git a/sysdeps/mach/hurd/i386/pt-machdep.c b/sysdeps/mach/hurd/ia32/pt-machdep.c index face46c..face46c 100644 --- a/sysdeps/mach/hurd/i386/pt-machdep.c +++ b/sysdeps/mach/hurd/ia32/pt-machdep.c diff --git a/sysdeps/mach/hurd/i386/pt-setup.c b/sysdeps/mach/hurd/ia32/pt-setup.c index ba438d6..ba438d6 100644 --- a/sysdeps/mach/hurd/i386/pt-setup.c +++ b/sysdeps/mach/hurd/ia32/pt-setup.c diff --git a/sysdeps/posix/pt-spin.c b/sysdeps/posix/pt-spin.c index 486030d..26793b0 100644 --- a/sysdeps/posix/pt-spin.c +++ b/sysdeps/posix/pt-spin.c @@ -1,5 +1,5 @@ /* Spin locks. - Copyright (C) 2000, 2004 Free Software Foundation, Inc. + Copyright (C) 2000, 2005 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 diff --git a/sysdeps/powerpc/bits/machine-lock.h b/sysdeps/powerpc/bits/machine-lock.h new file mode 100644 index 0000000..cba6b0a --- /dev/null +++ b/sysdeps/powerpc/bits/machine-lock.h @@ -0,0 +1,78 @@ +/* Machine-specific definition for spin locks. PowerPC version. + Copyright (C) 1994,97,2002 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 _MACHINE_LOCK_H +#define _MACHINE_LOCK_H + +/* The type of a spin lock variable. */ + +typedef __volatile long int __spin_lock_t; + +/* Value to initialize `__spin_lock_t' variables to. */ + +#define __SPIN_LOCK_INITIALIZER 0L + + +#ifndef _EXTERN_INLINE +#define _EXTERN_INLINE extern __inline +#endif + +/* Unlock LOCK. */ + +_EXTERN_INLINE void +__spin_unlock (__spin_lock_t *__lock) +{ + long int __locked; + __asm__ __volatile__ ("\ +0: lwarx %0,0,%1\n\ + stwcx. %2,0,%1\n\ + bne- 0b\n\ +" : "=&r" (__locked) : "r" (__lock), "r" (0) : "cr0"); +} + +/* Try to lock LOCK; return nonzero if we locked it, zero if another has. */ + +_EXTERN_INLINE int +__spin_try_lock (register __spin_lock_t *__lock) +{ + long int __rtn; + __asm__ __volatile__ ("\ +0: lwarx %0,0,%1\n\ + stwcx. %2,0,%1\n\ + bne- 0b\n\ +" : "=&r" (__rtn) : "r" (__lock), "r" (1) : "cr0"); + return !__rtn; +} + +/* Return nonzero if LOCK is locked. */ + +_EXTERN_INLINE int +__spin_lock_locked (__spin_lock_t *__lock) +{ + long int __rtn; + __asm__ __volatile__ ("\ +0: lwarx %0,0,%1\n\ + stwcx. %0,0,%1\n\ + bne- 0b\n\ +" : "=&r" (__rtn) : "r" (__lock) : "cr0"); + return __rtn; +} + + +#endif /* machine-lock.h */ diff --git a/sysdeps/powerpc/bits/memory.h b/sysdeps/powerpc/bits/memory.h new file mode 100644 index 0000000..96624c3 --- /dev/null +++ b/sysdeps/powerpc/bits/memory.h @@ -0,0 +1,36 @@ +/* Memory barrier operations. PowerPC version. + Copyright (C) 2003 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _BITS_MEMORY_H +#define _BITS_MEMORY_H 1 + +/* Prevent read and write reordering across this function. */ +inline void +__memory_barrier (void) +{ + asm ("sync" ::: "memory"); +} + +/* Prevent read reordering across this function. */ +#define __memory_read_barrier __memory_barrier + +/* Prevent write reordering across this function. */ +#define __memory_write_barrier __memory_barrier + +#endif diff --git a/sysdeps/powerpc/bits/spin-lock.h b/sysdeps/powerpc/bits/spin-lock.h new file mode 100644 index 0000000..1dc2571 --- /dev/null +++ b/sysdeps/powerpc/bits/spin-lock.h @@ -0,0 +1,108 @@ +/* Machine-specific definitions for spin locks. PowerPC version. + Copyright (C) 2003 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* + * Never include this file directly; use <pthread.h> or <cthreads.h> instead. + */ + +#ifndef _BITS_SPIN_LOCK_H +#define _BITS_SPIN_LOCK_H 1 + +#include <features.h> + +__BEGIN_DECLS + +/* The type of a spin lock object. */ +typedef __volatile int __pthread_spinlock_t; + +/* Initializer for a spin lock object. */ +# define __SPIN_LOCK_INITIALIZER ((__pthread_spinlock_t) 0) + +#if defined __USE_EXTERN_INLINES || defined _FORCE_INLINES + +# ifndef __EBUSY +# include <errno.h> +# define __EBUSY EBUSY +# endif + +# ifndef __PT_SPIN_INLINE +# define __PT_SPIN_INLINE extern __inline +# endif + +__PT_SPIN_INLINE int __pthread_spin_destroy (__pthread_spinlock_t *__lock); + +__PT_SPIN_INLINE int +__pthread_spin_destroy (__pthread_spinlock_t *__lock) +{ + return 0; +} + +__PT_SPIN_INLINE int __pthread_spin_init (__pthread_spinlock_t *__lock, + int __pshared); + +__PT_SPIN_INLINE int +__pthread_spin_init (__pthread_spinlock_t *__lock, int __pshared) +{ + *__lock = __SPIN_LOCK_INITIALIZER; + return 0; +} + +__PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock); + +__PT_SPIN_INLINE int +__pthread_spin_trylock (__pthread_spinlock_t *__lock) +{ + long int __rtn; + __asm__ __volatile__ ("\ +0: lwarx %0,0,%1\n\ + stwcx. %2,0,%1\n\ + bne- 0b\n\ +" : "=&r" (__rtn) : "r" (__lock), "r" (1) : "cr0"); + return __rtn ? __EBUSY : 0; +} + +extern inline int __pthread_spin_lock (__pthread_spinlock_t *__lock); +extern int _pthread_spin_lock (__pthread_spinlock_t *__lock); + +extern inline int +__pthread_spin_lock (__pthread_spinlock_t *__lock) +{ + if (__pthread_spin_trylock (__lock)) + return _pthread_spin_lock (__lock); + return 0; +} + +__PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock); + +__PT_SPIN_INLINE int +__pthread_spin_unlock (__pthread_spinlock_t *__lock) +{ + long int __locked; + __asm__ __volatile__ ("\ +0: lwarx %0,0,%1\n\ + stwcx. %2,0,%1\n\ + bne- 0b\n\ +" : "=&r" (__locked) : "r" (__lock), "r" (0) : "cr0"); +} + +#endif /* Use extern inlines or force inlines. */ + +__END_DECLS + +#endif /* bits/spin-lock.h */ diff --git a/sysdeps/powerpc/machine-sp.h b/sysdeps/powerpc/machine-sp.h new file mode 100644 index 0000000..aa787c5 --- /dev/null +++ b/sysdeps/powerpc/machine-sp.h @@ -0,0 +1,31 @@ +/* Machine-specific function to return the stack pointer. i386 version. + Copyright (C) 1994,97,2001 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 _MACHINE_SP_H +#define _MACHINE_SP_H + +/* Return the current stack pointer. */ + +#define __thread_stack_pointer() ({ \ + void *__sp__; \ + __asm__ ("mr %0, 1" : "=r" (__sp__)); \ + __sp__; \ +}) + +#endif /* machine-sp.h */ diff --git a/sysdeps/powerpc/pt-machdep.h b/sysdeps/powerpc/pt-machdep.h new file mode 100644 index 0000000..6d45636 --- /dev/null +++ b/sysdeps/powerpc/pt-machdep.h @@ -0,0 +1,29 @@ +/* Machine dependent pthreads internal defenitions. i386 version. + Copyright (C) 2000 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _PT_MACHDEP_H +#define _PT_MACHDEP_H 1 + +struct pthread_mcontext +{ + void *pc; + void *sp; +}; + +#endif /* pt-machdep.h */ |