More stuff
authorDavid Bartley <dtbartle@maltodextrin.csclub.uwaterloo.ca>
Sat, 4 Oct 2008 11:27:58 +0000 (07:27 -0400)
committerDavid Bartley <dtbartle@maltodextrin.csclub.uwaterloo.ca>
Sat, 4 Oct 2008 11:27:58 +0000 (07:27 -0400)
nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Makefile
nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Versions
nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/sysdep-cancel.h
nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthreaddef.h
nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/syscalls.list
nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_create.c
nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_stksegment.c
nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thread.h

index 24ba3d1..2b02bf7 100644 (file)
@@ -16,12 +16,11 @@ libpthread-routines += mutex_init mutex_lock mutex_trylock mutex_unlock \
     cond_signal cond_broadcast cond_destroy rwlock_init rwlock_destroy \
     rw_rdlock rw_wrlock rw_unlock rw_tryrdlock rw_trywrlock rw_timedrdlock \
     rw_timedwrlock sema_init sema_destroy sema_wait sema_trywait sema_post \
-    sema_timedwait thr_create thr_join thr_exit thr_self thr_main thr_yield \
+    sema_timedwait thr_create thr_join thr_exit thr_self thr_yield \
     thr_sigsetmask thr_getspecific thr_setspecific thr_keycreate \
     thr_keycreate_once thr_min_stack thr_getconcurrency thr_setconcurrency \
-    thr_continue thr_suspend thr_getprio thr_setprio thr_stksegment \
-    _lwp_sema_init _lwp_info __nthreads pthread_cond_reltimedwait_np \
-    pthread_mutex_reltimedlock_np
+    thr_continue thr_suspend thr_getprio thr_setprio _lwp_sema_init _lwp_info \
+    __nthreads pthread_cond_reltimedwait_np pthread_mutex_reltimedlock_np
 endif
 
 ifeq ($(subdir),posix)
@@ -29,6 +28,10 @@ CFLAGS-fork.c = -D_IO_MTSAFE_IO
 sysdep_routines += sys_forkx
 endif
 
+ifeq ($(subdir),misc)
+sysdep_routines += thr_main thr_stksegment
+endif
+
 # Needed in both the signal and nptl subdir.
 # We also need to enable exceptions.
 CFLAGS-sigaction.c = -DWRAPPER_INCLUDE='<nptl/sigaction.c>' -fexceptions
