mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-04 10:18:31 +00:00
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:
parent
15548b523c
commit
2d93788ce3
8 changed files with 35 additions and 7 deletions
26
libc/runtime/set_tls-sysv.S
Normal file
26
libc/runtime/set_tls-sysv.S
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│ vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2024 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
// we can't allow ftrace here since ftrace needs tls
|
||||
sys_set_tls:
|
||||
mov __NR_set_tls(%rip),%eax
|
||||
syscall
|
||||
ret
|
||||
.endfn sys_set_tls,globl
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue