Subject: SA under COMPAT_NETBSD32, a patch
To: None <tech-kern@netbsd.org>
From: Quentin Garnier <cube@cubidou.net>
List: tech-kern
Date: 03/16/2006 19:10:30
--hp5Mu6hJkc9hZLmH
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:

http://taryn.cubidou.net/~cube/netbsd/sa32

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 :-)

--=20
Quentin Garnier - cube@cubidou.net - cube@NetBSD.org
"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.

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (NetBSD)

iQEVAwUBRBmqFtgoQloHrPnoAQLA7ggAwYQFanojPdNvR+oCZrI6qPC/SJ3vcXh7
pNFXdgMxie6tbFcJ1Ntz5uQXRjZdKNSCGpkxX7A+2raYdq2yWWCxEn4bOEv4+KHG
aFd31yUgu0Rhi3DQ3WXhSxn/6YJh/vqT2az/12PCBQ2OiVI4HsnHrlpMpnTSAeeu
DHT/J3QO8wvtjg9oMotQDRYb/0IvA8Hqc/1Ymq9T4BipJcvEbWbTQ/yZUYquCud+
GhBquiS63MQx5fbUSBk9jbrQ6jjX3QsasNoOk5pJ4NPs5S7/q8FbKL/HjGYMeQYr
eGKnO9tWoPqBbEvj8fD3ICzfIrkRvnHHbepGKdynT+LDCBi/JH4wxw==
=Moe7
-----END PGP SIGNATURE-----

--hp5Mu6hJkc9hZLmH--