mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 15:38:22 +00:00
Fix warnings
This change fixes Cosmopolitan so it has fewer opinions about compiler warnings. The whole repository had to be cleaned up to be buildable in -Werror -Wall mode. This lets us benefit from things like strict const checking. Some actual bugs might have been caught too.
This commit is contained in:
parent
e2b3c3618e
commit
0d748ad58e
571 changed files with 1306 additions and 1888 deletions
|
@ -5,7 +5,7 @@ COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
__funline unsigned char C121(unsigned char al, unsigned char bl,
|
__funline unsigned char C121(unsigned char al, unsigned char bl,
|
||||||
unsigned char cl) {
|
unsigned char cl) {
|
||||||
unsigned short ax, bx;
|
unsigned short ax;
|
||||||
ax = al;
|
ax = al;
|
||||||
ax += bl;
|
ax += bl;
|
||||||
ax += bl;
|
ax += bl;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
|
|
||||||
__funline signed char C121S(signed char al, signed char bl, signed char cl) {
|
__funline signed char C121S(signed char al, signed char bl, signed char cl) {
|
||||||
short ax, bx;
|
short ax;
|
||||||
ax = al;
|
ax = al;
|
||||||
ax += bl;
|
ax += bl;
|
||||||
ax += bl;
|
ax += bl;
|
||||||
|
|
|
@ -31,13 +31,14 @@
|
||||||
* @param y needs to be 16-byte aligned
|
* @param y needs to be 16-byte aligned
|
||||||
*/
|
*/
|
||||||
void sad16x8n(size_t n, short x[n][8], const short y[n][8]) {
|
void sad16x8n(size_t n, short x[n][8], const short y[n][8]) {
|
||||||
size_t i, j;
|
size_t i;
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
*(__m128i *)x[i] = _mm_adds_epi16(*(__m128i *)x[i], *(__m128i *)y[i]);
|
*(__m128i *)x[i] = _mm_adds_epi16(*(__m128i *)x[i], *(__m128i *)y[i]);
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
*(int16x4_t *)x[i] = vqadd_s16(*(int16x4_t *)x[i], *(int16x4_t *)y[i]);
|
*(int16x4_t *)x[i] = vqadd_s16(*(int16x4_t *)x[i], *(int16x4_t *)y[i]);
|
||||||
#else
|
#else
|
||||||
|
size_t j;
|
||||||
for (j = 0; j < 8; ++j) {
|
for (j = 0; j < 8; ++j) {
|
||||||
x[i][j] = MIN(MAX(x[i][j] + y[i][j], INT16_MIN), INT16_MAX);
|
x[i][j] = MIN(MAX(x[i][j] + y[i][j], INT16_MIN), INT16_MAX);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ asm(".include \"libc/disclaimer.inc\"");
|
||||||
* @note discovered by Nasir Ahmed
|
* @note discovered by Nasir Ahmed
|
||||||
*/
|
*/
|
||||||
void plm_video_idct(int block[8][8]) {
|
void plm_video_idct(int block[8][8]) {
|
||||||
int i, j, t1, t2, m0;
|
int i, t1, t2, m0;
|
||||||
int b1, b3, b4, b6, b7;
|
int b1, b3, b4, b6, b7;
|
||||||
int y3, y4, y5, y6, y7;
|
int y3, y4, y5, y6, y7;
|
||||||
int x0, x1, x2, x3, x4;
|
int x0, x1, x2, x3, x4;
|
||||||
|
|
|
@ -1105,12 +1105,12 @@ plm_video_t *plm_video_create_with_buffer(plm_buffer_t *buffer,
|
||||||
|
|
||||||
static textstartup void plm_video_init(void) {
|
static textstartup void plm_video_init(void) {
|
||||||
PLM_VIDEO_MACROBLOCK_TYPE[0] = NULL;
|
PLM_VIDEO_MACROBLOCK_TYPE[0] = NULL;
|
||||||
PLM_VIDEO_MACROBLOCK_TYPE[1] = PLM_VIDEO_MACROBLOCK_TYPE_INTRA;
|
PLM_VIDEO_MACROBLOCK_TYPE[1] = (void *)PLM_VIDEO_MACROBLOCK_TYPE_INTRA;
|
||||||
PLM_VIDEO_MACROBLOCK_TYPE[2] = PLM_VIDEO_MACROBLOCK_TYPE_PREDICTIVE,
|
PLM_VIDEO_MACROBLOCK_TYPE[2] = (void *)PLM_VIDEO_MACROBLOCK_TYPE_PREDICTIVE;
|
||||||
PLM_VIDEO_MACROBLOCK_TYPE[3] = PLM_VIDEO_MACROBLOCK_TYPE_B;
|
PLM_VIDEO_MACROBLOCK_TYPE[3] = (void *)PLM_VIDEO_MACROBLOCK_TYPE_B;
|
||||||
PLM_VIDEO_DCT_SIZE[0] = PLM_VIDEO_DCT_SIZE_LUMINANCE;
|
PLM_VIDEO_DCT_SIZE[0] = (void *)PLM_VIDEO_DCT_SIZE_LUMINANCE;
|
||||||
PLM_VIDEO_DCT_SIZE[1] = PLM_VIDEO_DCT_SIZE_CHROMINANCE;
|
PLM_VIDEO_DCT_SIZE[1] = (void *)PLM_VIDEO_DCT_SIZE_CHROMINANCE;
|
||||||
PLM_VIDEO_DCT_SIZE[2] = PLM_VIDEO_DCT_SIZE_CHROMINANCE;
|
PLM_VIDEO_DCT_SIZE[2] = (void *)PLM_VIDEO_DCT_SIZE_CHROMINANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *const plm_video_init_ctor[] initarray = {plm_video_init};
|
const void *const plm_video_init_ctor[] initarray = {plm_video_init};
|
||||||
|
|
|
@ -55,10 +55,10 @@ void *cDecimate2xUint8x8(unsigned long n, unsigned char A[n],
|
||||||
K[4], K[5], K[4], K[5], K[4], K[5], K[4], K[5]};
|
K[4], K[5], K[4], K[5], K[4], K[5], K[4], K[5]};
|
||||||
signed char kMadd4[16] = {K[6], K[7], K[6], K[7], K[6], K[7], K[6], K[7],
|
signed char kMadd4[16] = {K[6], K[7], K[6], K[7], K[6], K[7], K[6], K[7],
|
||||||
K[6], K[7], K[6], K[7], K[6], K[7], K[6], K[7]};
|
K[6], K[7], K[6], K[7], K[6], K[7], K[6], K[7]};
|
||||||
unsigned char in1[16], in2[16], in3[16], in4[32];
|
|
||||||
unsigned char bv0[16], bv1[16], bv2[16], bv3[16];
|
unsigned char bv0[16], bv1[16], bv2[16], bv3[16];
|
||||||
|
unsigned char in1[16], in2[16], in3[16];
|
||||||
short wv0[8], wv1[8], wv2[8], wv3[8];
|
short wv0[8], wv1[8], wv2[8], wv3[8];
|
||||||
unsigned long i, j, v, w, o;
|
unsigned long i, j, w;
|
||||||
if (n >= STRIDE) {
|
if (n >= STRIDE) {
|
||||||
i = 0;
|
i = 0;
|
||||||
w = (n + RATIO / 2) / RATIO;
|
w = (n + RATIO / 2) / RATIO;
|
||||||
|
|
|
@ -82,7 +82,6 @@ static bool IsNormalized(int n, double A[n]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeSamplingSolution(struct SamplingSolution *ss) {
|
void FreeSamplingSolution(struct SamplingSolution *ss) {
|
||||||
long i;
|
|
||||||
if (ss) {
|
if (ss) {
|
||||||
free(ss->indices);
|
free(ss->indices);
|
||||||
free(ss->weights);
|
free(ss->weights);
|
||||||
|
@ -93,7 +92,7 @@ void FreeSamplingSolution(struct SamplingSolution *ss) {
|
||||||
struct SamplingSolution *ComputeSamplingSolution(long dn, long sn, double dar,
|
struct SamplingSolution *ComputeSamplingSolution(long dn, long sn, double dar,
|
||||||
double off, double par) {
|
double off, double par) {
|
||||||
double *fweights;
|
double *fweights;
|
||||||
double sum, hw, w, x, f;
|
double sum, hw, x, f;
|
||||||
short *weights, *indices;
|
short *weights, *indices;
|
||||||
struct SamplingSolution *res;
|
struct SamplingSolution *res;
|
||||||
long j, i, k, n, min, max, s, N[6];
|
long j, i, k, n, min, max, s, N[6];
|
||||||
|
@ -151,8 +150,8 @@ static void GyaradosImpl(long dyw, long dxw, int dst[dyw][dxw], long syw,
|
||||||
const short fyi[dyn][yfn], const short fyw[dyn][yfn],
|
const short fyi[dyn][yfn], const short fyw[dyn][yfn],
|
||||||
const short fxi[dxn][xfn], const short fxw[dxn][xfn],
|
const short fxi[dxn][xfn], const short fxw[dxn][xfn],
|
||||||
bool sharpen) {
|
bool sharpen) {
|
||||||
long i, j;
|
long i;
|
||||||
int eax, dy, dx, sy, sx;
|
int eax, dy, dx, sx;
|
||||||
for (sx = 0; sx < sxn; ++sx) {
|
for (sx = 0; sx < sxn; ++sx) {
|
||||||
for (dy = 0; dy < dyn; ++dy) {
|
for (dy = 0; dy < dyn; ++dy) {
|
||||||
for (eax = i = 0; i < yfn; ++i) {
|
for (eax = i = 0; i < yfn; ++i) {
|
||||||
|
|
|
@ -98,8 +98,8 @@ static int uncube(int x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static textstartup void rgb2ansi_init(void) {
|
static textstartup void rgb2ansi_init(void) {
|
||||||
uint8_t c, y;
|
uint8_t c;
|
||||||
uint32_t i, j;
|
uint32_t i;
|
||||||
memcpy(g_ansi2rgb_, &kCgaPalette, sizeof(kCgaPalette));
|
memcpy(g_ansi2rgb_, &kCgaPalette, sizeof(kCgaPalette));
|
||||||
for (i = 16; i < 232; ++i) {
|
for (i = 16; i < 232; ++i) {
|
||||||
g_ansi2rgb_[i].r = kXtermCube[((i - 020) / 044) % 06];
|
g_ansi2rgb_[i].r = kXtermCube[((i - 020) / 044) % 06];
|
||||||
|
|
|
@ -609,7 +609,7 @@ static struct Pick PickBlockUnicodeAnsi(struct TtyRgb tl, struct TtyRgb tr,
|
||||||
struct TtyRgb tr2 = GetQuant(tr);
|
struct TtyRgb tr2 = GetQuant(tr);
|
||||||
struct TtyRgb bl2 = GetQuant(bl);
|
struct TtyRgb bl2 = GetQuant(bl);
|
||||||
struct TtyRgb br2 = GetQuant(br);
|
struct TtyRgb br2 = GetQuant(br);
|
||||||
unsigned i, p1, p2;
|
unsigned p1, p2;
|
||||||
uint16_t picks1[96] forcealign(32);
|
uint16_t picks1[96] forcealign(32);
|
||||||
uint16_t picks2[32] forcealign(32);
|
uint16_t picks2[32] forcealign(32);
|
||||||
memset(picks1, 0x79, sizeof(picks1));
|
memset(picks1, 0x79, sizeof(picks1));
|
||||||
|
@ -646,7 +646,7 @@ static struct Pick PickBlockCp437Ansi(struct TtyRgb tl, struct TtyRgb tr,
|
||||||
struct TtyRgb tr2 = GetQuant(tr);
|
struct TtyRgb tr2 = GetQuant(tr);
|
||||||
struct TtyRgb bl2 = GetQuant(bl);
|
struct TtyRgb bl2 = GetQuant(bl);
|
||||||
struct TtyRgb br2 = GetQuant(br);
|
struct TtyRgb br2 = GetQuant(br);
|
||||||
unsigned i, p1, p2;
|
unsigned p1, p2;
|
||||||
uint16_t picks1[32] forcealign(32);
|
uint16_t picks1[32] forcealign(32);
|
||||||
uint16_t picks2[32] forcealign(32);
|
uint16_t picks2[32] forcealign(32);
|
||||||
memset(picks1, 0x79, sizeof(picks1));
|
memset(picks1, 0x79, sizeof(picks1));
|
||||||
|
@ -660,7 +660,6 @@ static struct Pick PickBlockCp437Ansi(struct TtyRgb tl, struct TtyRgb tr,
|
||||||
|
|
||||||
static struct Pick PickBlockCp437True(struct TtyRgb tl, struct TtyRgb tr,
|
static struct Pick PickBlockCp437True(struct TtyRgb tl, struct TtyRgb tr,
|
||||||
struct TtyRgb bl, struct TtyRgb br) {
|
struct TtyRgb bl, struct TtyRgb br) {
|
||||||
unsigned i;
|
|
||||||
uint16_t picks[32] forcealign(32);
|
uint16_t picks[32] forcealign(32);
|
||||||
memset(picks, 0x79, sizeof(picks));
|
memset(picks, 0x79, sizeof(picks));
|
||||||
PickCp437(picks, tl, tr, bl, br, tl, tr, bl, br);
|
PickCp437(picks, tl, tr, bl, br, tl, tr, bl, br);
|
||||||
|
|
|
@ -38,8 +38,8 @@
|
||||||
* @return 0 on success, or -1 w/ errno
|
* @return 0 on success, or -1 w/ errno
|
||||||
*/
|
*/
|
||||||
ssize_t ttywrite(int fd, const void *data, size_t size) {
|
ssize_t ttywrite(int fd, const void *data, size_t size) {
|
||||||
char *p;
|
|
||||||
ssize_t rc;
|
ssize_t rc;
|
||||||
|
const char *p;
|
||||||
size_t wrote, n;
|
size_t wrote, n;
|
||||||
p = data;
|
p = data;
|
||||||
n = size;
|
n = size;
|
||||||
|
|
|
@ -93,10 +93,8 @@ static void CompleteFilename(const char *p, const char *q, const char *b,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ShellCompletion(const char *p, linenoiseCompletions *c) {
|
static void ShellCompletion(const char *p, linenoiseCompletions *c) {
|
||||||
bool slashed;
|
|
||||||
const char *q, *b;
|
const char *q, *b;
|
||||||
for (slashed = false, b = p, q = (p += strlen(p)); p > b; --p) {
|
for (b = p, q = (p += strlen(p)); p > b; --p) {
|
||||||
if (p[-1] == '/' && p[-1] == '\\') slashed = true;
|
|
||||||
if (!isalnum(p[-1]) &&
|
if (!isalnum(p[-1]) &&
|
||||||
(p[-1] != '.' && p[-1] != '_' && p[-1] != '-' && p[-1] != '+' &&
|
(p[-1] != '.' && p[-1] != '_' && p[-1] != '-' && p[-1] != '+' &&
|
||||||
p[-1] != '[' && p[-1] != '/' && p[-1] != '\\')) {
|
p[-1] != '[' && p[-1] != '/' && p[-1] != '\\')) {
|
||||||
|
@ -143,8 +141,8 @@ int main(int argc, char *argv[]) {
|
||||||
char *prog, path[PATH_MAX];
|
char *prog, path[PATH_MAX];
|
||||||
sigset_t chldmask, savemask;
|
sigset_t chldmask, savemask;
|
||||||
int stdoutflags, stderrflags;
|
int stdoutflags, stderrflags;
|
||||||
|
int n, rc, ws, child, killcount;
|
||||||
const char *stdoutpath, *stderrpath;
|
const char *stdoutpath, *stderrpath;
|
||||||
int n, rc, ws, pid, child, killcount;
|
|
||||||
struct sigaction sa, saveint, savequit;
|
struct sigaction sa, saveint, savequit;
|
||||||
char *p, *line, **args, *arg, *start, *state, prompt[1024];
|
char *p, *line, **args, *arg, *start, *state, prompt[1024];
|
||||||
linenoiseSetFreeHintsCallback(free);
|
linenoiseSetFreeHintsCallback(free);
|
||||||
|
|
|
@ -36,6 +36,7 @@ dontubsan int main(int argc, char *argv[]) {
|
||||||
volatile double a = 0;
|
volatile double a = 0;
|
||||||
volatile double b = 23;
|
volatile double b = 23;
|
||||||
volatile double c = exp(b) / a;
|
volatile double c = exp(b) / a;
|
||||||
|
(void)c;
|
||||||
|
|
||||||
volatile int64_t x;
|
volatile int64_t x;
|
||||||
return 1 / (x = 0);
|
return 1 / (x = 0);
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
volatile int64_t x;
|
|
||||||
ShowCrashReports();
|
ShowCrashReports();
|
||||||
printf("please press ctrl+\\ and see what happens...\n");
|
printf("please press ctrl+\\ and see what happens...\n");
|
||||||
sigsuspend(0);
|
sigsuspend(0);
|
||||||
|
|
|
@ -35,8 +35,7 @@ void PrintUsage(int rc, FILE *f) {
|
||||||
|
|
||||||
void PrintUri(const char *path) {
|
void PrintUri(const char *path) {
|
||||||
size_t n;
|
size_t n;
|
||||||
void *img, *src, *mime;
|
void *img;
|
||||||
int opt, i;
|
|
||||||
if (!(img = gc(xslurp(path, &n)))) exit(2);
|
if (!(img = gc(xslurp(path, &n)))) exit(2);
|
||||||
fputs("data:", stdout);
|
fputs("data:", stdout);
|
||||||
fputs(FindContentType(path, -1), stdout);
|
fputs(FindContentType(path, -1), stdout);
|
||||||
|
|
|
@ -7,15 +7,15 @@
|
||||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||||
╚─────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────*/
|
||||||
#endif
|
#endif
|
||||||
#include "libc/mem/mem.h"
|
|
||||||
#include "libc/mem/gc.h"
|
#include "libc/mem/gc.h"
|
||||||
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cosmopolitan C is just as awesome as Go!
|
* Cosmopolitan C is just as awesome as Go!
|
||||||
* Example contributed by @Keithcat1 (#266)
|
* Example contributed by @Keithcat1 (#266)
|
||||||
*/
|
*/
|
||||||
main() {
|
int main() {
|
||||||
_defer(printf, "Done!\n");
|
_defer(printf, "Done!\n");
|
||||||
for (long i = 0; i < 100000; i++) {
|
for (long i = 0; i < 100000; i++) {
|
||||||
printf("%i ", i);
|
printf("%i ", i);
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int pid;
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
fputs("USAGE: FORKEXEC.COM PROG ARGV₀ [ARGV₁...]\n", stderr);
|
fputs("USAGE: FORKEXEC.COM PROG ARGV₀ [ARGV₁...]\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int pid;
|
|
||||||
volatile void *p;
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
fputs("USAGE: FORKEXECWAIT.COM PROG ARGV₀ [ARGV₁...]\n", stderr);
|
fputs("USAGE: FORKEXECWAIT.COM PROG ARGV₀ [ARGV₁...]\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -21,7 +21,7 @@ int main(int argc, char *argv[]) {
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
rc = gettimeofday(&tv, 0);
|
rc = gettimeofday(&tv, 0);
|
||||||
assert(!rc);
|
unassert(!rc);
|
||||||
t = tv.tv_sec;
|
t = tv.tv_sec;
|
||||||
gmtime_r(&t, &tm);
|
gmtime_r(&t, &tm);
|
||||||
FormatHttpDateTime(p, &tm);
|
FormatHttpDateTime(p, &tm);
|
||||||
|
|
|
@ -148,14 +148,13 @@ void *Worker(void *id) {
|
||||||
while (!closingtime) {
|
while (!closingtime) {
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
int64_t unixts;
|
int64_t unixts;
|
||||||
struct Url url;
|
|
||||||
ssize_t got, sent;
|
ssize_t got, sent;
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
struct HttpMessage msg;
|
struct HttpMessage msg;
|
||||||
uint32_t clientaddrsize;
|
uint32_t clientaddrsize;
|
||||||
struct sockaddr_in clientaddr;
|
struct sockaddr_in clientaddr;
|
||||||
char inbuf[1500], outbuf[512], *p, *q;
|
char inbuf[1500], outbuf[512], *p, *q;
|
||||||
int clientip, client, inmsglen, outmsglen;
|
int client, inmsglen, outmsglen;
|
||||||
|
|
||||||
// this slows the server down a lot but is needed on non-Linux to
|
// this slows the server down a lot but is needed on non-Linux to
|
||||||
// react to keyboard ctrl-c
|
// react to keyboard ctrl-c
|
||||||
|
|
|
@ -38,8 +38,8 @@
|
||||||
*/
|
*/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/struct/stat.h"
|
#include "libc/calls/struct/stat.h"
|
||||||
#include "libc/stdio/rand.h"
|
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
#include "libc/stdio/rand.h"
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/time/time.h"
|
#include "libc/time/time.h"
|
||||||
|
@ -178,8 +178,7 @@ void youwon()
|
||||||
printf("you win, the word is %s\n",realword);
|
printf("you win, the word is %s\n",realword);
|
||||||
}
|
}
|
||||||
|
|
||||||
main(argc,argv)
|
int main(int argc,char **argv)
|
||||||
char **argv;
|
|
||||||
{
|
{
|
||||||
if(argc==1) dictfile=DICT;
|
if(argc==1) dictfile=DICT;
|
||||||
else dictfile=argv[1];
|
else dictfile=argv[1];
|
||||||
|
|
|
@ -24,7 +24,7 @@ int main(int argc, char *argv[]) {
|
||||||
luaL_openlibs(L);
|
luaL_openlibs(L);
|
||||||
lua_pushcfunction(L, NativeAdd);
|
lua_pushcfunction(L, NativeAdd);
|
||||||
lua_setglobal(L, "NativeAdd");
|
lua_setglobal(L, "NativeAdd");
|
||||||
luaL_dofile(L, "/zip/examples/hellolua.lua");
|
(void)luaL_dofile(L, "/zip/examples/hellolua.lua");
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,14 +44,14 @@ void PrintUsage(int rc, FILE *f) {
|
||||||
|
|
||||||
void PrintImg(const char *path) {
|
void PrintImg(const char *path) {
|
||||||
size_t n;
|
size_t n;
|
||||||
int opt, i, yn, xn, cn, w, h;
|
int yn, xn, cn, w, h;
|
||||||
void *img, *pix, *src, *mime;
|
void *img, *pix, *src;
|
||||||
if (!(img = _gc(xslurp(path, &n)))) exit(2);
|
if (!(img = _gc(xslurp(path, &n)))) exit(2);
|
||||||
if (!(pix = _gc(stbi_load_from_memory(img, n, &xn, &yn, &cn, 0)))) exit(3);
|
if (!(pix = _gc(stbi_load_from_memory(img, n, &xn, &yn, &cn, 0)))) exit(3);
|
||||||
if (linktag) {
|
if (linktag) {
|
||||||
printf("<a href=\"%s\"\n >", path);
|
printf("<a href=\"%s\"\n >", path);
|
||||||
}
|
}
|
||||||
src = path;
|
src = (void *)path;
|
||||||
if (datauri) {
|
if (datauri) {
|
||||||
src = xasprintf("data:%s;base64,%s", FindContentType(path, -1),
|
src = xasprintf("data:%s;base64,%s", FindContentType(path, -1),
|
||||||
_gc(EncodeBase64(img, n, &n)));
|
_gc(EncodeBase64(img, n, &n)));
|
||||||
|
|
|
@ -413,9 +413,9 @@ void editorUpdateSyntax(erow *row) {
|
||||||
int i, prev_sep, in_string, in_comment;
|
int i, prev_sep, in_string, in_comment;
|
||||||
char *p;
|
char *p;
|
||||||
const char *const *keywords = E.syntax->keywords;
|
const char *const *keywords = E.syntax->keywords;
|
||||||
char *scs = E.syntax->singleline_comment_start;
|
const char *scs = E.syntax->singleline_comment_start;
|
||||||
char *mcs = E.syntax->multiline_comment_start;
|
const char *mcs = E.syntax->multiline_comment_start;
|
||||||
char *mce = E.syntax->multiline_comment_end;
|
const char *mce = E.syntax->multiline_comment_end;
|
||||||
|
|
||||||
/* Point to the first non-space char. */
|
/* Point to the first non-space char. */
|
||||||
p = row->render;
|
p = row->render;
|
||||||
|
@ -575,7 +575,7 @@ int editorSyntaxToColor(int hl) {
|
||||||
* setting it in the global state E.syntax. */
|
* setting it in the global state E.syntax. */
|
||||||
void editorSelectSyntaxHighlight(char *filename) {
|
void editorSelectSyntaxHighlight(char *filename) {
|
||||||
for (unsigned j = 0; j < HLDB_ENTRIES; j++) {
|
for (unsigned j = 0; j < HLDB_ENTRIES; j++) {
|
||||||
struct editorSyntax *s = HLDB + j;
|
const struct editorSyntax *s = HLDB + j;
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
while (s->filematch[i]) {
|
while (s->filematch[i]) {
|
||||||
char *p;
|
char *p;
|
||||||
|
@ -898,7 +898,7 @@ struct abuf {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void abAppend(struct abuf *ab, const char *s, int len) {
|
static void abAppend(struct abuf *ab, const char *s, int len) {
|
||||||
CONCAT(&ab->p, &ab->i, &ab->n, s, len);
|
CONCAT(&ab->p, &ab->i, &ab->n, (void *)s, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function writes the whole screen using VT100 escape characters
|
/* This function writes the whole screen using VT100 escape characters
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
long i, ns;
|
long i, ns;
|
||||||
struct timespec x, y, w;
|
struct timespec x, y;
|
||||||
timespec_sleep(timespec_fromnanos(0)); // warmup
|
timespec_sleep(timespec_fromnanos(0)); // warmup
|
||||||
|
|
||||||
printf("\nrelative sleep\n");
|
printf("\nrelative sleep\n");
|
||||||
|
|
|
@ -45,10 +45,10 @@
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
ssize_t rc;
|
ssize_t rc;
|
||||||
size_t i, got;
|
size_t i, got;
|
||||||
|
int opt, sock;
|
||||||
char buf[1500];
|
char buf[1500];
|
||||||
bool halfclose = true;
|
bool halfclose = true;
|
||||||
const char *host, *port;
|
const char *host, *port;
|
||||||
int opt, err, toto, sock;
|
|
||||||
struct addrinfo *ai = NULL;
|
struct addrinfo *ai = NULL;
|
||||||
struct linger linger = {true, 1};
|
struct linger linger = {true, 1};
|
||||||
struct pollfd fds[2] = {{-1, POLLIN}, {-1, POLLIN}};
|
struct pollfd fds[2] = {{-1, POLLIN}, {-1, POLLIN}};
|
||||||
|
|
|
@ -164,7 +164,6 @@ static struct TtyRgb* ttyrgb_;
|
||||||
static unsigned char *R, *G, *B;
|
static unsigned char *R, *G, *B;
|
||||||
static struct ZipGames zipgames_;
|
static struct ZipGames zipgames_;
|
||||||
static struct Action arrow_, button_;
|
static struct Action arrow_, button_;
|
||||||
static struct SamplingSolution* asx_;
|
|
||||||
static struct SamplingSolution* ssy_;
|
static struct SamplingSolution* ssy_;
|
||||||
static struct SamplingSolution* ssx_;
|
static struct SamplingSolution* ssx_;
|
||||||
static unsigned char pixels_[3][DYN][DXN];
|
static unsigned char pixels_[3][DYN][DXN];
|
||||||
|
@ -585,7 +584,6 @@ void Raster(void) {
|
||||||
f->p = stpcpy(f->p, "\e[0m\e[H");
|
f->p = stpcpy(f->p, "\e[0m\e[H");
|
||||||
f->p = stpcpy(f->p, status_.text);
|
f->p = stpcpy(f->p, status_.text);
|
||||||
}
|
}
|
||||||
CHECK_LT(f->p - f->mem, vtsize_);
|
|
||||||
PollAndSynchronize();
|
PollAndSynchronize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,7 +597,6 @@ void FlushScanline(unsigned py) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PutPixel(unsigned px, unsigned py, unsigned pixel, int offset) {
|
static void PutPixel(unsigned px, unsigned py, unsigned pixel, int offset) {
|
||||||
unsigned rgb;
|
|
||||||
static unsigned prev;
|
static unsigned prev;
|
||||||
pixels_[0][py][px] = palette_[offset][prev % 64][pixel][2];
|
pixels_[0][py][px] = palette_[offset][prev % 64][pixel][2];
|
||||||
pixels_[1][py][px] = palette_[offset][prev % 64][pixel][1];
|
pixels_[1][py][px] = palette_[offset][prev % 64][pixel][1];
|
||||||
|
@ -1811,8 +1808,8 @@ void GetOpts(int argc, char* argv[]) {
|
||||||
|
|
||||||
size_t FindZipGames(void) {
|
size_t FindZipGames(void) {
|
||||||
char* name;
|
char* name;
|
||||||
|
size_t i, cf;
|
||||||
struct Zipos* zipos;
|
struct Zipos* zipos;
|
||||||
size_t i, cf, namesize;
|
|
||||||
if ((zipos = __zipos_get())) {
|
if ((zipos = __zipos_get())) {
|
||||||
for (i = 0, cf = ZIP_CDIR_OFFSET(zipos->cdir);
|
for (i = 0, cf = ZIP_CDIR_OFFSET(zipos->cdir);
|
||||||
i < ZIP_CDIR_RECORDS(zipos->cdir);
|
i < ZIP_CDIR_RECORDS(zipos->cdir);
|
||||||
|
@ -1834,14 +1831,14 @@ int SelectGameFromZip(void) {
|
||||||
int i, rc;
|
int i, rc;
|
||||||
char *line, *uri;
|
char *line, *uri;
|
||||||
fputs("\nCOSMOPOLITAN NESEMU1\n\n", stdout);
|
fputs("\nCOSMOPOLITAN NESEMU1\n\n", stdout);
|
||||||
for (i = 0; i < zipgames_.i; ++i) {
|
for (i = 0; i < (int)zipgames_.i; ++i) {
|
||||||
printf(" [%d] %s\n", i, zipgames_.p[i]);
|
printf(" [%d] %s\n", i, zipgames_.p[i]);
|
||||||
}
|
}
|
||||||
fputs("\nPlease choose a game (or CTRL-C to quit) [default 0]: ", stdout);
|
fputs("\nPlease choose a game (or CTRL-C to quit) [default 0]: ", stdout);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
rc = 0;
|
rc = 0;
|
||||||
if ((line = GetLine())) {
|
if ((line = GetLine())) {
|
||||||
i = MAX(0, MIN(zipgames_.i - 1, atoi(line)));
|
i = MAX(0, MIN((int)zipgames_.i - 1, atoi(line)));
|
||||||
uri = zipgames_.p[i];
|
uri = zipgames_.p[i];
|
||||||
rc = PlayGame(uri, NULL);
|
rc = PlayGame(uri, NULL);
|
||||||
free(uri);
|
free(uri);
|
||||||
|
|
|
@ -122,7 +122,7 @@ void Clear(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout(void) {
|
void Layout(void) {
|
||||||
long i, j;
|
long i;
|
||||||
i = txn >> 1;
|
i = txn >> 1;
|
||||||
pan.left.top = 0;
|
pan.left.top = 0;
|
||||||
pan.left.left = 0;
|
pan.left.left = 0;
|
||||||
|
|
|
@ -113,9 +113,9 @@ main(int argc, char *argv[])
|
||||||
static char obuf[BUFSIZ];
|
static char obuf[BUFSIZ];
|
||||||
static char ibuf[BUFSIZ];
|
static char ibuf[BUFSIZ];
|
||||||
fd_set rfd;
|
fd_set rfd;
|
||||||
|
int fm_fd;
|
||||||
int aflg, Fflg, kflg, pflg, ch, k, n;
|
int aflg, Fflg, kflg, pflg, ch, k, n;
|
||||||
int flushtime, readstdin;
|
int flushtime, readstdin;
|
||||||
int fm_fd, fm_log;
|
|
||||||
|
|
||||||
aflg = Fflg = kflg = pflg = 0;
|
aflg = Fflg = kflg = pflg = 0;
|
||||||
usesleep = 1;
|
usesleep = 1;
|
||||||
|
@ -125,6 +125,8 @@ main(int argc, char *argv[])
|
||||||
warning. (not needed w/clang) */
|
warning. (not needed w/clang) */
|
||||||
showexit = 0;
|
showexit = 0;
|
||||||
|
|
||||||
|
(void)fm_fd;
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "adeFfkpqrt:")) != -1)
|
while ((ch = getopt(argc, argv, "adeFfkpqrt:")) != -1)
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
case 'a':
|
case 'a':
|
||||||
|
|
|
@ -1026,7 +1026,6 @@ struct t_op {
|
||||||
│ cosmopolitan § the unbourne shell » bss ─╬─│┼
|
│ cosmopolitan § the unbourne shell » bss ─╬─│┼
|
||||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||||
|
|
||||||
static int inter;
|
|
||||||
static char **argptr; /* argument list for builtin commands */
|
static char **argptr; /* argument list for builtin commands */
|
||||||
static char **gargv;
|
static char **gargv;
|
||||||
static char **t_wp;
|
static char **t_wp;
|
||||||
|
@ -5747,7 +5746,7 @@ static void CompleteCommand(const char *p, const char *q, const char *b,
|
||||||
}
|
}
|
||||||
closedir(d);
|
closedir(d);
|
||||||
}
|
}
|
||||||
free(path);
|
free((void *)path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5784,7 +5783,6 @@ static void CompleteFilename(const char *p, const char *q, const char *b,
|
||||||
static void ShellCompletion(const char *p, linenoiseCompletions *c) {
|
static void ShellCompletion(const char *p, linenoiseCompletions *c) {
|
||||||
bool slashed;
|
bool slashed;
|
||||||
const char *q, *b;
|
const char *q, *b;
|
||||||
struct tblentry **pp, *cmdp;
|
|
||||||
for (slashed = false, b = p, q = (p += strlen(p)); p > b; --p) {
|
for (slashed = false, b = p, q = (p += strlen(p)); p > b; --p) {
|
||||||
if (p[-1] == '/' && p[-1] == '\\') slashed = true;
|
if (p[-1] == '/' && p[-1] == '\\') slashed = true;
|
||||||
if (!isalnum(p[-1]) &&
|
if (!isalnum(p[-1]) &&
|
||||||
|
|
|
@ -75,7 +75,6 @@ char *GetHost(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *GetTime(void) {
|
char *GetTime(void) {
|
||||||
int64_t t;
|
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(0, &ts);
|
clock_gettime(0, &ts);
|
||||||
|
|
|
@ -183,7 +183,7 @@ textwindows bool __sig_handle(int sigops, int sig, int si_code,
|
||||||
if (__sig_is_fatal(sig)) {
|
if (__sig_is_fatal(sig)) {
|
||||||
intptr_t hStderr;
|
intptr_t hStderr;
|
||||||
const char *signame;
|
const char *signame;
|
||||||
char *end, sigbuf[15], output[16];
|
char *end, sigbuf[21], output[22];
|
||||||
signame = strsignal_r(sig, sigbuf);
|
signame = strsignal_r(sig, sigbuf);
|
||||||
STRACE("terminating due to uncaught %s", signame);
|
STRACE("terminating due to uncaught %s", signame);
|
||||||
hStderr = GetStdHandle(kNtStdErrorHandle);
|
hStderr = GetStdHandle(kNtStdErrorHandle);
|
||||||
|
@ -274,7 +274,6 @@ textwindows int __sig_add(int tid, int sig, int si_code) {
|
||||||
* @threadsafe
|
* @threadsafe
|
||||||
*/
|
*/
|
||||||
textwindows bool __sig_check(int sigops) {
|
textwindows bool __sig_check(int sigops) {
|
||||||
unsigned rva;
|
|
||||||
bool delivered;
|
bool delivered;
|
||||||
struct Signal *sig;
|
struct Signal *sig;
|
||||||
delivered = false;
|
delivered = false;
|
||||||
|
|
|
@ -37,7 +37,6 @@ static void sys_clock_gettime_mono_init(void) {
|
||||||
int sys_clock_gettime_mono(struct timespec *time) {
|
int sys_clock_gettime_mono(struct timespec *time) {
|
||||||
uint64_t nanos;
|
uint64_t nanos;
|
||||||
uint64_t cycles;
|
uint64_t cycles;
|
||||||
struct timespec res;
|
|
||||||
if (X86_HAVE(INVTSC)) {
|
if (X86_HAVE(INVTSC)) {
|
||||||
cosmo_once(&g_mono.once, sys_clock_gettime_mono_init);
|
cosmo_once(&g_mono.once, sys_clock_gettime_mono_init);
|
||||||
cycles = rdtsc() - g_mono.base_tick;
|
cycles = rdtsc() - g_mono.base_tick;
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
*/
|
*/
|
||||||
int closefrom(int first) {
|
int closefrom(int first) {
|
||||||
int rc, err;
|
int rc, err;
|
||||||
|
(void)err;
|
||||||
if (first < 0) {
|
if (first < 0) {
|
||||||
// consistent with openbsd
|
// consistent with openbsd
|
||||||
// freebsd allows this but it's dangerous
|
// freebsd allows this but it's dangerous
|
||||||
|
|
|
@ -39,8 +39,8 @@ static struct CopyFileRange {
|
||||||
} g_copy_file_range;
|
} g_copy_file_range;
|
||||||
|
|
||||||
static bool HasCopyFileRange(void) {
|
static bool HasCopyFileRange(void) {
|
||||||
|
int e;
|
||||||
bool ok;
|
bool ok;
|
||||||
int e, rc;
|
|
||||||
e = errno;
|
e = errno;
|
||||||
BLOCK_CANCELLATIONS;
|
BLOCK_CANCELLATIONS;
|
||||||
if (IsLinux()) {
|
if (IsLinux()) {
|
||||||
|
|
|
@ -43,9 +43,9 @@ int execl(const char *exe, const char *arg, ... /*, NULL*/) {
|
||||||
va_end(va);
|
va_end(va);
|
||||||
argv = alloca((i + 2) * sizeof(char *));
|
argv = alloca((i + 2) * sizeof(char *));
|
||||||
va_start(vb, arg);
|
va_start(vb, arg);
|
||||||
argv[0] = arg;
|
argv[0] = (char *)arg;
|
||||||
for (i = 1;; ++i) {
|
for (i = 1;; ++i) {
|
||||||
if (!(argv[i] = va_arg(vb, const char *))) break;
|
if (!(argv[i] = va_arg(vb, char *))) break;
|
||||||
}
|
}
|
||||||
va_end(vb);
|
va_end(vb);
|
||||||
return execv(exe, argv);
|
return execv(exe, argv);
|
||||||
|
|
|
@ -45,9 +45,9 @@ int execle(const char *exe, const char *arg,
|
||||||
va_end(va);
|
va_end(va);
|
||||||
argv = alloca((i + 2) * sizeof(char *));
|
argv = alloca((i + 2) * sizeof(char *));
|
||||||
va_start(vb, arg);
|
va_start(vb, arg);
|
||||||
argv[0] = arg;
|
argv[0] = (char *)arg;
|
||||||
for (i = 1;; ++i) {
|
for (i = 1;; ++i) {
|
||||||
if (!(argv[i] = va_arg(vb, const char *))) break;
|
if (!(argv[i] = va_arg(vb, char *))) break;
|
||||||
}
|
}
|
||||||
va_end(vb);
|
va_end(vb);
|
||||||
return execve(exe, argv, envp);
|
return execve(exe, argv, envp);
|
||||||
|
|
|
@ -49,9 +49,9 @@ int execlp(const char *prog, const char *arg, ... /*, NULL*/) {
|
||||||
va_end(va);
|
va_end(va);
|
||||||
argv = alloca((i + 2) * sizeof(char *));
|
argv = alloca((i + 2) * sizeof(char *));
|
||||||
va_start(vb, arg);
|
va_start(vb, arg);
|
||||||
argv[0] = arg;
|
argv[0] = (char *)arg;
|
||||||
for (i = 1;; ++i) {
|
for (i = 1;; ++i) {
|
||||||
if (!(argv[i] = va_arg(vb, const char *))) break;
|
if (!(argv[i] = va_arg(vb, char *))) break;
|
||||||
}
|
}
|
||||||
va_end(vb);
|
va_end(vb);
|
||||||
|
|
||||||
|
|
|
@ -89,15 +89,15 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
|
||||||
".ape-" APE_VERSION_STR, buf))) ||
|
".ape-" APE_VERSION_STR, buf))) ||
|
||||||
CanExecute((ape = Join(firstnonnull(getenv("HOME"), "."),
|
CanExecute((ape = Join(firstnonnull(getenv("HOME"), "."),
|
||||||
".ape-" APE_VERSION_STR, buf))))) {
|
".ape-" APE_VERSION_STR, buf))))) {
|
||||||
shargs[0] = ape;
|
shargs[0] = (char *)ape;
|
||||||
shargs[1] = "-";
|
shargs[1] = (char *)"-";
|
||||||
shargs[2] = prog;
|
shargs[2] = (char *)prog;
|
||||||
memcpy(shargs + 3, argv, (i + 1) * sizeof(char *));
|
memcpy(shargs + 3, argv, (i + 1) * sizeof(char *));
|
||||||
errno = e;
|
errno = e;
|
||||||
rc = __sys_execve(shargs[0], shargs, envp);
|
rc = __sys_execve(shargs[0], shargs, envp);
|
||||||
} else if (CanExecute(prog)) {
|
} else if (CanExecute(prog)) {
|
||||||
shargs[0] = _PATH_BSHELL;
|
shargs[0] = _PATH_BSHELL;
|
||||||
shargs[1] = prog;
|
shargs[1] = (char *)prog;
|
||||||
memcpy(shargs + 2, argv + 1, i * sizeof(char *));
|
memcpy(shargs + 2, argv + 1, i * sizeof(char *));
|
||||||
errno = e;
|
errno = e;
|
||||||
rc = __sys_execve(shargs[0], shargs, envp);
|
rc = __sys_execve(shargs[0], shargs, envp);
|
||||||
|
|
|
@ -56,9 +56,8 @@
|
||||||
* @vforksafe
|
* @vforksafe
|
||||||
*/
|
*/
|
||||||
int execve(const char *prog, char *const argv[], char *const envp[]) {
|
int execve(const char *prog, char *const argv[], char *const envp[]) {
|
||||||
struct ZiposUri uri;
|
|
||||||
int rc;
|
int rc;
|
||||||
size_t i;
|
struct ZiposUri uri;
|
||||||
if (!prog || !argv || !envp ||
|
if (!prog || !argv || !envp ||
|
||||||
(IsAsan() && (!__asan_is_valid_str(prog) || //
|
(IsAsan() && (!__asan_is_valid_str(prog) || //
|
||||||
!__asan_is_valid_strlist(argv) || //
|
!__asan_is_valid_strlist(argv) || //
|
||||||
|
|
|
@ -43,7 +43,7 @@ int sys_fadvise_netbsd(int, int, int64_t, int64_t, int) asm("sys_fadvise");
|
||||||
* @raise ENOSYS on XNU and OpenBSD
|
* @raise ENOSYS on XNU and OpenBSD
|
||||||
*/
|
*/
|
||||||
int fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
|
int fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
|
||||||
int rc, e = errno;
|
int rc;
|
||||||
if (IsLinux()) {
|
if (IsLinux()) {
|
||||||
rc = sys_fadvise(fd, offset, len, advice);
|
rc = sys_fadvise(fd, offset, len, advice);
|
||||||
} else if (IsFreebsd() || IsNetbsd()) {
|
} else if (IsFreebsd() || IsNetbsd()) {
|
||||||
|
|
|
@ -124,11 +124,10 @@ textwindows void sys_fcntl_nt_lock_cleanup(int fd) {
|
||||||
|
|
||||||
static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd,
|
static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd,
|
||||||
uintptr_t arg) {
|
uintptr_t arg) {
|
||||||
int e;
|
uint32_t flags;
|
||||||
struct flock *l;
|
struct flock *l;
|
||||||
uint32_t flags, err;
|
int64_t pos, off, len, end;
|
||||||
struct FileLock *fl, *ft, **flp;
|
struct FileLock *fl, *ft, **flp;
|
||||||
int64_t pos, off, len, end, size;
|
|
||||||
|
|
||||||
l = (struct flock *)arg;
|
l = (struct flock *)arg;
|
||||||
len = l->l_len;
|
len = l->l_len;
|
||||||
|
@ -171,7 +170,7 @@ static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd,
|
||||||
for (flp = &g_locks.list, fl = *flp; fl;) {
|
for (flp = &g_locks.list, fl = *flp; fl;) {
|
||||||
if (fl->fd == fd) {
|
if (fl->fd == fd) {
|
||||||
if (EqualsFileLock(fl, off, len)) {
|
if (EqualsFileLock(fl, off, len)) {
|
||||||
if (fl->exc == l->l_type == F_WRLCK) {
|
if (fl->exc == (l->l_type == F_WRLCK)) {
|
||||||
// we already have this lock
|
// we already have this lock
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -205,7 +204,7 @@ static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd,
|
||||||
l->l_whence = SEEK_SET;
|
l->l_whence = SEEK_SET;
|
||||||
l->l_start = fl->off;
|
l->l_start = fl->off;
|
||||||
l->l_len = fl->len;
|
l->l_len = fl->len;
|
||||||
l->l_type == fl->exc ? F_WRLCK : F_RDLCK;
|
l->l_type = fl->exc ? F_WRLCK : F_RDLCK;
|
||||||
l->l_pid = getpid();
|
l->l_pid = getpid();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -360,7 +359,6 @@ static textwindows int sys_fcntl_nt_setfl(int fd, unsigned *flags,
|
||||||
|
|
||||||
textwindows int sys_fcntl_nt(int fd, int cmd, uintptr_t arg) {
|
textwindows int sys_fcntl_nt(int fd, int cmd, uintptr_t arg) {
|
||||||
int rc;
|
int rc;
|
||||||
uint32_t flags;
|
|
||||||
if (__isfdkind(fd, kFdFile) || //
|
if (__isfdkind(fd, kFdFile) || //
|
||||||
__isfdkind(fd, kFdSocket) || //
|
__isfdkind(fd, kFdSocket) || //
|
||||||
__isfdkind(fd, kFdConsole)) {
|
__isfdkind(fd, kFdConsole)) {
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
|
|
||||||
static bool IsAPEFd(const int fd) {
|
static bool IsAPEFd(const int fd) {
|
||||||
char buf[8];
|
char buf[8];
|
||||||
bool res;
|
|
||||||
return (sys_pread(fd, buf, 8, 0, 0) == 8) && IsAPEMagic(buf);
|
return (sys_pread(fd, buf, 8, 0, 0) == 8) && IsAPEMagic(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +114,7 @@ static bool ape_to_elf(void *ape, const size_t apesize) {
|
||||||
* This does an inplace conversion of APE to ELF when detected!!!!
|
* This does an inplace conversion of APE to ELF when detected!!!!
|
||||||
*/
|
*/
|
||||||
static int fd_to_mem_fd(const int infd, char *path) {
|
static int fd_to_mem_fd(const int infd, char *path) {
|
||||||
if (!IsLinux() && !IsFreebsd() || !_weaken(mmap) || !_weaken(munmap)) {
|
if ((!IsLinux() && !IsFreebsd()) || !_weaken(mmap) || !_weaken(munmap)) {
|
||||||
return enosys();
|
return enosys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,9 +142,9 @@ static int fd_to_mem_fd(const int infd, char *path) {
|
||||||
bool success = readRc != -1;
|
bool success = readRc != -1;
|
||||||
if (success && (st.st_size > 8) && IsAPEMagic(space)) {
|
if (success && (st.st_size > 8) && IsAPEMagic(space)) {
|
||||||
int flags = fcntl(fd, F_GETFD);
|
int flags = fcntl(fd, F_GETFD);
|
||||||
if (success = (flags != -1) &&
|
if ((success = (flags != -1) &&
|
||||||
(fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC)) != -1) &&
|
(fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC)) != -1) &&
|
||||||
ape_to_elf(space, st.st_size)) {
|
ape_to_elf(space, st.st_size))) {
|
||||||
const int newfd = fcntl(fd, F_DUPFD, 9001);
|
const int newfd = fcntl(fd, F_DUPFD, 9001);
|
||||||
if (newfd != -1) {
|
if (newfd != -1) {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -232,7 +231,7 @@ int fexecve(int fd, char *const argv[], char *const envp[]) {
|
||||||
}
|
}
|
||||||
size_t numenvs;
|
size_t numenvs;
|
||||||
for (numenvs = 0; envp[numenvs];) ++numenvs;
|
for (numenvs = 0; envp[numenvs];) ++numenvs;
|
||||||
const size_t desenvs = min(500, max(numenvs + 1, 2));
|
// const size_t desenvs = min(500, max(numenvs + 1, 2));
|
||||||
static _Thread_local char *envs[500];
|
static _Thread_local char *envs[500];
|
||||||
memcpy(envs, envp, numenvs * sizeof(char *));
|
memcpy(envs, envp, numenvs * sizeof(char *));
|
||||||
envs[numenvs] = path;
|
envs[numenvs] = path;
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
*/
|
*/
|
||||||
int32_t sys_fstatat(int32_t dirfd, const char *path, struct stat *st,
|
int32_t sys_fstatat(int32_t dirfd, const char *path, struct stat *st,
|
||||||
int32_t flags) {
|
int32_t flags) {
|
||||||
int rc;
|
|
||||||
void *p;
|
void *p;
|
||||||
union metastat ms;
|
union metastat ms;
|
||||||
if (IsAsan() && !__asan_is_valid_str(path)) return efault();
|
if (IsAsan() && !__asan_is_valid_str(path)) return efault();
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
textwindows int sys_fstatfs_nt(int64_t handle, struct statfs *f) {
|
textwindows int sys_fstatfs_nt(int64_t handle, struct statfs *f) {
|
||||||
uint64_t w;
|
uint64_t w;
|
||||||
NtStatus st;
|
NtStatus st;
|
||||||
uint32_t type;
|
|
||||||
uint32_t h, i, j;
|
uint32_t h, i, j;
|
||||||
struct NtIoStatusBlock io;
|
struct NtIoStatusBlock io;
|
||||||
struct NtFileFsFullSizeInformation fs;
|
struct NtFileFsFullSizeInformation fs;
|
||||||
|
|
|
@ -57,7 +57,6 @@ textwindows int sys_getloadavg_nt(double *a, int n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static textstartup void sys_getloadavg_nt_init(void) {
|
static textstartup void sys_getloadavg_nt_init(void) {
|
||||||
double a[3];
|
|
||||||
if (IsWindows()) {
|
if (IsWindows()) {
|
||||||
load = 1;
|
load = 1;
|
||||||
cpus = __get_cpu_count() / 2;
|
cpus = __get_cpu_count() / 2;
|
||||||
|
|
|
@ -55,7 +55,6 @@ static gettimeofday_f *__gettimeofday = __gettimeofday_init;
|
||||||
*/
|
*/
|
||||||
int gettimeofday(struct timeval *tv, struct timezone *tz) {
|
int gettimeofday(struct timeval *tv, struct timezone *tz) {
|
||||||
int rc;
|
int rc;
|
||||||
axdx_t ad;
|
|
||||||
if (IsAsan() && ((tv && !__asan_is_valid(tv, sizeof(*tv))) ||
|
if (IsAsan() && ((tv && !__asan_is_valid(tv, sizeof(*tv))) ||
|
||||||
(tz && !__asan_is_valid(tz, sizeof(*tz))))) {
|
(tz && !__asan_is_valid(tz, sizeof(*tz))))) {
|
||||||
rc = efault();
|
rc = efault();
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
int sys_getgroups(int size, uint32_t list[]);
|
int sys_getgroups(int size, uint32_t list[]);
|
||||||
int sys_setgroups(size_t size, uint32_t list[]);
|
int sys_setgroups(size_t size, const uint32_t list[]);
|
||||||
|
|
||||||
const char *DescribeGidList(char[128], int, int, const uint32_t list[]);
|
const char *DescribeGidList(char[128], int, int, const uint32_t list[]);
|
||||||
#define DescribeGidList(rc, length, gidlist) \
|
#define DescribeGidList(rc, length, gidlist) \
|
||||||
|
|
|
@ -72,7 +72,6 @@ static struct HostAdapterInfoNode {
|
||||||
|
|
||||||
static int ioctl_default(int fd, unsigned long request, void *arg) {
|
static int ioctl_default(int fd, unsigned long request, void *arg) {
|
||||||
int rc;
|
int rc;
|
||||||
va_list va;
|
|
||||||
int64_t handle;
|
int64_t handle;
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
return sys_ioctl(fd, request, arg);
|
return sys_ioctl(fd, request, arg);
|
||||||
|
@ -94,7 +93,6 @@ static int ioctl_default(int fd, unsigned long request, void *arg) {
|
||||||
|
|
||||||
static int ioctl_fionread(int fd, uint32_t *arg) {
|
static int ioctl_fionread(int fd, uint32_t *arg) {
|
||||||
int rc;
|
int rc;
|
||||||
va_list va;
|
|
||||||
int64_t handle;
|
int64_t handle;
|
||||||
uint32_t avail;
|
uint32_t avail;
|
||||||
if (!IsWindows()) {
|
if (!IsWindows()) {
|
||||||
|
@ -323,7 +321,6 @@ static textwindows int createHostInfo(
|
||||||
struct NtIpAdapterPrefix *ap;
|
struct NtIpAdapterPrefix *ap;
|
||||||
struct HostAdapterInfoNode *node = NULL;
|
struct HostAdapterInfoNode *node = NULL;
|
||||||
char baseName[IFNAMSIZ];
|
char baseName[IFNAMSIZ];
|
||||||
char name[IFNAMSIZ];
|
|
||||||
int count, i;
|
int count, i;
|
||||||
/* __hostInfo must be empty */
|
/* __hostInfo must be empty */
|
||||||
unassert(__hostInfo == NULL);
|
unassert(__hostInfo == NULL);
|
||||||
|
@ -416,7 +413,6 @@ err:
|
||||||
|
|
||||||
static textwindows int ioctl_siocgifconf_nt(int fd, struct ifconf *ifc) {
|
static textwindows int ioctl_siocgifconf_nt(int fd, struct ifconf *ifc) {
|
||||||
struct ifreq *ptr;
|
struct ifreq *ptr;
|
||||||
struct NtIpAdapterAddresses *aa;
|
|
||||||
struct HostAdapterInfoNode *node;
|
struct HostAdapterInfoNode *node;
|
||||||
if (__hostInfo) {
|
if (__hostInfo) {
|
||||||
freeHostInfo();
|
freeHostInfo();
|
||||||
|
@ -480,12 +476,12 @@ static int ioctl_siocgifconf_sysv(int fd, struct ifconf *ifc) {
|
||||||
* BSD ABIs mainly differ by having sockaddr::sa_len
|
* BSD ABIs mainly differ by having sockaddr::sa_len
|
||||||
* XNU uses a 32-bit length in a struct that's packed!
|
* XNU uses a 32-bit length in a struct that's packed!
|
||||||
*/
|
*/
|
||||||
int i, rc, fam;
|
int rc, fam;
|
||||||
|
size_t bufMax;
|
||||||
char *b, *p, *e;
|
char *b, *p, *e;
|
||||||
char ifcBsd[16];
|
char ifcBsd[16];
|
||||||
struct ifreq *req;
|
struct ifreq *req;
|
||||||
uint32_t bufLen, ip;
|
uint32_t bufLen, ip;
|
||||||
size_t numReq, bufMax;
|
|
||||||
if (IsLinux()) {
|
if (IsLinux()) {
|
||||||
return sys_ioctl(fd, SIOCGIFCONF, ifc);
|
return sys_ioctl(fd, SIOCGIFCONF, ifc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
* @raise EPERM if pledge() was used without tty
|
* @raise EPERM if pledge() was used without tty
|
||||||
*/
|
*/
|
||||||
bool32 isatty(int fd) {
|
bool32 isatty(int fd) {
|
||||||
int e;
|
|
||||||
bool32 res;
|
bool32 res;
|
||||||
struct winsize ws;
|
struct winsize ws;
|
||||||
if (__isfdkind(fd, kFdZip)) {
|
if (__isfdkind(fd, kFdZip)) {
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
*/
|
*/
|
||||||
int mkfifo(const char *pathname, unsigned mode) {
|
int mkfifo(const char *pathname, unsigned mode) {
|
||||||
// TODO(jart): Windows?
|
// TODO(jart): Windows?
|
||||||
int e, rc;
|
int rc;
|
||||||
if (IsAsan() && !__asan_is_valid_str(pathname)) {
|
if (IsAsan() && !__asan_is_valid_str(pathname)) {
|
||||||
rc = efault();
|
rc = efault();
|
||||||
} else if (IsLinux()) {
|
} else if (IsLinux()) {
|
||||||
|
|
|
@ -71,7 +71,6 @@ textwindows int mkntcmdline(char16_t cmdline[ARG_MAX / 2], char *const argv[]) {
|
||||||
wint_t x, y;
|
wint_t x, y;
|
||||||
int slashes, n;
|
int slashes, n;
|
||||||
bool needsquote;
|
bool needsquote;
|
||||||
char16_t cbuf[2];
|
|
||||||
char *ansiargv[2];
|
char *ansiargv[2];
|
||||||
size_t i, j, k, s;
|
size_t i, j, k, s;
|
||||||
if (!argv[0]) {
|
if (!argv[0]) {
|
||||||
|
|
|
@ -36,9 +36,9 @@ static inline int IsAlpha(int c) {
|
||||||
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
|
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char *StrChr(char *s, int c) {
|
static inline char *StrChr(const char *s, int c) {
|
||||||
for (;; ++s) {
|
for (;; ++s) {
|
||||||
if ((*s & 255) == (c & 255)) return s;
|
if ((*s & 255) == (c & 255)) return (char *)s;
|
||||||
if (!*s) return 0;
|
if (!*s) return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,6 @@ static textwindows inline int CompareStrings(const char *l, const char *r) {
|
||||||
|
|
||||||
static textwindows void FixPath(char *path) {
|
static textwindows void FixPath(char *path) {
|
||||||
char *p;
|
char *p;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
// skip over variable name
|
// skip over variable name
|
||||||
while (*path++) {
|
while (*path++) {
|
||||||
|
@ -71,7 +70,7 @@ static textwindows void FixPath(char *path) {
|
||||||
|
|
||||||
// turn \c\... into c:\...
|
// turn \c\... into c:\...
|
||||||
p = path;
|
p = path;
|
||||||
if ((p[0] == '/' | p[0] == '\\') && IsAlpha(p[1]) &&
|
if ((p[0] == '/' || p[0] == '\\') && IsAlpha(p[1]) &&
|
||||||
(p[2] == '/' || p[2] == '\\')) {
|
(p[2] == '/' || p[2] == '\\')) {
|
||||||
p[0] = p[1];
|
p[0] = p[1];
|
||||||
p[1] = ':';
|
p[1] = ':';
|
||||||
|
@ -92,7 +91,7 @@ static textwindows void FixPath(char *path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static textwindows void InsertString(char **a, size_t i, char *s,
|
static textwindows void InsertString(char **a, size_t i, const char *s,
|
||||||
char buf[ARG_MAX], size_t *bufi,
|
char buf[ARG_MAX], size_t *bufi,
|
||||||
bool *have_systemroot) {
|
bool *have_systemroot) {
|
||||||
char *v;
|
char *v;
|
||||||
|
@ -119,7 +118,7 @@ static textwindows void InsertString(char **a, size_t i, char *s,
|
||||||
for (j = i; j > 0 && CompareStrings(s, a[j - 1]) < 0; --j) {
|
for (j = i; j > 0 && CompareStrings(s, a[j - 1]) < 0; --j) {
|
||||||
a[j] = a[j - 1];
|
a[j] = a[j - 1];
|
||||||
}
|
}
|
||||||
a[j] = s;
|
a[j] = (char *)s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,8 +135,6 @@ static textwindows void InsertString(char **a, size_t i, char *s,
|
||||||
textwindows int mkntenvblock(char16_t envvars[ARG_MAX / 2], char *const envp[],
|
textwindows int mkntenvblock(char16_t envvars[ARG_MAX / 2], char *const envp[],
|
||||||
const char *extravar, char buf[ARG_MAX]) {
|
const char *extravar, char buf[ARG_MAX]) {
|
||||||
bool v;
|
bool v;
|
||||||
char *t;
|
|
||||||
axdx_t rc;
|
|
||||||
uint64_t w;
|
uint64_t w;
|
||||||
char **vars;
|
char **vars;
|
||||||
wint_t x, y;
|
wint_t x, y;
|
||||||
|
|
|
@ -25,7 +25,7 @@ int32_t sys_mount_linux(const char *source, const char *target,
|
||||||
const char *filesystemtype, uint64_t mountflags,
|
const char *filesystemtype, uint64_t mountflags,
|
||||||
const void *data) asm("sys_mount");
|
const void *data) asm("sys_mount");
|
||||||
int32_t sys_mount_bsd(const char *type, const char *dir, int32_t flags,
|
int32_t sys_mount_bsd(const char *type, const char *dir, int32_t flags,
|
||||||
void *data) asm("sys_mount");
|
const void *data) asm("sys_mount");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mounts file system.
|
* Mounts file system.
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
void *sys_mremap(void *p, size_t n, size_t m, int f, void *q) {
|
void *sys_mremap(void *p, size_t n, size_t m, int f, void *q) {
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
bool cf;
|
bool cf;
|
||||||
uintptr_t res, rdi, rsi, rdx;
|
uintptr_t res, rdx;
|
||||||
register uintptr_t r8 asm("r8");
|
register uintptr_t r8 asm("r8");
|
||||||
register uintptr_t r10 asm("r10");
|
register uintptr_t r10 asm("r10");
|
||||||
if (IsLinux()) {
|
if (IsLinux()) {
|
||||||
|
|
|
@ -102,7 +102,6 @@ static long double nowl_vdso(void) {
|
||||||
|
|
||||||
long double nowl_setup(void) {
|
long double nowl_setup(void) {
|
||||||
bool isfast;
|
bool isfast;
|
||||||
uint64_t ticks;
|
|
||||||
__gettime = __clock_gettime_get(&isfast);
|
__gettime = __clock_gettime_get(&isfast);
|
||||||
if (isfast) {
|
if (isfast) {
|
||||||
nowl = nowl_vdso;
|
nowl = nowl_vdso;
|
||||||
|
|
|
@ -26,13 +26,12 @@
|
||||||
#include "libc/sysv/consts/sicode.h"
|
#include "libc/sysv/consts/sicode.h"
|
||||||
#include "libc/sysv/consts/sig.h"
|
#include "libc/sysv/consts/sig.h"
|
||||||
#include "libc/thread/tls.h"
|
#include "libc/thread/tls.h"
|
||||||
#include "libc/thread/tls2.h"
|
#include "libc/thread/tls2.internal.h"
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
|
||||||
textwindows bool32 __onntconsoleevent(uint32_t dwCtrlType) {
|
textwindows bool32 __onntconsoleevent(uint32_t dwCtrlType) {
|
||||||
struct CosmoTib tib;
|
struct CosmoTib tib;
|
||||||
struct StackFrame *fr;
|
|
||||||
|
|
||||||
// win32 spawns a thread on its own just to deliver sigint
|
// win32 spawns a thread on its own just to deliver sigint
|
||||||
// TODO(jart): make signal code lockless so we can delete!
|
// TODO(jart): make signal code lockless so we can delete!
|
||||||
|
|
|
@ -48,7 +48,7 @@ struct IoctlPtmGet {
|
||||||
static int openpty_impl(int *mfd, int *sfd, char *name,
|
static int openpty_impl(int *mfd, int *sfd, char *name,
|
||||||
const struct termios *tio, //
|
const struct termios *tio, //
|
||||||
const struct winsize *wsz) {
|
const struct winsize *wsz) {
|
||||||
int m, s, p;
|
int m, s;
|
||||||
struct IoctlPtmGet t;
|
struct IoctlPtmGet t;
|
||||||
RETURN_ON_ERROR((m = posix_openpt(O_RDWR | O_NOCTTY)));
|
RETURN_ON_ERROR((m = posix_openpt(O_RDWR | O_NOCTTY)));
|
||||||
if (!IsOpenbsd()) {
|
if (!IsOpenbsd()) {
|
||||||
|
@ -66,7 +66,7 @@ static int openpty_impl(int *mfd, int *sfd, char *name,
|
||||||
*sfd = s;
|
*sfd = s;
|
||||||
if (name) strcpy(name, t.sname);
|
if (name) strcpy(name, t.sname);
|
||||||
if (tio) npassert(!tcsetattr(s, TCSAFLUSH, tio));
|
if (tio) npassert(!tcsetattr(s, TCSAFLUSH, tio));
|
||||||
if (wsz) npassert(!tcgetwinsize(s, wsz));
|
if (wsz) npassert(!tcsetwinsize(s, wsz));
|
||||||
return 0;
|
return 0;
|
||||||
OnError:
|
OnError:
|
||||||
if (m != -1) sys_close(m);
|
if (m != -1) sys_close(m);
|
||||||
|
|
|
@ -1079,11 +1079,11 @@ static privileged int GetTid(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static privileged void Log(const char *s, ...) {
|
static privileged void Log(const char *s, ...) {
|
||||||
int res;
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, s);
|
va_start(va, s);
|
||||||
do {
|
do {
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
int res;
|
||||||
asm volatile("syscall"
|
asm volatile("syscall"
|
||||||
: "=a"(res)
|
: "=a"(res)
|
||||||
: "0"(__NR_linux_write), "D"(2), "S"(s), "d"(StrLen(s))
|
: "0"(__NR_linux_write), "D"(2), "S"(s), "d"(StrLen(s))
|
||||||
|
@ -1156,10 +1156,10 @@ static privileged int SigProcMask(int how, int64_t set, int64_t *old) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static privileged void KillThisProcess(void) {
|
static privileged void KillThisProcess(void) {
|
||||||
int res;
|
|
||||||
SigAction(Sigabrt, &(struct sigaction){0}, 0);
|
SigAction(Sigabrt, &(struct sigaction){0}, 0);
|
||||||
SigProcMask(Sig_Setmask, -1, 0);
|
SigProcMask(Sig_Setmask, -1, 0);
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
int res;
|
||||||
asm volatile("syscall"
|
asm volatile("syscall"
|
||||||
: "=a"(res)
|
: "=a"(res)
|
||||||
: "0"(__NR_linux_kill), "D"(GetPid()), "S"(Sigabrt)
|
: "0"(__NR_linux_kill), "D"(GetPid()), "S"(Sigabrt)
|
||||||
|
@ -1196,10 +1196,10 @@ static privileged void KillThisProcess(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static privileged void KillThisThread(void) {
|
static privileged void KillThisThread(void) {
|
||||||
int res;
|
|
||||||
SigAction(Sigabrt, &(struct sigaction){0}, 0);
|
SigAction(Sigabrt, &(struct sigaction){0}, 0);
|
||||||
SigProcMask(Sig_Setmask, -1, 0);
|
SigProcMask(Sig_Setmask, -1, 0);
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
int res;
|
||||||
asm volatile("syscall"
|
asm volatile("syscall"
|
||||||
: "=a"(res)
|
: "=a"(res)
|
||||||
: "0"(__NR_linux_tkill), "D"(GetTid()), "S"(Sigabrt)
|
: "0"(__NR_linux_tkill), "D"(GetTid()), "S"(Sigabrt)
|
||||||
|
@ -1233,7 +1233,7 @@ static privileged const char *GetSyscallName(uint16_t n) {
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
static privileged int HasSyscall(struct Pledges *p, uint16_t n) {
|
static privileged int HasSyscall(const struct Pledges *p, uint16_t n) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < p->len; ++i) {
|
for (i = 0; i < p->len; ++i) {
|
||||||
if (p->syscalls[i] == n) {
|
if (p->syscalls[i] == n) {
|
||||||
|
@ -1249,11 +1249,11 @@ static privileged int HasSyscall(struct Pledges *p, uint16_t n) {
|
||||||
static privileged void OnSigSys(int sig, siginfo_t *si, void *vctx) {
|
static privileged void OnSigSys(int sig, siginfo_t *si, void *vctx) {
|
||||||
bool found;
|
bool found;
|
||||||
char ord[17];
|
char ord[17];
|
||||||
int i, ok, mode = si->si_errno;
|
int i, mode = si->si_errno;
|
||||||
ucontext_t *ctx = vctx;
|
ucontext_t *ctx = vctx;
|
||||||
ctx->uc_mcontext.MCONTEXT_SYSCALL_RESULT_REGISTER = -Eperm;
|
ctx->uc_mcontext.MCONTEXT_SYSCALL_RESULT_REGISTER = -Eperm;
|
||||||
FixCpy(ord, si->si_syscall, 12);
|
FixCpy(ord, si->si_syscall, 12);
|
||||||
for (found = i = 0; i < ARRAYLEN(kPledge); ++i) {
|
for (found = false, i = 0; i < ARRAYLEN(kPledge); ++i) {
|
||||||
if (HasSyscall(kPledge + i, si->si_syscall)) {
|
if (HasSyscall(kPledge + i, si->si_syscall)) {
|
||||||
Log("error: protected syscall ", GetSyscallName(si->si_syscall),
|
Log("error: protected syscall ", GetSyscallName(si->si_syscall),
|
||||||
" (ord=", ord, "); pledge promise '", kPledge[i].name, "' to allow\n",
|
" (ord=", ord, "); pledge promise '", kPledge[i].name, "' to allow\n",
|
||||||
|
@ -1289,8 +1289,8 @@ static privileged void MonitorSigSys(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static privileged void AppendFilter(struct Filter *f, struct sock_filter *p,
|
static privileged void AppendFilter(struct Filter *f,
|
||||||
size_t n) {
|
const struct sock_filter *p, size_t n) {
|
||||||
if (UNLIKELY(f->n + n > ARRAYLEN(f->p))) notpossible;
|
if (UNLIKELY(f->n + n > ARRAYLEN(f->p))) notpossible;
|
||||||
MemCpy(f->p + f->n, p, n * sizeof(*f->p));
|
MemCpy(f->p + f->n, p, n * sizeof(*f->p));
|
||||||
f->n += n;
|
f->n += n;
|
||||||
|
@ -2290,8 +2290,8 @@ static privileged void AppendPledge(struct Filter *f, //
|
||||||
* @vforksafe
|
* @vforksafe
|
||||||
*/
|
*/
|
||||||
privileged int sys_pledge_linux(unsigned long ipromises, int mode) {
|
privileged int sys_pledge_linux(unsigned long ipromises, int mode) {
|
||||||
|
int i, rc = -1;
|
||||||
struct Filter f;
|
struct Filter f;
|
||||||
int i, e, rc = -1;
|
|
||||||
struct sock_filter sf[1] = {BPF_STMT(BPF_RET | BPF_K, 0)};
|
struct sock_filter sf[1] = {BPF_STMT(BPF_RET | BPF_K, 0)};
|
||||||
CheckLargeStackAllocation(&f, sizeof(f));
|
CheckLargeStackAllocation(&f, sizeof(f));
|
||||||
f.n = 0;
|
f.n = 0;
|
||||||
|
|
|
@ -67,7 +67,7 @@ ssize_t pwrite(int fd, const void *buf, size_t size, int64_t offset) {
|
||||||
} else if (__isfdkind(fd, kFdSocket)) {
|
} else if (__isfdkind(fd, kFdSocket)) {
|
||||||
rc = espipe();
|
rc = espipe();
|
||||||
} else if (__isfdkind(fd, kFdFile)) {
|
} else if (__isfdkind(fd, kFdFile)) {
|
||||||
rc = sys_write_nt(fd, (struct iovec[]){{buf, size}}, 1, offset);
|
rc = sys_write_nt(fd, (struct iovec[]){{(void *)buf, size}}, 1, offset);
|
||||||
} else {
|
} else {
|
||||||
return ebadf();
|
return ebadf();
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ static dontubsan void RaiseSigFpe(void) {
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
*/
|
*/
|
||||||
int raise(int sig) {
|
int raise(int sig) {
|
||||||
int rc, tid, event;
|
int rc;
|
||||||
STRACE("raise(%G) → ...", sig);
|
STRACE("raise(%G) → ...", sig);
|
||||||
if (sig == SIGTRAP) {
|
if (sig == SIGTRAP) {
|
||||||
DebugBreak();
|
DebugBreak();
|
||||||
|
|
|
@ -66,7 +66,6 @@ static textwindows ssize_t sys_read_nt_impl(struct Fd *fd, void *data,
|
||||||
int filetype;
|
int filetype;
|
||||||
int64_t handle;
|
int64_t handle;
|
||||||
uint32_t remain;
|
uint32_t remain;
|
||||||
uint32_t conmode;
|
|
||||||
char *targetdata;
|
char *targetdata;
|
||||||
uint32_t targetsize;
|
uint32_t targetsize;
|
||||||
bool is_console_input;
|
bool is_console_input;
|
||||||
|
@ -205,7 +204,6 @@ StartOver:
|
||||||
textwindows ssize_t sys_read_nt(struct Fd *fd, const struct iovec *iov,
|
textwindows ssize_t sys_read_nt(struct Fd *fd, const struct iovec *iov,
|
||||||
size_t iovlen, int64_t opt_offset) {
|
size_t iovlen, int64_t opt_offset) {
|
||||||
ssize_t rc;
|
ssize_t rc;
|
||||||
uint32_t size;
|
|
||||||
size_t i, total;
|
size_t i, total;
|
||||||
if (opt_offset < -1) return einval();
|
if (opt_offset < -1) return einval();
|
||||||
if (_check_interrupts(kSigOpRestartable)) return -1;
|
if (_check_interrupts(kSigOpRestartable)) return -1;
|
||||||
|
|
|
@ -45,7 +45,7 @@ textwindows ssize_t sys_readlinkat_nt(int dirfd, const char *path, char *buf,
|
||||||
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
|
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
|
||||||
mem = 16384;
|
mem = 16384;
|
||||||
memory = alloca(mem);
|
memory = alloca(mem);
|
||||||
CheckLargeStackAllocation(memory, mem);
|
CheckLargeStackAllocation((char *)memory, mem);
|
||||||
rdb = (struct NtReparseDataBuffer *)memory;
|
rdb = (struct NtReparseDataBuffer *)memory;
|
||||||
if ((h = CreateFile(path16, 0, 0, 0, kNtOpenExisting,
|
if ((h = CreateFile(path16, 0, 0, 0, kNtOpenExisting,
|
||||||
kNtFileFlagOpenReparsePoint | kNtFileFlagBackupSemantics,
|
kNtFileFlagOpenReparsePoint | kNtFileFlagBackupSemantics,
|
||||||
|
|
|
@ -26,7 +26,7 @@ static bool IsDataAvailable(struct Fd *fd) {
|
||||||
return inb(fd->handle + UART_LSR) & UART_TTYDA;
|
return inb(fd->handle + UART_LSR) & UART_TTYDA;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetFirstIov(struct iovec *iov, int iovlen) {
|
static int GetFirstIov(const struct iovec *iov, int iovlen) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < iovlen; ++i) {
|
for (i = 0; i < iovlen; ++i) {
|
||||||
if (iov[i].iov_len) {
|
if (iov[i].iov_len) {
|
||||||
|
|
|
@ -39,7 +39,6 @@ static volatile size_t mapsize;
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
*/
|
*/
|
||||||
int __ensurefds_unlocked(int fd) {
|
int __ensurefds_unlocked(int fd) {
|
||||||
bool relocate;
|
|
||||||
if (fd < g_fds.n) return fd;
|
if (fd < g_fds.n) return fd;
|
||||||
g_fds.n = fd + 1;
|
g_fds.n = fd + 1;
|
||||||
g_fds.e = _extend(g_fds.p, g_fds.n * sizeof(*g_fds.p), g_fds.e, MAP_PRIVATE,
|
g_fds.e = _extend(g_fds.p, g_fds.n * sizeof(*g_fds.p), g_fds.e, MAP_PRIVATE,
|
||||||
|
|
|
@ -488,7 +488,6 @@ static privileged void linuxssefpustate2xnu(
|
||||||
privileged void __sigenter_xnu(void *fn, int infostyle, int sig,
|
privileged void __sigenter_xnu(void *fn, int infostyle, int sig,
|
||||||
struct siginfo_xnu *xnuinfo,
|
struct siginfo_xnu *xnuinfo,
|
||||||
struct __darwin_ucontext *xnuctx) {
|
struct __darwin_ucontext *xnuctx) {
|
||||||
intptr_t ax;
|
|
||||||
int rva, flags;
|
int rva, flags;
|
||||||
struct Goodies {
|
struct Goodies {
|
||||||
ucontext_t uc;
|
ucontext_t uc;
|
||||||
|
@ -571,6 +570,7 @@ privileged void __sigenter_xnu(void *fn, int infostyle, int sig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
intptr_t ax;
|
||||||
asm volatile("syscall"
|
asm volatile("syscall"
|
||||||
: "=a"(ax)
|
: "=a"(ax)
|
||||||
: "0"(0x20000b8 /* sigreturn */), "D"(xnuctx), "S"(infostyle)
|
: "0"(0x20000b8 /* sigreturn */), "D"(xnuctx), "S"(infostyle)
|
||||||
|
|
|
@ -50,9 +50,8 @@
|
||||||
* @vforksafe
|
* @vforksafe
|
||||||
*/
|
*/
|
||||||
int sigprocmask(int how, const sigset_t *opt_set, sigset_t *opt_out_oldset) {
|
int sigprocmask(int how, const sigset_t *opt_set, sigset_t *opt_out_oldset) {
|
||||||
int res, rc, arg1;
|
int rc;
|
||||||
sigset_t old = {0};
|
sigset_t old = {0};
|
||||||
const sigset_t *arg2;
|
|
||||||
if (IsAsan() &&
|
if (IsAsan() &&
|
||||||
((opt_set && !__asan_is_valid(opt_set, sizeof(*opt_set))) ||
|
((opt_set && !__asan_is_valid(opt_set, sizeof(*opt_set))) ||
|
||||||
(opt_out_oldset &&
|
(opt_out_oldset &&
|
||||||
|
|
|
@ -47,7 +47,8 @@
|
||||||
*/
|
*/
|
||||||
int sigsuspend(const sigset_t *ignore) {
|
int sigsuspend(const sigset_t *ignore) {
|
||||||
int rc;
|
int rc;
|
||||||
sigset_t save, *arg, mask = {0};
|
const sigset_t *arg;
|
||||||
|
sigset_t save, mask = {0};
|
||||||
STRACE("sigsuspend(%s) → ...", DescribeSigset(0, ignore));
|
STRACE("sigsuspend(%s) → ...", DescribeSigset(0, ignore));
|
||||||
BEGIN_CANCELLATION_POINT;
|
BEGIN_CANCELLATION_POINT;
|
||||||
|
|
||||||
|
|
|
@ -47,10 +47,11 @@
|
||||||
int sigtimedwait(const sigset_t *set, siginfo_t *info,
|
int sigtimedwait(const sigset_t *set, siginfo_t *info,
|
||||||
const struct timespec *timeout) {
|
const struct timespec *timeout) {
|
||||||
int rc;
|
int rc;
|
||||||
char strsig[15];
|
char strsig[21];
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
union siginfo_meta si = {0};
|
union siginfo_meta si = {0};
|
||||||
BEGIN_CANCELLATION_POINT;
|
BEGIN_CANCELLATION_POINT;
|
||||||
|
(void)strsig;
|
||||||
|
|
||||||
if (IsAsan() && (!__asan_is_valid(set, sizeof(*set)) ||
|
if (IsAsan() && (!__asan_is_valid(set, sizeof(*set)) ||
|
||||||
(info && !__asan_is_valid(info, sizeof(*info))) ||
|
(info && !__asan_is_valid(info, sizeof(*info))) ||
|
||||||
|
|
|
@ -36,8 +36,8 @@ static struct Splice {
|
||||||
} g_splice;
|
} g_splice;
|
||||||
|
|
||||||
static bool HasSplice(void) {
|
static bool HasSplice(void) {
|
||||||
|
int e;
|
||||||
bool ok;
|
bool ok;
|
||||||
int e, rc;
|
|
||||||
e = errno;
|
e = errno;
|
||||||
if (IsLinux()) {
|
if (IsLinux()) {
|
||||||
// Our testing indicates splice() doesn't work as documneted on
|
// Our testing indicates splice() doesn't work as documneted on
|
||||||
|
|
|
@ -15,7 +15,7 @@ struct sock_filter {
|
||||||
|
|
||||||
struct sock_fprog {
|
struct sock_fprog {
|
||||||
unsigned short len;
|
unsigned short len;
|
||||||
struct sock_filter *filter;
|
const struct sock_filter *filter;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BPF_RVAL(code) ((code)&0x18)
|
#define BPF_RVAL(code) ((code)&0x18)
|
||||||
|
|
|
@ -21,7 +21,7 @@ ssize_t sys_writev_metal(struct Fd *, const struct iovec *, int);
|
||||||
ssize_t sys_writev_nt(int, const struct iovec *, int);
|
ssize_t sys_writev_nt(int, const struct iovec *, int);
|
||||||
ssize_t sys_writev_serial(struct Fd *, const struct iovec *, int);
|
ssize_t sys_writev_serial(struct Fd *, const struct iovec *, int);
|
||||||
ssize_t sys_send_nt(int, const struct iovec *, size_t, uint32_t);
|
ssize_t sys_send_nt(int, const struct iovec *, size_t, uint32_t);
|
||||||
ssize_t sys_sendto_nt(int, const struct iovec *, size_t, uint32_t, void *,
|
ssize_t sys_sendto_nt(int, const struct iovec *, size_t, uint32_t, const void *,
|
||||||
uint32_t);
|
uint32_t);
|
||||||
|
|
||||||
const char *DescribeIovec(char[300], ssize_t, const struct iovec *, int);
|
const char *DescribeIovec(char[300], ssize_t, const struct iovec *, int);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
const char *DescribeTermios(char[1024], ssize_t, struct termios *);
|
const char *DescribeTermios(char[1024], ssize_t, const struct termios *);
|
||||||
|
|
||||||
#define DescribeTermios(rc, tio) DescribeTermios(alloca(1024), rc, tio)
|
#define DescribeTermios(rc, tio) DescribeTermios(alloca(1024), rc, tio)
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ static inline bool timespec_iszero(struct timespec __ts) {
|
||||||
return !(__ts.tv_sec | __ts.tv_nsec);
|
return !(__ts.tv_sec | __ts.tv_nsec);
|
||||||
}
|
}
|
||||||
static inline bool timespec_isvalid(struct timespec __ts) {
|
static inline bool timespec_isvalid(struct timespec __ts) {
|
||||||
return __ts.tv_sec >= 0 && __ts.tv_nsec < 1000000000ull;
|
return __ts.tv_sec >= 0 && __ts.tv_nsec + 0ull < 1000000000ull;
|
||||||
}
|
}
|
||||||
#endif /* _COSMO_SOURCE */
|
#endif /* _COSMO_SOURCE */
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ static inline bool timeval_iszero(struct timeval __tv) {
|
||||||
return !(__tv.tv_sec | __tv.tv_usec);
|
return !(__tv.tv_sec | __tv.tv_usec);
|
||||||
}
|
}
|
||||||
static inline bool timeval_isvalid(struct timeval __tv) {
|
static inline bool timeval_isvalid(struct timeval __tv) {
|
||||||
return __tv.tv_sec >= 0 && __tv.tv_usec < 1000000ull;
|
return __tv.tv_sec >= 0 && __tv.tv_usec + 0ull < 1000000ull;
|
||||||
}
|
}
|
||||||
#endif /* _COSMO_SOURCE */
|
#endif /* _COSMO_SOURCE */
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
int tcgetwinsize_nt(int, struct winsize *);
|
int tcgetwinsize_nt(int, struct winsize *);
|
||||||
const char *DescribeWinsize(char[64], int, struct winsize *);
|
const char *DescribeWinsize(char[64], int, const struct winsize *);
|
||||||
#define DescribeWinsize(rc, ws) DescribeWinsize(alloca(64), rc, ws)
|
#define DescribeWinsize(rc, ws) DescribeWinsize(alloca(64), rc, ws)
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
|
|
|
@ -164,7 +164,6 @@ textwindows void __echo_terminal_input(struct Fd *fd, char *p, size_t n) {
|
||||||
|
|
||||||
textwindows int tcsetattr_nt(int fd, int opt, const struct termios *tio) {
|
textwindows int tcsetattr_nt(int fd, int opt, const struct termios *tio) {
|
||||||
bool32 ok;
|
bool32 ok;
|
||||||
int infd;
|
|
||||||
int64_t hInput, hOutput;
|
int64_t hInput, hOutput;
|
||||||
uint32_t inmode, outmode;
|
uint32_t inmode, outmode;
|
||||||
if (__isfdkind(fd, kFdConsole)) {
|
if (__isfdkind(fd, kFdConsole)) {
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
|
|
||||||
static textwindows errno_t sys_ttyname_nt(int fd, char *buf, size_t size) {
|
static textwindows errno_t sys_ttyname_nt(int fd, char *buf, size_t size) {
|
||||||
uint32_t mode;
|
uint32_t mode;
|
||||||
const char *s;
|
|
||||||
if (GetConsoleMode(g_fds.p[fd].handle, &mode)) {
|
if (GetConsoleMode(g_fds.p[fd].handle, &mode)) {
|
||||||
if (strlcpy(buf,
|
if (strlcpy(buf,
|
||||||
(mode & kNtEnableVirtualTerminalInput) ? "CONIN$" : "CONOUT$",
|
(mode & kNtEnableVirtualTerminalInput) ? "CONIN$" : "CONOUT$",
|
||||||
|
|
|
@ -66,7 +66,6 @@ static void GetBsdStr(int c0, int c1, char *s) {
|
||||||
|
|
||||||
// Gets NT name ignoring errors with guaranteed NUL-terminator.
|
// Gets NT name ignoring errors with guaranteed NUL-terminator.
|
||||||
static textwindows void GetNtName(char *name, int kind) {
|
static textwindows void GetNtName(char *name, int kind) {
|
||||||
uint32_t n = SYS_NMLN;
|
|
||||||
char16_t name16[256];
|
char16_t name16[256];
|
||||||
uint32_t size = ARRAYLEN(name16);
|
uint32_t size = ARRAYLEN(name16);
|
||||||
if (GetComputerNameEx(kind, name16, &size)) {
|
if (GetComputerNameEx(kind, name16, &size)) {
|
||||||
|
|
|
@ -211,8 +211,8 @@ static int unveil_init(void) {
|
||||||
static char *JoinPaths(char *buf, size_t size, const char *path,
|
static char *JoinPaths(char *buf, size_t size, const char *path,
|
||||||
const char *other) {
|
const char *other) {
|
||||||
size_t pathlen, otherlen;
|
size_t pathlen, otherlen;
|
||||||
if (!other) return path;
|
if (!other) return (char *)path;
|
||||||
if (!path) return other;
|
if (!path) return (char *)other;
|
||||||
pathlen = strlen(path);
|
pathlen = strlen(path);
|
||||||
if (!pathlen || *other == '/') {
|
if (!pathlen || *other == '/') {
|
||||||
return (/*unconst*/ char *)other;
|
return (/*unconst*/ char *)other;
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
|
|
||||||
int sys_utimensat_xnu(int dirfd, const char *path, const struct timespec ts[2],
|
int sys_utimensat_xnu(int dirfd, const char *path, const struct timespec ts[2],
|
||||||
int flags) {
|
int flags) {
|
||||||
int i;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct timeval now, tv[2];
|
struct timeval now, tv[2];
|
||||||
if (flags) return einval();
|
if (flags) return einval();
|
||||||
|
|
|
@ -81,11 +81,11 @@ static textwindows void AddProcessStats(int64_t h, struct rusage *ru) {
|
||||||
static textwindows int sys_wait4_nt_impl(int *pid, int *opt_out_wstatus,
|
static textwindows int sys_wait4_nt_impl(int *pid, int *opt_out_wstatus,
|
||||||
int options,
|
int options,
|
||||||
struct rusage *opt_out_rusage) {
|
struct rusage *opt_out_rusage) {
|
||||||
|
int pids[64];
|
||||||
int64_t handle;
|
int64_t handle;
|
||||||
int rc, pids[64];
|
uint32_t i, count;
|
||||||
int64_t handles[64];
|
int64_t handles[64];
|
||||||
uint32_t dwExitCode;
|
uint32_t dwExitCode;
|
||||||
uint32_t i, j, count;
|
|
||||||
if (*pid != -1 && *pid != 0) {
|
if (*pid != -1 && *pid != 0) {
|
||||||
if (*pid < 0) {
|
if (*pid < 0) {
|
||||||
// XXX: this is sloppy
|
// XXX: this is sloppy
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "libc/sysv/consts/sicode.h"
|
#include "libc/sysv/consts/sicode.h"
|
||||||
#include "libc/sysv/consts/sig.h"
|
#include "libc/sysv/consts/sig.h"
|
||||||
#include "libc/thread/tls.h"
|
#include "libc/thread/tls.h"
|
||||||
#include "libc/thread/tls2.h"
|
#include "libc/thread/tls2.internal.h"
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,6 @@ Finish:
|
||||||
// this makes it possible for our read() implementation to periodically
|
// this makes it possible for our read() implementation to periodically
|
||||||
// poll for signals while performing a blocking overlapped io operation
|
// poll for signals while performing a blocking overlapped io operation
|
||||||
dontasan dontubsan dontinstrument textwindows void WinMainStdin(void) {
|
dontasan dontubsan dontinstrument textwindows void WinMainStdin(void) {
|
||||||
uint32_t mode;
|
|
||||||
char16_t pipename[64];
|
char16_t pipename[64];
|
||||||
int64_t hStdin, hWriter, hReader, hThread, hSemaphore;
|
int64_t hStdin, hWriter, hReader, hThread, hSemaphore;
|
||||||
if (!SupportsWindows()) return;
|
if (!SupportsWindows()) return;
|
||||||
|
|
|
@ -79,9 +79,9 @@ ssize_t write(int fd, const void *buf, size_t size) {
|
||||||
} else if (fd >= g_fds.n) {
|
} else if (fd >= g_fds.n) {
|
||||||
rc = ebadf();
|
rc = ebadf();
|
||||||
} else if (IsMetal()) {
|
} else if (IsMetal()) {
|
||||||
rc = sys_writev_metal(g_fds.p + fd, &(struct iovec){buf, size}, 1);
|
rc = sys_writev_metal(g_fds.p + fd, &(struct iovec){(void *)buf, size}, 1);
|
||||||
} else if (IsWindows()) {
|
} else if (IsWindows()) {
|
||||||
rc = sys_writev_nt(fd, &(struct iovec){buf, size}, 1);
|
rc = sys_writev_nt(fd, &(struct iovec){(void *)buf, size}, 1);
|
||||||
} else {
|
} else {
|
||||||
rc = enosys();
|
rc = enosys();
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,6 @@ int getaddrinfo(const char *name, const char *service,
|
||||||
const struct addrinfo *hints, struct addrinfo **res) {
|
const struct addrinfo *hints, struct addrinfo **res) {
|
||||||
int rc, port;
|
int rc, port;
|
||||||
const char *canon;
|
const char *canon;
|
||||||
size_t protolen;
|
|
||||||
struct addrinfo *ai;
|
struct addrinfo *ai;
|
||||||
char proto[32];
|
char proto[32];
|
||||||
port = 0;
|
port = 0;
|
||||||
|
|
|
@ -58,7 +58,7 @@ int getnameinfo(const struct sockaddr *addr, uint32_t addrlen, char *name,
|
||||||
int flags) {
|
int flags) {
|
||||||
char *p, rdomain[1 + sizeof "255.255.255.255.in-addr.arpa"];
|
char *p, rdomain[1 + sizeof "255.255.255.255.in-addr.arpa"];
|
||||||
char info[NI_MAXHOST + 1];
|
char info[NI_MAXHOST + 1];
|
||||||
int rc, port;
|
int port;
|
||||||
uint8_t *ip;
|
uint8_t *ip;
|
||||||
unsigned int valid_flags;
|
unsigned int valid_flags;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ COSMOPOLITAN_C_START_
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § executable linkable format ─╬─│┼
|
│ cosmopolitan § executable linkable format ─╬─│┼
|
||||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||||
|
/* clang-format off */
|
||||||
|
|
||||||
bool IsElfSymbolContent(const Elf64_Sym *);
|
bool IsElfSymbolContent(const Elf64_Sym *);
|
||||||
bool IsElf64Binary(const Elf64_Ehdr *, size_t);
|
bool IsElf64Binary(const Elf64_Ehdr *, size_t);
|
||||||
|
@ -18,11 +19,11 @@ Elf64_Sym *GetElfSymbols(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
|
||||||
Elf64_Shdr *GetElfSymbolTable(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
|
Elf64_Shdr *GetElfSymbolTable(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
|
||||||
Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
|
Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
|
||||||
Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
|
Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
|
||||||
Elf64_Shdr *FindElfSectionByName(Elf64_Ehdr *, size_t, char *, const char *);
|
Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *, size_t, char *, const char *);
|
||||||
const char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word);
|
char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word);
|
||||||
void *GetElfSectionAddress(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
|
void *GetElfSectionAddress(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
|
||||||
void *GetElfSegmentAddress(const Elf64_Ehdr *, size_t, const Elf64_Phdr *);
|
void *GetElfSegmentAddress(const Elf64_Ehdr *, size_t, const Elf64_Phdr *);
|
||||||
const char *GetElfSectionName(const Elf64_Ehdr *, size_t, Elf64_Shdr *);
|
char *GetElfSectionName(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
|
||||||
char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t);
|
char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t);
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
* @param mapsize is the number of bytes past `elf` we can access
|
* @param mapsize is the number of bytes past `elf` we can access
|
||||||
* @return pointer to section header within image, or null
|
* @return pointer to section header within image, or null
|
||||||
*/
|
*/
|
||||||
Elf64_Shdr *FindElfSectionByName(Elf64_Ehdr *elf, size_t mapsize,
|
Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *elf, size_t mapsize,
|
||||||
char *shdrstrtab, const char *name) {
|
char *shdrstrtab, const char *name) {
|
||||||
long i;
|
long i;
|
||||||
Elf64_Shdr *shdr;
|
Elf64_Shdr *shdr;
|
||||||
|
|
|
@ -39,7 +39,7 @@ void *GetElfSectionAddress(const Elf64_Ehdr *elf, // validated
|
||||||
const Elf64_Shdr *shdr) { // foreign
|
const Elf64_Shdr *shdr) { // foreign
|
||||||
Elf64_Off last;
|
Elf64_Off last;
|
||||||
if (!shdr) return 0;
|
if (!shdr) return 0;
|
||||||
if (!shdr->sh_size) return elf;
|
if (!shdr->sh_size) return (void *)elf;
|
||||||
if (shdr->sh_type == SHT_NOBITS) return 0;
|
if (shdr->sh_type == SHT_NOBITS) return 0;
|
||||||
if (ckd_add(&last, shdr->sh_offset, shdr->sh_size)) return 0;
|
if (ckd_add(&last, shdr->sh_offset, shdr->sh_size)) return 0;
|
||||||
if (last > mapsize) return 0;
|
if (last > mapsize) return 0;
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/elf/elf.h"
|
#include "libc/elf/elf.h"
|
||||||
|
|
||||||
const char *GetElfSectionName(const Elf64_Ehdr *elf, size_t mapsize,
|
char *GetElfSectionName(const Elf64_Ehdr *elf, size_t mapsize,
|
||||||
Elf64_Shdr *shdr) {
|
const Elf64_Shdr *shdr) {
|
||||||
if (!shdr) return 0;
|
if (!shdr) return 0;
|
||||||
return GetElfString(elf, mapsize, GetElfSectionNameStringTable(elf, mapsize),
|
return GetElfString(elf, mapsize, GetElfSectionNameStringTable(elf, mapsize),
|
||||||
shdr->sh_name);
|
shdr->sh_name);
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
* 3. a nul byte wasn't present within `[strtab+i,elf+mapsize)`, or
|
* 3. a nul byte wasn't present within `[strtab+i,elf+mapsize)`, or
|
||||||
* 4. an arithmetic overflow occurred
|
* 4. an arithmetic overflow occurred
|
||||||
*/
|
*/
|
||||||
const char *GetElfString(const Elf64_Ehdr *elf, // validated
|
char *GetElfString(const Elf64_Ehdr *elf, // validated
|
||||||
size_t mapsize, // validated
|
size_t mapsize, // validated
|
||||||
const char *strtab, // validated
|
const char *strtab, // validated
|
||||||
Elf64_Word i) { // foreign
|
Elf64_Word i) { // foreign
|
||||||
|
@ -50,5 +50,5 @@ const char *GetElfString(const Elf64_Ehdr *elf, // validated
|
||||||
if (i >= mapsize) return 0;
|
if (i >= mapsize) return 0;
|
||||||
if (strtab + i >= e + mapsize) return 0;
|
if (strtab + i >= e + mapsize) return 0;
|
||||||
if (!memchr(strtab + i, 0, (e + mapsize) - (strtab + i))) return 0;
|
if (!memchr(strtab + i, 0, (e + mapsize) - (strtab + i))) return 0;
|
||||||
return (const char *)strtab + i;
|
return (char *)strtab + i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ char *GetElfStringTable(const Elf64_Ehdr *elf, //
|
||||||
const char *section_name) {
|
const char *section_name) {
|
||||||
int i;
|
int i;
|
||||||
char *name;
|
char *name;
|
||||||
Elf64_Shdr *shdr;
|
const Elf64_Shdr *shdr;
|
||||||
for (i = 0; i < elf->e_shnum; ++i) {
|
for (i = 0; i < elf->e_shnum; ++i) {
|
||||||
if ((shdr = GetElfSectionHeaderAddress(elf, mapsize, i)) &&
|
if ((shdr = GetElfSectionHeaderAddress(elf, mapsize, i)) &&
|
||||||
shdr->sh_type == SHT_STRTAB &&
|
shdr->sh_type == SHT_STRTAB &&
|
||||||
|
|
|
@ -22,7 +22,7 @@ COSMOPOLITAN_C_START_
|
||||||
((Elf64_Shdr *)((intptr_t)(e) + (e)->e_shoff + \
|
((Elf64_Shdr *)((intptr_t)(e) + (e)->e_shoff + \
|
||||||
(unsigned)(e)->e_shentsize * (i)))
|
(unsigned)(e)->e_shentsize * (i)))
|
||||||
|
|
||||||
static inline char *GetStrtab(Elf64_Ehdr *e, size_t *n) {
|
static inline char *GetStrtab(const Elf64_Ehdr *e, size_t *n) {
|
||||||
int i;
|
int i;
|
||||||
char *name;
|
char *name;
|
||||||
Elf64_Shdr *shdr;
|
Elf64_Shdr *shdr;
|
||||||
|
@ -39,7 +39,7 @@ static inline char *GetStrtab(Elf64_Ehdr *e, size_t *n) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Elf64_Sym *GetSymtab(Elf64_Ehdr *e, Elf64_Xword *n) {
|
static inline Elf64_Sym *GetSymtab(const Elf64_Ehdr *e, Elf64_Xword *n) {
|
||||||
int i;
|
int i;
|
||||||
Elf64_Shdr *shdr;
|
Elf64_Shdr *shdr;
|
||||||
for (i = e->e_shnum; i-- > 0;) {
|
for (i = e->e_shnum; i-- > 0;) {
|
||||||
|
@ -52,9 +52,10 @@ static inline Elf64_Sym *GetSymtab(Elf64_Ehdr *e, Elf64_Xword *n) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void GetImageRange(Elf64_Ehdr *elf, intptr_t *x, intptr_t *y) {
|
static inline void GetImageRange(const Elf64_Ehdr *elf, intptr_t *x,
|
||||||
|
intptr_t *y) {
|
||||||
unsigned i;
|
unsigned i;
|
||||||
Elf64_Phdr *phdr;
|
const Elf64_Phdr *phdr;
|
||||||
intptr_t start, end, pstart, pend;
|
intptr_t start, end, pstart, pend;
|
||||||
start = INTPTR_MAX;
|
start = INTPTR_MAX;
|
||||||
end = 0;
|
end = 0;
|
||||||
|
|
|
@ -17,7 +17,7 @@ int snprintf(char *, size_t, const char *, ...)
|
||||||
printfesque(3) dontthrow nocallback;
|
printfesque(3) dontthrow nocallback;
|
||||||
int vsnprintf(char *, size_t, const char *, va_list)
|
int vsnprintf(char *, size_t, const char *, va_list)
|
||||||
dontthrow nocallback;
|
dontthrow nocallback;
|
||||||
int sprintf(char *, const char *, ...) printfesque(2) dontthrow nocallback;
|
int sprintf(char *, const char *, ...) dontthrow nocallback;
|
||||||
int vsprintf(char *, const char *, va_list)
|
int vsprintf(char *, const char *, va_list)
|
||||||
dontthrow nocallback;
|
dontthrow nocallback;
|
||||||
int sscanf(const char *, const char *, ...) scanfesque(2);
|
int sscanf(const char *, const char *, ...) scanfesque(2);
|
||||||
|
|
|
@ -14,7 +14,7 @@ char *sleb64(char *, int64_t);
|
||||||
char *zleb64(char[hasatleast 10], int64_t);
|
char *zleb64(char[hasatleast 10], int64_t);
|
||||||
char *uleb64(char[hasatleast 10], uint64_t);
|
char *uleb64(char[hasatleast 10], uint64_t);
|
||||||
int unzleb64(const char *, size_t, int64_t *);
|
int unzleb64(const char *, size_t, int64_t *);
|
||||||
int unuleb64(char *, size_t, uint64_t *);
|
int unuleb64(const char *, size_t, uint64_t *);
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
#endif /* _COSMO_SOURCE */
|
#endif /* _COSMO_SOURCE */
|
||||||
|
|
|
@ -28,9 +28,9 @@ extern const struct MagnumStr kSockOptnames[];
|
||||||
extern const struct MagnumStr kTcpOptnames[];
|
extern const struct MagnumStr kTcpOptnames[];
|
||||||
extern const struct MagnumStr kPollNames[];
|
extern const struct MagnumStr kPollNames[];
|
||||||
|
|
||||||
char *DescribeMagnum(char *, const struct MagnumStr *, const char *, int);
|
const char *DescribeMagnum(char *, const struct MagnumStr *, const char *, int);
|
||||||
|
|
||||||
__funline char *GetMagnumStr(const struct MagnumStr *ms, int x) {
|
__funline const char *GetMagnumStr(const struct MagnumStr *ms, int x) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; ms[i].x != MAGNUM_TERMINATOR; ++i) {
|
for (i = 0; ms[i].x != MAGNUM_TERMINATOR; ++i) {
|
||||||
if (x == MAGNUM_NUMBER(ms, i)) {
|
if (x == MAGNUM_NUMBER(ms, i)) {
|
||||||
|
@ -44,7 +44,7 @@ __funline char *GetMagnumStr(const struct MagnumStr *ms, int x) {
|
||||||
* Converts errno value to descriptive sentence.
|
* Converts errno value to descriptive sentence.
|
||||||
* @return non-null rodata string or null if not found
|
* @return non-null rodata string or null if not found
|
||||||
*/
|
*/
|
||||||
__funline char *_strerdoc(int x) {
|
__funline const char *_strerdoc(int x) {
|
||||||
if (x) {
|
if (x) {
|
||||||
return GetMagnumStr(kErrnoDocs, x);
|
return GetMagnumStr(kErrnoDocs, x);
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,7 +56,7 @@ __funline char *_strerdoc(int x) {
|
||||||
* Converts errno value to symbolic name.
|
* Converts errno value to symbolic name.
|
||||||
* @return non-null rodata string or null if not found
|
* @return non-null rodata string or null if not found
|
||||||
*/
|
*/
|
||||||
__funline char *_strerrno(int x) {
|
__funline const char *_strerrno(int x) {
|
||||||
if (x) {
|
if (x) {
|
||||||
return GetMagnumStr(kErrnoNames, x);
|
return GetMagnumStr(kErrnoNames, x);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -53,7 +53,7 @@ long strtol(const char *s, char **endptr, int base) {
|
||||||
char t = 0;
|
char t = 0;
|
||||||
long x = 0;
|
long x = 0;
|
||||||
int d, c = *s;
|
int d, c = *s;
|
||||||
CONSUME_SPACES(s, c);
|
CONSUME_SPACES(char, s, c);
|
||||||
GET_SIGN(s, c, d);
|
GET_SIGN(s, c, d);
|
||||||
GET_RADIX(s, c, base);
|
GET_RADIX(s, c, base);
|
||||||
if ((c = kBase36[c & 255]) && --c < base) {
|
if ((c = kBase36[c & 255]) && --c < base) {
|
||||||
|
@ -67,7 +67,9 @@ long strtol(const char *s, char **endptr, int base) {
|
||||||
} while ((c = kBase36[*++s & 255]) && --c < base);
|
} while ((c = kBase36[*++s & 255]) && --c < base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (t && endptr) *endptr = s;
|
if (t && endptr) {
|
||||||
|
*endptr = (char *)s;
|
||||||
|
}
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
#define COSMOPOLITAN_LIBC_FMT_STRTOL_H_
|
#define COSMOPOLITAN_LIBC_FMT_STRTOL_H_
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
|
|
||||||
#define CONSUME_SPACES(s, c) \
|
#define CONSUME_SPACES(t, s, c) \
|
||||||
if (endptr) *endptr = s; \
|
if (endptr) *endptr = (t *)(s); \
|
||||||
while (c == ' ' || c == '\t') c = *++s
|
while (c == ' ' || c == '\t') c = *++s
|
||||||
|
|
||||||
#define GET_SIGN(s, c, d) \
|
#define GET_SIGN(s, c, d) \
|
||||||
|
|
|
@ -42,20 +42,24 @@ unsigned long strtoul(const char *s, char **endptr, int base) {
|
||||||
char t = 0;
|
char t = 0;
|
||||||
int d, c = *s;
|
int d, c = *s;
|
||||||
unsigned long x = 0;
|
unsigned long x = 0;
|
||||||
CONSUME_SPACES(s, c);
|
CONSUME_SPACES(char, s, c);
|
||||||
GET_SIGN(s, c, d);
|
GET_SIGN(s, c, d);
|
||||||
GET_RADIX(s, c, base);
|
GET_RADIX(s, c, base);
|
||||||
if ((c = kBase36[c & 255]) && --c < base) {
|
if ((c = kBase36[c & 255]) && --c < base) {
|
||||||
t |= 1;
|
t |= 1;
|
||||||
do {
|
do {
|
||||||
if (ckd_mul(&x, x, base) || ckd_add(&x, x, c)) {
|
if (ckd_mul(&x, x, base) || ckd_add(&x, x, c)) {
|
||||||
if (endptr) *endptr = s + 1;
|
if (endptr) {
|
||||||
|
*endptr = (char *)(s + 1);
|
||||||
|
}
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
return ULONG_MAX;
|
return ULONG_MAX;
|
||||||
}
|
}
|
||||||
} while ((c = kBase36[*++s & 255]) && --c < base);
|
} while ((c = kBase36[*++s & 255]) && --c < base);
|
||||||
}
|
}
|
||||||
if (t && endptr) *endptr = s;
|
if (t && endptr) {
|
||||||
|
*endptr = (char *)s;
|
||||||
|
}
|
||||||
return d > 0 ? x : -x;
|
return d > 0 ? x : -x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* @param x receives number number
|
* @param x receives number number
|
||||||
* @return bytes decoded or -1 on error
|
* @return bytes decoded or -1 on error
|
||||||
*/
|
*/
|
||||||
int unuleb64(char *p, size_t n, uint64_t *x) {
|
int unuleb64(const char *p, size_t n, uint64_t *x) {
|
||||||
int k;
|
int k;
|
||||||
size_t i;
|
size_t i;
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue