mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-04 18:28:30 +00:00
Improve documentation
The Cosmo API documentation page is pretty good now https://justine.lol/cosmopolitan/documentation.html
This commit is contained in:
parent
13437dd19b
commit
1bc3a25505
367 changed files with 2542 additions and 26178 deletions
|
@ -226,6 +226,7 @@ static noinline void smoothsort(
|
|||
* @param width is the size of each item
|
||||
* @param cmp is a callback returning <0, 0, or >0
|
||||
* @param arg will optionally be passed as the third argument to cmp
|
||||
* @see qsort()
|
||||
*/
|
||||
void qsort_r(void *base, size_t count, size_t width, cmpfun cmp, void *arg) {
|
||||
unsigned lp[12 * sizeof(unsigned)];
|
||||
|
@ -235,7 +236,12 @@ void qsort_r(void *base, size_t count, size_t width, cmpfun cmp, void *arg) {
|
|||
|
||||
/**
|
||||
* Sorts array.
|
||||
* @see qsort_r() for further details
|
||||
*
|
||||
* @param base points to an array to sort in-place
|
||||
* @param count is the item count
|
||||
* @param width is the size of each item
|
||||
* @param cmp is a callback returning <0, 0, or >0
|
||||
* @see qsort_r()
|
||||
*/
|
||||
void qsort(void *base, size_t count, size_t width,
|
||||
int cmp(const void *, const void *)) {
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/arraylist2.internal.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/arraylist2.internal.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
|
|
@ -166,7 +166,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
|
|||
│ cosmopolitan § bits » some assembly required ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
/**
|
||||
/*
|
||||
* Constraints for virtual machine flags.
|
||||
* @note we beseech clang devs for flag constraints
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
|
||||
/**
|
||||
* Returns string where empty string is made null.
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_MMINTRIN_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_MMINTRIN_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
typedef long long __m64 _Vector_size(8);
|
||||
typedef float __v2sf _Vector_size(8);
|
||||
typedef int __v2si _Vector_size(8);
|
||||
typedef short __v4hi _Vector_size(8);
|
||||
typedef char __v8qi _Vector_size(8);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_MMINTRIN_H_ */
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
|
||||
/**
|
||||
* Returns 𝑠 converting null to empty string.
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
|
||||
/**
|
||||
* Subtracts unsigned integers w/ wraparound.
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_XMMINTRIN_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_XMMINTRIN_H_
|
||||
#include "libc/bits/emmintrin.internal.h"
|
||||
#include "libc/bits/mmintrin.internal.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/dce.h"
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
* @param mode can be R_OK, W_OK, X_OK, F_OK
|
||||
* @return 0 if ok, or -1 and sets errno
|
||||
* @asyncsignalsafe
|
||||
* @syscall
|
||||
*/
|
||||
int access(const char *path, int mode) {
|
||||
char16_t path16[PATH_MAX];
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
/**
|
||||
* Sets current directory.
|
||||
* @asyncsignalsafe
|
||||
* @syscall
|
||||
*/
|
||||
int chdir(const char *path) {
|
||||
if (!path) return efault();
|
||||
|
|
|
@ -26,15 +26,15 @@
|
|||
/**
|
||||
* Changes permissions on file, e.g.:
|
||||
*
|
||||
* CHECK_NE(-1, chmod("foo/bar.txt", 0644));
|
||||
* CHECK_NE(-1, chmod("o/default/program.com", 0755));
|
||||
* CHECK_NE(-1, chmod("privatefolder/", 0700));
|
||||
* CHECK_NE(-1, chmod("foo/bar.txt", 0644));
|
||||
* CHECK_NE(-1, chmod("o/default/program.com", 0755));
|
||||
* CHECK_NE(-1, chmod("privatefolder/", 0700));
|
||||
*
|
||||
* The esoteric bits generally available on System Five are:
|
||||
*
|
||||
* CHECK_NE(-1, chmod("/opt/", 01000)); // sticky bit
|
||||
* CHECK_NE(-1, chmod("/usr/bin/sudo", 04755)); // setuid bit
|
||||
* CHECK_NE(-1, chmod("/usr/bin/wall", 02755)); // setgid bit
|
||||
* CHECK_NE(-1, chmod("/opt/", 01000)); // sticky bit
|
||||
* CHECK_NE(-1, chmod("/usr/bin/sudo", 04755)); // setuid bit
|
||||
* CHECK_NE(-1, chmod("/usr/bin/wall", 02755)); // setgid bit
|
||||
*
|
||||
* This works on Windows NT if you ignore the error ;-)
|
||||
*
|
||||
|
@ -43,6 +43,7 @@
|
|||
* @errors ENOENT, ENOTDIR, ENOSYS
|
||||
* @asyncsignalsafe
|
||||
* @see fchmod()
|
||||
* @syscall
|
||||
*/
|
||||
int chmod(const char *pathname, uint32_t mode) {
|
||||
if (!pathname) return efault();
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
* @see /etc/passwd for user ids
|
||||
* @see /etc/group for group ids
|
||||
* @asyncsignalsafe
|
||||
* @syscall
|
||||
*/
|
||||
int chown(const char *pathname, uint32_t uid, uint32_t gid) {
|
||||
if (!pathname) return efault();
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
* Returns how much CPU program has consumed on time-sharing system.
|
||||
*
|
||||
* @return value that can be divided by CLOCKS_PER_SEC, or -1 w/ errno
|
||||
* @see clock_gettime()
|
||||
*/
|
||||
int64_t clock(void) {
|
||||
struct timespec ts;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
|
@ -51,6 +51,7 @@
|
|||
* errno isn't restored to its original value, to detect prec. loss
|
||||
* @see strftime(), gettimeofday()
|
||||
* @asyncsignalsafe
|
||||
* @syscall
|
||||
*/
|
||||
int clock_gettime(int clockid, struct timespec *out_ts) {
|
||||
/* TODO(jart): Just ignore O/S for MONOTONIC and measure RDTSC on start */
|
||||
|
|
|
@ -28,8 +28,12 @@
|
|||
/**
|
||||
* Closes file descriptor.
|
||||
*
|
||||
* This function may be used for file descriptors returned by socket,
|
||||
* accept, epoll_create, and zipos file descriptors too.
|
||||
*
|
||||
* @return 0 on success, or -1 w/ errno
|
||||
* @asyncsignalsafe
|
||||
* @syscall
|
||||
*/
|
||||
int close(int fd) {
|
||||
int rc;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/errno.h"
|
||||
|
|
|
@ -23,12 +23,16 @@
|
|||
/**
|
||||
* Creates new file, returning open()'d file descriptor.
|
||||
*
|
||||
* This function is shorthand for:
|
||||
*
|
||||
* open(file, O_CREAT | O_WRONLY | O_TRUNC, mode)
|
||||
*
|
||||
* @param file is a UTF-8 string, which is truncated if it exists
|
||||
* @param mode is an octal user/group/other permission, e.g. 0755
|
||||
* @return a number registered with the system to track the open file,
|
||||
* which must be stored using a 64-bit type in order to support both
|
||||
* System V and Windows, and must be closed later on using close()
|
||||
* @see touch()
|
||||
* @see open(), touch()
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
nodiscard int creat(const char *file, uint32_t mode) {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "libc/calls/calls.h"
|
||||
|
||||
/**
|
||||
* Formats string directly to system i/o device.
|
||||
* Formats string directly to file descriptor.
|
||||
*/
|
||||
int(dprintf)(int fd, const char *fmt, ...) {
|
||||
int rc;
|
||||
|
|
|
@ -43,8 +43,8 @@ textwindows int dup$nt(int oldfd, int newfd, int flags) {
|
|||
return -1;
|
||||
}
|
||||
if (DuplicateHandle(GetCurrentProcess(), g_fds.p[oldfd].handle,
|
||||
GetCurrentProcess(), &g_fds.p[newfd].handle, 0,
|
||||
flags & O_CLOEXEC, kNtDuplicateSameAccess)) {
|
||||
GetCurrentProcess(), &g_fds.p[newfd].handle, 0, true,
|
||||
kNtDuplicateSameAccess)) {
|
||||
g_fds.p[newfd].kind = g_fds.p[oldfd].kind;
|
||||
g_fds.p[newfd].flags = flags;
|
||||
return newfd;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* @param fd remains open afterwards
|
||||
* @return some arbitrary new number for fd
|
||||
* @asyncsignalsafe
|
||||
* @syscall
|
||||
*/
|
||||
nodiscard int dup(int fd) {
|
||||
if (!IsWindows()) {
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
* unless it's equal to oldfd, in which case dup2() is a no-op
|
||||
* @return new file descriptor, or -1 w/ errno
|
||||
* @asyncsignalsafe
|
||||
* @syscall
|
||||
*/
|
||||
int dup2(int oldfd, int newfd) {
|
||||
if (oldfd == newfd) return newfd;
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
* @param newfd if already assigned, is silently closed beforehand;
|
||||
* unless it's equal to oldfd, in which case dup2() is a no-op
|
||||
* @flags can have O_CLOEXEC
|
||||
* @see dup(), dup2()
|
||||
* @syscall
|
||||
*/
|
||||
int dup3(int oldfd, int newfd, int flags) {
|
||||
if (oldfd == newfd) return einval();
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
* @param flags can be R_OK, W_OK, X_OK, F_OK
|
||||
* @return 0 if ok, or -1 and sets errno
|
||||
* @asyncsignalsafe
|
||||
* @syscall
|
||||
*/
|
||||
int faccessat(int dirfd, const char *path, int mode, uint32_t flags) {
|
||||
if (!path) return efault();
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
* @param len 0 means ‘til end of file
|
||||
* @param advice can be MADV_SEQUENTIAL, MADV_RANDOM, etc.
|
||||
* @return -1 on error
|
||||
* @syscall
|
||||
*/
|
||||
int fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
|
||||
if (!IsWindows()) {
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
* @param length is how much physical space to reserve / commit
|
||||
* @return 0 on success, or -1 w/ errno
|
||||
* @see ftruncate()
|
||||
* @syscall
|
||||
*/
|
||||
int fallocate(int fd, int32_t mode, int64_t offset, int64_t length) {
|
||||
int rc;
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
* @errors ENOSYS
|
||||
* @asyncsignalsafe
|
||||
* @see chmod()
|
||||
* @syscall
|
||||
*/
|
||||
int fchmod(int fd, uint32_t mode) {
|
||||
/* TODO(jart): Windows */
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
* @return 0 on success, or -1 w/ errno
|
||||
* @see /etc/passwd for user ids
|
||||
* @see /etc/group for group ids
|
||||
* @syscall
|
||||
*/
|
||||
int fchown(int fd, uint32_t uid, uint32_t gid) {
|
||||
/* TODO(jart): Windows? */
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
* @see /etc/passwd for user ids
|
||||
* @see /etc/group for group ids
|
||||
* @asyncsignalsafe
|
||||
* @syscall
|
||||
*/
|
||||
int fchownat(int dirfd, const char *pathname, uint32_t uid, uint32_t gid,
|
||||
uint32_t flags) {
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
* @param arg can be FD_CLOEXEC, etc. depending
|
||||
* @return 0 on success, or -1 w/ errno
|
||||
* @asyncsignalsafe
|
||||
* @syscall
|
||||
*/
|
||||
int fcntl(int fd, int cmd, ...) {
|
||||
va_list va;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* @return 0 on success, or -1 w/ errno
|
||||
* @see fsync(), sync_file_range()
|
||||
* @asyncsignalsafe
|
||||
* @syscall
|
||||
*/
|
||||
int fdatasync(int fd) {
|
||||
if (!IsWindows()) {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
|
||||
STATIC_YOINK("_init_g_fds");
|
||||
|
||||
struct Fds g_fds;
|
||||
hidden struct Fds g_fds;
|
||||
|
||||
void InitializeFileDescriptors(void) {
|
||||
hidden void InitializeFileDescriptors(void) {
|
||||
struct Fds *fds;
|
||||
fds = VEIL("r", &g_fds);
|
||||
pushmov(&fds->f, 3ul);
|
||||
|
|
|
@ -21,10 +21,6 @@
|
|||
#include "libc/nt/startupinfo.h"
|
||||
#include "libc/nt/struct/startupinfo.h"
|
||||
|
||||
/**
|
||||
* GetStartupInfo() singleton.
|
||||
* @see libc/runtime/winmain.c
|
||||
*/
|
||||
struct NtStartupInfo g_ntstartupinfo;
|
||||
hidden struct NtStartupInfo g_ntstartupinfo;
|
||||
|
||||
STATIC_YOINK("_init_g_ntstartupinfo");
|
||||
|
|
|
@ -21,10 +21,6 @@
|
|||
#include "libc/nt/struct/systeminfo.h"
|
||||
#include "libc/nt/systeminfo.h"
|
||||
|
||||
/**
|
||||
* GetSystemInfo() singleton.
|
||||
* @see libc/runtime/winmain.c
|
||||
*/
|
||||
struct NtSystemInfo g_ntsysteminfo;
|
||||
hidden struct NtSystemInfo g_ntsysteminfo;
|
||||
|
||||
STATIC_YOINK("_init_g_ntsysteminfo");
|
||||
|
|
|
@ -19,4 +19,4 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
|
||||
int g_sighandrvas[NSIG];
|
||||
hidden int g_sighandrvas[NSIG];
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/arraylist.internal.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/hefty/ntspawn.h"
|
||||
#include "libc/calls/internal.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
|
|
@ -68,7 +68,6 @@ hidden extern const struct NtSecurityAttributes kNtIsInheritable;
|
|||
ssize_t __getemptyfd(void) hidden;
|
||||
int __ensurefds(int) hidden;
|
||||
void __removefd(int) hidden;
|
||||
enum FdKind fdkind(int) hidden nosideeffect;
|
||||
bool __isfdopen(int) hidden nosideeffect;
|
||||
bool __isfdkind(int, enum FdKind) hidden nosideeffect;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
|
|
|
@ -19,4 +19,4 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
|
||||
const struct Fd kEmptyFd;
|
||||
hidden const struct Fd kEmptyFd;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "libc/nt/enum/processcreationflags.h"
|
||||
#include "libc/nt/enum/threadpriority.h"
|
||||
|
||||
const struct NtPriorityCombo kNtPriorityCombos[] = {
|
||||
hidden const struct NtPriorityCombo kNtPriorityCombos[] = {
|
||||
{-20, ffs(kNtHighPriorityClass), kNtThreadPriorityHighest, 15},
|
||||
{-18, ffs(kNtHighPriorityClass), kNtThreadPriorityTimeCritical, 15},
|
||||
{-17, ffs(kNtNormalPriorityClass), kNtThreadPriorityTimeCritical, 15},
|
||||
|
@ -54,4 +54,4 @@ const struct NtPriorityCombo kNtPriorityCombos[] = {
|
|||
{19, ffs(kNtIdlePriorityClass), kNtThreadPriorityIdle, 1},
|
||||
};
|
||||
|
||||
const unsigned kNtPriorityCombosLen = ARRAYLEN(kNtPriorityCombos);
|
||||
hidden const unsigned kNtPriorityCombosLen = ARRAYLEN(kNtPriorityCombos);
|
||||
|
|
|
@ -10,8 +10,8 @@ struct NtPriorityCombo {
|
|||
int8_t prio;
|
||||
};
|
||||
|
||||
extern const unsigned kNtPriorityCombosLen;
|
||||
extern const struct NtPriorityCombo kNtPriorityCombos[];
|
||||
hidden extern const unsigned kNtPriorityCombosLen;
|
||||
hidden extern const struct NtPriorityCombo kNtPriorityCombos[];
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "libc/nt/thunk/msabi.h"
|
||||
#include "libc/sysv/consts/nr.h"
|
||||
|
||||
extern __msabi typeof(VirtualProtect) *const __imp_VirtualProtect;
|
||||
|
||||
/**
|
||||
* Modifies restrictions on virtual memory address range.
|
||||
*
|
||||
|
@ -34,7 +36,6 @@
|
|||
* @see mmap()
|
||||
*/
|
||||
int mprotect(void *addr, uint64_t len, int prot) {
|
||||
extern __msabi typeof(VirtualProtect) *const __imp_VirtualProtect;
|
||||
bool cf;
|
||||
int64_t rc;
|
||||
uint32_t oldprot;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/sysv/consts/prio.h"
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/initializer.internal.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nexgen32e/rdtsc.h"
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/ntmagicpaths.internal.h"
|
||||
|
||||
const struct NtMagicPaths kNtMagicPaths = {
|
||||
hidden const struct NtMagicPaths kNtMagicPaths = {
|
||||
#define TAB(NAME, STRING) STRING,
|
||||
#include "libc/calls/ntmagicpaths.inc"
|
||||
#undef TAB
|
||||
|
|
|
@ -9,7 +9,7 @@ struct NtMagicPaths {
|
|||
#undef TAB
|
||||
};
|
||||
|
||||
extern const struct NtMagicPaths kNtMagicPaths;
|
||||
hidden extern const struct NtMagicPaths kNtMagicPaths;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -17,19 +17,21 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/nt/privilege.h"
|
||||
#include "libc/nt/struct/tokenprivileges.h"
|
||||
#include "libc/calls/internal.h"
|
||||
|
||||
/**
|
||||
* Sets NT permission thing, e.g.
|
||||
*
|
||||
* int64_t htoken;
|
||||
* if (OpenProcessToken(GetCurrentProcess(),
|
||||
* kNtTokenAdjustPrivileges | kNtTokenQuery, &htoken)) {
|
||||
* ntsetprivilege(htoken, u"SeManageVolumePrivilege", kNtSePrivilegeEnabled);
|
||||
* CloseHandle(htoken);
|
||||
* }
|
||||
* int64_t htoken;
|
||||
* if (OpenProcessToken(GetCurrentProcess(),
|
||||
* kNtTokenAdjustPrivileges | kNtTokenQuery,
|
||||
* &htoken)) {
|
||||
* ntsetprivilege(htoken, u"SeManageVolumePrivilege",
|
||||
* kNtSePrivilegeEnabled);
|
||||
* CloseHandle(htoken);
|
||||
* }
|
||||
*/
|
||||
textwindows bool32 ntsetprivilege(int64_t token, const char16_t *name,
|
||||
uint32_t attrs) {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/iovec.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/iovec.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/kntprioritycombos.internal.h"
|
||||
#include "libc/nt/process.h"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/sysinfo.h"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_TERMIOS_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_TERMIOS_INTERNAL_H_
|
||||
#ifndef __STRICT_ANSI__
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/struct/metatermios.internal.h"
|
||||
#include "libc/calls/struct/termios.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "libc/calls/internal.h"
|
||||
#include "libc/nt/struct/securityattributes.h"
|
||||
|
||||
const struct NtSecurityAttributes kNtIsInheritable = {
|
||||
hidden const struct NtSecurityAttributes kNtIsInheritable = {
|
||||
sizeof(struct NtSecurityAttributes),
|
||||
NULL,
|
||||
true,
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/dns/dns.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dns/dns.h"
|
||||
#include "libc/dns/hoststxt.h"
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/pushpop.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/dns/hoststxt.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "libc/elf/struct/phdr.h"
|
||||
#include "libc/elf/struct/shdr.h"
|
||||
#include "libc/elf/struct/sym.h"
|
||||
#include "libc/runtime/ezmap.h"
|
||||
#include "libc/runtime/ezmap.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
.source __FILE__
|
||||
|
||||
/ Embeds ASCII names for errno constants into binary.
|
||||
/
|
||||
/ @see libc/sysv/consts.sh
|
||||
.section .rodata,"aS",@progbits
|
||||
kErrnoNames:
|
||||
/ <SORTED-ORDER-C>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/time/time.h"
|
||||
|
||||
const unsigned short kMonthYearDay[2][12] = {
|
||||
hidden const unsigned short kMonthYearDay[2][12] = {
|
||||
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
|
||||
{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335},
|
||||
};
|
||||
|
|
|
@ -91,27 +91,27 @@ static int ppatoi(const char **str) {
|
|||
*
|
||||
* Precision Modifiers
|
||||
*
|
||||
* - `%.8s` supplied byte length (obeys nul terminator)
|
||||
* - `%.*s` supplied byte length argument (obeys nul terminator)
|
||||
* - `%`.*s` supplied byte length argument c escaped (ignores nul terminator)
|
||||
* - `%#.*s` supplied byte length argument visualized (ignores nul terminator)
|
||||
* - `%.*hs` supplied char16_t length argument (obeys nul terminator)
|
||||
* - `%.*ls` supplied wchar_t length argument (obeys nul terminator)
|
||||
* - `%.8s` supplied byte length (obeys nul terminator)
|
||||
* - `%.*s` supplied byte length argument (obeys nul terminator)
|
||||
* - ``%`.*s`` supplied byte length argument c escaped (ignores nul term)
|
||||
* - `%#.*s` supplied byte length argument visualized (ignores nul term)
|
||||
* - `%.*hs` supplied char16_t length argument (obeys nul terminator)
|
||||
* - `%.*ls` supplied wchar_t length argument (obeys nul terminator)
|
||||
*
|
||||
* Formatting Modifiers
|
||||
*
|
||||
* - `%,d` thousands separators
|
||||
* - `%'s` escaped c string literal
|
||||
* - `%`c` c escaped character
|
||||
* - `%`'c` c escaped character quoted
|
||||
* - `%`s` c escaped string
|
||||
* - `%`'s` c escaped string quoted
|
||||
* - `%`s` escaped double quoted c string literal
|
||||
* - `%`c` escaped double quoted c character literal
|
||||
* - `%+d` plus leftpad if positive (aligns w/ negatives)
|
||||
* - `% d` space leftpad if positive (aligns w/ negatives)
|
||||
* - `%#s` datum (radix 256 null-terminated ibm cp437)
|
||||
* - `%#x` int (radix 16 hexadecimal w/ 0x prefix if not zero)
|
||||
* - `%,d` thousands separators
|
||||
* - `%'s` escaped c string literal
|
||||
* - ``%`c`` c escaped character
|
||||
* - ``%`'c`` c escaped character quoted
|
||||
* - ``%`s`` c escaped string
|
||||
* - ``%`'s`` c escaped string quoted
|
||||
* - ``%`s`` escaped double quoted c string literal
|
||||
* - ``%`c`` escaped double quoted c character literal
|
||||
* - `%+d` plus leftpad if positive (aligns w/ negatives)
|
||||
* - `% d` space leftpad if positive (aligns w/ negatives)
|
||||
* - `%#s` datum (radix 256 null-terminated ibm cp437)
|
||||
* - `%#x` int (radix 16 hexadecimal w/ 0x prefix if not zero)
|
||||
*
|
||||
* @note implementation detail of printf(), snprintf(), etc.
|
||||
* @see printf() for wordier documentation
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
int spacepad(int(long, void *), void *, unsigned long) hidden;
|
||||
int ftoa(int(long, void *), void *, long double, int, unsigned long,
|
||||
int spacepad(int (*)(long, void *), void *, unsigned long) hidden;
|
||||
int ftoa(int (*)(long, void *), void *, long double, int, unsigned long,
|
||||
unsigned long) hidden;
|
||||
int stoa(int(long, void *), void *, void *, unsigned long, unsigned long,
|
||||
int stoa(int (*)(long, void *), void *, void *, unsigned long, unsigned long,
|
||||
unsigned long, unsigned char, unsigned char) hidden;
|
||||
int ntoa(int(long, void *), void *, va_list, unsigned char, unsigned long,
|
||||
int ntoa(int (*)(long, void *), void *, va_list, unsigned char, unsigned long,
|
||||
unsigned long, unsigned long, unsigned char, const char *) hidden;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/limits.h"
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
forceinline long LinuxMmap(void *addr, size_t size, long prot, long flags,
|
||||
long fd, long off) {
|
||||
long rc;
|
||||
register long r10 asm("r10") = flags;
|
||||
register long r8 asm("r8") = fd;
|
||||
register long r9 asm("r9") = off;
|
||||
asm volatile("syscall"
|
||||
asm volatile("mov\t%5,%%r10\n\t"
|
||||
"mov\t%6,%%r8\n\t"
|
||||
"mov\t%7,%%r9\n\t"
|
||||
"syscall"
|
||||
: "=a"(rc)
|
||||
: "0"(9), "D"(addr), "S"(size), "d"(prot), "r"(r10), "r"(r8),
|
||||
"r"(r9)
|
||||
: "rcx", "r11", "memory");
|
||||
: "0"(9), "D"(addr), "S"(size), "d"(prot), "g"(flags), "g"(fd),
|
||||
"g"(off)
|
||||
: "rcx", "r8", "r9", "r10", "r11", "memory");
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
|
@ -44,13 +44,13 @@ STATIC_YOINK("_init_asan");
|
|||
* so it can emit fast code, that checks the validity of each memory op
|
||||
* with byte granularity, by probing shadow memory.
|
||||
*
|
||||
* AddressSanitizer dedicates one-eighth of the virtual address space
|
||||
* - AddressSanitizer dedicates one-eighth of the virtual address space
|
||||
* to its shadow memory and uses a direct mapping with a scale and
|
||||
* offset to translate an application address to its corresponding
|
||||
* shadow address. Given the application memory address Addr, the
|
||||
* address of the shadow byte is computed as (Addr>>3)+Offset."
|
||||
*
|
||||
* We use the following encoding for each shadow byte: 0 means that
|
||||
* - We use the following encoding for each shadow byte: 0 means that
|
||||
* all 8 bytes of the corresponding application memory region are
|
||||
* addressable; k (1 ≤ k ≤ 7) means that the first k bytes are
|
||||
* addressible; any negative value indicates that the entire 8-byte
|
||||
|
@ -60,11 +60,11 @@ STATIC_YOINK("_init_asan");
|
|||
*
|
||||
* Here's what the generated code looks like for 64-bit reads:
|
||||
*
|
||||
* movq %addr,%tmp
|
||||
* shrq $3,%tmp
|
||||
* cmpb $0,0x7fff8000(%tmp)
|
||||
* jnz abort
|
||||
* movq (%addr),%dst
|
||||
* movq %addr,%tmp
|
||||
* shrq $3,%tmp
|
||||
* cmpb $0,0x7fff8000(%tmp)
|
||||
* jnz abort
|
||||
* movq (%addr),%dst
|
||||
*/
|
||||
|
||||
#define HOOK(HOOK, IMPL) \
|
||||
|
@ -142,7 +142,6 @@ static const char *__asan_describe_access_poison(int c) {
|
|||
case kAsanUnscoped:
|
||||
return "unscoped";
|
||||
default:
|
||||
DebugBreak();
|
||||
return "poisoned";
|
||||
}
|
||||
}
|
||||
|
@ -399,9 +398,8 @@ void __asan_map_shadow(void *p, size_t n) {
|
|||
b = ROUNDUP(SHADOW(ROUNDUP((uintptr_t)p + n, 8)), 1 << 16) >> 16;
|
||||
for (; a < b; ++a) {
|
||||
if (!__asan_is_mapped(a)) {
|
||||
sm = DirectMap((void *)((uintptr_t)a << 16), 1 << 16,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
|
||||
sm = __mmap((void *)((uintptr_t)a << 16), 1 << 16, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
|
||||
if (sm.addr == MAP_FAILED ||
|
||||
TrackMemoryInterval(&_mmi, a, a, sm.maphandle, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED) == -1) {
|
||||
|
@ -412,7 +410,8 @@ void __asan_map_shadow(void *p, size_t n) {
|
|||
}
|
||||
|
||||
static char *__asan_get_stack_base(void) {
|
||||
register uintptr_t rsp asm("rsp");
|
||||
uintptr_t rsp;
|
||||
asm("mov\t%%rsp,%0" : "=r"(rsp));
|
||||
return (char *)ROUNDDOWN(ROUNDDOWN(rsp, STACKSIZE), FRAMESIZE);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/hefty/spawn.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/bisectcarleft.internal.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/hefty/spawn.h"
|
||||
|
|
|
@ -41,15 +41,15 @@
|
|||
* It's a common antipattern to check isatty(STDERR_FILENO), since that
|
||||
* usually makes colors harder to get than they are to remove:
|
||||
*
|
||||
* sed 's/\x1b\[[;[:digit:]]*m//g' <color.txt >uncolor.txt
|
||||
* sed 's/\x1b\[[;[:digit:]]*m//g' <color.txt >uncolor.txt
|
||||
*
|
||||
* Ideally, all software should be updated to understand color, since
|
||||
* it's been formally standardized nearly as long as ASCII. Even old
|
||||
* MS-DOS supports it (but Windows didn't until Windows 10) yet even
|
||||
* tools like less may need wrapper scripts, e.g.:
|
||||
*
|
||||
* #!/bin/sh
|
||||
* LESSCHARSET=UTF-8 exec /usr/bin/less -RS "$@"
|
||||
* #!/bin/sh
|
||||
* LESSCHARSET=UTF-8 exec /usr/bin/less -RS "$@"
|
||||
*
|
||||
* It's that easy fam.
|
||||
*/
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
|
|
@ -26,7 +26,9 @@
|
|||
#include "libc/sysv/consts/fileno.h"
|
||||
|
||||
/**
|
||||
* Aborts process after printing details on its current state.
|
||||
* Aborts process after printing a backtrace.
|
||||
*
|
||||
* If a debugger is present then this will trigger a breakpoint.
|
||||
*/
|
||||
relegated wontreturn void __die(void) {
|
||||
static bool once;
|
||||
|
|
|
@ -44,12 +44,12 @@ int attachdebugger(intptr_t);
|
|||
({ \
|
||||
int64_t WaAx; \
|
||||
if (!IsWindows()) { \
|
||||
register void *Reg10 asm("r10") = (OPT_OUT_RUSAGE); \
|
||||
asm volatile("syscall" \
|
||||
asm volatile("mov\t%5,%%r10\n\t" \
|
||||
"syscall" \
|
||||
: "=a"(WaAx) \
|
||||
: "0"(__NR_wait4), "D"(PID), "S"(OPT_OUT_WSTATUS), \
|
||||
"d"(OPTIONS), "r"(Reg10) \
|
||||
: "rcx", "r11", "cc", "memory"); \
|
||||
"d"(OPTIONS), "g"(OPT_OUT_RUSAGE) \
|
||||
: "rcx", "r10", "r11", "cc", "memory"); \
|
||||
} else { \
|
||||
WaAx = wait4$nt(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE); \
|
||||
} \
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/hefty/spawn.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
|
|
|
@ -19,4 +19,4 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/log/gdb.h"
|
||||
|
||||
volatile int g_gdbsync;
|
||||
volatile int g_gdbsync hidden;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/termios.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -64,8 +64,8 @@ static const char kGodHatesFlags[12] forcealign(1) = "CVPRAKZSTIDO";
|
|||
static const char kCrashSigNames[8][5] forcealign(1) = {
|
||||
"QUIT", "FPE", "ILL", "SEGV", "TRAP", "ABRT", "BUS"};
|
||||
|
||||
int kCrashSigs[8];
|
||||
struct sigaction g_oldcrashacts[8];
|
||||
hidden int kCrashSigs[8];
|
||||
hidden struct sigaction g_oldcrashacts[8];
|
||||
|
||||
relegated static const char *TinyStrSignal(int sig) {
|
||||
size_t i;
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
#include "libc/math/math.h"
|
||||
|
||||
double fmax(double x, double y)
|
||||
{
|
||||
if (isnan(x))
|
||||
return y;
|
||||
if (isnan(y))
|
||||
return x;
|
||||
/* handle signed zeros, see C99 Annex F.9.9.2 */
|
||||
if (signbit(x) != signbit(y))
|
||||
return signbit(x) ? y : x;
|
||||
return x < y ? y : x;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
#include "libc/math/math.h"
|
||||
|
||||
float fmaxf(float x, float y)
|
||||
{
|
||||
if (isnan(x))
|
||||
return y;
|
||||
if (isnan(y))
|
||||
return x;
|
||||
/* handle signed zeroes, see C99 Annex F.9.9.2 */
|
||||
if (signbit(x) != signbit(y))
|
||||
return signbit(x) ? y : x;
|
||||
return x < y ? y : x;
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
#include "libc/math/math.h"
|
||||
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double fmaxl(long double x, long double y)
|
||||
{
|
||||
return fmax(x, y);
|
||||
}
|
||||
#else
|
||||
long double fmaxl(long double x, long double y)
|
||||
{
|
||||
if (isnan(x))
|
||||
return y;
|
||||
if (isnan(y))
|
||||
return x;
|
||||
/* handle signed zeros, see C99 Annex F.9.9.2 */
|
||||
if (signbit(x) != signbit(y))
|
||||
return signbit(x) ? y : x;
|
||||
return x < y ? y : x;
|
||||
}
|
||||
#endif
|
|
@ -1,13 +0,0 @@
|
|||
#include "libc/math/math.h"
|
||||
|
||||
double fmin(double x, double y)
|
||||
{
|
||||
if (isnan(x))
|
||||
return y;
|
||||
if (isnan(y))
|
||||
return x;
|
||||
/* handle signed zeros, see C99 Annex F.9.9.2 */
|
||||
if (signbit(x) != signbit(y))
|
||||
return signbit(x) ? x : y;
|
||||
return x < y ? x : y;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
#include "libc/math/math.h"
|
||||
|
||||
float fminf(float x, float y)
|
||||
{
|
||||
if (isnan(x))
|
||||
return y;
|
||||
if (isnan(y))
|
||||
return x;
|
||||
/* handle signed zeros, see C99 Annex F.9.9.2 */
|
||||
if (signbit(x) != signbit(y))
|
||||
return signbit(x) ? x : y;
|
||||
return x < y ? x : y;
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
#include "libc/math/math.h"
|
||||
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double fminl(long double x, long double y)
|
||||
{
|
||||
return fmin(x, y);
|
||||
}
|
||||
#else
|
||||
long double fminl(long double x, long double y)
|
||||
{
|
||||
if (isnan(x))
|
||||
return y;
|
||||
if (isnan(y))
|
||||
return x;
|
||||
/* handle signed zeros, see C99 Annex F.9.9.2 */
|
||||
if (signbit(x) != signbit(y))
|
||||
return signbit(x) ? x : y;
|
||||
return x < y ? x : y;
|
||||
}
|
||||
#endif
|
|
@ -20,24 +20,19 @@
|
|||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/buffer.h"
|
||||
|
||||
/* TODO(jart): Delete */
|
||||
|
||||
#define kGuard PAGESIZE
|
||||
#define kGrain FRAMESIZE
|
||||
|
||||
/**
|
||||
* Allocates page-guarded buffer.
|
||||
*
|
||||
* ┌─────────────────────────────────────┬s─i─g─s─e─g─v┐
|
||||
* │ 𝑣₀..𝑣ₙ₋₁ │𝑣ₙ..𝑣ₙ₊₄₀₉₆₋₁│
|
||||
* └─────────────────────────────────────┴s─i─g─s─e─g─v┘
|
||||
*
|
||||
* @param b is metadata object owned by caller, initialized to zero for
|
||||
* first call; subsequent calls will resize
|
||||
* @param a is alignment requirement in bytes, e.g. 1,2,4,8,16,...
|
||||
* @param n is buffer size in bytes
|
||||
* @return b->p
|
||||
* @see ralloc()
|
||||
* @deprecated
|
||||
*/
|
||||
void *balloc(struct GuardedBuffer *b, unsigned a, size_t n) {
|
||||
return (b->p = memalign(a, n));
|
||||
|
|
|
@ -22,8 +22,10 @@
|
|||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/buffer.h"
|
||||
|
||||
/* TODO(jart): Delete */
|
||||
|
||||
/**
|
||||
* Frees memory return by balloc().
|
||||
* @deprecated
|
||||
*/
|
||||
void bfree(struct GuardedBuffer *b) {
|
||||
free(b->p);
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
|
||||
/ Frees memory the C++ way.
|
||||
/
|
||||
/ @param %rdi is pointer, or NULL for no-op
|
||||
/ @param %rsi is ignored
|
||||
/ @param %rdx is ignored
|
||||
/ \param %rdi is pointer, or NULL for no-op
|
||||
/ \param %rsi is ignored
|
||||
/ \param %rdx is ignored
|
||||
_ZdlPvSt11align_val_tRKSt9nothrow_t:
|
||||
/ operator delete(void*, std::align_val_t, std::nothrow_t const&)
|
||||
nop
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
|
||||
/ Allocates memory the C++ way.
|
||||
/
|
||||
/ @param %rdi is bytes to allocate
|
||||
/ @param %rsi is ignored
|
||||
/ @return new memory or NULL on OOM
|
||||
/ \param %rdi is bytes to allocate
|
||||
/ \param %rsi is ignored
|
||||
/ \return new memory or NULL on OOM
|
||||
_ZnamRKSt9nothrow_t:
|
||||
/ operator new[](unsigned long, std::nothrow_t const&)
|
||||
nop
|
||||
|
|
|
@ -22,10 +22,10 @@
|
|||
|
||||
/ Allocates aligned memory the C++ way.
|
||||
/
|
||||
/ @param %rdi is bytes to allocate
|
||||
/ @param %rsi is byte alignment
|
||||
/ @param %rdx is ignored
|
||||
/ @return new memory or NULL on OOM
|
||||
/ \param %rdi is bytes to allocate
|
||||
/ \param %rsi is byte alignment
|
||||
/ \param %rdx is ignored
|
||||
/ \return new memory or NULL on OOM
|
||||
_ZnamSt11align_val_tRKSt9nothrow_t:
|
||||
/ operator new[](unsigned long, std::align_val_t, std::nothrow_t const&)
|
||||
nop
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
int PutEnvImpl(char *string, bool overwrite) hidden;
|
||||
int PutEnvImpl(char *, bool) hidden;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -36,12 +36,12 @@
|
|||
/
|
||||
/ Please note that p is NOT free()'d should realloc() fail, thus:
|
||||
/
|
||||
/ if ((p2 = realloc(p, n2))) {
|
||||
/ p = p2;
|
||||
/ ...
|
||||
/ } else {
|
||||
/ ...
|
||||
/ }
|
||||
/ if ((p2 = realloc(p, n2))) {
|
||||
/ p = p2;
|
||||
/ ...
|
||||
/ } else {
|
||||
/ ...
|
||||
/ }
|
||||
/
|
||||
/ if n is for fewer bytes than already held by p, the newly unused
|
||||
/ space is lopped off and freed if possible.
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Allocates copy of wide string.
|
||||
*/
|
||||
wchar_t *wcsdup(const wchar_t *s) {
|
||||
size_t len = wcslen(s);
|
||||
char *s2 = malloc(len * sizeof(wchar_t) + 1);
|
||||
|
|
|
@ -19,6 +19,23 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/bsf.h"
|
||||
|
||||
/**
|
||||
* Returns position of first bit set.
|
||||
*
|
||||
* ctz(𝑥) 31^clz(𝑥) clz(𝑥)
|
||||
* uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
|
||||
* 0x00000000 wut 32 0 wut 32
|
||||
* 0x00000001 0 0 1 0 31
|
||||
* 0x80000001 0 0 1 31 0
|
||||
* 0x80000000 31 31 32 31 0
|
||||
* 0x00000010 4 4 5 4 27
|
||||
* 0x08000010 4 4 5 27 4
|
||||
* 0x08000000 27 27 28 27 4
|
||||
* 0xffffffff 0 0 1 31 0
|
||||
*
|
||||
* @param x is a 32-bit integer
|
||||
* @return number in range 0..31 or undefined if 𝑥 is 0
|
||||
*/
|
||||
int(bsf)(int x) {
|
||||
return bsf(x);
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue