NetBSD-Bugs archive

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

Re: port-mips/59064 (jemalloc switch to 5.3 broke userland)



> Date: Sun, 13 Apr 2025 12:42:29 +0000
> From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
> 
> > Date: Sun, 13 Apr 2025 13:39:54 +0900
> > From: Rin Okuyama <rokuyama.rk%gmail.com@localhost>
> > 
> > I forgot to mention, but userland works even with "initial-exec"
> > TLS model on QEMU and GXemul for mips somehow. Emulation may be
> > not precise enough, or our TLS handling relays on some undefined
> > H/W behaviors?
> 
> Is this for emulating the  RDHWR $3,$29  instruction, 0x7c03e83b?

I just tried the attached program on an erlite3 and it seemed to work
fine, at least for this simple case:

# ./rdhwr
tcb_syscall 0x10010d70
tcb_rdhwr 0x10010d70

Will try running atf tests once I finish a build from _after_ the
bsd.lib.mk change (cleverly kicked off a build from _just before_ it
and then installed that a couple hours later and realized oops).
#include <machine/lwp_private.h>

#include <lwp.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

struct tls_tcb tcb_storage[0x8000];

__noinline
static struct tls_tcb *
gettcb_rdhwr(void)
{
	struct tls_tcb *tcb;

	asm(".set push\n\t"
	    ".set mips32r2\n\t"
	    "rdhwr $3,$29\n\t"
	    "move %[tcb],$3\n\t"
	    ".set pop"
	    : [tcb]"=r"(tcb)
	    :
	    : "$3");

	return tcb - (TLS_TP_OFFSET/sizeof(*tcb) + 1);
}

int
main(void)
{
	char buf[1024];
	struct tls_tcb *tcb_rdhwr, *tcb_syscall;

	__lwp_settcb(tcb_storage);

	tcb_syscall = __lwp_gettcb_fast();
	snprintf_ss(buf, sizeof(buf), "tcb_syscall %p\n", tcb_syscall);
	(void)write(STDOUT_FILENO, buf, strlen(buf));

	tcb_rdhwr = gettcb_rdhwr();
	snprintf_ss(buf, sizeof(buf), "tcb_rdhwr %p\n", tcb_rdhwr);
	(void)write(STDOUT_FILENO, buf, strlen(buf));

	return 0;
}


Home | Main Index | Thread Index | Old Index