Improve system calls

- Wrap clock_getres()
- Wrap sched_setscheduler()
- Make sleep() api conformant
- Polyfill sleep() using select()
- Improve clock_gettime() polyfill
- Make nanosleep() POSIX conformant
- Slightly improve some DNS functions
- Further strengthen pledge() sandboxing
- Improve rounding of timeval / timespec
- Allow layering of pledge() calls on Linux
- Polyfill sched_yield() using select() on XNU
- Delete more system constants we probably don't need
This commit is contained in:
Justine Tunney 2022-07-08 06:29:24 -07:00
parent 5df3e4e7a8
commit 853b6c3864
330 changed files with 1971 additions and 1223 deletions

View file

@ -16,11 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/bits/atomic.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/spinlock.h"
#include "libc/log/color.internal.h"
#include "libc/log/internal.h"
#include "libc/log/libfatal.internal.h"
@ -32,16 +32,12 @@ const char *testlib_showerror_func;
const char *testlib_showerror_isfatal;
const char *testlib_showerror_macro;
const char *testlib_showerror_symbol;
_Alignas(64) static char testlib_showerror_lock;
testonly void testlib_showerror(const char *file, int line, const char *func,
const char *method, const char *symbol,
const char *code, char *v1, char *v2) {
char *p;
char hostname[128];
_spinlock(&testlib_showerror_lock);
if (!IsWindows()) __getpid(); /* make strace easier to read */
if (!IsWindows()) __getpid();
__stpcpy(hostname, "unknown");
gethostname(hostname, sizeof(hostname));
kprintf("%serror%s%s:%s:%d%s: %s() in %s(%s) on %s pid %d tid %d\n"
@ -55,7 +51,6 @@ testonly void testlib_showerror(const char *file, int line, const char *func,
SUBTLE, strerror(errno), GetProgramExecutableName(), RESET);
free_s(&v1);
free_s(&v2);
_spunlock(&testlib_showerror_lock);
}
/* TODO(jart): Pay off tech debt re duplication */
@ -65,10 +60,7 @@ testonly void testlib_showerror_(int line, const char *wantcode,
int e;
va_list va;
char hostname[128];
_spinlock(&testlib_showerror_lock);
e = errno;
if (!IsWindows()) __getpid();
if (!IsWindows()) __getpid();
if (gethostname(hostname, sizeof(hostname))) {
__stpcpy(hostname, "unknown");
}
@ -98,6 +90,7 @@ testonly void testlib_showerror_(int line, const char *wantcode,
free_s(&FREED_want);
free_s(&FREED_got);
++g_testlib_failed;
if (testlib_showerror_isfatal) testlib_abort();
_spunlock(&testlib_showerror_lock);
if (testlib_showerror_isfatal) {
testlib_abort();
}
}