Skip to content

Commit

Permalink
Make use of musl's weak macro. NFC (#19385)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed May 17, 2023
1 parent daecbfc commit fba7c2e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
4 changes: 0 additions & 4 deletions system/lib/libc/emscripten_syscall_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ static mode_t g_umask = S_IRWXU | S_IRWXG | S_IRWXO;
#define STRINGIFY(s) #s
#define STR(s) STRINGIFY(s)

#ifndef weak
#define weak __attribute__((__weak__))
#endif

weak int __syscall_uname(intptr_t buf) {
if (!buf) {
return -EFAULT;
Expand Down
28 changes: 13 additions & 15 deletions system/lib/standalone/standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ int clock_getres(clockid_t clk_id, struct timespec *tp) {

// Mark these as weak so that wasmfs does not collide with it. That is, if
// wasmfs is in use, we want to use that and not this.
__attribute__((__weak__)) int _mmap_js(size_t length,
int prot,
int flags,
int fd,
size_t offset,
int* allocated,
void** addr) {
weak int _mmap_js(size_t length,
int prot,
int flags,
int fd,
size_t offset,
int* allocated,
void** addr) {
return -ENOSYS;
}

__attribute__((__weak__)) int _munmap_js(
weak int _munmap_js(
intptr_t addr, size_t length, int prot, int flags, int fd, size_t offset) {
return -ENOSYS;
}
Expand All @@ -89,8 +89,7 @@ __attribute__((__weak__)) int _munmap_js(
// corner case error checking; everything else is not permitted.
// TODO: full file support for WASI, or an option for it
// open()
__attribute__((__weak__))
int __syscall_openat(int dirfd, intptr_t path, int flags, ...) {
weak int __syscall_openat(int dirfd, intptr_t path, int flags, ...) {
if (!strcmp((const char*)path, "/dev/stdin")) {
return STDIN_FILENO;
}
Expand All @@ -103,22 +102,21 @@ int __syscall_openat(int dirfd, intptr_t path, int flags, ...) {
return -EPERM;
}

__attribute__((__weak__)) int __syscall_ioctl(int fd, int op, ...) {
weak int __syscall_ioctl(int fd, int op, ...) {
return -ENOSYS;
}

__attribute__((__weak__)) int __syscall_fcntl64(int fd, int cmd, ...) {
weak int __syscall_fcntl64(int fd, int cmd, ...) {
return -ENOSYS;
}

__attribute__((__weak__)) int __syscall_fstat64(int fd, intptr_t buf) {
weak int __syscall_fstat64(int fd, intptr_t buf) {
return -ENOSYS;
}

// There is no good source of entropy without an import. Make this weak so that
// it can be replaced with a pRNG or a proper import.
__attribute__((__weak__))
int getentropy(void* buffer, size_t length) {
weak int getentropy(void* buffer, size_t length) {
abort();
}

Expand Down
1 change: 1 addition & 0 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2047,6 +2047,7 @@ def can_use(self):
class libstubs(DebugLibrary):
name = 'libstubs'
src_dir = 'system/lib/libc'
includes = ['system/lib/libc/musl/src/include']
src_files = ['emscripten_syscall_stubs.c', 'emscripten_libc_stubs.c']


Expand Down

0 comments on commit fba7c2e

Please sign in to comment.