Create a fake syscall() function due to Python

This commit is contained in:
Justine Tunney 2023-06-09 05:18:38 -07:00
parent 4b2023ffab
commit 2eb7148474
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
8 changed files with 74 additions and 8 deletions

View file

@ -401,6 +401,7 @@ SECTIONS {
/*BEGIN: NT FORK COPYING */
KEEP(*(.dataprologue))
*(.data .data.*)
*(.PyRuntime) /* for python */
*(.subrs) /* for emacs */
KEEP(*(SORT_BY_NAME(.sort.data.*)))
. += . > 0 ? CODE_GRANULE : 0;

View file

@ -5,6 +5,7 @@
#include "libc/sock/struct/ip_mreq.h"
#include "libc/sock/struct/sockaddr.h"
#include "libc/sock/struct/sockaddr6.h"
#include "libc/sysv/consts/in.h"
#include "libc/sysv/consts/inaddr.h"
#include "libc/sysv/consts/inet6.h"
#include "libc/sysv/consts/ip.h"

View file

@ -1,4 +1,4 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_SYSCALL_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_SYSCALL_H_
#include "libc/calls/calls.h"
#include "libc/stdio/syscall.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SYSCALL_H_ */

View file

@ -1,4 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_SYS_XATTR_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_SYS_XATTR_H_
#include "libc/calls/xattr.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SYS_XATTR_H_ */

49
libc/stdio/syscall.c Normal file
View file

@ -0,0 +1,49 @@
/*-*- 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 2023 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/stdio/syscall.h"
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/stdio/rand.h"
/**
* Translation layer for some Linux system calls:
*
* - `SYS_gettid`
* - `SYS_getrandom`
*
* @return negative errno on error
*/
long syscall(long number, ...) {
switch (number) {
default:
return -ENOSYS;
case SYS_gettid:
return gettid();
case SYS_getrandom: {
va_list va;
va_start(va, number);
void *buf = va_arg(va, void *);
size_t buflen = va_arg(va, size_t);
unsigned flags = va_arg(va, unsigned);
va_end(va);
ssize_t rc = getrandom(buf, buflen, flags);
return rc == -1 ? -errno : rc;
}
}
}

13
libc/stdio/syscall.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef COSMOPOLITAN_LIBC_STDIO_SYSCALL_H_
#define COSMOPOLITAN_LIBC_STDIO_SYSCALL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define SYS_gettid 186
#define SYS_getrandom 318
long syscall(long, ...);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STDIO_SYSCALL_H_ */

View file

@ -9,13 +9,18 @@ extern const uint32_t FIONBIO;
extern const uint32_t FIONCLEX;
extern const uint32_t FIONREAD;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#define FIOASYNC FIOASYNC
#define FIOCLEX FIOCLEX
#define FIONBIO FIONBIO
#define FIONCLEX FIONCLEX
#define FIONREAD FIONREAD
#define __tmpcosmo_FIOASYNC -484047213
#define __tmpcosmo_FIOCLEX -1198942590
#define __tmpcosmo_FIONBIO 2035363853
#define __tmpcosmo_FIONCLEX -25760400
#define __tmpcosmo_FIONREAD 1333957726
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_FIO_H_ */

View file

@ -27,5 +27,6 @@
#define IN_OPEN 0x20
#define IN_Q_OVERFLOW 0x4000
#define IN_UNMOUNT 0x2000
#define IN_CLASSA_NSHIFT 24
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_IN_H_ */