mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
sync and try changes
This commit is contained in:
commit
dbd7edba10
811 changed files with 2014 additions and 11694 deletions
5
.vscode/vscode.h
vendored
5
.vscode/vscode.h
vendored
|
@ -1,4 +1,8 @@
|
||||||
|
#define __VSCODE_INTELLISENSE__ 1
|
||||||
|
#define __LP64__ /* TODO: this is a lazy kludge */
|
||||||
|
#include "libc/integral/normalize.inc"
|
||||||
|
|
||||||
|
#if 0
|
||||||
#define __VSCODE_INTELLISENSE__ 1
|
#define __VSCODE_INTELLISENSE__ 1
|
||||||
#define __BIGGEST_ALIGNMENT__ 1
|
#define __BIGGEST_ALIGNMENT__ 1
|
||||||
#define __CHAR_MAX__ 0x7F
|
#define __CHAR_MAX__ 0x7F
|
||||||
|
@ -161,3 +165,4 @@ typedef struct { int ax, dx; } axdx_t;
|
||||||
#endif /* UriKeyval */
|
#endif /* UriKeyval */
|
||||||
|
|
||||||
#define _Static_assert(...) 0
|
#define _Static_assert(...) 0
|
||||||
|
#endif /* 0 */
|
||||||
|
|
10
Makefile
10
Makefile
|
@ -135,7 +135,6 @@ include dsp/tty/tty.mk # ├──ONLINE RUNTIME
|
||||||
include libc/dns/dns.mk # │ You can communicate with the network
|
include libc/dns/dns.mk # │ You can communicate with the network
|
||||||
include libc/crypto/crypto.mk # │
|
include libc/crypto/crypto.mk # │
|
||||||
include net/http/http.mk #─┘
|
include net/http/http.mk #─┘
|
||||||
include third_party/lemon/lemon.mk
|
|
||||||
include third_party/duktape/duktape.mk
|
include third_party/duktape/duktape.mk
|
||||||
include third_party/regex/regex.mk
|
include third_party/regex/regex.mk
|
||||||
include third_party/third_party.mk
|
include third_party/third_party.mk
|
||||||
|
@ -149,7 +148,6 @@ include third_party/chibicc/test/test.mk
|
||||||
include tool/build/emucrt/emucrt.mk
|
include tool/build/emucrt/emucrt.mk
|
||||||
include tool/build/emubin/emubin.mk
|
include tool/build/emubin/emubin.mk
|
||||||
include tool/build/build.mk
|
include tool/build/build.mk
|
||||||
include tool/calc/calc.mk
|
|
||||||
include tool/decode/lib/decodelib.mk
|
include tool/decode/lib/decodelib.mk
|
||||||
include tool/decode/decode.mk
|
include tool/decode/decode.mk
|
||||||
include tool/hash/hash.mk
|
include tool/hash/hash.mk
|
||||||
|
@ -328,6 +326,14 @@ o/cosmopolitan.html: \
|
||||||
-fno-common -include libc/integral/normalize.inc -o $@ \
|
-fno-common -include libc/integral/normalize.inc -o $@ \
|
||||||
$(filter-out %.s,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_SRCS)))
|
$(filter-out %.s,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_SRCS)))
|
||||||
|
|
||||||
|
$(SRCS): \
|
||||||
|
libc/integral/normalize.inc \
|
||||||
|
libc/integral/c.inc \
|
||||||
|
libc/integral/cxx.inc \
|
||||||
|
libc/integral/cxxtypescompat.inc \
|
||||||
|
libc/integral/lp64arg.inc \
|
||||||
|
libc/integral/lp64.inc
|
||||||
|
|
||||||
# UNSPECIFIED PREREQUISITES TUTORIAL
|
# UNSPECIFIED PREREQUISITES TUTORIAL
|
||||||
#
|
#
|
||||||
# A build rule must exist for all files that make needs to consider in
|
# A build rule must exist for all files that make needs to consider in
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
![Cosmopolitan Honeybadger](usr/share/img/honeybadger.png)
|
||||||
|
|
||||||
# Cosmopolitan
|
# Cosmopolitan
|
||||||
|
|
||||||
[Cosmopolitan Libc](https://justine.lol/cosmopolitan/index.html) makes C
|
[Cosmopolitan Libc](https://justine.lol/cosmopolitan/index.html) makes C
|
||||||
|
|
|
@ -663,7 +663,7 @@ ape.macho:
|
||||||
.quad 0 # r13
|
.quad 0 # r13
|
||||||
.quad 0 # r14
|
.quad 0 # r14
|
||||||
.quad 0 # r15
|
.quad 0 # r15
|
||||||
.quad _start_xnu # rip
|
.quad _xnu # rip
|
||||||
.quad 0 # rflags
|
.quad 0 # rflags
|
||||||
.quad 0 # cs
|
.quad 0 # cs
|
||||||
.quad 0 # fs
|
.quad 0 # fs
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/**
|
/**
|
||||||
* Divides integer in half w/ rounding.
|
* Divides integer in half w/ rounding.
|
||||||
*/
|
*/
|
||||||
#define HALF(X) (((X) + 1) / (2 / TYPE_INTEGRAL(typeof(X))))
|
#define HALF(X) (((X) + 1) / 2)
|
||||||
|
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
#endif /* COSMOPOLITAN_DSP_CORE_HALF_H_ */
|
#endif /* COSMOPOLITAN_DSP_CORE_HALF_H_ */
|
||||||
|
|
|
@ -41,6 +41,7 @@ EXAMPLES_PACKAGE_OBJS = \
|
||||||
# Note that linking stubs is always a good idea due to synthetic code.
|
# Note that linking stubs is always a good idea due to synthetic code.
|
||||||
EXAMPLES_PACKAGE_DIRECTDEPS = \
|
EXAMPLES_PACKAGE_DIRECTDEPS = \
|
||||||
EXAMPLES_PACKAGE_LIB \
|
EXAMPLES_PACKAGE_LIB \
|
||||||
|
LIBC_INTRIN \
|
||||||
LIBC_STDIO \
|
LIBC_STDIO \
|
||||||
LIBC_STUBS \
|
LIBC_STUBS \
|
||||||
LIBC_TINYMATH
|
LIBC_TINYMATH
|
||||||
|
|
|
@ -70,6 +70,7 @@ EXAMPLES_PACKAGE_LIB_A_CHECKS = \
|
||||||
# Note that linking stubs is always a good idea due to synthetic code.
|
# Note that linking stubs is always a good idea due to synthetic code.
|
||||||
EXAMPLES_PACKAGE_LIB_A_DIRECTDEPS = \
|
EXAMPLES_PACKAGE_LIB_A_DIRECTDEPS = \
|
||||||
LIBC_STDIO \
|
LIBC_STDIO \
|
||||||
|
LIBC_INTRIN \
|
||||||
LIBC_NEXGEN32E \
|
LIBC_NEXGEN32E \
|
||||||
LIBC_STUBS
|
LIBC_STUBS
|
||||||
|
|
||||||
|
|
|
@ -13,17 +13,17 @@ extern const uint8_t kReverseBits[256];
|
||||||
|
|
||||||
uint32_t gray(uint32_t) pureconst;
|
uint32_t gray(uint32_t) pureconst;
|
||||||
uint32_t ungray(uint32_t) pureconst;
|
uint32_t ungray(uint32_t) pureconst;
|
||||||
|
|
||||||
uint8_t bitreverse8(uint8_t) libcesque pureconst;
|
uint8_t bitreverse8(uint8_t) libcesque pureconst;
|
||||||
uint16_t bitreverse16(uint16_t) libcesque pureconst;
|
uint16_t bitreverse16(uint16_t) libcesque pureconst;
|
||||||
uint32_t bitreverse32(uint32_t) libcesque pureconst;
|
uint32_t bitreverse32(uint32_t) libcesque pureconst;
|
||||||
uint64_t bitreverse64(uint64_t) libcesque pureconst;
|
uint64_t bitreverse64(uint64_t) libcesque pureconst;
|
||||||
|
|
||||||
unsigned long roundup2pow(unsigned long) libcesque pureconst;
|
unsigned long roundup2pow(unsigned long) libcesque pureconst;
|
||||||
unsigned long roundup2log(unsigned long) libcesque pureconst;
|
unsigned long roundup2log(unsigned long) libcesque pureconst;
|
||||||
unsigned long rounddown2pow(unsigned long) libcesque pureconst;
|
unsigned long rounddown2pow(unsigned long) libcesque pureconst;
|
||||||
|
|
||||||
unsigned long hamming(unsigned long, unsigned long) pureconst;
|
unsigned long hamming(unsigned long, unsigned long) pureconst;
|
||||||
|
intptr_t lockxchg(void *, void *, size_t);
|
||||||
|
bool cmpxchg(void *, intptr_t, intptr_t, size_t);
|
||||||
|
bool lockcmpxchg(void *, intptr_t, intptr_t, size_t);
|
||||||
|
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § bits » no assembly required ─╬─│┼
|
│ cosmopolitan § bits » no assembly required ─╬─│┼
|
||||||
|
@ -70,38 +70,6 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
|
||||||
(uint64_t)((unsigned char *)(S))[6] << 010 | \
|
(uint64_t)((unsigned char *)(S))[6] << 010 | \
|
||||||
(uint64_t)((unsigned char *)(S))[7] << 000)
|
(uint64_t)((unsigned char *)(S))[7] << 000)
|
||||||
|
|
||||||
#define read16le(S) \
|
|
||||||
({ \
|
|
||||||
unsigned char *Str = (unsigned char *)(S); \
|
|
||||||
READ16LE(Str); \
|
|
||||||
})
|
|
||||||
#define read32le(S) \
|
|
||||||
({ \
|
|
||||||
unsigned char *Str = (unsigned char *)(S); \
|
|
||||||
READ32LE(Str); \
|
|
||||||
})
|
|
||||||
#define read64le(S) \
|
|
||||||
({ \
|
|
||||||
unsigned char *Str = (unsigned char *)(S); \
|
|
||||||
READ64LE(Str); \
|
|
||||||
})
|
|
||||||
|
|
||||||
#define read16be(S) \
|
|
||||||
({ \
|
|
||||||
unsigned char *Str = (unsigned char *)(S); \
|
|
||||||
READ16BE(Str); \
|
|
||||||
})
|
|
||||||
#define read32be(S) \
|
|
||||||
({ \
|
|
||||||
unsigned char *Str = (unsigned char *)(S); \
|
|
||||||
READ32BE(Str); \
|
|
||||||
})
|
|
||||||
#define read64be(S) \
|
|
||||||
({ \
|
|
||||||
unsigned char *Str = (unsigned char *)(S); \
|
|
||||||
READ64BE(Str); \
|
|
||||||
})
|
|
||||||
|
|
||||||
#define WRITE16LE(P, V) \
|
#define WRITE16LE(P, V) \
|
||||||
do { \
|
do { \
|
||||||
uint8_t *Ple = (uint8_t *)(P); \
|
uint8_t *Ple = (uint8_t *)(P); \
|
||||||
|
@ -165,6 +133,7 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § bits » some assembly required ─╬─│┼
|
│ cosmopolitan § bits » some assembly required ─╬─│┼
|
||||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||||
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constraints for virtual machine flags.
|
* Constraints for virtual machine flags.
|
||||||
|
@ -416,6 +385,14 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
|
||||||
OldBit; \
|
OldBit; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define cmpxchg(MEM, CMP, VAL) \
|
||||||
|
cmpxchg(MEM, (intptr_t)(CMP), (intptr_t)(VAL), sizeof(*(MEM)))
|
||||||
|
#define lockcmpxchg(MEM, CMP, VAL) \
|
||||||
|
lockcmpxchg(MEM, (intptr_t)(CMP), (intptr_t)(VAL), sizeof(*(MEM)))
|
||||||
|
#define lockxchg(MEM, VAR) \
|
||||||
|
lockxchg(MEM, VAR, sizeof(*(MEM)) / (sizeof(*(MEM)) == sizeof(*(VAR))))
|
||||||
|
#endif /* __GNUC__ && !__STRICT_ANSI__ */
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
#endif /* COSMOPOLITAN_LIBC_BITS_H_ */
|
#endif /* COSMOPOLITAN_LIBC_BITS_H_ */
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||||
│ │
|
│ │
|
||||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||||
│ any purpose with or without fee is hereby granted, provided that the │
|
│ any purpose with or without fee is hereby granted, provided that the │
|
||||||
|
@ -16,26 +16,32 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/str/str.h"
|
#include "libc/bits/bits.h"
|
||||||
#include "libc/str/utf16.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helps runtime decode UTF-16 with slightly smaller code size.
|
* Compares and exchanges.
|
||||||
|
*
|
||||||
|
* @param ifthing is uint𝑘_t[hasatleast 1] where 𝑘 ∈ {8,16,32,64}
|
||||||
|
* @param size is automatically supplied by macro wrapper
|
||||||
|
* @return true if value was exchanged, otherwise false
|
||||||
|
* @see lockcmpxchg()
|
||||||
*/
|
*/
|
||||||
wint_t DecodeNtsUtf16(const char16_t **s) {
|
bool(cmpxchg)(void *ifthing, intptr_t isequaltome, intptr_t replaceitwithme,
|
||||||
wint_t x, y;
|
size_t size) {
|
||||||
for (;;) {
|
switch (size) {
|
||||||
if (!(x = *(*s)++)) break;
|
case 1:
|
||||||
if (IsUtf16Cont(x)) continue;
|
return cmpxchg((int8_t *)ifthing, (int8_t)isequaltome,
|
||||||
if (IsUcs2(x)) {
|
(int8_t)replaceitwithme);
|
||||||
return x;
|
case 2:
|
||||||
} else {
|
return cmpxchg((int16_t *)ifthing, (int16_t)isequaltome,
|
||||||
if ((y = *(*s)++)) {
|
(int16_t)replaceitwithme);
|
||||||
return MergeUtf16(x, y);
|
case 4:
|
||||||
} else {
|
return cmpxchg((int32_t *)ifthing, (int32_t)isequaltome,
|
||||||
return 0;
|
(int32_t)replaceitwithme);
|
||||||
}
|
case 8:
|
||||||
}
|
return cmpxchg((int64_t *)ifthing, (int64_t)isequaltome,
|
||||||
|
(int64_t)replaceitwithme);
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return x;
|
|
||||||
}
|
}
|
|
@ -2,8 +2,8 @@
|
||||||
#define COSMOPOLITAN_LIBC_BITS_LIKELY_H_
|
#define COSMOPOLITAN_LIBC_BITS_LIKELY_H_
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
|
|
||||||
#define likely(expr) __builtin_expect(!!(expr), 1)
|
#define LIKELY(expr) __builtin_expect(!!(expr), 1)
|
||||||
#define unlikely(expr) __builtin_expect(!!(expr), 0)
|
#define UNLIKELY(expr) __builtin_expect(!!(expr), 0)
|
||||||
|
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
#endif /* COSMOPOLITAN_LIBC_BITS_LIKELY_H_ */
|
#endif /* COSMOPOLITAN_LIBC_BITS_LIKELY_H_ */
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||||
│ │
|
│ │
|
||||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||||
│ any purpose with or without fee is hereby granted, provided that the │
|
│ any purpose with or without fee is hereby granted, provided that the │
|
||||||
|
@ -16,27 +16,32 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/bits/bits.h"
|
||||||
#include "libc/nt/enum/filemapflags.h"
|
|
||||||
#include "libc/nt/enum/pageflags.h"
|
|
||||||
#include "libc/nt/memory.h"
|
|
||||||
#include "libc/sysv/consts/map.h"
|
|
||||||
#include "libc/sysv/consts/prot.h"
|
|
||||||
|
|
||||||
#define HAS(X, BITS) (((X) & (BITS)) == (BITS))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts System Five memory protection flags to Windows NT, Part 2.
|
* Compares and exchanges w/ lock prefix.
|
||||||
* @see libc/sysv/consts.sh
|
*
|
||||||
|
* @param ifthing is uint𝑘_t[hasatleast 1] where 𝑘 ∈ {8,16,32,64}
|
||||||
|
* @param size is automatically supplied by macro wrapper
|
||||||
|
* @return true if value was exchanged, otherwise false
|
||||||
|
* @see cmpxchg()
|
||||||
*/
|
*/
|
||||||
uint32_t fprot2nt(int prot, int flags) {
|
bool(lockcmpxchg)(void *ifthing, intptr_t isequaltome, intptr_t replaceitwithme,
|
||||||
return (HAS(prot, PROT_READ) ? kNtFileMapRead : 0) |
|
size_t size) {
|
||||||
(HAS(prot, PROT_WRITE) ? kNtFileMapWrite : 0) |
|
switch (size) {
|
||||||
(HAS(prot, PROT_EXEC) ? kNtFileMapExecute : 0) |
|
case 1:
|
||||||
(HAS(flags, kNtSecLargePages) ? kNtFileMapLargePages : 0) |
|
return lockcmpxchg((int8_t *)ifthing, (int8_t)isequaltome,
|
||||||
(HAS(flags, kNtSecReserve) ? kNtFileMapReserve : 0) |
|
(int8_t)replaceitwithme);
|
||||||
((HAS(flags, MAP_PRIVATE) && HAS(prot, PROT_READ) &&
|
case 2:
|
||||||
HAS(prot, PROT_WRITE))
|
return lockcmpxchg((int16_t *)ifthing, (int16_t)isequaltome,
|
||||||
? kNtFileMapCopy
|
(int16_t)replaceitwithme);
|
||||||
: 0);
|
case 4:
|
||||||
|
return lockcmpxchg((int32_t *)ifthing, (int32_t)isequaltome,
|
||||||
|
(int32_t)replaceitwithme);
|
||||||
|
case 8:
|
||||||
|
return lockcmpxchg((int64_t *)ifthing, (int64_t)isequaltome,
|
||||||
|
(int64_t)replaceitwithme);
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||||
│ │
|
│ │
|
||||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||||
│ any purpose with or without fee is hereby granted, provided that the │
|
│ any purpose with or without fee is hereby granted, provided that the │
|
||||||
|
@ -16,19 +16,27 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/bits/bits.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modifies characteristics of open file descriptor.
|
* Compares and exchanges w/ lock prefix.
|
||||||
|
*
|
||||||
|
* @param memory is uint𝑘_t[hasatleast 1] where 𝑘 ∈ {8,16,32,64}
|
||||||
|
* @param size is automatically supplied by macro wrapper
|
||||||
|
* @return true if value was exchanged, otherwise false
|
||||||
|
* @see xchg()
|
||||||
*/
|
*/
|
||||||
int tunefd$sysv(int fd, int getcmd, int setcmd, int addflags) {
|
intptr_t(lockxchg)(void *memory, void *localvar, size_t size) {
|
||||||
int current;
|
switch (size) {
|
||||||
if (fd != -1 && addflags) {
|
case 1:
|
||||||
if ((current = fcntl$sysv(fd, getcmd, 0)) == -1 ||
|
return lockxchg((int8_t *)memory, (int8_t *)localvar);
|
||||||
fcntl$sysv(fd, setcmd, current | addflags) == -1) {
|
case 2:
|
||||||
close$sysv(fd);
|
return lockxchg((int16_t *)memory, (int16_t *)localvar);
|
||||||
return -1;
|
case 4:
|
||||||
}
|
return lockxchg((int32_t *)memory, (int32_t *)localvar);
|
||||||
|
case 8:
|
||||||
|
return lockxchg((int64_t *)memory, (int64_t *)localvar);
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return fd;
|
|
||||||
}
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
#ifndef COSMOPOLITAN_LIBC_BITS_SAFEMACROS_H_
|
#ifndef COSMOPOLITAN_LIBC_BITS_SAFEMACROS_H_
|
||||||
#define COSMOPOLITAN_LIBC_BITS_SAFEMACROS_H_
|
#define COSMOPOLITAN_LIBC_BITS_SAFEMACROS_H_
|
||||||
#ifndef __STRICT_ANSI__
|
|
||||||
#include "libc/macros.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
|
@ -84,5 +83,4 @@ uint64_t(unsignedsubtract)(uint64_t, uint64_t) pureconst;
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
#endif /* !ANSI */
|
|
||||||
#endif /* COSMOPOLITAN_LIBC_BITS_SAFEMACROS_H_ */
|
#endif /* COSMOPOLITAN_LIBC_BITS_SAFEMACROS_H_ */
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_
|
#ifndef COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_
|
||||||
#define COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_
|
#define COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads scalar from memory, offset by segment.
|
* Reads scalar from memory, offset by segment.
|
||||||
|
@ -19,5 +20,6 @@
|
||||||
Pk; \
|
Pk; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#endif /* __GNUC__ && !__STRICT_ANSI__ */
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
#endif /* COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_ */
|
#endif /* COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_ */
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "libc/nt/synchronization.h"
|
#include "libc/nt/synchronization.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int chdir$nt(const char *path) {
|
textwindows int sys_chdir_nt(const char *path) {
|
||||||
int e, ms, len;
|
int e, ms, len;
|
||||||
char16_t path16[PATH_MAX];
|
char16_t path16[PATH_MAX];
|
||||||
if ((len = __mkntpath(path, path16)) == -1) return -1;
|
if ((len = __mkntpath(path, path16)) == -1) return -1;
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
*/
|
*/
|
||||||
int chdir(const char *path) {
|
int chdir(const char *path) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return chdir$sysv(path);
|
return sys_chdir(path);
|
||||||
} else {
|
} else {
|
||||||
return chdir$nt(path);
|
return sys_chdir_nt(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,5 +45,5 @@
|
||||||
*/
|
*/
|
||||||
int chmod(const char *pathname, uint32_t mode) {
|
int chmod(const char *pathname, uint32_t mode) {
|
||||||
if (!pathname) return efault();
|
if (!pathname) return efault();
|
||||||
return fchmodat$sysv(AT_FDCWD, pathname, mode, 0);
|
return sys_fchmodat(AT_FDCWD, pathname, mode, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,5 +34,5 @@
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
*/
|
*/
|
||||||
int chown(const char *pathname, uint32_t uid, uint32_t gid) {
|
int chown(const char *pathname, uint32_t uid, uint32_t gid) {
|
||||||
return fchownat$sysv(AT_FDCWD, pathname, uid, gid, 0);
|
return sys_fchownat(AT_FDCWD, pathname, uid, gid, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ int clock_gettime(int clockid, struct timespec *out_ts) {
|
||||||
out_ts->tv_sec = 0;
|
out_ts->tv_sec = 0;
|
||||||
out_ts->tv_nsec = 0;
|
out_ts->tv_nsec = 0;
|
||||||
}
|
}
|
||||||
return clock_gettime$sysv(clockid, out_ts);
|
return sys_clock_gettime(clockid, out_ts);
|
||||||
} else {
|
} else {
|
||||||
int rc;
|
int rc;
|
||||||
_Static_assert(sizeof(struct timeval) == sizeof(struct timespec));
|
_Static_assert(sizeof(struct timeval) == sizeof(struct timespec));
|
||||||
|
@ -67,7 +67,7 @@ int clock_gettime(int clockid, struct timespec *out_ts) {
|
||||||
out_ts->tv_sec = 0;
|
out_ts->tv_sec = 0;
|
||||||
out_ts->tv_nsec = 0;
|
out_ts->tv_nsec = 0;
|
||||||
}
|
}
|
||||||
rc = gettimeofday$sysv((struct timeval *)out_ts, NULL);
|
rc = sys_gettimeofday((struct timeval *)out_ts, NULL);
|
||||||
if (out_ts) {
|
if (out_ts) {
|
||||||
out_ts->tv_nsec *= 1000;
|
out_ts->tv_nsec *= 1000;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "libc/nt/runtime.h"
|
#include "libc/nt/runtime.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int close$nt(int fd) {
|
textwindows int sys_close_nt(int fd) {
|
||||||
bool32 ok;
|
bool32 ok;
|
||||||
if (g_fds.p[fd].kind == kFdFile &&
|
if (g_fds.p[fd].kind == kFdFile &&
|
||||||
GetFileType(g_fds.p[fd].handle) == kNtFileTypeDisk) {
|
GetFileType(g_fds.p[fd].handle) == kNtFileTypeDisk) {
|
||||||
|
|
|
@ -40,15 +40,15 @@ int close(int fd) {
|
||||||
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
|
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
|
||||||
rc = weaken(__zipos_close)(fd);
|
rc = weaken(__zipos_close)(fd);
|
||||||
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdEpoll) {
|
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdEpoll) {
|
||||||
rc = weaken(close$epoll)(fd);
|
rc = weaken(sys_close_epoll)(fd);
|
||||||
} else if (!IsWindows()) {
|
} else if (!IsWindows()) {
|
||||||
rc = close$sysv(fd);
|
rc = sys_close(fd);
|
||||||
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdSocket) {
|
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdSocket) {
|
||||||
rc = weaken(closesocket$nt)(fd);
|
rc = weaken(sys_closesocket_nt)(fd);
|
||||||
} else if (fd < g_fds.n &&
|
} else if (fd < g_fds.n &&
|
||||||
(g_fds.p[fd].kind == kFdFile || g_fds.p[fd].kind == kFdConsole ||
|
(g_fds.p[fd].kind == kFdFile || g_fds.p[fd].kind == kFdConsole ||
|
||||||
g_fds.p[fd].kind == kFdProcess)) {
|
g_fds.p[fd].kind == kFdProcess)) {
|
||||||
rc = close$nt(fd);
|
rc = sys_close_nt(fd);
|
||||||
} else {
|
} else {
|
||||||
rc = ebadf();
|
rc = ebadf();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "libc/sysv/consts/o.h"
|
#include "libc/sysv/consts/o.h"
|
||||||
#include "libc/time/time.h"
|
#include "libc/time/time.h"
|
||||||
|
|
||||||
static textwindows int copyfile$nt(const char *src, const char *dst,
|
static textwindows int sys_copyfile_nt(const char *src, const char *dst,
|
||||||
int flags) {
|
int flags) {
|
||||||
int64_t fhsrc, fhdst;
|
int64_t fhsrc, fhdst;
|
||||||
struct NtFileTime accessed, modified;
|
struct NtFileTime accessed, modified;
|
||||||
|
@ -58,7 +58,7 @@ static textwindows int copyfile$nt(const char *src, const char *dst,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int copyfile$sysv(const char *src, const char *dst, int flags) {
|
static int sys_copyfile(const char *src, const char *dst, int flags) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
size_t remaining;
|
size_t remaining;
|
||||||
ssize_t transferred;
|
ssize_t transferred;
|
||||||
|
@ -66,12 +66,12 @@ static int copyfile$sysv(const char *src, const char *dst, int flags) {
|
||||||
int64_t inoffset, outoffset;
|
int64_t inoffset, outoffset;
|
||||||
int rc, srcfd, dstfd, oflags, omode;
|
int rc, srcfd, dstfd, oflags, omode;
|
||||||
rc = -1;
|
rc = -1;
|
||||||
if ((srcfd = openat$sysv(AT_FDCWD, src, O_RDONLY, 0)) != -1) {
|
if ((srcfd = sys_openat(AT_FDCWD, src, O_RDONLY, 0)) != -1) {
|
||||||
if (fstat$sysv(srcfd, &st) != -1) {
|
if (sys_fstat(srcfd, &st) != -1) {
|
||||||
omode = st.st_mode & 0777;
|
omode = st.st_mode & 0777;
|
||||||
oflags = O_WRONLY | O_CREAT;
|
oflags = O_WRONLY | O_CREAT;
|
||||||
if (flags & COPYFILE_NOCLOBBER) oflags |= O_EXCL;
|
if (flags & COPYFILE_NOCLOBBER) oflags |= O_EXCL;
|
||||||
if ((dstfd = openat$sysv(AT_FDCWD, dst, oflags, omode)) != -1) {
|
if ((dstfd = sys_openat(AT_FDCWD, dst, oflags, omode)) != -1) {
|
||||||
remaining = st.st_size;
|
remaining = st.st_size;
|
||||||
ftruncate(dstfd, remaining);
|
ftruncate(dstfd, remaining);
|
||||||
inoffset = 0;
|
inoffset = 0;
|
||||||
|
@ -86,13 +86,13 @@ static int copyfile$sysv(const char *src, const char *dst, int flags) {
|
||||||
if (flags & COPYFILE_PRESERVE_TIMESTAMPS) {
|
if (flags & COPYFILE_PRESERVE_TIMESTAMPS) {
|
||||||
amtime[0] = st.st_atim;
|
amtime[0] = st.st_atim;
|
||||||
amtime[1] = st.st_mtim;
|
amtime[1] = st.st_mtim;
|
||||||
utimensat$sysv(dstfd, NULL, amtime, 0);
|
sys_utimensat(dstfd, NULL, amtime, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rc |= close$sysv(dstfd);
|
rc |= sys_close(dstfd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rc |= close$sysv(srcfd);
|
rc |= sys_close(srcfd);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -102,8 +102,8 @@ static int copyfile$sysv(const char *src, const char *dst, int flags) {
|
||||||
*/
|
*/
|
||||||
int copyfile(const char *src, const char *dst, int flags) {
|
int copyfile(const char *src, const char *dst, int flags) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return copyfile$sysv(src, dst, flags);
|
return sys_copyfile(src, dst, flags);
|
||||||
} else {
|
} else {
|
||||||
return copyfile$nt(src, dst, flags);
|
return sys_copyfile_nt(src, dst, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
/**
|
/**
|
||||||
* Implements dup(), dup2(), and dup3() for Windows NT.
|
* Implements dup(), dup2(), and dup3() for Windows NT.
|
||||||
*/
|
*/
|
||||||
textwindows int dup$nt(int oldfd, int newfd, int flags) {
|
textwindows int sys_dup_nt(int oldfd, int newfd, int flags) {
|
||||||
int64_t proc;
|
int64_t proc;
|
||||||
if (oldfd < 0) return einval();
|
if (oldfd < 0) return einval();
|
||||||
if (oldfd >= g_fds.n ||
|
if (oldfd >= g_fds.n ||
|
||||||
|
|
|
@ -30,8 +30,8 @@
|
||||||
*/
|
*/
|
||||||
nodiscard int dup(int fd) {
|
nodiscard int dup(int fd) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return dup$sysv(fd);
|
return sys_dup(fd);
|
||||||
} else {
|
} else {
|
||||||
return dup$nt(fd, -1, 0);
|
return sys_dup_nt(fd, -1, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,8 @@
|
||||||
int dup2(int oldfd, int newfd) {
|
int dup2(int oldfd, int newfd) {
|
||||||
if (oldfd == newfd) return newfd;
|
if (oldfd == newfd) return newfd;
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return dup3$sysv(oldfd, newfd, 0);
|
return sys_dup3(oldfd, newfd, 0);
|
||||||
} else {
|
} else {
|
||||||
return dup$nt(oldfd, newfd, 0);
|
return sys_dup_nt(oldfd, newfd, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,12 @@
|
||||||
|
|
||||||
#define __NR_dup3_linux 0x0124 /*RHEL5:CVE-2010-3301*/
|
#define __NR_dup3_linux 0x0124 /*RHEL5:CVE-2010-3301*/
|
||||||
|
|
||||||
int32_t dup3$sysv(int32_t oldfd, int32_t newfd, int flags) {
|
int32_t sys_dup3(int32_t oldfd, int32_t newfd, int flags) {
|
||||||
static bool once, demodernize;
|
static bool once, demodernize;
|
||||||
int olderr, fd;
|
int olderr, fd;
|
||||||
if (!once) {
|
if (!once) {
|
||||||
olderr = errno;
|
olderr = errno;
|
||||||
fd = __dup3$sysv(oldfd, newfd, flags);
|
fd = __sys_dup3(oldfd, newfd, flags);
|
||||||
if ((fd == -1 && errno == ENOSYS) || fd == __NR_dup3_linux) {
|
if ((fd == -1 && errno == ENOSYS) || fd == __NR_dup3_linux) {
|
||||||
demodernize = true;
|
demodernize = true;
|
||||||
once = true;
|
once = true;
|
||||||
|
@ -36,7 +36,7 @@ int32_t dup3$sysv(int32_t oldfd, int32_t newfd, int flags) {
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
} else if (!demodernize) {
|
} else if (!demodernize) {
|
||||||
return __dup3$sysv(oldfd, newfd, flags);
|
return __sys_dup3(oldfd, newfd, flags);
|
||||||
}
|
}
|
||||||
return fixupnewfd$sysv(dup2$sysv(oldfd, newfd), flags);
|
return __fixupnewfd(sys_dup2(oldfd, newfd), flags);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,8 @@
|
||||||
*/
|
*/
|
||||||
int dup3(int oldfd, int newfd, int flags) {
|
int dup3(int oldfd, int newfd, int flags) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return dup3$sysv(oldfd, newfd, flags);
|
return sys_dup3(oldfd, newfd, flags);
|
||||||
} else {
|
} else {
|
||||||
return dup$nt(oldfd, newfd, flags);
|
return sys_dup_nt(oldfd, newfd, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/consts/o.h"
|
#include "libc/sysv/consts/o.h"
|
||||||
|
|
||||||
textwindows int execve$nt(const char *program, char *const argv[],
|
textwindows int sys_execve_nt(const char *program, char *const argv[],
|
||||||
char *const envp[]) {
|
char *const envp[]) {
|
||||||
int rc;
|
int rc;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
|
@ -24,10 +24,10 @@
|
||||||
#include "libc/paths.h"
|
#include "libc/paths.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
int execve$sysv(const char *prog, char *const argv[], char *const envp[]) {
|
int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
|
||||||
size_t i;
|
size_t i;
|
||||||
char **shargs;
|
char **shargs;
|
||||||
if (__execve$sysv(prog, argv, envp) != -1) return 0;
|
if (__sys_execve(prog, argv, envp) != -1) return 0;
|
||||||
if (errno != ENOEXEC) return -1;
|
if (errno != ENOEXEC) return -1;
|
||||||
for (i = 0; argv[i];) ++i;
|
for (i = 0; argv[i];) ++i;
|
||||||
shargs = alloca((i + 2) * sizeof(char *));
|
shargs = alloca((i + 2) * sizeof(char *));
|
||||||
|
@ -36,5 +36,5 @@ int execve$sysv(const char *prog, char *const argv[], char *const envp[]) {
|
||||||
: firstnonnull(commandv("bash", alloca(PATH_MAX)),
|
: firstnonnull(commandv("bash", alloca(PATH_MAX)),
|
||||||
_PATH_BSHELL);
|
_PATH_BSHELL);
|
||||||
shargs[1] = prog;
|
shargs[1] = prog;
|
||||||
return __execve$sysv(shargs[0], shargs, envp);
|
return __sys_execve(shargs[0], shargs, envp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,8 @@
|
||||||
*/
|
*/
|
||||||
int execve(const char *program, char *const argv[], char *const envp[]) {
|
int execve(const char *program, char *const argv[], char *const envp[]) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return execve$sysv(program, argv, envp);
|
return sys_execve(program, argv, envp);
|
||||||
} else {
|
} else {
|
||||||
return execve$nt(program, argv, envp);
|
return sys_execve_nt(program, argv, envp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "libc/sysv/consts/at.h"
|
#include "libc/sysv/consts/at.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
int faccessat$nt(int dirfd, const char *path, int mode, uint32_t flags) {
|
int sys_faccessat_nt(int dirfd, const char *path, int mode, uint32_t flags) {
|
||||||
char16_t path16[PATH_MAX];
|
char16_t path16[PATH_MAX];
|
||||||
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
|
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
|
||||||
return ntaccesscheck(path16, mode);
|
return ntaccesscheck(path16, mode);
|
||||||
|
|
|
@ -36,8 +36,8 @@
|
||||||
int faccessat(int dirfd, const char *path, int mode, uint32_t flags) {
|
int faccessat(int dirfd, const char *path, int mode, uint32_t flags) {
|
||||||
if (!path) return efault();
|
if (!path) return efault();
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return faccessat$sysv(dirfd, path, mode, flags);
|
return sys_faccessat(dirfd, path, mode, flags);
|
||||||
} else {
|
} else {
|
||||||
return faccessat$nt(dirfd, path, mode, flags);
|
return sys_faccessat_nt(dirfd, path, mode, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int fadvise$nt(int fd, uint64_t offset, uint64_t len, int advice) {
|
textwindows int sys_fadvise_nt(int fd, uint64_t offset, uint64_t len, int advice) {
|
||||||
int64_t h2;
|
int64_t h2;
|
||||||
NtStatus status;
|
NtStatus status;
|
||||||
uint32_t sharemode;
|
uint32_t sharemode;
|
||||||
|
|
|
@ -32,8 +32,8 @@
|
||||||
*/
|
*/
|
||||||
int fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
|
int fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return fadvise$sysv(fd, offset, len, advice); /* linux & freebsd */
|
return sys_fadvise(fd, offset, len, advice); /* linux & freebsd */
|
||||||
} else {
|
} else {
|
||||||
return fadvise$nt(fd, offset, len, advice);
|
return sys_fadvise_nt(fd, offset, len, advice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,11 +45,11 @@ int fallocate(int fd, int32_t mode, int64_t offset, int64_t length) {
|
||||||
if (mode == -1 /* our sysvconsts definition */) return eopnotsupp();
|
if (mode == -1 /* our sysvconsts definition */) return eopnotsupp();
|
||||||
if (!mode && !length) return ftruncate(fd, offset);
|
if (!mode && !length) return ftruncate(fd, offset);
|
||||||
if (IsLinux()) {
|
if (IsLinux()) {
|
||||||
rc = fallocate$sysv(fd, mode, offset, length);
|
rc = sys_fallocate(fd, mode, offset, length);
|
||||||
if (rc == 0x011d) rc = enosys(); /*RHEL5:CVE-2010-3301*/
|
if (rc == 0x011d) rc = enosys(); /*RHEL5:CVE-2010-3301*/
|
||||||
return rc;
|
return rc;
|
||||||
} else if (!IsWindows()) {
|
} else if (!IsWindows()) {
|
||||||
return posix_fallocate$sysv(fd, offset, length);
|
return sys_posix_fallocate(fd, offset, length);
|
||||||
} else if (IsWindows()) {
|
} else if (IsWindows()) {
|
||||||
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
||||||
if (mode == FALLOC_FL_ZERO_RANGE) {
|
if (mode == FALLOC_FL_ZERO_RANGE) {
|
||||||
|
@ -66,7 +66,7 @@ int fallocate(int fd, int32_t mode, int64_t offset, int64_t length) {
|
||||||
* this should commit physical space
|
* this should commit physical space
|
||||||
* but not guaranteed zero'd like linux
|
* but not guaranteed zero'd like linux
|
||||||
*/
|
*/
|
||||||
return ftruncate$nt(fd, length);
|
return sys_ftruncate_nt(fd, length);
|
||||||
} else {
|
} else {
|
||||||
return enosys();
|
return enosys();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int fchdir$nt(int dirfd) {
|
textwindows int sys_fchdir_nt(int dirfd) {
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
char16_t dir[PATH_MAX];
|
char16_t dir[PATH_MAX];
|
||||||
if (!__isfdkind(dirfd, kFdFile)) return ebadf();
|
if (!__isfdkind(dirfd, kFdFile)) return ebadf();
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
*/
|
*/
|
||||||
int fchdir(int dirfd) {
|
int fchdir(int dirfd) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return fchdir$sysv(dirfd);
|
return sys_fchdir(dirfd);
|
||||||
} else {
|
} else {
|
||||||
return fchdir$nt(dirfd);
|
return sys_fchdir_nt(dirfd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,5 +43,5 @@
|
||||||
*/
|
*/
|
||||||
int fchmod(int fd, uint32_t mode) {
|
int fchmod(int fd, uint32_t mode) {
|
||||||
/* TODO(jart): Windows */
|
/* TODO(jart): Windows */
|
||||||
return fchmod$sysv(fd, mode);
|
return sys_fchmod(fd, mode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,5 +31,5 @@
|
||||||
*/
|
*/
|
||||||
int fchown(int fd, uint32_t uid, uint32_t gid) {
|
int fchown(int fd, uint32_t uid, uint32_t gid) {
|
||||||
/* TODO(jart): Windows? */
|
/* TODO(jart): Windows? */
|
||||||
return fchown$sysv(fd, uid, gid);
|
return sys_fchown(fd, uid, gid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,5 +34,5 @@
|
||||||
*/
|
*/
|
||||||
int fchownat(int dirfd, const char *pathname, uint32_t uid, uint32_t gid,
|
int fchownat(int dirfd, const char *pathname, uint32_t uid, uint32_t gid,
|
||||||
uint32_t flags) {
|
uint32_t flags) {
|
||||||
return fchownat$sysv(dirfd, pathname, uid, gid, flags);
|
return sys_fchownat(dirfd, pathname, uid, gid, flags);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "libc/sysv/consts/o.h"
|
#include "libc/sysv/consts/o.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int fcntl$nt(int fd, int cmd, unsigned arg) {
|
textwindows int sys_fcntl_nt(int fd, int cmd, unsigned arg) {
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
if (__isfdkind(fd, kFdFile) || __isfdkind(fd, kFdSocket)) {
|
if (__isfdkind(fd, kFdFile) || __isfdkind(fd, kFdSocket)) {
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
|
|
|
@ -37,8 +37,8 @@ int fcntl(int fd, int cmd, ...) {
|
||||||
arg = va_arg(va, unsigned);
|
arg = va_arg(va, unsigned);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return fcntl$sysv(fd, cmd, arg);
|
return sys_fcntl(fd, cmd, arg);
|
||||||
} else {
|
} else {
|
||||||
return fcntl$nt(fd, cmd, arg);
|
return sys_fcntl_nt(fd, cmd, arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int fdatasync$nt(int fd) {
|
textwindows int sys_fdatasync_nt(int fd) {
|
||||||
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
||||||
/*
|
/*
|
||||||
* XXX: On Windows NT this might be more analagous to fflush() and
|
* XXX: On Windows NT this might be more analagous to fflush() and
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
*/
|
*/
|
||||||
int fdatasync(int fd) {
|
int fdatasync(int fd) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return fdatasync$sysv(fd);
|
return sys_fdatasync(fd);
|
||||||
} else {
|
} else {
|
||||||
return fdatasync$nt(fd);
|
return sys_fdatasync_nt(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,12 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies file descriptor fixups on XNU or old Linux.
|
* Applies file descriptor fixups on XNU or old Linux.
|
||||||
* @see fixupnewsockfd$sysv() for socket file descriptors
|
* @see __fixupnewsockfd() for socket file descriptors
|
||||||
*/
|
*/
|
||||||
int fixupnewfd$sysv(int fd, int flags) {
|
int __fixupnewfd(int fd, int flags) {
|
||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
if (flags & O_CLOEXEC) {
|
if (flags & O_CLOEXEC) {
|
||||||
fcntl$sysv(fd, F_SETFD, FD_CLOEXEC);
|
sys_fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "libc/sysv/consts/lock.h"
|
#include "libc/sysv/consts/lock.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int flock$nt(int fd, int op) {
|
textwindows int sys_flock_nt(int fd, int op) {
|
||||||
struct NtOverlapped ov;
|
struct NtOverlapped ov;
|
||||||
struct NtByHandleFileInformation info;
|
struct NtByHandleFileInformation info;
|
||||||
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
*/
|
*/
|
||||||
int flock(int fd, int op) {
|
int flock(int fd, int op) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return flock$sysv(fd, op);
|
return sys_flock(fd, op);
|
||||||
} else {
|
} else {
|
||||||
return flock$nt(fd, op);
|
return sys_flock_nt(fd, op);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/consts/s.h"
|
#include "libc/sysv/consts/s.h"
|
||||||
|
|
||||||
textwindows int fstat$nt(int64_t handle, struct stat *st) {
|
textwindows int sys_fstat_nt(int64_t handle, struct stat *st) {
|
||||||
int filetype;
|
int filetype;
|
||||||
uint64_t actualsize;
|
uint64_t actualsize;
|
||||||
struct NtFileCompressionInfo fci;
|
struct NtFileCompressionInfo fci;
|
||||||
|
|
|
@ -22,10 +22,10 @@
|
||||||
* Supports fstat(), etc. implementations.
|
* Supports fstat(), etc. implementations.
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
*/
|
*/
|
||||||
textstartup int32_t fstat$sysv(int32_t fd, struct stat *st) {
|
textstartup int32_t sys_fstat(int32_t fd, struct stat *st) {
|
||||||
int res;
|
int res;
|
||||||
if ((res = __fstat$sysv(fd, st)) != -1) {
|
if ((res = __sys_fstat(fd, st)) != -1) {
|
||||||
stat2linux(st);
|
__stat2linux(st);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,12 +33,12 @@ int fstat(int fd, struct stat *st) {
|
||||||
(struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, st);
|
(struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, st);
|
||||||
} else if (!IsWindows()) {
|
} else if (!IsWindows()) {
|
||||||
if (!IsMetal()) {
|
if (!IsMetal()) {
|
||||||
return fstat$sysv(fd, st);
|
return sys_fstat(fd, st);
|
||||||
} else {
|
} else {
|
||||||
return fstat$metal(fd, st);
|
return fstat$metal(fd, st);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
||||||
return fstat$nt(g_fds.p[fd].handle, st);
|
return sys_fstat_nt(g_fds.p[fd].handle, st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "libc/nt/runtime.h"
|
#include "libc/nt/runtime.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
||||||
textwindows int fstatat$nt(int dirfd, const char *path, struct stat *st,
|
textwindows int sys_fstatat_nt(int dirfd, const char *path, struct stat *st,
|
||||||
uint32_t flags) {
|
uint32_t flags) {
|
||||||
int rc;
|
int rc;
|
||||||
int64_t fh;
|
int64_t fh;
|
||||||
|
@ -37,7 +37,7 @@ textwindows int fstatat$nt(int dirfd, const char *path, struct stat *st,
|
||||||
kNtFileShareRead | kNtFileShareWrite | kNtFileShareDelete, NULL,
|
kNtFileShareRead | kNtFileShareWrite | kNtFileShareDelete, NULL,
|
||||||
kNtOpenExisting, kNtFileAttributeNormal | kNtFileFlagBackupSemantics,
|
kNtOpenExisting, kNtFileAttributeNormal | kNtFileFlagBackupSemantics,
|
||||||
0)) != -1) {
|
0)) != -1) {
|
||||||
rc = fstat$nt(fh, st);
|
rc = sys_fstat_nt(fh, st);
|
||||||
CloseHandle(fh);
|
CloseHandle(fh);
|
||||||
return rc;
|
return rc;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -22,11 +22,11 @@
|
||||||
* Supports stat(), lstat(), fstatat(), etc. implementations.
|
* Supports stat(), lstat(), fstatat(), etc. implementations.
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
*/
|
*/
|
||||||
int32_t fstatat$sysv(int32_t dirfd, const char *pathname, struct stat *st,
|
int32_t sys_fstatat(int32_t dirfd, const char *pathname, struct stat *st,
|
||||||
int32_t flags) {
|
int32_t flags) {
|
||||||
int32_t rc;
|
int32_t rc;
|
||||||
if ((rc = __fstatat$sysv(dirfd, pathname, st, flags)) != -1) {
|
if ((rc = __sys_fstatat(dirfd, pathname, st, flags)) != -1) {
|
||||||
stat2linux(st);
|
__stat2linux(st);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,8 @@ int fstatat(int dirfd, const char *path, struct stat *st, uint32_t flags) {
|
||||||
if (weaken(__zipos_stat) && weaken(__zipos_parseuri)(path, &zipname) != -1) {
|
if (weaken(__zipos_stat) && weaken(__zipos_parseuri)(path, &zipname) != -1) {
|
||||||
return weaken(__zipos_stat)(&zipname, st);
|
return weaken(__zipos_stat)(&zipname, st);
|
||||||
} else if (!IsWindows()) {
|
} else if (!IsWindows()) {
|
||||||
return fstatat$sysv(dirfd, path, st, flags);
|
return sys_fstatat(dirfd, path, st, flags);
|
||||||
} else {
|
} else {
|
||||||
return fstatat$nt(dirfd, path, st, flags);
|
return sys_fstatat_nt(dirfd, path, st, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
*/
|
*/
|
||||||
int fsync(int fd) {
|
int fsync(int fd) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return fsync$sysv(fd);
|
return sys_fsync(fd);
|
||||||
} else {
|
} else {
|
||||||
return fdatasync$nt(fd);
|
return sys_fdatasync_nt(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int ftruncate$nt(int fd, uint64_t length) {
|
textwindows int sys_ftruncate_nt(int fd, uint64_t length) {
|
||||||
bool32 ok;
|
bool32 ok;
|
||||||
int64_t tell;
|
int64_t tell;
|
||||||
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
||||||
|
|
|
@ -33,8 +33,8 @@
|
||||||
*/
|
*/
|
||||||
int ftruncate(int fd, int64_t length) {
|
int ftruncate(int fd, int64_t length) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return ftruncate$sysv(fd, length);
|
return sys_ftruncate(fd, length);
|
||||||
} else {
|
} else {
|
||||||
return ftruncate$nt(fd, length);
|
return sys_ftruncate_nt(fd, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,6 @@
|
||||||
#include "libc/nt/startupinfo.h"
|
#include "libc/nt/startupinfo.h"
|
||||||
#include "libc/nt/struct/startupinfo.h"
|
#include "libc/nt/struct/startupinfo.h"
|
||||||
|
|
||||||
hidden struct NtStartupInfo g_ntstartupinfo;
|
hidden struct NtStartupInfo __nt_startupinfo;
|
||||||
|
|
||||||
STATIC_YOINK("_init_g_ntstartupinfo");
|
STATIC_YOINK("_init___nt_startupinfo");
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
#include "libc/macros.h"
|
#include "libc/macros.h"
|
||||||
.source __FILE__
|
.source __FILE__
|
||||||
|
|
||||||
.init.start 400,_init_g_ntstartupinfo
|
.init.start 400,_init___nt_startupinfo
|
||||||
ezlea g_ntstartupinfo,cx
|
ezlea __nt_startupinfo,cx
|
||||||
mov %rsp,%rbp
|
mov %rsp,%rbp
|
||||||
ntcall __imp_GetStartupInfoW
|
ntcall __imp_GetStartupInfoW
|
||||||
.init.end 400,_init_g_ntstartupinfo,globl,hidden
|
.init.end 400,_init___nt_startupinfo,globl,hidden
|
||||||
|
|
|
@ -20,6 +20,6 @@
|
||||||
#include "libc/nt/struct/systeminfo.h"
|
#include "libc/nt/struct/systeminfo.h"
|
||||||
#include "libc/nt/systeminfo.h"
|
#include "libc/nt/systeminfo.h"
|
||||||
|
|
||||||
hidden struct NtSystemInfo g_ntsysteminfo;
|
hidden struct NtSystemInfo __nt_systeminfo;
|
||||||
|
|
||||||
STATIC_YOINK("_init_g_ntsysteminfo");
|
STATIC_YOINK("_init___nt_systeminfo");
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
#include "libc/macros.h"
|
#include "libc/macros.h"
|
||||||
.source __FILE__
|
.source __FILE__
|
||||||
|
|
||||||
.init.start 400,_init_g_ntsysteminfo
|
.init.start 400,_init___nt_systeminfo
|
||||||
ezlea g_ntsysteminfo,cx
|
ezlea __nt_systeminfo,cx
|
||||||
mov %rsp,%rbp
|
mov %rsp,%rbp
|
||||||
ntcall __imp_GetSystemInfo
|
ntcall __imp_GetSystemInfo
|
||||||
.init.end 400,_init_g_ntsysteminfo,globl,hidden
|
.init.end 400,_init___nt_systeminfo,globl,hidden
|
||||||
|
|
|
@ -36,26 +36,10 @@ unsigned long getauxval(unsigned long at) {
|
||||||
if (at != -1) {
|
if (at != -1) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
if (!g_auxv) return 0;
|
if (!g_auxv) return 0;
|
||||||
if (IsXnu()) {
|
for (const unsigned long *ap = g_auxv; *ap; ap += 2) {
|
||||||
if (at) {
|
if (ap[0] == at) {
|
||||||
const char *name =
|
res = ap[1];
|
||||||
at == AT_EXECFN ? "executable_path" : (const char *)at;
|
break;
|
||||||
const char **auxv = (const char **)g_auxv;
|
|
||||||
unsigned namelen = strlen(name);
|
|
||||||
for (int i = 0; auxv[i]; ++i) {
|
|
||||||
if (strncmp(auxv[i], name, namelen) == 0 &&
|
|
||||||
auxv[i][namelen] == '=') {
|
|
||||||
res = (intptr_t)&auxv[i][namelen + 1];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (const unsigned long *ap = g_auxv; *ap; ap += 2) {
|
|
||||||
if (ap[0] == at) {
|
|
||||||
res = ap[1];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows char *getcwd$nt(char *buf, size_t size) {
|
textwindows char *sys_getcwd_nt(char *buf, size_t size) {
|
||||||
uint16_t name16[PATH_MAX];
|
uint16_t name16[PATH_MAX];
|
||||||
if (GetCurrentDirectory(ARRAYLEN(name16), name16)) {
|
if (GetCurrentDirectory(ARRAYLEN(name16), name16)) {
|
||||||
tprecode16to8(buf, size, name16);
|
tprecode16to8(buf, size, name16);
|
||||||
|
|
|
@ -27,15 +27,15 @@
|
||||||
#define XNU_F_GETPATH 50
|
#define XNU_F_GETPATH 50
|
||||||
#define XNU_MAXPATHLEN 1024
|
#define XNU_MAXPATHLEN 1024
|
||||||
|
|
||||||
char *getcwd$xnu(char *res, size_t size) {
|
char *sys_getcwd_xnu(char *res, size_t size) {
|
||||||
int fd;
|
int fd;
|
||||||
struct stat st[2];
|
struct stat st[2];
|
||||||
char buf[XNU_MAXPATHLEN], *ret = NULL;
|
char buf[XNU_MAXPATHLEN], *ret = NULL;
|
||||||
if ((fd = openat$sysv(AT_FDCWD, ".", O_RDONLY | O_DIRECTORY)) != -1) {
|
if ((fd = sys_openat(AT_FDCWD, ".", O_RDONLY | O_DIRECTORY)) != -1) {
|
||||||
if (fstat$sysv(fd, &st[0]) != -1) {
|
if (sys_fstat(fd, &st[0]) != -1) {
|
||||||
if (st[0].st_dev && st[0].st_ino) {
|
if (st[0].st_dev && st[0].st_ino) {
|
||||||
if (fcntl$sysv(fd, XNU_F_GETPATH, buf) != -1) {
|
if (sys_fcntl(fd, XNU_F_GETPATH, buf) != -1) {
|
||||||
if (fstatat$sysv(AT_FDCWD, buf, &st[1], 0) != -1) {
|
if (sys_fstatat(AT_FDCWD, buf, &st[1], 0) != -1) {
|
||||||
if (st[0].st_dev == st[1].st_dev && st[0].st_ino == st[1].st_ino) {
|
if (st[0].st_dev == st[1].st_dev && st[0].st_ino == st[1].st_ino) {
|
||||||
if (memccpy(res, buf, '\0', size)) {
|
if (memccpy(res, buf, '\0', size)) {
|
||||||
ret = res;
|
ret = res;
|
||||||
|
|
|
@ -35,13 +35,13 @@ char *(getcwd)(char *buf, size_t size) {
|
||||||
if (buf && size) buf[0] = '\0';
|
if (buf && size) buf[0] = '\0';
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
if (IsXnu()) {
|
if (IsXnu()) {
|
||||||
return getcwd$xnu(buf, size);
|
return sys_getcwd_xnu(buf, size);
|
||||||
} else if (getcwd$sysv(buf, size) != (void *)-1) {
|
} else if (sys_getcwd(buf, size) != (void *)-1) {
|
||||||
return buf;
|
return buf;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return getcwd$nt(buf, size);
|
return sys_getcwd_nt(buf, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
*/
|
*/
|
||||||
int getitimer(int which, struct itimerval *curvalue) {
|
int getitimer(int which, struct itimerval *curvalue) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return getitimer$sysv(which, curvalue);
|
return sys_getitimer(which, curvalue);
|
||||||
} else {
|
} else {
|
||||||
return setitimer$nt(which, NULL, curvalue);
|
return sys_setitimer_nt(which, NULL, curvalue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ static int __pid;
|
||||||
|
|
||||||
static int __getpid(void) {
|
static int __getpid(void) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return getpid$sysv();
|
return sys_getpid();
|
||||||
} else {
|
} else {
|
||||||
return GetCurrentProcessId();
|
return GetCurrentProcessId();
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ static void __updatepid(void) {
|
||||||
int getpid(void) {
|
int getpid(void) {
|
||||||
static bool once;
|
static bool once;
|
||||||
if (__vforked) {
|
if (__vforked) {
|
||||||
return getpid$sysv();
|
return sys_getpid();
|
||||||
}
|
}
|
||||||
if (!once) {
|
if (!once) {
|
||||||
__updatepid();
|
__updatepid();
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "libc/nt/runtime.h"
|
#include "libc/nt/runtime.h"
|
||||||
#include "libc/nt/struct/processbasicinformation.h"
|
#include "libc/nt/struct/processbasicinformation.h"
|
||||||
|
|
||||||
textwindows int getppid$nt(void) {
|
textwindows int sys_getppid_nt(void) {
|
||||||
struct NtProcessBasicInformation ProcessInformation;
|
struct NtProcessBasicInformation ProcessInformation;
|
||||||
uint32_t gotsize = 0;
|
uint32_t gotsize = 0;
|
||||||
if (!NtError(
|
if (!NtError(
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
*/
|
*/
|
||||||
int32_t getppid(void) {
|
int32_t getppid(void) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return getppid$sysv();
|
return sys_getppid();
|
||||||
} else {
|
} else {
|
||||||
return getppid$nt();
|
return sys_getppid_nt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include "libc/sysv/consts/prio.h"
|
#include "libc/sysv/consts/prio.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int getpriority$nt(int ignored) {
|
textwindows int sys_getpriority_nt(int ignored) {
|
||||||
size_t i;
|
size_t i;
|
||||||
uint32_t tier, lg2tier, wut;
|
uint32_t tier, lg2tier, wut;
|
||||||
if ((tier = GetPriorityClass(GetCurrentProcess())) != 0 &&
|
if ((tier = GetPriorityClass(GetCurrentProcess())) != 0 &&
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
*/
|
*/
|
||||||
int getpriority(int which, unsigned who) {
|
int getpriority(int which, unsigned who) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return getpriority$sysv(which, who) - 20;
|
return sys_getpriority(which, who) - 20;
|
||||||
} else {
|
} else {
|
||||||
return getsetpriority$nt(which, who, 0, getpriority$nt);
|
return sys_getsetpriority_nt(which, who, 0, sys_getpriority_nt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,5 +31,5 @@
|
||||||
*/
|
*/
|
||||||
int getrlimit(int resource, struct rlimit *rlim) {
|
int getrlimit(int resource, struct rlimit *rlim) {
|
||||||
if (resource == -1) return einval();
|
if (resource == -1) return einval();
|
||||||
return getrlimit$sysv(resource, rlim);
|
return sys_getrlimit(resource, rlim);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/consts/rusage.h"
|
#include "libc/sysv/consts/rusage.h"
|
||||||
|
|
||||||
textwindows int getrusage$nt(int who, struct rusage *usage) {
|
textwindows int sys_getrusage_nt(int who, struct rusage *usage) {
|
||||||
struct NtFileTime CreationFileTime;
|
struct NtFileTime CreationFileTime;
|
||||||
struct NtFileTime ExitFileTime;
|
struct NtFileTime ExitFileTime;
|
||||||
struct NtFileTime KernelFileTime;
|
struct NtFileTime KernelFileTime;
|
||||||
|
|
|
@ -30,8 +30,8 @@ int getrusage(int who, struct rusage *usage) {
|
||||||
if (who == 99) return enosys(); /* @see libc/sysv/consts.sh */
|
if (who == 99) return enosys(); /* @see libc/sysv/consts.sh */
|
||||||
if (!usage) return efault();
|
if (!usage) return efault();
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return getrusage$sysv(who, usage);
|
return sys_getrusage(who, usage);
|
||||||
} else {
|
} else {
|
||||||
return getrusage$nt(who, usage);
|
return sys_getrusage_nt(who, usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "libc/sysv/consts/prio.h"
|
#include "libc/sysv/consts/prio.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int getsetpriority$nt(int which, unsigned who, int value,
|
textwindows int sys_getsetpriority_nt(int which, unsigned who, int value,
|
||||||
int (*impl)(int)) {
|
int (*impl)(int)) {
|
||||||
if (which != PRIO_PROCESS && which != PRIO_PGRP) return einval();
|
if (which != PRIO_PROCESS && which != PRIO_PGRP) return einval();
|
||||||
if (who && abs(who) != getpid() && abs(who) != gettid()) return eopnotsupp();
|
if (who && abs(who) != getpid() && abs(who) != gettid()) return eopnotsupp();
|
||||||
|
|
|
@ -23,5 +23,5 @@
|
||||||
* Creates session and sets the process group id.
|
* Creates session and sets the process group id.
|
||||||
*/
|
*/
|
||||||
uint32_t getsid(int pid) {
|
uint32_t getsid(int pid) {
|
||||||
return getsid$sysv(pid);
|
return sys_getsid(pid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
uint32_t gettid(void) {
|
uint32_t gettid(void) {
|
||||||
uint32_t res;
|
uint32_t res;
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
res = gettid$sysv();
|
res = sys_gettid();
|
||||||
if (res <= 0) {
|
if (res <= 0) {
|
||||||
res = getpid();
|
res = getpid();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/time/struct/timezone.h"
|
#include "libc/time/struct/timezone.h"
|
||||||
|
|
||||||
int gettimeofday$nt(struct timeval *tv, struct timezone *tz) {
|
int sys_gettimeofday_nt(struct timeval *tv, struct timezone *tz) {
|
||||||
struct NtFileTime ft;
|
struct NtFileTime ft;
|
||||||
GetSystemTimeAsFileTime(&ft);
|
GetSystemTimeAsFileTime(&ft);
|
||||||
FileTimeToTimeVal(tv, ft);
|
FileTimeToTimeVal(tv, ft);
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
/ @return always zero
|
/ @return always zero
|
||||||
/ @see clock_gettime() for nanosecond precision
|
/ @see clock_gettime() for nanosecond precision
|
||||||
/ @see strftime() for string formatting
|
/ @see strftime() for string formatting
|
||||||
gettimeofday$sysv:
|
sys_gettimeofday:
|
||||||
push %rbp
|
push %rbp
|
||||||
mov %rsp,%rbp
|
mov %rsp,%rbp
|
||||||
.profilable
|
.profilable
|
||||||
|
@ -36,7 +36,7 @@ gettimeofday$sysv:
|
||||||
pop (%rsi)
|
pop (%rsi)
|
||||||
1: xor %esi,%esi # no one zones this way.
|
1: xor %esi,%esi # no one zones this way.
|
||||||
xor %edx,%edx # i64*mach_absolute_time
|
xor %edx,%edx # i64*mach_absolute_time
|
||||||
call __gettimeofday$sysv
|
call __sys_gettimeofday
|
||||||
#if SupportsXnu()
|
#if SupportsXnu()
|
||||||
testb IsXnu() # XNU might do %rax:%rdx
|
testb IsXnu() # XNU might do %rax:%rdx
|
||||||
jz 1f
|
jz 1f
|
||||||
|
@ -50,4 +50,4 @@ gettimeofday$sysv:
|
||||||
1: xor %eax,%eax # nevar fail
|
1: xor %eax,%eax # nevar fail
|
||||||
pop %rbp
|
pop %rbp
|
||||||
ret
|
ret
|
||||||
.endfn gettimeofday$sysv,globl,hidden
|
.endfn sys_gettimeofday,globl,hidden
|
||||||
|
|
|
@ -33,8 +33,8 @@
|
||||||
*/
|
*/
|
||||||
int gettimeofday(struct timeval *tv, struct timezone *tz) {
|
int gettimeofday(struct timeval *tv, struct timezone *tz) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return gettimeofday$sysv(tv, tz);
|
return sys_gettimeofday(tv, tz);
|
||||||
} else {
|
} else {
|
||||||
return gettimeofday$nt(tv, tz);
|
return sys_gettimeofday_nt(tv, tz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ static uint32_t getuidgid(int at, uint32_t impl(void)) {
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
*/
|
*/
|
||||||
uint32_t getuid(void) {
|
uint32_t getuid(void) {
|
||||||
return getuidgid(AT_UID, getuid$sysv);
|
return getuidgid(AT_UID, sys_getuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,5 +76,5 @@ uint32_t getuid(void) {
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
*/
|
*/
|
||||||
uint32_t getgid(void) {
|
uint32_t getgid(void) {
|
||||||
return getuidgid(AT_GID, getgid$sysv);
|
return getuidgid(AT_GID, sys_getgid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#ifndef COSMOPOLITAN_LIBC_CALLS_INTERNAL_H_
|
#ifndef COSMOPOLITAN_LIBC_CALLS_INTERNAL_H_
|
||||||
#define COSMOPOLITAN_LIBC_CALLS_INTERNAL_H_
|
#define COSMOPOLITAN_LIBC_CALLS_INTERNAL_H_
|
||||||
#ifndef __STRICT_ANSI__
|
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/struct/iovec.h"
|
#include "libc/calls/struct/iovec.h"
|
||||||
#include "libc/calls/struct/itimerval.h"
|
#include "libc/calls/struct/itimerval.h"
|
||||||
|
@ -69,8 +68,8 @@ hidden extern volatile bool __interrupted;
|
||||||
hidden extern int __vforked;
|
hidden extern int __vforked;
|
||||||
hidden extern unsigned __sighandrvas[NSIG];
|
hidden extern unsigned __sighandrvas[NSIG];
|
||||||
hidden extern struct Fds g_fds;
|
hidden extern struct Fds g_fds;
|
||||||
hidden extern struct NtSystemInfo g_ntsysteminfo;
|
hidden extern struct NtSystemInfo __nt_systeminfo;
|
||||||
hidden extern struct NtStartupInfo g_ntstartupinfo;
|
hidden extern struct NtStartupInfo __nt_startupinfo;
|
||||||
hidden extern const struct NtSecurityAttributes kNtIsInheritable;
|
hidden extern const struct NtSecurityAttributes kNtIsInheritable;
|
||||||
|
|
||||||
int __reservefd(void) hidden;
|
int __reservefd(void) hidden;
|
||||||
|
@ -104,108 +103,108 @@ forceinline size_t clampio(size_t size) {
|
||||||
│ cosmopolitan § syscalls » system five » synthetic jump slots ─╬─│┼
|
│ cosmopolitan § syscalls » system five » synthetic jump slots ─╬─│┼
|
||||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||||
|
|
||||||
char *getcwd$sysv(char *, u64) hidden;
|
char *sys_getcwd(char *, u64) hidden;
|
||||||
char *getcwd$xnu(char *, u64) hidden;
|
char *sys_getcwd_xnu(char *, u64) hidden;
|
||||||
i32 __dup3$sysv(i32, i32, i32) hidden;
|
i32 __sys_dup3(i32, i32, i32) hidden;
|
||||||
i32 __execve$sysv(const char *, char *const[], char *const[]) hidden;
|
i32 __sys_execve(const char *, char *const[], char *const[]) hidden;
|
||||||
i32 __fstat$sysv(i32, struct stat *) hidden;
|
i32 __sys_fstat(i32, struct stat *) hidden;
|
||||||
i32 __fstatat$sysv(i32, const char *, struct stat *, i32) hidden;
|
i32 __sys_fstatat(i32, const char *, struct stat *, i32) hidden;
|
||||||
i32 __pipe2$sysv(i32[hasatleast 2], u32) hidden;
|
i32 __sys_pipe2(i32[hasatleast 2], u32) hidden;
|
||||||
i32 __utimensat$sysv(i32, const char *, const struct timespec *, i32) hidden;
|
i32 __sys_utimensat(i32, const char *, const struct timespec *, i32) hidden;
|
||||||
i32 chdir$sysv(const char *) hidden;
|
|
||||||
i32 clock_gettime$sysv(i32, struct timespec *) hidden;
|
|
||||||
i32 close$sysv(i32) hidden;
|
|
||||||
i32 dup$sysv(i32) hidden;
|
|
||||||
i32 dup2$sysv(i32, i32) hidden;
|
|
||||||
i32 dup3$sysv(i32, i32, i32) hidden;
|
|
||||||
i32 execve$sysv(const char *, char *const[], char *const[]) hidden;
|
|
||||||
i32 faccessat$sysv(i32, const char *, i32, u32) hidden;
|
|
||||||
i32 fadvise$sysv(i32, i64, i64, i32) hidden;
|
|
||||||
i32 fallocate$sysv(i64, i32, i64, i64) hidden;
|
|
||||||
i32 fchdir$sysv(i32) hidden;
|
|
||||||
i32 fchmod$sysv(i32, u32) hidden;
|
|
||||||
i32 fchmodat$sysv(i32, const char *, u32, u32) hidden;
|
|
||||||
i32 fchown$sysv(i64, u32, u32) hidden;
|
|
||||||
i32 fchownat$sysv(i32, const char *, u32, u32, u32) hidden;
|
|
||||||
i32 fcntl$sysv(i32, i32, ...) hidden;
|
|
||||||
i32 fdatasync$sysv(i32) hidden;
|
|
||||||
i32 flock$sysv(i32, i32) hidden;
|
|
||||||
i32 fork$sysv(void) hidden;
|
|
||||||
i32 fstat$sysv(i32, struct stat *) hidden;
|
|
||||||
i32 fstatat$sysv(i32, const char *, struct stat *, i32) hidden;
|
|
||||||
i32 fsync$sysv(i32) hidden;
|
|
||||||
i32 ftruncate$sysv(i32, i64) hidden;
|
|
||||||
i32 futimes$sysv(i32, const struct timeval *) hidden;
|
|
||||||
i32 futimesat$sysv(i32, const char *, const struct timeval *) hidden;
|
|
||||||
i32 getdents(i32, char *, u32, i64 *) hidden;
|
i32 getdents(i32, char *, u32, i64 *) hidden;
|
||||||
i32 getitimer$sysv(i32, struct itimerval *) hidden;
|
i32 sys_chdir(const char *) hidden;
|
||||||
i32 getppid$sysv(void) hidden;
|
i32 sys_clock_gettime(i32, struct timespec *) hidden;
|
||||||
i32 getpriority$sysv(i32, u32) hidden;
|
i32 sys_close(i32) hidden;
|
||||||
i32 getrlimit$sysv(i32, struct rlimit *) hidden;
|
i32 sys_dup(i32) hidden;
|
||||||
i32 getrusage$sysv(i32, struct rusage *) hidden;
|
i32 sys_dup2(i32, i32) hidden;
|
||||||
i32 gettimeofday$sysv(struct timeval *, struct timezone *) hidden;
|
i32 sys_dup3(i32, i32, i32) hidden;
|
||||||
i32 ioctl$sysv(i32, u64, void *) hidden;
|
i32 sys_execve(const char *, char *const[], char *const[]) hidden;
|
||||||
i32 kill$sysv(i32, i32, i32) hidden;
|
i32 sys_faccessat(i32, const char *, i32, u32) hidden;
|
||||||
i32 linkat$sysv(i32, const char *, i32, const char *, i32) hidden;
|
i32 sys_fadvise(i32, i64, i64, i32) hidden;
|
||||||
i32 lseek$sysv(i32, i64, i32) hidden;
|
i32 sys_fallocate(i64, i32, i64, i64) hidden;
|
||||||
i32 lutimes$sysv(const char *, const struct timeval *) hidden;
|
i32 sys_fchdir(i32) hidden;
|
||||||
i32 madvise$sysv(void *, size_t, i32) hidden;
|
i32 sys_fchmod(i32, u32) hidden;
|
||||||
i32 memfd_create$sysv(const char *, u32) hidden;
|
i32 sys_fchmodat(i32, const char *, u32, u32) hidden;
|
||||||
i32 mkdirat$sysv(i32, const char *, u32) hidden;
|
i32 sys_fchown(i64, u32, u32) hidden;
|
||||||
i32 mkfifo$sysv(const char *, u32) hidden;
|
i32 sys_fchownat(i32, const char *, u32, u32, u32) hidden;
|
||||||
i32 mknod$sysv(const char *, u32, u64) hidden;
|
i32 sys_fcntl(i32, i32, ...) hidden;
|
||||||
i32 mprotect$sysv(void *, u64, i32) hidden;
|
i32 sys_fdatasync(i32) hidden;
|
||||||
i32 msync$sysv(void *, u64, i32) hidden;
|
i32 sys_flock(i32, i32) hidden;
|
||||||
i32 munmap$sysv(void *, u64) hidden;
|
i32 sys_fork(void) hidden;
|
||||||
i32 nanosleep$sysv(const struct timespec *, struct timespec *) hidden;
|
i32 sys_fstat(i32, struct stat *) hidden;
|
||||||
i32 openat$sysv(i32, const char *, i32, ...) hidden;
|
i32 sys_fstatat(i32, const char *, struct stat *, i32) hidden;
|
||||||
i32 pause$sysv(void) hidden;
|
i32 sys_fsync(i32) hidden;
|
||||||
i32 pipe$sysv(i32[hasatleast 2]) hidden;
|
i32 sys_ftruncate(i32, i64) hidden;
|
||||||
i32 pipe2$sysv(i32[hasatleast 2], u32) hidden;
|
i32 sys_futimes(i32, const struct timeval *) hidden;
|
||||||
i32 posix_fallocate$sysv(i64, i64, i64) hidden;
|
i32 sys_futimesat(i32, const char *, const struct timeval *) hidden;
|
||||||
i32 posix_openpt$sysv(i32) hidden;
|
i32 sys_getitimer(i32, struct itimerval *) hidden;
|
||||||
i32 renameat$sysv(i32, const char *, i32, const char *) hidden;
|
i32 sys_getppid(void) hidden;
|
||||||
i32 sched_setaffinity$sysv(i32, u64, const void *) hidden;
|
i32 sys_getpriority(i32, u32) hidden;
|
||||||
i32 sched_yield$sysv(void) hidden;
|
i32 sys_getrlimit(i32, struct rlimit *) hidden;
|
||||||
i32 setitimer$sysv(i32, const struct itimerval *, struct itimerval *) hidden;
|
i32 sys_getrusage(i32, struct rusage *) hidden;
|
||||||
i32 setpriority$sysv(i32, u32, i32) hidden;
|
i32 sys_gettimeofday(struct timeval *, struct timezone *) hidden;
|
||||||
i32 setresgid$sysv(uint32_t, uint32_t, uint32_t) hidden;
|
i32 sys_ioctl(i32, u64, void *) hidden;
|
||||||
i32 setresuid$sysv(uint32_t, uint32_t, uint32_t) hidden;
|
i32 sys_kill(i32, i32, i32) hidden;
|
||||||
i32 setrlimit$sysv(i32, const struct rlimit *) hidden;
|
i32 sys_linkat(i32, const char *, i32, const char *, i32) hidden;
|
||||||
i32 setsid$sysv(void) hidden;
|
i32 sys_lseek(i32, i64, i32) hidden;
|
||||||
i32 sigaction$sysv(i32, const void *, void *, i64) hidden;
|
i32 sys_lutimes(const char *, const struct timeval *) hidden;
|
||||||
i32 sigprocmask$sysv(i32, const sigset *, sigset *, u64) hidden;
|
i32 sys_madvise(void *, size_t, i32) hidden;
|
||||||
i32 sigsuspend$sysv(const sigset *, u64) hidden;
|
i32 sys_memfd_create(const char *, u32) hidden;
|
||||||
i32 symlinkat$sysv(const char *, i32, const char *) hidden;
|
i32 sys_mkdirat(i32, const char *, u32) hidden;
|
||||||
i32 sync$sysv(void) hidden;
|
i32 sys_mkfifo(const char *, u32) hidden;
|
||||||
i32 sync_file_range$sysv(i32, i64, i64, u32) hidden;
|
i32 sys_mknod(const char *, u32, u64) hidden;
|
||||||
i32 sysinfo$sysv(struct sysinfo *) hidden;
|
i32 sys_mprotect(void *, u64, i32) hidden;
|
||||||
i32 truncate$sysv(const char *, u64) hidden;
|
i32 sys_msync(void *, u64, i32) hidden;
|
||||||
i32 uname$sysv(char *) hidden;
|
i32 sys_munmap(void *, u64) hidden;
|
||||||
i32 unlinkat$sysv(i32, const char *, i32) hidden;
|
i32 sys_nanosleep(const struct timespec *, struct timespec *) hidden;
|
||||||
i32 utime$sysv(const char *, const struct utimbuf *) hidden;
|
i32 sys_openat(i32, const char *, i32, ...) hidden;
|
||||||
i32 utimensat$sysv(i32, const char *, const struct timespec *, i32) hidden;
|
i32 sys_pause(void) hidden;
|
||||||
i32 utimes$sysv(const char *, const struct timeval *) hidden;
|
i32 sys_pipe(i32[hasatleast 2]) hidden;
|
||||||
i32 wait4$sysv(i32, i32 *, i32, struct rusage *) hidden;
|
i32 sys_pipe2(i32[hasatleast 2], u32) hidden;
|
||||||
i64 copy_file_range$sysv(i32, long *, i32, long *, u64, u32) hidden;
|
i32 sys_posix_fallocate(i64, i64, i64) hidden;
|
||||||
i64 getrandom$sysv(void *, u64, u32) hidden;
|
i32 sys_posix_openpt(i32) hidden;
|
||||||
i64 pread$sysv(i32, void *, u64, i64) hidden;
|
i32 sys_renameat(i32, const char *, i32, const char *) hidden;
|
||||||
i64 preadv$sysv(i32, struct iovec *, i32, i64) hidden;
|
i32 sys_sched_setaffinity(i32, u64, const void *) hidden;
|
||||||
i64 ptrace$sysv(int, i32, void *, void *) hidden;
|
i32 sys_sched_yield(void) hidden;
|
||||||
i64 pwrite$sysv(i32, const void *, u64, i64) hidden;
|
i32 sys_setitimer(i32, const struct itimerval *, struct itimerval *) hidden;
|
||||||
i64 pwritev$sysv(i32, const struct iovec *, i32, i64) hidden;
|
i32 sys_setpriority(i32, u32, i32) hidden;
|
||||||
i64 read$sysv(i32, void *, u64) hidden;
|
i32 sys_setresgid(uint32_t, uint32_t, uint32_t) hidden;
|
||||||
i64 sendfile$sysv(i32, i32, i64 *, u64) hidden;
|
i32 sys_setresuid(uint32_t, uint32_t, uint32_t) hidden;
|
||||||
i64 splice$sysv(i32, i64 *, i32, i64 *, u64, u32) hidden;
|
i32 sys_setrlimit(i32, const struct rlimit *) hidden;
|
||||||
i64 vmsplice$sysv(i32, const struct iovec *, i64, u32) hidden;
|
i32 sys_setsid(void) hidden;
|
||||||
i64 write$sysv(i32, const void *, u64) hidden;
|
i32 sys_sigaction(i32, const void *, void *, i64) hidden;
|
||||||
u32 getgid$sysv(void) hidden;
|
i32 sys_sigprocmask(i32, const sigset *, sigset *, u64) hidden;
|
||||||
u32 getpid$sysv(void) hidden;
|
i32 sys_sigsuspend(const sigset *, u64) hidden;
|
||||||
u32 getsid$sysv(int) hidden;
|
i32 sys_symlinkat(const char *, i32, const char *) hidden;
|
||||||
u32 gettid$sysv(void) hidden;
|
i32 sys_sync(void) hidden;
|
||||||
u32 getuid$sysv(void) hidden;
|
i32 sys_sync_file_range(i32, i64, i64, u32) hidden;
|
||||||
void *mmap$sysv(void *, u64, u32, u32, i64, i64) hidden;
|
i32 sys_sysinfo(struct sysinfo *) hidden;
|
||||||
void *mremap$sysv(void *, u64, u64, i32, void *) hidden;
|
i32 sys_truncate(const char *, u64) hidden;
|
||||||
|
i32 sys_uname(char *) hidden;
|
||||||
|
i32 sys_unlinkat(i32, const char *, i32) hidden;
|
||||||
|
i32 sys_utime(const char *, const struct utimbuf *) hidden;
|
||||||
|
i32 sys_utimensat(i32, const char *, const struct timespec *, i32) hidden;
|
||||||
|
i32 sys_utimes(const char *, const struct timeval *) hidden;
|
||||||
|
i32 sys_wait4(i32, i32 *, i32, struct rusage *) hidden;
|
||||||
|
i64 sys_copy_file_range(i32, long *, i32, long *, u64, u32) hidden;
|
||||||
|
i64 sys_getrandom(void *, u64, u32) hidden;
|
||||||
|
i64 sys_pread(i32, void *, u64, i64) hidden;
|
||||||
|
i64 sys_preadv(i32, struct iovec *, i32, i64) hidden;
|
||||||
|
i64 sys_ptrace(int, i32, void *, void *) hidden;
|
||||||
|
i64 sys_pwrite(i32, const void *, u64, i64) hidden;
|
||||||
|
i64 sys_pwritev(i32, const struct iovec *, i32, i64) hidden;
|
||||||
|
i64 sys_read(i32, void *, u64) hidden;
|
||||||
|
i64 sys_sendfile(i32, i32, i64 *, u64) hidden;
|
||||||
|
i64 sys_splice(i32, i64 *, i32, i64 *, u64, u32) hidden;
|
||||||
|
i64 sys_vmsplice(i32, const struct iovec *, i64, u32) hidden;
|
||||||
|
i64 sys_write(i32, const void *, u64) hidden;
|
||||||
|
u32 sys_getgid(void) hidden;
|
||||||
|
u32 sys_getpid(void) hidden;
|
||||||
|
u32 sys_getsid(int) hidden;
|
||||||
|
u32 sys_gettid(void) hidden;
|
||||||
|
u32 sys_getuid(void) hidden;
|
||||||
|
void *sys_mmap(void *, u64, u32, u32, i64, i64) hidden;
|
||||||
|
void *sys_mremap(void *, u64, u64, i32, void *) hidden;
|
||||||
|
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § syscalls » system five » support ─╬─│┼
|
│ cosmopolitan § syscalls » system five » support ─╬─│┼
|
||||||
|
@ -213,64 +212,62 @@ void *mremap$sysv(void *, u64, u64, i32, void *) hidden;
|
||||||
|
|
||||||
void __onfork(void) hidden;
|
void __onfork(void) hidden;
|
||||||
bool32 __sigenter(i32, struct siginfo *, struct ucontext *) hidden;
|
bool32 __sigenter(i32, struct siginfo *, struct ucontext *) hidden;
|
||||||
i32 fixupnewfd$sysv(i32, i32) hidden;
|
i32 __fixupnewfd(i32, i32) hidden;
|
||||||
i32 tunefd$sysv(i32, i32, i32, i32) hidden;
|
u32 __prot2nt(i32, i32) privileged;
|
||||||
u32 fprot2nt(i32, i32) hidden;
|
|
||||||
u32 prot2nt(i32, i32) privileged;
|
|
||||||
void __restore_rt() hidden;
|
void __restore_rt() hidden;
|
||||||
void __sigenter$xnu(void *, i32, i32, void *, void *) hidden wontreturn;
|
void __sigenter_xnu(void *, i32, i32, void *, void *) hidden wontreturn;
|
||||||
int utimensat$xnu(int, const char *, const struct timespec *, int) hidden;
|
int sys_utimensat_xnu(int, const char *, const struct timespec *, int) hidden;
|
||||||
int nanosleep$xnu(const struct timespec *, struct timespec *) hidden;
|
int sys_nanosleep_xnu(const struct timespec *, struct timespec *) hidden;
|
||||||
void stat2linux(void *) hidden;
|
void __stat2linux(void *) hidden;
|
||||||
void xnutrampoline(void *, i32, i32, const struct __darwin_siginfo *,
|
void __xnutrampoline(void *, i32, i32, const struct __darwin_siginfo *,
|
||||||
const struct __darwin_ucontext *) hidden wontreturn;
|
const struct __darwin_ucontext *) hidden wontreturn;
|
||||||
|
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § syscalls » windows nt » veneers ─╬─│┼
|
│ cosmopolitan § syscalls » windows nt » veneers ─╬─│┼
|
||||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||||
|
|
||||||
bool32 isatty$nt(int) hidden;
|
bool32 sys_isatty_nt(int) hidden;
|
||||||
char *getcwd$nt(char *, size_t) hidden;
|
char *sys_getcwd_nt(char *, size_t) hidden;
|
||||||
i64 lseek$nt(int, i64, int) hidden;
|
i64 sys_lseek_nt(int, i64, int) hidden;
|
||||||
int chdir$nt(const char *) hidden;
|
int sys_chdir_nt(const char *) hidden;
|
||||||
int close$nt(int) hidden;
|
int sys_close_nt(int) hidden;
|
||||||
int dup$nt(int, int, int) hidden;
|
int sys_dup_nt(int, int, int) hidden;
|
||||||
int execve$nt(const char *, char *const[], char *const[]) hidden;
|
int sys_execve_nt(const char *, char *const[], char *const[]) hidden;
|
||||||
int faccessat$nt(int, const char *, int, uint32_t) hidden;
|
int sys_faccessat_nt(int, const char *, int, uint32_t) hidden;
|
||||||
int fadvise$nt(int, u64, u64, int) hidden;
|
int sys_fadvise_nt(int, u64, u64, int) hidden;
|
||||||
int fchdir$nt(int) hidden;
|
int sys_fchdir_nt(int) hidden;
|
||||||
int fcntl$nt(int, int, unsigned) hidden;
|
int sys_fcntl_nt(int, int, unsigned) hidden;
|
||||||
int fdatasync$nt(int) hidden;
|
int sys_fdatasync_nt(int) hidden;
|
||||||
int flock$nt(int, int) hidden;
|
int sys_flock_nt(int, int) hidden;
|
||||||
int fork$nt(void) hidden;
|
int sys_fork_nt(void) hidden;
|
||||||
int fstat$nt(i64, struct stat *) hidden;
|
int sys_fstat_nt(i64, struct stat *) hidden;
|
||||||
int fstatat$nt(int, const char *, struct stat *, uint32_t) hidden;
|
int sys_fstatat_nt(int, const char *, struct stat *, uint32_t) hidden;
|
||||||
int ftruncate$nt(int, u64) hidden;
|
int sys_ftruncate_nt(int, u64) hidden;
|
||||||
int getppid$nt(void) hidden;
|
int sys_getppid_nt(void) hidden;
|
||||||
int getpriority$nt(int) hidden;
|
int sys_getpriority_nt(int) hidden;
|
||||||
int getrusage$nt(int, struct rusage *) hidden;
|
int sys_getrusage_nt(int, struct rusage *) hidden;
|
||||||
int gettimeofday$nt(struct timeval *, struct timezone *) hidden;
|
int sys_gettimeofday_nt(struct timeval *, struct timezone *) hidden;
|
||||||
int kill$nt(int, int) hidden;
|
int sys_kill_nt(int, int) hidden;
|
||||||
int link$nt(const char *, const char *) hidden;
|
int sys_link_nt(const char *, const char *) hidden;
|
||||||
int lstat$nt(const char *, struct stat *) hidden;
|
int sys_lstat_nt(const char *, struct stat *) hidden;
|
||||||
int madvise$nt(void *, size_t, int) hidden;
|
int sys_madvise_nt(void *, size_t, int) hidden;
|
||||||
int mkdirat$nt(int, const char *, uint32_t) hidden;
|
int sys_mkdirat_nt(int, const char *, uint32_t) hidden;
|
||||||
int msync$nt(void *, size_t, int) hidden;
|
int sys_msync_nt(void *, size_t, int) hidden;
|
||||||
int nanosleep$nt(const struct timespec *, struct timespec *) hidden;
|
int sys_nanosleep_nt(const struct timespec *, struct timespec *) hidden;
|
||||||
int pipe$nt(int[hasatleast 2], unsigned) hidden;
|
int sys_pipe_nt(int[hasatleast 2], unsigned) hidden;
|
||||||
int renameat$nt(int, const char *, int, const char *) hidden;
|
int sys_renameat_nt(int, const char *, int, const char *) hidden;
|
||||||
int sched_yield$nt(void) hidden;
|
int sys_sched_yield_nt(void) hidden;
|
||||||
int setitimer$nt(int, const struct itimerval *, struct itimerval *) hidden;
|
int sys_setitimer_nt(int, const struct itimerval *, struct itimerval *) hidden;
|
||||||
int setpriority$nt(int) hidden;
|
int sys_setpriority_nt(int) hidden;
|
||||||
int symlinkat$nt(const char *, int, const char *) hidden;
|
int sys_symlinkat_nt(const char *, int, const char *) hidden;
|
||||||
int sync$nt(void) hidden;
|
int sys_sync_nt(void) hidden;
|
||||||
int sysinfo$nt(struct sysinfo *) hidden;
|
int sys_sysinfo_nt(struct sysinfo *) hidden;
|
||||||
int truncate$nt(const char *, u64) hidden;
|
int sys_truncate_nt(const char *, u64) hidden;
|
||||||
int unlinkat$nt(int, const char *, int) hidden;
|
int sys_unlinkat_nt(int, const char *, int) hidden;
|
||||||
int utimensat$nt(int, const char *, const struct timespec *, int) hidden;
|
int sys_utimensat_nt(int, const char *, const struct timespec *, int) hidden;
|
||||||
ssize_t open$nt(int, const char *, u32, i32) nodiscard hidden;
|
ssize_t sys_open_nt(int, const char *, u32, i32) nodiscard hidden;
|
||||||
ssize_t read$nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden;
|
ssize_t sys_read_nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden;
|
||||||
ssize_t write$nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden;
|
ssize_t sys_write_nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden;
|
||||||
|
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § syscalls » windows nt » support ─╬─│┼
|
│ cosmopolitan § syscalls » windows nt » support ─╬─│┼
|
||||||
|
@ -279,7 +276,7 @@ ssize_t write$nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden;
|
||||||
int64_t ntreturn(uint32_t);
|
int64_t ntreturn(uint32_t);
|
||||||
void WinMainForked(void) hidden;
|
void WinMainForked(void) hidden;
|
||||||
void *GetProcAddressModule(const char *, const char *) hidden;
|
void *GetProcAddressModule(const char *, const char *) hidden;
|
||||||
int getsetpriority$nt(int, unsigned, int, int (*)(int));
|
int sys_getsetpriority_nt(int, unsigned, int, int (*)(int));
|
||||||
void ntcontext2linux(struct ucontext *, const struct NtContext *) hidden;
|
void ntcontext2linux(struct ucontext *, const struct NtContext *) hidden;
|
||||||
struct NtOverlapped *offset2overlap(int64_t, struct NtOverlapped *) hidden;
|
struct NtOverlapped *offset2overlap(int64_t, struct NtOverlapped *) hidden;
|
||||||
bool32 ntsetprivilege(i64, const char16_t *, u32) hidden;
|
bool32 ntsetprivilege(i64, const char16_t *, u32) hidden;
|
||||||
|
@ -289,7 +286,7 @@ int64_t __winerr(void) nocallback privileged;
|
||||||
int __mkntpath(const char *, char16_t[hasatleast PATH_MAX - 16]) hidden;
|
int __mkntpath(const char *, char16_t[hasatleast PATH_MAX - 16]) hidden;
|
||||||
int __mkntpath2(const char *, char16_t[hasatleast PATH_MAX - 16], int) hidden;
|
int __mkntpath2(const char *, char16_t[hasatleast PATH_MAX - 16], int) hidden;
|
||||||
int __mkntpathat(int, const char *, int, char16_t[PATH_MAX]) hidden;
|
int __mkntpathat(int, const char *, int, char16_t[PATH_MAX]) hidden;
|
||||||
unsigned __wincrash$nt(struct NtExceptionPointers *);
|
unsigned __wincrash_nt(struct NtExceptionPointers *);
|
||||||
|
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § syscalls » metal ─╬─│┼
|
│ cosmopolitan § syscalls » metal ─╬─│┼
|
||||||
|
@ -311,5 +308,4 @@ ssize_t writev$serial(struct Fd *, const struct iovec *, int) hidden;
|
||||||
#undef u64
|
#undef u64
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
#endif /* !ANSI */
|
|
||||||
#endif /* COSMOPOLITAN_LIBC_CALLS_INTERNAL_H_ */
|
#endif /* COSMOPOLITAN_LIBC_CALLS_INTERNAL_H_ */
|
||||||
|
|
|
@ -27,11 +27,11 @@ int ioctl$default(int fd, uint64_t request, void *memory) {
|
||||||
int rc;
|
int rc;
|
||||||
int64_t handle;
|
int64_t handle;
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return ioctl$sysv(fd, request, memory);
|
return sys_ioctl(fd, request, memory);
|
||||||
} else if (__isfdopen(fd)) {
|
} else if (__isfdopen(fd)) {
|
||||||
if (g_fds.p[fd].kind == kFdSocket) {
|
if (g_fds.p[fd].kind == kFdSocket) {
|
||||||
handle = g_fds.p[fd].handle;
|
handle = g_fds.p[fd].handle;
|
||||||
if ((rc = weaken(__ioctlsocket$nt)(handle, request, memory)) != -1) {
|
if ((rc = weaken(__sys_ioctlsocket_nt)(handle, request, memory)) != -1) {
|
||||||
return rc;
|
return rc;
|
||||||
} else {
|
} else {
|
||||||
return weaken(__winsockerr)();
|
return weaken(__winsockerr)();
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "libc/sysv/consts/termios.h"
|
#include "libc/sysv/consts/termios.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int ioctl$tcgets$nt(int ignored, struct termios *tio) {
|
textwindows int ioctl$sys_tcgets_nt(int ignored, struct termios *tio) {
|
||||||
int64_t in, out;
|
int64_t in, out;
|
||||||
bool32 inok, outok;
|
bool32 inok, outok;
|
||||||
uint32_t inmode, outmode;
|
uint32_t inmode, outmode;
|
||||||
|
|
|
@ -21,12 +21,12 @@
|
||||||
#include "libc/calls/termios.internal.h"
|
#include "libc/calls/termios.internal.h"
|
||||||
#include "libc/sysv/consts/termios.h"
|
#include "libc/sysv/consts/termios.h"
|
||||||
|
|
||||||
int ioctl$tcgets$nt(int, struct termios *);
|
int ioctl$sys_tcgets_nt(int, struct termios *);
|
||||||
|
|
||||||
static int ioctl$tcgets$sysv(int fd, struct termios *tio) {
|
static int ioctl$sys_tcgets(int fd, struct termios *tio) {
|
||||||
int rc;
|
int rc;
|
||||||
union metatermios t;
|
union metatermios t;
|
||||||
if ((rc = ioctl$sysv(fd, TCGETS, &t)) != -1) {
|
if ((rc = sys_ioctl(fd, TCGETS, &t)) != -1) {
|
||||||
termios2linux(tio, &t);
|
termios2linux(tio, &t);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -41,8 +41,8 @@ static int ioctl$tcgets$sysv(int fd, struct termios *tio) {
|
||||||
*/
|
*/
|
||||||
int ioctl$tcgets(int fd, struct termios *tio) {
|
int ioctl$tcgets(int fd, struct termios *tio) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return ioctl$tcgets$sysv(fd, tio);
|
return ioctl$sys_tcgets(fd, tio);
|
||||||
} else {
|
} else {
|
||||||
return ioctl$tcgets$nt(fd, tio);
|
return ioctl$sys_tcgets_nt(fd, tio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "libc/sysv/consts/termios.h"
|
#include "libc/sysv/consts/termios.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int ioctl$tcsets$nt(int ignored, uint64_t request,
|
textwindows int ioctl$sys_tcsets_nt(int ignored, uint64_t request,
|
||||||
const struct termios *tio) {
|
const struct termios *tio) {
|
||||||
int64_t in, out;
|
int64_t in, out;
|
||||||
bool32 inok, outok;
|
bool32 inok, outok;
|
||||||
|
|
|
@ -22,12 +22,12 @@
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/sysv/consts/termios.h"
|
#include "libc/sysv/consts/termios.h"
|
||||||
|
|
||||||
int ioctl$tcsets$nt(int, uint64_t, const struct termios *);
|
int ioctl$sys_tcsets_nt(int, uint64_t, const struct termios *);
|
||||||
|
|
||||||
static int ioctl$tcsets$sysv(int fd, uint64_t request,
|
static int ioctl$sys_tcsets(int fd, uint64_t request,
|
||||||
const struct termios *tio) {
|
const struct termios *tio) {
|
||||||
union metatermios t;
|
union metatermios t;
|
||||||
return ioctl$sysv(fd, request, termios2host(&t, tio));
|
return sys_ioctl(fd, request, termios2host(&t, tio));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,8 +39,8 @@ static int ioctl$tcsets$sysv(int fd, uint64_t request,
|
||||||
*/
|
*/
|
||||||
int ioctl$tcsets(int fd, uint64_t request, const struct termios *tio) {
|
int ioctl$tcsets(int fd, uint64_t request, const struct termios *tio) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return ioctl$tcsets$sysv(fd, request, tio);
|
return ioctl$sys_tcsets(fd, request, tio);
|
||||||
} else {
|
} else {
|
||||||
return ioctl$tcsets$nt(fd, request, tio);
|
return ioctl$sys_tcsets_nt(fd, request, tio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int ioctl$tiocgwinsz$nt(int fd, struct winsize *ws) {
|
textwindows int ioctl$sys_tiocgwinsz_nt(int fd, struct winsize *ws) {
|
||||||
int i, fds[3];
|
int i, fds[3];
|
||||||
uint32_t mode;
|
uint32_t mode;
|
||||||
struct NtConsoleScreenBufferInfoEx sbinfo;
|
struct NtConsoleScreenBufferInfoEx sbinfo;
|
||||||
|
@ -42,9 +42,9 @@ textwindows int ioctl$tiocgwinsz$nt(int fd, struct winsize *ws) {
|
||||||
ws->ws_xpixel = 0;
|
ws->ws_xpixel = 0;
|
||||||
ws->ws_ypixel = 0;
|
ws->ws_ypixel = 0;
|
||||||
return 0;
|
return 0;
|
||||||
} else if (g_ntstartupinfo.dwFlags & kNtStartfUsecountchars) {
|
} else if (__nt_startupinfo.dwFlags & kNtStartfUsecountchars) {
|
||||||
ws->ws_col = g_ntstartupinfo.dwXCountChars;
|
ws->ws_col = __nt_startupinfo.dwXCountChars;
|
||||||
ws->ws_row = g_ntstartupinfo.dwYCountChars;
|
ws->ws_row = __nt_startupinfo.dwYCountChars;
|
||||||
ws->ws_xpixel = 0;
|
ws->ws_xpixel = 0;
|
||||||
ws->ws_ypixel = 0;
|
ws->ws_ypixel = 0;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/sysv/consts/termios.h"
|
#include "libc/sysv/consts/termios.h"
|
||||||
|
|
||||||
int ioctl$tiocgwinsz$nt(int, struct winsize *);
|
int ioctl$sys_tiocgwinsz_nt(int, struct winsize *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns width and height of terminal.
|
* Returns width and height of terminal.
|
||||||
|
@ -30,8 +30,8 @@ int ioctl$tiocgwinsz$nt(int, struct winsize *);
|
||||||
*/
|
*/
|
||||||
int ioctl$tiocgwinsz(int fd, struct winsize *ws) {
|
int ioctl$tiocgwinsz(int fd, struct winsize *ws) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return ioctl$sysv(fd, TIOCGWINSZ, ws);
|
return sys_ioctl(fd, TIOCGWINSZ, ws);
|
||||||
} else {
|
} else {
|
||||||
return ioctl$tiocgwinsz$nt(fd, ws);
|
return ioctl$sys_tiocgwinsz_nt(fd, ws);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int ioctl$tiocswinsz$nt(int fd, const struct winsize *ws) {
|
textwindows int ioctl$sys_tiocswinsz_nt(int fd, const struct winsize *ws) {
|
||||||
uint32_t mode;
|
uint32_t mode;
|
||||||
struct NtCoord coord;
|
struct NtCoord coord;
|
||||||
if (!ws) return efault();
|
if (!ws) return efault();
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/sysv/consts/termios.h"
|
#include "libc/sysv/consts/termios.h"
|
||||||
|
|
||||||
int ioctl$tiocswinsz$nt(int, const struct winsize *);
|
int ioctl$sys_tiocswinsz_nt(int, const struct winsize *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns width and height of terminal.
|
* Returns width and height of terminal.
|
||||||
|
@ -30,8 +30,8 @@ int ioctl$tiocswinsz$nt(int, const struct winsize *);
|
||||||
*/
|
*/
|
||||||
int ioctl$tiocswinsz(int fd, const struct winsize *ws) {
|
int ioctl$tiocswinsz(int fd, const struct winsize *ws) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return ioctl$sysv(fd, TIOCSWINSZ, ws);
|
return sys_ioctl(fd, TIOCSWINSZ, ws);
|
||||||
} else {
|
} else {
|
||||||
return ioctl$tiocswinsz$nt(fd, ws);
|
return ioctl$sys_tiocswinsz_nt(fd, ws);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,13 +29,13 @@ int ioctl(int, uint64_t, void *);
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
int ioctl$tcgets(int, void *);
|
int ioctl$tcgets(int, void *);
|
||||||
int ioctl$tcgets$nt(int, void *);
|
int ioctl$sys_tcgets_nt(int, void *);
|
||||||
int ioctl$tcsets(int, uint64_t, void *);
|
int ioctl$tcsets(int, uint64_t, void *);
|
||||||
int ioctl$tcsets$nt(int, uint64_t, void *);
|
int ioctl$sys_tcsets_nt(int, uint64_t, void *);
|
||||||
int ioctl$tiocgwinsz(int, void *);
|
int ioctl$tiocgwinsz(int, void *);
|
||||||
int ioctl$tiocgwinsz$nt(int, void *);
|
int ioctl$sys_tiocgwinsz_nt(int, void *);
|
||||||
int ioctl$tiocswinsz(int, void *);
|
int ioctl$tiocswinsz(int, void *);
|
||||||
int ioctl$tiocswinsz$nt(int, void *);
|
int ioctl$sys_tiocswinsz_nt(int, void *);
|
||||||
int ioctl$default(int, uint64_t, void *);
|
int ioctl$default(int, uint64_t, void *);
|
||||||
|
|
||||||
forceinline int ioctl$dispatch(int fd, uint64_t request, void *memory) {
|
forceinline int ioctl$dispatch(int fd, uint64_t request, void *memory) {
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows bool32 isatty$nt(int fd) {
|
textwindows bool32 sys_isatty_nt(int fd) {
|
||||||
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
||||||
return GetFileType(g_fds.p[fd].handle) == kNtFileTypeChar;
|
return GetFileType(g_fds.p[fd].handle) == kNtFileTypeChar;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
bool32 isatty(int fd) {
|
bool32 isatty(int fd) {
|
||||||
_Alignas(short) char buf[sizeof(uint16_t) * 4];
|
_Alignas(short) char buf[sizeof(uint16_t) * 4];
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return ioctl$sysv(fd, TIOCGWINSZ, &buf) != -1;
|
return sys_ioctl(fd, TIOCGWINSZ, &buf) != -1;
|
||||||
} else {
|
} else {
|
||||||
return isatty$nt(fd);
|
return sys_isatty_nt(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,12 +54,12 @@ int IsDebuggerPresent(bool force) {
|
||||||
if (IsWindows()) {
|
if (IsWindows()) {
|
||||||
res = NtBeingDebugged();
|
res = NtBeingDebugged();
|
||||||
} else if (IsLinux()) {
|
} else if (IsLinux()) {
|
||||||
if ((fd = openat$sysv(AT_FDCWD, kProcStatus, O_RDONLY, 0)) != -1) {
|
if ((fd = sys_openat(AT_FDCWD, kProcStatus, O_RDONLY, 0)) != -1) {
|
||||||
if ((got = read$sysv(fd, buf, sizeof(buf) - sizeof(kPid))) != -1) {
|
if ((got = sys_read(fd, buf, sizeof(buf) - sizeof(kPid))) != -1) {
|
||||||
buf[got] = '\0';
|
buf[got] = '\0';
|
||||||
res = atoi(firstnonnull(strstr(buf, kPid), kPid) + strlen(kPid));
|
res = atoi(firstnonnull(strstr(buf, kPid), kPid) + strlen(kPid));
|
||||||
}
|
}
|
||||||
close$sysv(fd);
|
sys_close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "libc/nt/process.h"
|
#include "libc/nt/process.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int kill$nt(int pid, int sig) {
|
textwindows int sys_kill_nt(int pid, int sig) {
|
||||||
int target;
|
int target;
|
||||||
uint32_t event;
|
uint32_t event;
|
||||||
if (!pid) return raise(sig);
|
if (!pid) return raise(sig);
|
||||||
|
|
|
@ -39,8 +39,8 @@
|
||||||
*/
|
*/
|
||||||
int kill(int pid, int sig) {
|
int kill(int pid, int sig) {
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return kill$sysv(pid, sig, 1);
|
return sys_kill(pid, sig, 1);
|
||||||
} else {
|
} else {
|
||||||
return kill$nt(pid, sig);
|
return sys_kill_nt(pid, sig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,5 +31,5 @@
|
||||||
* @see /etc/group for group ids
|
* @see /etc/group for group ids
|
||||||
*/
|
*/
|
||||||
int lchown(const char *pathname, uint32_t uid, uint32_t gid) {
|
int lchown(const char *pathname, uint32_t uid, uint32_t gid) {
|
||||||
return fchownat$sysv(AT_FDCWD, pathname, uid, gid, AT_SYMLINK_NOFOLLOW);
|
return sys_fchownat(AT_FDCWD, pathname, uid, gid, AT_SYMLINK_NOFOLLOW);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
#include "libc/nt/runtime.h"
|
#include "libc/nt/runtime.h"
|
||||||
|
|
||||||
textwindows int link$nt(const char *existingpath, const char *newpath) {
|
textwindows int sys_link_nt(const char *existingpath, const char *newpath) {
|
||||||
char16_t newpath16[PATH_MAX];
|
char16_t newpath16[PATH_MAX];
|
||||||
char16_t existingpath16[PATH_MAX];
|
char16_t existingpath16[PATH_MAX];
|
||||||
if (__mkntpath(existingpath, existingpath16) != -1 &&
|
if (__mkntpath(existingpath, existingpath16) != -1 &&
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
int link(const char *existingpath, const char *newpath) {
|
int link(const char *existingpath, const char *newpath) {
|
||||||
if (!existingpath || !newpath) return efault();
|
if (!existingpath || !newpath) return efault();
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return linkat$sysv(AT_FDCWD, existingpath, AT_FDCWD, newpath, 0);
|
return sys_linkat(AT_FDCWD, existingpath, AT_FDCWD, newpath, 0);
|
||||||
} else {
|
} else {
|
||||||
return link$nt(existingpath, newpath);
|
return sys_link_nt(existingpath, newpath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
textwindows int64_t lseek$nt(int fd, int64_t offset, int whence) {
|
textwindows int64_t sys_lseek_nt(int fd, int64_t offset, int whence) {
|
||||||
int64_t res;
|
int64_t res;
|
||||||
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
if (!__isfdkind(fd, kFdFile)) return ebadf();
|
||||||
if (SetFilePointerEx(g_fds.p[fd].handle, offset, &res, whence)) {
|
if (SetFilePointerEx(g_fds.p[fd].handle, offset, &res, whence)) {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue