Skip to content

Commit

Permalink
Fix some todos
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Oct 10, 2023
1 parent 9d372f4 commit 9cc4f33
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 139 deletions.
17 changes: 15 additions & 2 deletions ape/ape-m1.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <libkern/OSCacheControl.h>
#include <limits.h>
#include <pthread.h>
#include <semaphore.h>
#include <signal.h>
#include <stdarg.h>
#include <stdint.h>
Expand All @@ -30,7 +31,6 @@
#include <sys/uio.h>
#include <time.h>
#include <unistd.h>
#include <semaphore.h>

#define pagesz 16384
#define SYSLIB_MAGIC ('s' | 'l' << 8 | 'i' << 16 | 'b' << 24)
Expand Down Expand Up @@ -89,6 +89,8 @@ struct Syslib {
long (*sem_post)(int *);
long (*sem_wait)(int *);
long (*sem_trywait)(int *);
long (*getrlimit)(int, struct rlimit *);
long (*setrlimit)(int, const struct rlimit *);
};

#define ELFCLASS32 1
Expand Down Expand Up @@ -814,7 +816,8 @@ static long sys_getentropy(void *buf, size_t buflen) {
return sysret(getentropy(buf, buflen));
}

static long sys_sem_open(const char *name, int oflags, mode_t mode, unsigned value) {
static long sys_sem_open(const char *name, int oflags, mode_t mode,
unsigned value) {
return sysret((long)sem_open(name, oflags, mode, value));
}

Expand All @@ -838,6 +841,14 @@ static long sys_sem_trywait(sem_t *sem) {
return sysret(sem_trywait(sem));
}

static long sys_getrlimit(int which, struct rlimit *rlim) {
return sysret(getrlimit(which, rlim));
}

static long sys_setrlimit(int which, const struct rlimit *rlim) {
return sysret(setrlimit(which, rlim));
}

static long sys_write(int fd, const void *data, size_t size) {
return sysret(write(fd, data, size));
}
Expand Down Expand Up @@ -930,6 +941,8 @@ int main(int argc, char **argv, char **envp) {
M->lib.sem_post = sys_sem_post;
M->lib.sem_wait = sys_sem_wait;
M->lib.sem_trywait = sys_sem_trywait;
M->lib.getrlimit = sys_getrlimit;
M->lib.setrlimit = sys_setrlimit;

/* getenv("_") is close enough to at_execfn */
execfn = argc > 0 ? argv[0] : 0;
Expand Down
Binary file removed execve_test_prog1.com
Binary file not shown.
2 changes: 1 addition & 1 deletion libc/calls/clock_nanosleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static int cosmo_clock_nanosleep(int clock, int flags,
if (timespec_cmp(remain, quantum) > 0) {
waitfor = timespec_sub(remain, quantum);
if (sys_clock_nanosleep(sleep_clock, 0, &waitfor, rem) == -1) {
if (rem && errno == EINTR) {
if (!flags && rem && errno == EINTR) {
*rem = timespec_add(*rem, quantum);
}
return -1;
Expand Down
110 changes: 0 additions & 110 deletions libc/calls/diagnose_syscall.S

This file was deleted.

4 changes: 4 additions & 0 deletions libc/calls/getrlimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/rlimit.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/runtime/stack.h"
#include "libc/runtime/syslib.internal.h"
#include "libc/sysv/consts/rlimit.h"
#include "libc/sysv/errfuns.h"

Expand All @@ -40,6 +42,8 @@ int getrlimit(int resource, struct rlimit *rlim) {
rc = einval();
} else if (!rlim || (IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim)))) {
rc = efault();
} else if (IsXnuSilicon()) {
rc = _sysret(__syslib->__getrlimit(resource, rlim));
} else if (!IsWindows()) {
rc = sys_getrlimit(resource, rlim);
} else if (resource == RLIMIT_STACK) {
Expand Down
33 changes: 18 additions & 15 deletions libc/calls/read-nt.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,23 +342,26 @@ static textwindows int ProcessMouseEvent(const struct NtInputRecord *r,
bs &= kNtFromLeft1stButtonPressed | kNtRightmostButtonPressed;
if (ev & kNtMouseWheeled) {
// scroll wheel (unnatural mode)
if (!(r->Event.MouseEvent.dwControlKeyState &
(kNtShiftPressed | kNtLeftCtrlPressed | kNtRightCtrlPressed |
kNtLeftAltPressed | kNtRightAltPressed))) {
bool isup = ((int)r->Event.MouseEvent.dwButtonState >> 16) > 0;
if (__ttyconf.magic & kTtyXtMouse) {
bool isup = ((int)r->Event.MouseEvent.dwButtonState >> 16) > 0;
if (__ttyconf.magic & kTtyXtMouse) {
if (r->Event.MouseEvent.dwControlKeyState &
(kNtLeftCtrlPressed | kNtRightCtrlPressed)) {
e = isup ? 80 : 81;
goto OutputXtermMouseEvent;
} else {
// we disable mouse highlighting when the tty is put in raw mode
// to mouse wheel events with widely understood vt100 arrow keys
*p++ = 033;
*p++ = !__keystroke.ohno_decckm ? '[' : 'O';
if (isup) {
*p++ = 'A';
} else {
*p++ = 'B';
}
e = isup ? 64 : 65;
}
goto OutputXtermMouseEvent;
} else if (!(r->Event.MouseEvent.dwControlKeyState &
(kNtShiftPressed | kNtLeftCtrlPressed | kNtRightCtrlPressed |
kNtLeftAltPressed | kNtRightAltPressed))) {
// we disable mouse highlighting when the tty is put in raw mode
// to mouse wheel events with widely understood vt100 arrow keys
*p++ = 033;
*p++ = !__keystroke.ohno_decckm ? '[' : 'O';
if (isup) {
*p++ = 'A';
} else {
*p++ = 'B';
}
}
} else if ((bs || currentbs) && (__ttyconf.magic & kTtyXtMouse)) {
Expand Down
4 changes: 4 additions & 0 deletions libc/calls/setrlimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/rlimit.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h"
#include "libc/runtime/syslib.internal.h"
#include "libc/sysv/consts/rlimit.h"
#include "libc/sysv/errfuns.h"

Expand Down Expand Up @@ -79,6 +81,8 @@ int setrlimit(int resource, const struct rlimit *rlim) {
rc = einval();
} else if (!rlim || (IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim)))) {
rc = efault();
} else if (IsXnuSilicon()) {
rc = _sysret(__syslib->__setrlimit(resource, rlim));
} else if (!IsWindows()) {
rc = sys_setrlimit(resource, rlim);
if (IsXnu() && !rc && resource == RLIMIT_AS) {
Expand Down
2 changes: 2 additions & 0 deletions libc/runtime/syslib.internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ struct Syslib {
long (*__sem_post)(int *);
long (*__sem_wait)(int *);
long (*__sem_trywait)(int *);
long (*__getrlimit)(int, void *);
long (*__setrlimit)(int, const void *);
};

extern struct Syslib *__syslib;
Expand Down
3 changes: 1 addition & 2 deletions libc/thread/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

#define TLS_ALIGNMENT 64

#define TIB_FLAG_VFORKED 1
#define TIB_FLAG_WINCRASHING 2
#define TIB_FLAG_VFORKED 1

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
Expand Down
4 changes: 0 additions & 4 deletions test/libc/calls/clock_nanosleep_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
#include "libc/testlib/testlib.h"
#include "libc/time/time.h"

void SetUpOnce(void) {
if (!IsWindows()) _Exit(0);
}

void OnAlrm(int sig) {
// do nothing
STRACE("OnAlrm()");
Expand Down
Loading

0 comments on commit 9cc4f33

Please sign in to comment.