Subject: SA under COMPAT_NETBSD32, a patch
To: None <>
From: Quentin Garnier <>
List: tech-kern
Date: 03/16/2006 19:10:30
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi folks,

Finally, I've made SA work for 32-bits binaries on sparc64 and amd64.

You'll find the set of patches here:

There are five files, each applying to a specific part of the work:

 - sa.diff:  Changes to our native SA code.  It adds information to
             struct emul, and makes kern_{sa,lwp}.c use it.  It also
             changes a few syscalls so they can be invoked from the
             COMPAT_NETBSD32 path.

             One thing that should be noted is that the code makes the
             assumption that sizeof(ucontext32_t) < sizeof(ucontext_t),
             which is reasonable.

             I've left a XXX about _UC_CONTEXT_ALIGN, which theorically
             could be an issue, but not in the case of i386/amd64 and
             even less in the sparc/sparc64 one.

 - netbsd32.diff: Adds the necessary bits to make 32-bits binaries work
             with libpthread.

             Note the assumption that sizeof(siginfo32_t) is less then
             sizeof(siginfo_t).  Again, reasonable.

 - md.amd64.diff, md.sparc64.diff:  Changes to the affected platforms.

             netbsd32_cpu_upcall() on sparc64 becomes the exact copy of
             sparc's cpu_upcall().

 - libpthread.diff:  This is specific to amd64/i386.

             As I explained in a couple of previous posts on that list,
             the order of GDT entries is different between i386 and
             amd64 which means libpthread cannot guess the correct
             values for segment registers:  what works for i386 gets a
             bus error under COMPAT_NETBSD32.

             The solution in that patch is not perfect because it
             involves a call to getcontext(2), but _INITCONTEXT_U_MD()
             must be stand-alone (libpthread_dbg uses it too...) so
             using an extern filled in a pthread_init() time is not a
             satisfying option either.  I'm open to suggestions here :-)

Thanks to all the people who gave valuable input on the matter.  I'm no
more a total n00b on sparc64 :-)

Quentin Garnier - -
"When I find the controls, I'll go where I like, I'll know where I want
to be, but maybe for now I'll stay right here on a silent sea."
KT Tunstall, Silent Sea, Eye to the Telescope, 2004.

Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.2.6 (NetBSD)