mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-03 03:02:28 +00:00
Clean up the clone() code a bit
This commit is contained in:
parent
ce71677156
commit
2743f3d012
20 changed files with 252 additions and 150 deletions
38
libc/nexgen32e/checkstackalign.S
Normal file
38
libc/nexgen32e/checkstackalign.S
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*-*- 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 2022 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"
|
||||
|
||||
// Checks that stack is 16-byte aligned.
|
||||
//
|
||||
// This function crashes if called with a misaligned stack.
|
||||
_checkstackalign:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
|
||||
/ allocate sixteen bytes
|
||||
push %rax
|
||||
push %rax
|
||||
|
||||
/ put a value in it
|
||||
xorps %xmm0,%xmm0
|
||||
movaps %xmm0,-16(%rbp)
|
||||
|
||||
leave
|
||||
ret
|
||||
.endfn _checkstackalign,globl
|
|
@ -7,6 +7,7 @@ extern long kHalfCache3;
|
|||
|
||||
void imapxlatab(void *);
|
||||
void insertionsort(int32_t *, size_t);
|
||||
void _checkstackalign(void);
|
||||
|
||||
int64_t div10int64(int64_t) libcesque pureconst;
|
||||
int64_t div100int64(int64_t) libcesque pureconst;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/threaded.h"
|
||||
#include "libc/nexgen32e/threaded.h"
|
||||
|
||||
bool __threaded;
|
||||
bool __tls_enabled;
|
||||
|
|
39
libc/nexgen32e/threaded.h
Normal file
39
libc/nexgen32e/threaded.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_THREADED_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_THREADED_H_
|
||||
#include "libc/dce.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
extern bool __threaded;
|
||||
extern bool __tls_enabled;
|
||||
extern unsigned __tls_index;
|
||||
|
||||
void *__initialize_tls(char[hasatleast 64]);
|
||||
void __install_tls(char[hasatleast 64]);
|
||||
|
||||
#if defined(__GNUC__) && defined(__x86_64__)
|
||||
/**
|
||||
* Returns address of thread information block.
|
||||
*
|
||||
* This function must not be called until TLS is initialized.
|
||||
*
|
||||
* @see __install_tls()
|
||||
* @see clone()
|
||||
*/
|
||||
static noasan inline char *__get_tls(void) {
|
||||
char *tib, *lin = (char *)0x30;
|
||||
if (IsLinux() || IsFreebsd() || IsNetbsd() || IsOpenbsd()) {
|
||||
asm("mov\t%%fs:(%1),%0" : "=a"(tib) : "r"(lin));
|
||||
} else {
|
||||
asm("mov\t%%gs:(%1),%0" : "=a"(tib) : "r"(lin));
|
||||
if (IsWindows()) {
|
||||
tib = *(char **)(tib + 0x1480 + __tls_index * 8);
|
||||
}
|
||||
}
|
||||
return tib;
|
||||
}
|
||||
#endif /* GNU x86-64 */
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_THREADED_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue