mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 00:08:30 +00:00
Introduce #include <cosmo.h>
to toolchain users
This change improves the way internal APIs are being hidden behind the `COSMO` define. The cosmo.h header will take care of defining that, so that a separate define statement isn't needed. This change also does a lot more to define which APIs are standard, and which belong to Cosmo.
This commit is contained in:
parent
9b55dbe417
commit
4a59210008
115 changed files with 699 additions and 422 deletions
|
@ -28,7 +28,7 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "libc/zip.h"
|
||||
#include "libc/zip.internal.h"
|
||||
#include "libc/zipos/zipos.internal.h"
|
||||
#include "third_party/puff/puff.h"
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "libc/intrin/nopl.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/version.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/stack.h"
|
||||
#include "libc/sysv/consts/ss.h"
|
||||
#include "libc/thread/tls.h"
|
||||
|
|
|
@ -367,10 +367,10 @@ noasan inline void *_Mmap(void *addr, size_t size, int prot, int flags, int fd,
|
|||
// however this 1mb behavior oddly enough is smart enough to not
|
||||
// apply if the mapping is a manually-created guard page.
|
||||
int e = errno;
|
||||
if ((dm = sys_mmap(p + size - GUARDSIZE, GUARDSIZE, prot,
|
||||
if ((dm = sys_mmap(p + size - APE_GUARDSIZE, APE_GUARDSIZE, prot,
|
||||
f | MAP_GROWSDOWN_linux, fd, off))
|
||||
.addr != MAP_FAILED) {
|
||||
_npassert(sys_mmap(p, GUARDSIZE, PROT_NONE,
|
||||
_npassert(sys_mmap(p, APE_GUARDSIZE, PROT_NONE,
|
||||
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)
|
||||
.addr == p);
|
||||
dm.addr = p;
|
||||
|
@ -398,11 +398,11 @@ noasan inline void *_Mmap(void *addr, size_t size, int prot, int flags, int fd,
|
|||
if (needguard) {
|
||||
if (!IsWindows()) {
|
||||
// make windows fork() code simpler
|
||||
mprotect(p, GUARDSIZE, PROT_NONE);
|
||||
mprotect(p, APE_GUARDSIZE, PROT_NONE);
|
||||
}
|
||||
if (IsAsan()) {
|
||||
__repstosb((void *)(((intptr_t)p >> 3) + 0x7fff8000),
|
||||
kAsanStackOverflow, GUARDSIZE / 8);
|
||||
kAsanStackOverflow, APE_GUARDSIZE / 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,19 +41,10 @@ extern bool __isworker;
|
|||
|
||||
void mcount(void);
|
||||
int daemon(int, int);
|
||||
int _freestack(void *);
|
||||
void _bt(const char *, ...);
|
||||
int _cocmd(int, char **, char **);
|
||||
unsigned long getauxval(unsigned long);
|
||||
void *_mapanon(size_t) attributeallocsize((1)) mallocesque;
|
||||
void *_mapshared(size_t) attributeallocsize((1)) mallocesque;
|
||||
void *_mapstack(void) returnsaligned((FRAMESIZE)) mallocesque;
|
||||
int setjmp(jmp_buf)
|
||||
libcesque returnstwice paramsnonnull();
|
||||
void longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
|
||||
axdx_t setlongerjmp(jmp_buf)
|
||||
libcesque returnstwice paramsnonnull();
|
||||
void longerjmp(jmp_buf, intptr_t) libcesque wontreturn paramsnonnull();
|
||||
int _setjmp(jmp_buf)
|
||||
libcesque returnstwice paramsnonnull();
|
||||
int sigsetjmp(sigjmp_buf, int) libcesque returnstwice paramsnonnull();
|
||||
|
@ -62,8 +53,6 @@ void _longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
|
|||
void exit(int) wontreturn;
|
||||
void _exit(int) libcesque wontreturn;
|
||||
void _Exit(int) libcesque wontreturn;
|
||||
void _Exitr(int) libcesque wontreturn;
|
||||
void _Exit1(int) libcesque wontreturn;
|
||||
void quick_exit(int) wontreturn;
|
||||
void abort(void) wontreturn;
|
||||
int __cxa_atexit(void *, void *, void *) libcesque;
|
||||
|
@ -92,38 +81,61 @@ int vhangup(void);
|
|||
int getdtablesize(void);
|
||||
int sethostname(const char *, size_t);
|
||||
int acct(const char *);
|
||||
|
||||
#ifdef COSMO
|
||||
/* utilities */
|
||||
void _intsort(int *, size_t);
|
||||
void _longsort(long *, size_t);
|
||||
bool _isheap(void *);
|
||||
int NtGetVersion(void) pureconst;
|
||||
/* diagnostics */
|
||||
void ShowCrashReports(void);
|
||||
void __printargs(const char *);
|
||||
int _getcpucount(void) pureconst;
|
||||
long _missingno();
|
||||
void __oom_hook(size_t);
|
||||
void _loadxmm(void *);
|
||||
void _peekall(void);
|
||||
void _savexmm(void *);
|
||||
void _weakfree(void *);
|
||||
int _OpenExecutable(void);
|
||||
int ftrace_install(void);
|
||||
int ftrace_enabled(int);
|
||||
int strace_enabled(int);
|
||||
long _GetResourceLimit(int);
|
||||
void _bt(const char *, ...);
|
||||
void __print_maps(void);
|
||||
long _GetMaxFd(void);
|
||||
/* builtin shell language */
|
||||
int _cocmd(int, char **, char **);
|
||||
/* executable program */
|
||||
char *GetProgramExecutableName(void);
|
||||
char *GetInterpreterExecutableName(char *, size_t);
|
||||
void __printargs(const char *);
|
||||
void __paginate(int, const char *);
|
||||
int __arg_max(void);
|
||||
void __print_maps(void);
|
||||
void __warn_if_powersave(void);
|
||||
const char *__describe_os(void);
|
||||
int _OpenExecutable(void);
|
||||
bool _IsDynamicExecutable(const char *);
|
||||
/* execution control */
|
||||
int MakeProcessNice(void);
|
||||
axdx_t setlongerjmp(jmp_buf)
|
||||
libcesque returnstwice paramsnonnull();
|
||||
void longerjmp(jmp_buf, intptr_t) libcesque wontreturn paramsnonnull();
|
||||
void __warn_if_powersave(void);
|
||||
void _Exitr(int) libcesque wontreturn;
|
||||
void _Exit1(int) libcesque wontreturn;
|
||||
void _restorewintty(void);
|
||||
void __paginate(int, const char *);
|
||||
void _loadxmm(void *);
|
||||
void _savexmm(void *);
|
||||
long _missingno();
|
||||
/* memory management */
|
||||
void _weakfree(void *);
|
||||
void *_mapanon(size_t) attributeallocsize((1)) mallocesque;
|
||||
void *_mapshared(size_t) attributeallocsize((1)) mallocesque;
|
||||
void *_mapstack(void) returnsaligned((FRAMESIZE)) mallocesque;
|
||||
int _freestack(void *);
|
||||
void __oom_hook(size_t);
|
||||
void _peekall(void);
|
||||
bool _isheap(void *);
|
||||
/* portability */
|
||||
int NtGetVersion(void) pureconst;
|
||||
bool IsGenuineBlink(void);
|
||||
bool IsCygwin(void);
|
||||
const char *GetCpuidOs(void);
|
||||
const char *GetCpuidEmulator(void);
|
||||
void GetCpuidBrand(char[13], uint32_t);
|
||||
bool IsGenuineBlink(void);
|
||||
bool IsCygwin(void);
|
||||
long _GetResourceLimit(int);
|
||||
const char *__describe_os(void);
|
||||
int __arg_max(void);
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
|
||||
#define COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
|
||||
#include "ape/config.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nt/version.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
#ifdef COSMO
|
||||
|
||||
/**
|
||||
* Tunes APE stack maximum size.
|
||||
*
|
||||
* This defaults to `STACKSIZE`. The bottom-most page will be protected
|
||||
* to ensure your stack does not magically grow beyond this value. It's
|
||||
* possible to detect stack overflows, by calling `ShowCrashReports()`.
|
||||
* Your stack size must be a power of two; the linker will check this.
|
||||
* The bottom-most page will be protected to ensure your stack does not
|
||||
* magically grow beyond this value. It's possible to detect stack
|
||||
* overflows, by calling `ShowCrashReports()`. Your stack size must be a
|
||||
* power of two; the linker will check this.
|
||||
*
|
||||
* If you want to know how much stack your programs needs, then
|
||||
*
|
||||
|
@ -24,7 +21,7 @@
|
|||
* @see ape/ape.lds
|
||||
*/
|
||||
#define STATIC_STACK_SIZE(BYTES) \
|
||||
STATIC_SYMBOL("ape_stack_memsz", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)
|
||||
_STACK_SYMBOL("ape_stack_memsz", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)
|
||||
|
||||
/**
|
||||
* Tunes APE stack virtual address.
|
||||
|
@ -46,7 +43,7 @@
|
|||
* @see ape/ape.lds
|
||||
*/
|
||||
#define STATIC_STACK_ADDR(ADDR) \
|
||||
STATIC_SYMBOL("ape_stack_vaddr", _STACK_STRINGIFY(ADDR))
|
||||
_STACK_SYMBOL("ape_stack_vaddr", _STACK_STRINGIFY(ADDR))
|
||||
|
||||
/**
|
||||
* Makes program stack executable if declared, e.g.
|
||||
|
@ -63,11 +60,14 @@
|
|||
* printf("result %d should be 7\n", func());
|
||||
* }
|
||||
*/
|
||||
#define STATIC_EXEC_STACK() STATIC_SYMBOL("ape_stack_pf", "7")
|
||||
#define STATIC_EXEC_STACK() _STACK_SYMBOL("ape_stack_pf", "7")
|
||||
|
||||
#define _STACK_STRINGIFY(ADDR) #ADDR
|
||||
#define _STACK_SYMBOL(NAME, VALUE) \
|
||||
asm(".equ\t" NAME "," VALUE "\n\t" \
|
||||
".globl\t" NAME)
|
||||
|
||||
#if IsAsan()
|
||||
#ifdef __SANITIZE_ADDRESS__
|
||||
#define _STACK_EXTRA "*2"
|
||||
#else
|
||||
#define _STACK_EXTRA ""
|
||||
|
@ -125,7 +125,7 @@ extern char ape_stack_align[] __attribute__((__weak__));
|
|||
* Returns true if at least `n` bytes of stack are available.
|
||||
*/
|
||||
#define HaveStackMemory(n) \
|
||||
((intptr_t)__builtin_frame_address(0) >= GetStackAddr() + GUARDSIZE + (n))
|
||||
((intptr_t)__builtin_frame_address(0) >= GetStackAddr() + APE_GUARDSIZE + (n))
|
||||
|
||||
forceinline void CheckLargeStackAllocation(void *p, ssize_t n) {
|
||||
for (; n > 0; n -= 4096) {
|
||||
|
@ -133,6 +133,7 @@ forceinline void CheckLargeStackAllocation(void *p, ssize_t n) {
|
|||
}
|
||||
}
|
||||
|
||||
#endif /* COSMO */
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* GNU ELF */
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_SYMBOLS_H_
|
||||
#define COSMOPOLITAN_LIBC_SYMBOLS_H_
|
||||
#include "libc/intrin/bits.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define SYMBOLS_MAGIC READ32LE("SYMT")
|
||||
#define SYMBOLS_MAGIC 0x544d5953 /* SYMT */
|
||||
#define SYMBOLS_ABI 1
|
||||
|
||||
struct Symbol {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue