Improve locks and signals

- Introduce fast spinlock API
- Double rand64() perf w/ spinlock
- Improve raise() on New Technology
- Support gettid() across platforms
- Implement SA_NODEFER on New Technology
- Move the lock intrinsics into LIBC_INTRIN
- Make SIGTRAP recoverable on New Technology
- Block SIGCHLD in wait4() on New Technology
- Add threading prototypes for XNU and FreeBSD
- Rewrite abort() fixing its minor bugs on XNU/NT
- Shave down a lot of the content in libc/bits/bits.h
- Let signal handlers modify CPU registers on New Technology
This commit is contained in:
Justine Tunney 2022-04-12 05:20:17 -07:00
parent f68f1789bd
commit 046c7ebd4a
110 changed files with 1514 additions and 876 deletions

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/bits/asmflag.h"
#include "libc/bits/bits.h"
#include "libc/calls/calls.h"
#include "libc/dce.h"
@ -113,12 +114,14 @@ static int arch_prctl_freebsd(int code, int64_t addr) {
static privileged dontinline int arch_prctl_xnu(int code, int64_t addr) {
int ax;
bool failed;
switch (code) {
case ARCH_SET_GS:
asm volatile("syscall"
: "=a"(ax)
: "0"(0x3000003), "D"(addr - 0x8a0 /* wat */)
asm volatile(CFLAG_ASM("syscall")
: CFLAG_CONSTRAINT(failed), "=a"(ax)
: "1"(0x3000003), "D"(addr - 0x8a0 /* wat */)
: "rcx", "r11", "memory", "cc");
if (failed) errno = ax, ax = -1;
return ax;
case ARCH_GET_FS:
case ARCH_SET_FS:
@ -130,21 +133,30 @@ static privileged dontinline int arch_prctl_xnu(int code, int64_t addr) {
}
static privileged dontinline int arch_prctl_openbsd(int code, int64_t addr) {
bool failed;
int64_t rax;
switch (code) {
case ARCH_GET_FS:
asm volatile("syscall"
: "=a"(rax)
: "0"(0x014a /* __get_tcb */)
asm volatile(CFLAG_ASM("syscall")
: CFLAG_CONSTRAINT(failed), "=a"(rax)
: "1"(0x014a /* __get_tcb */)
: "rcx", "r11", "cc", "memory");
if (failed) {
errno = rax;
return -1;
}
*(int64_t *)addr = rax;
return 0;
case ARCH_SET_FS:
asm volatile("syscall"
: "=a"(rax)
: "0"(0x0149 /* __set_tcb */), "D"(addr)
asm volatile(CFLAG_ASM("syscall")
: CFLAG_CONSTRAINT(failed), "=a"(rax)
: "1"(0x0149 /* __set_tcb */), "D"(addr)
: "rcx", "r11", "cc", "memory");
return 0;
if (failed) {
errno = rax;
rax = -1;
}
return rax;
case ARCH_GET_GS:
case ARCH_SET_GS:
return enosys();