Fix --ftrace with cosmo_dlopen()

This change ensures function call logging won't crash the process when
cosmo_dlopen() is called.
This commit is contained in:
Justine Tunney 2024-01-05 15:11:37 -08:00
parent 15548b523c
commit 2d93788ce3
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
8 changed files with 35 additions and 7 deletions

View file

@ -28,12 +28,13 @@
int sys_set_tls();
textstartup void __set_tls(struct CosmoTib *tib) {
// we can't allow --ftrace here because cosmo_dlopen() calls this
// function to fix the tls register, and ftrace needs it unbroken
dontinstrument textstartup void __set_tls(struct CosmoTib *tib) {
tib = __adj_tls(tib);
#ifdef __x86_64__
// ask the operating system to change the x86 segment register
if (IsWindows()) {
npassert(0 <= __tls_index && __tls_index < 64);
asm("mov\t%1,%%gs:%0" : "=m"(*((long *)0x1480 + __tls_index)) : "r"(tib));
} else if (IsFreebsd()) {
sys_set_tls(129 /*AMD64_SET_FSBASE*/, tib);