NetBSD Problem Report #41891

From takashi@siro.lan  Sat Aug 15 05:57:07 2009
Return-Path: <takashi@siro.lan>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 657F563C285
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 15 Aug 2009 05:57:07 +0000 (UTC)
Message-Id: <20090815035839.1EC1D74527@siro.lan>
Date: Sat, 15 Aug 2009 12:58:39 +0900 (JST)
From: yamamoto@valinux.co.jp
Reply-To: yamamoto@valinux.co.jp
To: gnats-bugs@gnats.NetBSD.org
Subject: our pthread doesn't like wine 1.1.27
X-Send-Pr-Version: 3.95

>Number:         41891
>Category:       lib
>Synopsis:       our pthread doesn't like wine 1.1.27
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Aug 15 06:00:00 +0000 2009
>Closed-Date:    Mon Oct 07 04:43:41 +0000 2013
>Last-Modified:  Mon Oct 07 04:43:41 +0000 2013
>Originator:     YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
>Release:        NetBSD 5.99.15
>Organization:

>Environment:
System: NetBSD 5.99.15
Architecture: i386
Machine: i386
>Description:
	it seems that wine 1.1.27 alters stack and uses libpthread.
	it doesn't work with our pthread implementation, which relies on
	the stack pointer for pthread_self().
>How-To-Repeat:
	run wine 1.1.27 and observe that it dies in the middle of malloc().
	it might not be so obvious for ones who are not familiar with
	wine (eg. me) because the SIGSEGV will be caught by their SEH handler.
>Fix:


>Release-Note:

>Audit-Trail:

From: yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi)
To: gnats-bugs@NetBSD.org, lib-bug-people@netbsd.org,gnats-admin@netbsd.org,netbsd-bugs@netbsd.org
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__))

State-Changed-From-To: open->feedback
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Thu, 03 Jan 2013 22:34:04 +0000
State-Changed-Why:
This problem (and patch) is obsoleted by the TLS changes, right?


From: yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi)
To: gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org, netbsd-bugs@netbsd.org, gnats-admin@netbsd.org,
	dholland@NetBSD.org
Subject: Re: lib/41891 (our pthread doesn't like wine 1.1.27)
Date: Fri,  5 Apr 2013 05:17:55 +0000 (UTC)

 > Synopsis: our pthread doesn't like wine 1.1.27
 > 
 > State-Changed-From-To: open->feedback
 > State-Changed-By: dholland@NetBSD.org
 > State-Changed-When: Thu, 03 Jan 2013 22:34:04 +0000
 > State-Changed-Why:
 > This problem (and patch) is obsoleted by the TLS changes, right?

 i guess so.

 YAMAMOTO Takashi

State-Changed-From-To: feedback->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Mon, 07 Oct 2013 04:43:41 +0000
State-Changed-Why:
feedback received in january (my fault ignoring it this long)


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.