Improve system call wrappers

This change improves copy_file_range(), sendfile(), splice(), openpty(),
closefrom(), close_range(), fadvise() and posix_fadvise() in addition to
writing tests that confirm things like errno and seeking behavior across
platforms. We now less aggressively polyfill behavior with some of these
functions when the platform support isn't available. Please see:

https://justine.lol/cosmopolitan/functions.html
This commit is contained in:
Justine Tunney 2022-09-19 15:01:48 -07:00
parent 224c12f54d
commit c7a8cd21e9
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
89 changed files with 1151 additions and 414 deletions

View file

@ -20,6 +20,7 @@ const char *DescribeFrame(char[32], int);
const char *DescribeFutexOp(char[64], int);
const char *DescribeFutexResult(char[12], int);
const char *DescribeHow(char[12], int);
const char *DescribeInOutInt64(char[23], ssize_t, int64_t *);
const char *DescribeMapFlags(char[64], int);
const char *DescribeMapping(char[8], int, int);
const char *DescribeNtConsoleInFlags(char[256], uint32_t);
@ -64,6 +65,7 @@ const char *DescribeWhence(char[12], int);
#define DescribeFutexOp(x) DescribeFutexOp(alloca(64), x)
#define DescribeFutexResult(x) DescribeFutexResult(alloca(12), x)
#define DescribeHow(x) DescribeHow(alloca(12), x)
#define DescribeInOutInt64(rc, x) DescribeInOutInt64(alloca(23), rc, x)
#define DescribeMapFlags(x) DescribeMapFlags(alloca(64), x)
#define DescribeMapping(x, y) DescribeMapping(alloca(8), x, y)
#define DescribeNtConsoleInFlags(x) DescribeNtConsoleInFlags(alloca(256), x)

View file

@ -0,0 +1,37 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/errno.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/describeflags.internal.h"
const char *(DescribeInOutInt64)(char buf[23], ssize_t rc, int64_t *x) {
if (!x) return "NULL";
char *p = buf;
if (rc != -1) *p++ = '[';
if (rc == -1 && errno == EFAULT) {
*p++ = '!';
*p++ = '!';
*p++ = '!';
} else {
p = FormatInt64(p, *x);
}
if (rc != -1) *p++ = ']';
*p = 0;
return buf;
}

View file

@ -34,7 +34,7 @@
* @raise EBUSY if lock is already held
* @raise ENOTRECOVERABLE if `mutex` is corrupted
*/
int pthread_mutex_trylock(pthread_mutex_t *mutex) {
errno_t pthread_mutex_trylock(pthread_mutex_t *mutex) {
int c, d, t;
if (__tls_enabled && //

View file

@ -44,7 +44,7 @@
*
* @return 0 on success, or errno on error
*/
int pthread_once(pthread_once_t *once, void init(void)) {
errno_t pthread_once(pthread_once_t *once, void init(void)) {
uint32_t old;
if (_weaken(nsync_run_once)) {
_weaken(nsync_run_once)((nsync_once *)once, init);

View file

@ -40,10 +40,10 @@ static bool __isrestorable;
static union metatermios __oldtermios;
// called weakly by libc/calls/ioctl_tcsets.c to avoid pledge("tty")
void __on_ioctl_tcsets(void) {
void __on_ioctl_tcsets(int fd) {
int e;
e = errno;
if (sys_ioctl(0, TCGETS, &__oldtermios) != -1) {
if (sys_ioctl(fd, TCGETS, &__oldtermios) != -1) {
__isrestorable = true;
}
errno = e;