NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: lib/41891: our pthread doesn't like wine 1.1.27



The following reply was made to PR lib/41891; it has been noted by GNATS.

From: yamt%mwd.biglobe.ne.jp@localhost (YAMAMOTO Takashi)
To: gnats-bugs%NetBSD.org@localhost, 
lib-bug-people%netbsd.org@localhost,gnats-admin%netbsd.org@localhost,netbsd-bugs%netbsd.org@localhost
Cc: 
Subject: Re: lib/41891: our pthread doesn't like wine 1.1.27
Date: Sun, 16 Aug 2009 07:50:32 +0000 (UTC)

 the following patch implements pthread_self using %gs register for i386.
 
 YAMAMOTO Takashi
 
 Index: lib/libc/arch/i386/gen/_lwp.c
 ===================================================================
 RCS file: /cvsroot/src/lib/libc/arch/i386/gen/_lwp.c,v
 retrieving revision 1.6
 diff -u -p -r1.6 _lwp.c
 --- lib/libc/arch/i386/gen/_lwp.c      28 Apr 2008 20:22:56 -0000      1.6
 +++ lib/libc/arch/i386/gen/_lwp.c      16 Aug 2009 07:20:40 -0000
 @@ -66,5 +66,11 @@ _lwp_makecontext(ucontext_t *u, void (*s
        /* LINTED uintptr_t is safe */
        u->uc_mcontext.__gregs[_REG_UESP] = (uintptr_t) sp;
  
 -      /* LINTED private is currently unused */
 +      /*
 +       * abuse _REG_ESP to pass the private pointer.
 +       * cf. cpu_setmcontext
 +       */
 +      /* LINTED uintptr_t is safe */
 +      u->uc_mcontext.__gregs[_REG_ESP] = (uintptr_t)private;
 +      u->uc_flags |= _UC_LWPPRIVATE;
  }
 Index: sys/sys/ucontext.h
 ===================================================================
 RCS file: /cvsroot/src/sys/sys/ucontext.h,v
 retrieving revision 1.11
 diff -u -p -r1.11 ucontext.h
 --- sys/sys/ucontext.h 15 Oct 2008 06:51:21 -0000      1.11
 +++ sys/sys/ucontext.h 16 Aug 2009 07:20:40 -0000
 @@ -57,6 +57,7 @@ struct __ucontext {
  #define _UC_STACK     0x02            /* valid uc_stack */
  #define _UC_CPU               0x04            /* valid GPR context in 
uc_mcontext */
  #define _UC_FPU               0x08            /* valid FPU context in 
uc_mcontext */
 +#define _UC_LWPPRIVATE        0x10            /* valid lwp private in 
uc_mcontext */
  
  #ifdef _KERNEL
  struct lwp;
 Index: sys/arch/i386/i386/machdep.c
 ===================================================================
 RCS file: /cvsroot/src/sys/arch/i386/i386/machdep.c,v
 retrieving revision 1.670
 diff -u -p -r1.670 machdep.c
 --- sys/arch/i386/i386/machdep.c       29 Jul 2009 12:02:05 -0000      1.670
 +++ sys/arch/i386/i386/machdep.c       16 Aug 2009 07:20:41 -0000
 @@ -1833,6 +1833,14 @@ cpu_setmcontext(struct lwp *l, const mco
                tf->tf_esp    = gr[_REG_UESP];
                tf->tf_ss     = gr[_REG_SS];
        }
 +      if ((flags & _UC_LWPPRIVATE) != 0) {
 +              /*
 +               * abuse _REG_ESP for the private pointer.
 +               * cf. _lwp_makecontext
 +               */
 +              l->l_private = (void *)gr[_REG_ESP];
 +              cpu_lwp_setprivate(l, l->l_private);
 +      }
  
  #if NNPX > 0
        /*
 Index: lib/libpthread/pthread_int.h
 ===================================================================
 RCS file: /cvsroot/src/lib/libpthread/pthread_int.h,v
 retrieving revision 1.72
 diff -u -p -r1.72 pthread_int.h
 --- lib/libpthread/pthread_int.h       17 May 2009 14:49:00 -0000      1.72
 +++ lib/libpthread/pthread_int.h       16 Aug 2009 07:20:41 -0000
 @@ -253,7 +253,9 @@ int        pthread__find(pthread_t) PTHREAD_HID
  #define pthread__id(sp) \
        ((pthread_t) (((vaddr_t)(sp)) & pthread__threadmask))
  
 -#ifdef PTHREAD__HAVE_THREADREG
 +#if defined(PTHREAD__HAVE_MD_PTHREAD_SELF)
 +#define       pthread__self()         pthread__md_self()
 +#elif defined(PTHREAD__HAVE_THREADREG)
  #define       pthread__self()         pthread__threadreg_get()
  #else
  #define pthread__self()       (pthread__id(pthread__sp()))
 Index: lib/libpthread/arch/i386/pthread_md.h
 ===================================================================
 RCS file: /cvsroot/src/lib/libpthread/arch/i386/pthread_md.h,v
 retrieving revision 1.17
 diff -u -p -r1.17 pthread_md.h
 --- lib/libpthread/arch/i386/pthread_md.h      16 May 2009 22:20:40 -0000      
1.17
 +++ lib/libpthread/arch/i386/pthread_md.h      16 Aug 2009 07:20:41 -0000
 @@ -46,6 +46,16 @@ pthread__sp(void)
  
  #define pthread__uc_sp(ucp) ((ucp)->uc_mcontext.__gregs[_REG_UESP])
  
 +static inline pthread_t
 +pthread__md_self(void)
 +{
 +      void *ret;
 +
 +      /* 0 == offsetof(pthread_t, pt_self) */
 +      __asm("movl %%gs:0, %0" : "=r" (ret));
 +      return ret;
 +}
 +
  /*
   * Set initial, sane values for registers whose values aren't just
   * "don't care".
 @@ -80,6 +90,8 @@ pthread__sp(void)
  /* Don't need additional memory barriers. */
  #define       PTHREAD__ATOMIC_IS_MEMBAR
  
 +#define       PTHREAD__HAVE_MD_PTHREAD_SELF
 +
  static inline pthread_t
  #ifdef __GNUC__
  __attribute__ ((__const__))
 


Home | Main Index | Thread Index | Old Index