index 3638ef7..2924399 100644 (file)
@@ -2,6 +2,9 @@ libc {
   GLIBC_2.3.2 {
     __register_atfork;
   }
+  GLIBC_2.7 {
+    thr_stksegment; thr_main;
+  }
   GLIBC_PRIVATE {
     __libc_pthread_init;
     __libc_current_sigrtmin_private; __libc_current_sigrtmax_private;
@@ -48,6 +51,6 @@ libpthread {
     thr_create; thr_join; thr_exit; thr_suspend; thr_continue; thr_self;
     thr_setconcurrency; thr_getconcurrency; thr_main; thr_kill; thr_yield;
     thr_setprio; thr_getprio; thr_keycreate; thr_keycreate_once; thr_min_stack;
-    thr_getspecific; thr_setspecific; thr_sigsetmask; thr_stksegment; thr_main;
+    thr_getspecific; thr_setspecific; thr_sigsetmask;
   }
 }
index 2d59131..f9d010c 100644 (file)
 #undef PSEUDO_ERRVAL
 #undef PSEUDO_SUBCALL_NOERRNO
 
+#ifdef SYSCALL_RESTARTABLE
+# define DO_RESTART_CANCEL \
+    cmpl $ERESTART, %eax; \
+    je L(restart_cancel);
+#else
+# define DO_RESTART_CANCEL
+#endif
+
 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
 
 /* Note that CDISABLE is an internal function, so we need to
@@ -47,8 +55,7 @@
   L(restart):                                       \
     DO_CALL (syscall_name, args);                         \
     jnb 2f;                                                                            \
-    cmpl $ERESTART, %eax;                   \
-    je L(restart);                                      \
+    DO_RESTART                             \
     jmp SYSCALL_ERROR_LABEL;                           \
 2:  ret;                                            \
   .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;           \
@@ -58,8 +65,7 @@
     movl %eax, %ecx;                    \
     DO_CALL (syscall_name, args);                         \
     jnb 3f;                                                                            \
-    cmpl $ERESTART, %eax;                   \
-    je L(restart_cancel);                                      \
+    DO_RESTART_CANCEL                             \
     pushl %eax; cfi_adjust_cfa_offset (4);  \
     movl %ecx, %eax;                        \
     CDISABLE;                           \
@@ -89,8 +95,7 @@
   L(restart):                                       \
     DO_CALL (syscall_name, args);                         \
     jnb 2f;                                                                            \
-    cmpl $ERESTART, %eax;                   \
-    je L(restart);                                      \
+    DO_RESTART                             \
     movl %ecx, 4(%esp);                                                        \
     addl $-4, %esp;                             \
     jmp SYSCALL_ERROR_LABEL;                           \
   L(restart_cancel):                                       \
     DO_CALL (syscall_name, args);                         \
     jnb 3f;                                                                            \
-    cmpl $ERESTART, %eax;                   \
-    je L(restart_cancel);                                      \
+    DO_RESTART_CANCEL                             \
     pushl %eax; cfi_adjust_cfa_offset (4);  \
     movl %ecx, %eax;                        \
     CDISABLE;                           \
index c6cdef5..383e5fd 100644 (file)
@@ -18,7 +18,7 @@
    02111-1307 USA.  */
 
 #include <ucontext.h>
-#include <sys/isa_defs.h>
+#include <signal.h>
 
 /* Get the arch-specific version.  */
 #include_next <pthreaddef.h>
 /* Register atfork handlers to protect signal_lock.  */
 extern void sigaction_atfork (void);
 
-#define PLATFORM_PTHREAD_INIT                   \
-    sigaction_atfork ();                        \
-    THREAD_SETMEM (pd, main_thread, 1);         \
-    ucontext_t _ctx;                            \
-    if (getcontext (&_ctx) == 0)                \
-      {                                         \
-        main_stackaddr = _ctx.uc_stack.ss_sp;   \
-        main_stacksize = _ctx.uc_stack.ss_size; \
+/* TODO: Need to deal with stacks that grow up.  */
+#define PLATFORM_PTHREAD_INIT                                       \
+    sigaction_atfork ();                                            \
+    THREAD_SETMEM (pd, main_thread, 1);                             \
+    ucontext_t _ctx;                                                \
+    if (getcontext (&_ctx) == 0)                                    \
+      {                                                             \
+        THREAD_SETMEM (pd, stackblock, _ctx.uc_stack.ss_sp -        \
+            _ctx.uc_stack.ss_size);                                 \
+        THREAD_SETMEM (pd, stackblock_size, _ctx.uc_stack.ss_size); \
       }
 
+/* We need to tell the kernel about the allocated stack.  */
+#define PLATFORM_THREAD_START                                       \
+    {                                                               \
+        stack_t stack;                                              \
+        stack.ss_sp = pd->stackblock;                               \
+        stack.ss_sp = pd->stackblock_size;                          \
+        stack.ss_flags = 0;                                         \
+        setustack (&stack);                                         \
+    }
+
 /* Additional descr fields.  */
 # define PLATFORM_DESCR_FIELDS              \
     int sigpipe_disabled;                   \
     int main_thread;
 
-/* Static variables.  */
-#define PLATFORM_STATIC_DECLS   \
-    void *main_stackaddr;       \
-    size_t main_stacksize;
-extern void *main_stackaddr;
-extern size_t main_stacksize;
-
-/* We can get the main thread's stack via getcontext (see above).  */
-#define GET_MAIN_STACK_INFO(stackaddr, stacksize)       \
-    ({*stackaddr = main_stackaddr + main_stacksize;     \
-      *stacksize = main_stacksize;                      \
-      0;})
+/* If we call this then the getcontext call above failed.  */
+#define GET_MAIN_STACK_INFO(stackaddr, stacksize)   ENOSYS
 
 /* Use tid as pthread_t (instead of descr).  */
 #define PTHREAD_T_IS_TID
@@ -69,6 +71,9 @@ extern size_t main_stacksize;
 /* It is known that the first lwpid is 1.  */
 #define FIRST_THREAD_TID       1
 
+/* We need to be passed the stacksize.  */
+#define NEED_STACK_SIZE
+
 /* __exit_thread_inline is the same for all architectures.  */
 #include <inline-syscall.h>
 
index f22fa99..ae8e167 100644 (file)
@@ -8,7 +8,7 @@ sys_lwp_self            - lwp_self              Ei:     __syscall_lwp_self
 sys_lwp_create          - lwp_create            Vi:pip  __syscall_lwp_create
 sys_lwp_wait            - lwp_wait              Vi:ip   __syscall_lwp_wait
 sys_lwp_exit            - lwp_exit              Ei:     __syscall_lwp_exit
-sys_lwp_suspend         - lwp_suspend           Vi:i    __syscall_lwp_suspend
+sys_lwp_suspend         - lwp_suspend           RVi:i   __syscall_lwp_suspend
 sys_lwp_continue        - lwp_continue          Vi:i    __syscall_lwp_continue
 sys_lwp_kill            - lwp_kill              Vi:ii   __syscall_lwp_kill
 
@@ -20,7 +20,7 @@ sys_lwp_info            - lwp_info              i:p     __syscall_lwp_info
 sys_lwp_detach          - lwp_detach            i:i     __syscall_lwp_detach
 
 sys_lwp_mutex_wakeup    - lwp_mutex_wakeup      Vi:pi   __syscall_lwp_mutex_wakeup
-sys_lwp_mutex_timedlock - lwp_mutex_timedlock   Vi:pi   __syscall_lwp_mutex_timedlock
+sys_lwp_mutex_timedlock - lwp_mutex_timedlock   RVi:pi  __syscall_lwp_mutex_timedlock
 sys_lwp_mutex_unlock    - lwp_mutex_unlock      Vi:p    __syscall_lwp_mutex_unlock
 sys_lwp_mutex_trylock   - lwp_mutex_trylock     Vi:p    __syscall_lwp_mutex_trylock
 sys_lwp_mutex_register  - lwp_mutex_register    Vi:p    __syscall_lwp_mutex_register
index c8e8dc5..a56b074 100644 (file)
@@ -44,6 +44,10 @@ int thr_create (void *stack_address, size_t stack_size,
     ((flags & THR_SUSPENDED) ? ATTR_FLAG_SUSPENDED : 0) |
     ((flags & THR_DAEMON) ? ATTR_FLAG_DAEMON : 0);
 
-  return pthread_create ((pthread_t *)new_thread, (pthread_attr_t *)&iattr,
+  pthread_t thread;
+  int res = pthread_create (&thread, (pthread_attr_t *)&iattr,
       start_routine, arg);
+  if (res == 0 && new_thread)
+    *new_thread = (thread_t)thread;
+  return res;
 }
index 2ef33d7..a6bc286 100644 (file)
 #include <sys/ucontext.h>
 #include <sys/syscall.h>
 #include <string.h>
+#include <stdio.h>
 
 int thr_stksegment (stk)
       stack_t *stk;
 {
-  /* We can get the stack base and size from getcontext.  */
-  sysret_t ret;
-  ucontext_t ctx;
-  int errval = __systemcall (&ret, SYS_context, GETCONTEXT, &ctx);
-  if (errval != 0)
-    return errval;
+  struct pthread *self = THREAD_SELF;
+  stk->ss_size = THREAD_GETMEM (self, stackblock_size);
+  // TODO: handle stacks that grow up
+  stk->ss_sp = THREAD_GETMEM (self, stackblock) + stk->ss_size;
+  stk->ss_flags = 0;
 
-  memcpy (stk, &ctx.uc_stack, sizeof (stack_t));
   return 0;
 }
index 57fd669..355967b 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef _THREAD_H
 #define _THREAD_H
 
-#include <sys/signal.h>
+#include <signal.h>
 #include <synch.h>
 
 typedef unsigned int thread_t;
@@ -78,6 +78,8 @@ extern int thr_getspecific (thread_key_t, void **);
 
 extern int thr_sigsetmask (int how, const sigset_t *set, sigset_t *oset);
 
+extern int thr_stksegment (stack_t *stk);
+
 __END_DECLS
 
 #endif /* _THREAD_H */