From 2ce58c995946f85666e793c4f06efff683e76ae4 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Wed, 12 Nov 2025 00:37:26 +0100 Subject: fixes --- programs/initd/initd.c | 17 +++----- programs/libc/CMakeLists.txt | 27 +++++++++++++ programs/libc/fcntl/CMakeLists.txt | 19 +++++++++ programs/libc/fcntl/open.c | 41 +++++++++++++++++++ programs/libc/malloc_init.c | 29 ++++++++++++++ programs/libc/start.c | 72 ++++++++++++++++++++++++++++++++++ programs/libc/sys/CMakeLists.txt | 18 +++++++++ programs/libc/sys/mount/CMakeLists.txt | 19 +++++++++ programs/libc/sys/mount/mount.c | 32 +++++++++++++++ programs/libc/sys/stat/CMakeLists.txt | 20 ++++++++++ programs/libc/sys/stat/mkdir.c | 30 ++++++++++++++ programs/libc/sys/stat/umask.c | 29 ++++++++++++++ programs/libc/unistd/CMakeLists.txt | 21 ++++++++++ programs/libc/unistd/close.c | 30 ++++++++++++++ programs/libc/unistd/sbrk.c | 56 ++++++++++++++++++++++++++ programs/libc/unistd/write.c | 32 +++++++++++++++ programs/wasm-clang-toolchain.cmake | 1 + programs/wnix/CMakeLists.txt | 26 ------------ programs/wnix/mkdir.c | 30 -------------- programs/wnix/mount.c | 32 --------------- programs/wnix/sbrk.c | 56 -------------------------- programs/wnix/start.c | 64 ------------------------------ programs/yes/CMakeLists.txt | 13 +----- 23 files changed, 484 insertions(+), 230 deletions(-) create mode 100644 programs/libc/CMakeLists.txt create mode 100644 programs/libc/fcntl/CMakeLists.txt create mode 100644 programs/libc/fcntl/open.c create mode 100644 programs/libc/malloc_init.c create mode 100644 programs/libc/start.c create mode 100644 programs/libc/sys/CMakeLists.txt create mode 100644 programs/libc/sys/mount/CMakeLists.txt create mode 100644 programs/libc/sys/mount/mount.c create mode 100644 programs/libc/sys/stat/CMakeLists.txt create mode 100644 programs/libc/sys/stat/mkdir.c create mode 100644 programs/libc/sys/stat/umask.c create mode 100644 programs/libc/unistd/CMakeLists.txt create mode 100644 programs/libc/unistd/close.c create mode 100644 programs/libc/unistd/sbrk.c create mode 100644 programs/libc/unistd/write.c delete mode 100644 programs/wnix/CMakeLists.txt delete mode 100644 programs/wnix/mkdir.c delete mode 100644 programs/wnix/mount.c delete mode 100644 programs/wnix/sbrk.c delete mode 100644 programs/wnix/start.c (limited to 'programs') diff --git a/programs/initd/initd.c b/programs/initd/initd.c index 5e200b3..3ca3f6e 100644 --- a/programs/initd/initd.c +++ b/programs/initd/initd.c @@ -16,9 +16,7 @@ * along with this program. If not, see . */ -#if 1 #include -#endif #include #include #include @@ -27,17 +25,14 @@ int main(int argc, char *argv[]) { + puts("Starting second-stage bootloader from WebAssembly!"); + #if 0 - puts("hi from wasm!"); -#endif -#if 1 - if (mkdir("/home", 0755)) - return errno; -#endif -#if 1 - if (mount("/dev/mc0", "/home", NULL, 0, NULL)) + if (mkdir("/home", 0755) + || mkdir("/home/wnix", 0755) + || mount("/dev/mc0", "/home/wnix", "ps1mcfs", 0, NULL)) return errno; #endif - return 1; + return EXIT_SUCCESS; } diff --git a/programs/libc/CMakeLists.txt b/programs/libc/CMakeLists.txt new file mode 100644 index 0000000..a0c6d97 --- /dev/null +++ b/programs/libc/CMakeLists.txt @@ -0,0 +1,27 @@ +# wnix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +set(LIBC_FREESTANDING ON) +set(libc_dir ${CMAKE_CURRENT_LIST_DIR}/../../src/libc) +add_subdirectory(${libc_dir} ${CMAKE_CURRENT_BINARY_DIR}/libc) +add_subdirectory(fcntl) +add_subdirectory(sys) +add_subdirectory(unistd) +target_compile_definitions(c PRIVATE PRINTF_DISABLE_SUPPORT_FLOAT) +target_sources(c PRIVATE + malloc_init.c + start.c +) diff --git a/programs/libc/fcntl/CMakeLists.txt b/programs/libc/fcntl/CMakeLists.txt new file mode 100644 index 0000000..c0ca1d1 --- /dev/null +++ b/programs/libc/fcntl/CMakeLists.txt @@ -0,0 +1,19 @@ +# wnix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +target_sources(c PRIVATE + open.c +) diff --git a/programs/libc/fcntl/open.c b/programs/libc/fcntl/open.c new file mode 100644 index 0000000..71511a7 --- /dev/null +++ b/programs/libc/fcntl/open.c @@ -0,0 +1,41 @@ +/* + * wnix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +int open(const char *const path, const int flags, ...) +{ + int __wnix_open(const char *, int, mode_t, int *) __attribute__(( + __import_module__("wnix"), + __import_name__("open") + )); + + mode_t mode = 0; + va_list ap; + + va_start(ap, flags); + + if (flags & O_CREAT) + mode = va_arg(ap, mode_t); + + va_end(ap); + return __wnix_open(path, flags, mode, &errno); +} diff --git a/programs/libc/malloc_init.c b/programs/libc/malloc_init.c new file mode 100644 index 0000000..969f523 --- /dev/null +++ b/programs/libc/malloc_init.c @@ -0,0 +1,29 @@ +/* + * wnix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +void __malloc_init(void) +{ + /* README.md states 16 is a "good default value". */ + if (!ta_init(64, 16, sizeof (intmax_t))) + abort(); +} diff --git a/programs/libc/start.c b/programs/libc/start.c new file mode 100644 index 0000000..5e56239 --- /dev/null +++ b/programs/libc/start.c @@ -0,0 +1,72 @@ +/* + * wnix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +void _start(void) +{ + /* clang mangles main if argc/argv are present: + * https://reviews.llvm.org/D127888 */ + int __main_argc_argv(int, char *[]); + int __wnix_argc(void) __attribute__(( + __import_module__("wnix"), + __import_name__("argc") + )); + _Noreturn void __wnix_exit(int) __attribute__(( + __import_module__("wnix"), + __import_name__("exit") + )); + + if (!(__stdin = fopen("/dev/stdin", "rb")) + || !(__stdout = fopen("/dev/stdout", "wb")) + || !(__stderr = fopen("/dev/stderr", "wb"))) + __wnix_exit(EXIT_FAILURE); + + const int argc = __wnix_argc(); + char **argv = malloc((argc + 1) * sizeof *argv); + + if (!argv) + __wnix_exit(EXIT_FAILURE); + + for (int i = 0; i < argc; i++) + { + size_t __wnix_arglen(int) __attribute__(( + __import_module__("wnix"), + __import_name__("arglen") + )); + + int __wnix_argcopy(int, char *, int *) __attribute__(( + __import_module__("wnix"), + __import_name__("argcopy") + )); + + char *const arg = malloc(__wnix_arglen(i)); + + if (!arg) + __wnix_exit(EXIT_FAILURE); + + __wnix_argcopy(i, arg, &errno); + argv[i] = arg; + } + + argv[argc] = NULL; + __wnix_exit(__main_argc_argv(argc, argv)); +} diff --git a/programs/libc/sys/CMakeLists.txt b/programs/libc/sys/CMakeLists.txt new file mode 100644 index 0000000..ea57403 --- /dev/null +++ b/programs/libc/sys/CMakeLists.txt @@ -0,0 +1,18 @@ +# wnix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +add_subdirectory(mount) +add_subdirectory(stat) diff --git a/programs/libc/sys/mount/CMakeLists.txt b/programs/libc/sys/mount/CMakeLists.txt new file mode 100644 index 0000000..222e506 --- /dev/null +++ b/programs/libc/sys/mount/CMakeLists.txt @@ -0,0 +1,19 @@ +# wnix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +target_sources(c PRIVATE + mount.c +) diff --git a/programs/libc/sys/mount/mount.c b/programs/libc/sys/mount/mount.c new file mode 100644 index 0000000..2512f73 --- /dev/null +++ b/programs/libc/sys/mount/mount.c @@ -0,0 +1,32 @@ +/* + * wnix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include + +int mount(const char *const src, const char *const tgt, const char *const type, + const unsigned long flags, const void *const args) +{ + int __wnix_mount(const char *, const char *, const char *, + unsigned long, const void *, int *) __attribute__(( + __import_module__("wnix"), + __import_name__("mount") + )); + + return __wnix_mount(src, tgt, type, flags, args, &errno); +} diff --git a/programs/libc/sys/stat/CMakeLists.txt b/programs/libc/sys/stat/CMakeLists.txt new file mode 100644 index 0000000..60a8d6c --- /dev/null +++ b/programs/libc/sys/stat/CMakeLists.txt @@ -0,0 +1,20 @@ +# wnix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +target_sources(c PRIVATE + mkdir.c + umask.c +) diff --git a/programs/libc/sys/stat/mkdir.c b/programs/libc/sys/stat/mkdir.c new file mode 100644 index 0000000..5547616 --- /dev/null +++ b/programs/libc/sys/stat/mkdir.c @@ -0,0 +1,30 @@ +/* + * wnix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include + +int mkdir(const char *const pathname, mode_t flags) +{ + int __wnix_mkdir(const char *, mode_t, int *) __attribute__(( + __import_module__("wnix"), + __import_name__("mkdir") + )); + + return __wnix_mkdir(pathname, flags, &errno); +} diff --git a/programs/libc/sys/stat/umask.c b/programs/libc/sys/stat/umask.c new file mode 100644 index 0000000..f42a6e5 --- /dev/null +++ b/programs/libc/sys/stat/umask.c @@ -0,0 +1,29 @@ +/* + * wnix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include + +mode_t umask(const mode_t mask) +{ + int __wnix_umask(mode_t) __attribute__(( + __import_module__("wnix"), + __import_name__("umask") + )); + + return __wnix_umask(mask); +} diff --git a/programs/libc/unistd/CMakeLists.txt b/programs/libc/unistd/CMakeLists.txt new file mode 100644 index 0000000..e3481bc --- /dev/null +++ b/programs/libc/unistd/CMakeLists.txt @@ -0,0 +1,21 @@ +# wnix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +target_sources(c PRIVATE + close.c + sbrk.c + write.c +) diff --git a/programs/libc/unistd/close.c b/programs/libc/unistd/close.c new file mode 100644 index 0000000..94ca6fc --- /dev/null +++ b/programs/libc/unistd/close.c @@ -0,0 +1,30 @@ +/* + * wnix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include + +int close(const int fd) +{ + int __wnix_close(int, int *) __attribute__(( + __import_module__("wnix"), + __import_name__("close") + )); + + return __wnix_close(fd, &errno); +} diff --git a/programs/libc/unistd/sbrk.c b/programs/libc/unistd/sbrk.c new file mode 100644 index 0000000..7e32118 --- /dev/null +++ b/programs/libc/unistd/sbrk.c @@ -0,0 +1,56 @@ +/* + * wnix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +void *sbrk(const intptr_t increment) +{ + const unsigned pagesize = 64 << 10; + extern char __heap_base[]; + static char *cur = __heap_base, *end; + + if (increment < 0) + { + errno = EINVAL; + return NULL; + } + else if (!end) + end = cur + __builtin_wasm_memory_size(0) * pagesize; + + if (increment >= (intptr_t)end || cur >= end - increment) + { + const unsigned long pages = (uintptr_t)increment / pagesize, + new_end = __builtin_wasm_memory_grow(0, pages); + + if (!new_end) + { + errno = ENOMEM; + return NULL; + } + + end = (void *)new_end; + } + + void *ret = cur; + + cur += increment; + return ret; +} diff --git a/programs/libc/unistd/write.c b/programs/libc/unistd/write.c new file mode 100644 index 0000000..9151e61 --- /dev/null +++ b/programs/libc/unistd/write.c @@ -0,0 +1,32 @@ +/* + * wnix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +ssize_t write(const int fd, const void *const p, const size_t sz) +{ + int __wnix_write(int, const void *, size_t, int *) __attribute__(( + __import_module__("wnix"), + __import_name__("write") + )); + + return __wnix_write(fd, p, sz, &errno); +} diff --git a/programs/wasm-clang-toolchain.cmake b/programs/wasm-clang-toolchain.cmake index a6890f8..746392c 100644 --- a/programs/wasm-clang-toolchain.cmake +++ b/programs/wasm-clang-toolchain.cmake @@ -23,6 +23,7 @@ set(CMAKE_C_COMPILER_WORKS 1) set(CMAKE_C_FLAGS " \ ${CMAKE_C_FLAGS} \ --target=wasm32-unknown-unknown-wasm \ + -mcpu=mvp \ -fno-exceptions \ -nostdinc \ -nostdlib \ diff --git a/programs/wnix/CMakeLists.txt b/programs/wnix/CMakeLists.txt deleted file mode 100644 index a118bd0..0000000 --- a/programs/wnix/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# wnix, a Unix-like operating system for WebAssembly applications. -# Copyright (C) 2025 Xavier Del Campo Romero -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -add_library(wnix - mkdir.c - mount.c - sbrk.c - start.c -) -set(LIBC_FREESTANDING ON) -add_subdirectory(../../src/libc ${CMAKE_CURRENT_BINARY_DIR}/libc) -target_compile_definitions(c PRIVATE PRINTF_DISABLE_SUPPORT_FLOAT) -target_link_libraries(wnix PUBLIC c) diff --git a/programs/wnix/mkdir.c b/programs/wnix/mkdir.c deleted file mode 100644 index 5547616..0000000 --- a/programs/wnix/mkdir.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * wnix, a Unix-like operating system for WebAssembly applications. - * Copyright (C) 2025 Xavier Del Campo Romero - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include -#include - -int mkdir(const char *const pathname, mode_t flags) -{ - int __wnix_mkdir(const char *, mode_t, int *) __attribute__(( - __import_module__("wnix"), - __import_name__("mkdir") - )); - - return __wnix_mkdir(pathname, flags, &errno); -} diff --git a/programs/wnix/mount.c b/programs/wnix/mount.c deleted file mode 100644 index 2512f73..0000000 --- a/programs/wnix/mount.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * wnix, a Unix-like operating system for WebAssembly applications. - * Copyright (C) 2025 Xavier Del Campo Romero - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include -#include - -int mount(const char *const src, const char *const tgt, const char *const type, - const unsigned long flags, const void *const args) -{ - int __wnix_mount(const char *, const char *, const char *, - unsigned long, const void *, int *) __attribute__(( - __import_module__("wnix"), - __import_name__("mount") - )); - - return __wnix_mount(src, tgt, type, flags, args, &errno); -} diff --git a/programs/wnix/sbrk.c b/programs/wnix/sbrk.c deleted file mode 100644 index 7e32118..0000000 --- a/programs/wnix/sbrk.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * wnix, a Unix-like operating system for WebAssembly applications. - * Copyright (C) 2025 Xavier Del Campo Romero - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include - -void *sbrk(const intptr_t increment) -{ - const unsigned pagesize = 64 << 10; - extern char __heap_base[]; - static char *cur = __heap_base, *end; - - if (increment < 0) - { - errno = EINVAL; - return NULL; - } - else if (!end) - end = cur + __builtin_wasm_memory_size(0) * pagesize; - - if (increment >= (intptr_t)end || cur >= end - increment) - { - const unsigned long pages = (uintptr_t)increment / pagesize, - new_end = __builtin_wasm_memory_grow(0, pages); - - if (!new_end) - { - errno = ENOMEM; - return NULL; - } - - end = (void *)new_end; - } - - void *ret = cur; - - cur += increment; - return ret; -} diff --git a/programs/wnix/start.c b/programs/wnix/start.c deleted file mode 100644 index 06dc4d5..0000000 --- a/programs/wnix/start.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * wnix, a Unix-like operating system for WebAssembly applications. - * Copyright (C) 2025 Xavier Del Campo Romero - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include -#include -#include - -void _start(void) -{ - int main(int, char *[]); - int __wnix_argc(void) __attribute__(( - __import_module__("wnix"), - __import_name__("argc") - )); - _Noreturn void __wnix_exit(int) __attribute__(( - __import_module__("wnix"), - __import_name__("exit") - )); - - const int argc = __wnix_argc(); - char **argv = malloc((argc + 1) * sizeof *argv); - - if (!argv) - __wnix_exit(EXIT_FAILURE); - - for (int i = 0; i < argc; i++) - { - size_t __wnix_arglen(int) __attribute__(( - __import_module__("wnix"), - __import_name__("arglen") - )); - - int __wnix_argcopy(int, char *, int *) __attribute__(( - __import_module__("wnix"), - __import_name__("argcopy") - )); - - char *const arg = malloc(__wnix_arglen(i)); - - if (!arg) - __wnix_exit(EXIT_FAILURE); - - __wnix_argcopy(i, arg, &errno); - argv[i] = arg; - } - - argv[argc] = NULL; - __wnix_exit(main(argc, argv)); -} diff --git a/programs/yes/CMakeLists.txt b/programs/yes/CMakeLists.txt index 59abf8f..cebd1c4 100644 --- a/programs/yes/CMakeLists.txt +++ b/programs/yes/CMakeLists.txt @@ -18,14 +18,5 @@ cmake_minimum_required(VERSION 3.13) include(GNUInstallDirs) project(yes C) add_executable(${PROJECT_NAME} yes.c) -add_subdirectory(../wnix ${CMAKE_CURRENT_BINARY_DIR}/wnix) -target_link_libraries(${PROJECT_NAME} PRIVATE wnix) -# TODO: Debugging symbols could still be there, but nwc still has issues. -add_custom_target(${PROJECT_NAME}_strip ALL - ${CMAKE_STRIP} ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} - BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} -) -add_dependencies(${PROJECT_NAME}_strip ${PROJECT_NAME}) -install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) +include(wnix_program) +wnix_program() -- cgit v1.2.3