diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-07-07 13:22:53 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-11-11 00:08:15 +0100 |
| commit | 7861a52adf92a083bb2aed4c35f98d8035dce032 (patch) | |
| tree | 28cd3c40e4c878f730f5df3c1d93bdf91af490c3 /src/bin/private_include | |
| parent | 7fc48e9216ff809da5f8055a50b0be17628ef1df (diff) | |
| download | wnix-7861a52adf92a083bb2aed4c35f98d8035dce032.tar.gz | |
Setup project skeleton
Diffstat (limited to 'src/bin/private_include')
| -rw-r--r-- | src/bin/private_include/bin/mod.h | 39 | ||||
| -rw-r--r-- | src/bin/private_include/bin/proc.h | 49 | ||||
| -rw-r--r-- | src/bin/private_include/bin/routines.h | 32 | ||||
| -rw-r--r-- | src/bin/private_include/bin/types.h | 99 | ||||
| -rw-r--r-- | src/bin/private_include/bin/wasi.h | 41 | ||||
| -rw-r--r-- | src/bin/private_include/bin/wasi/errno.h | 105 | ||||
| -rw-r--r-- | src/bin/private_include/bin/wnix.h | 37 | ||||
| -rw-r--r-- | src/bin/private_include/bin/wnix/routines.h | 29 |
8 files changed, 431 insertions, 0 deletions
diff --git a/src/bin/private_include/bin/mod.h b/src/bin/private_include/bin/mod.h new file mode 100644 index 0000000..13ef55c --- /dev/null +++ b/src/bin/private_include/bin/mod.h @@ -0,0 +1,39 @@ +/* + * 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 <https://www.gnu.org/licenses/>. + */ + +#ifndef BIN_MOD_H +#define BIN_MOD_H + +#include <bin/types.h> +#include <nanowasm/nw.h> +#include <stddef.h> + +const struct bin_mod *bin_mod(const char *path); +int bin_mod_lock(struct bin_mod *m); +int bin_mod_unlock(struct bin_mod *m); +int bin_mod_move(struct bin_mod *m, struct bin *from, struct bin *to); +void bin_mod_free(struct bin_mod *m); +int bin_mod_read(void *buf, size_t n, void *user); +int bin_mod_eof(void *user); +enum nw_state bin_mod_pc(long offset, struct nw_next *next, void *user); +enum nw_state bin_mod_seek(long offset, void *user); +enum nw_state bin_mod_tell(long *offset, void *user); + +extern const struct nw_mod_cfg bin_mod_cfg; + +#endif diff --git a/src/bin/private_include/bin/proc.h b/src/bin/private_include/bin/proc.h new file mode 100644 index 0000000..cf0c04e --- /dev/null +++ b/src/bin/private_include/bin/proc.h @@ -0,0 +1,49 @@ +/* + * 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 <https://www.gnu.org/licenses/>. + */ + +#ifndef BIN_PROC_H +#define BIN_PROC_H + +#include <bin/types.h> +#include <nanowasm/nw.h> +#include <stddef.h> + +int bin_proc_init(struct bin_proc *p); +int bin_proc_add(struct bin_proc *p); +void bin_proc_free(struct bin_proc *p); +int bin_proc_read(void *buf, size_t n, void *user); +int bin_proc_eof(void *user); +enum nw_state bin_proc_pc(long offset, struct nw_next *next, void *user); +enum nw_state bin_proc_seek(long offset, void *user); +enum nw_state bin_proc_tell(long *offset, void *user); +int bin_proc_lock(struct bin_proc *p); +int bin_proc_unlock(struct bin_proc *p); +int bin_proc_move(struct bin_proc *p, struct bin *from, struct bin *to); +int bin_proc_l_load(unsigned long pos, void *dst, size_t n, void *user); +int bin_proc_l_store(unsigned long pos, const void *src, size_t n, void *user); +int bin_proc_g_load(unsigned long pos, void *dst, size_t n, void *user); +int bin_proc_g_store(unsigned long pos, const void *src, size_t n, void *user); +int bin_proc_s_push(const void *src, size_t n, void *user); +int bin_proc_s_pop(void *dst, size_t n, void *user); +int bin_proc_s_read(size_t offset, void *dst, size_t n, void *user); +int bin_proc_s_write(size_t offset, const void *dst, size_t n, void *user); +size_t bin_proc_s_ptr(void *user); + +extern const struct nw_inst_cfg bin_proc_cfg; + +#endif diff --git a/src/bin/private_include/bin/routines.h b/src/bin/private_include/bin/routines.h new file mode 100644 index 0000000..c78ad18 --- /dev/null +++ b/src/bin/private_include/bin/routines.h @@ -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 <https://www.gnu.org/licenses/>. + */ + +#ifndef BIN_ROUTINES_H +#define BIN_ROUTINES_H + +#include <bin/types.h> +#include <sys/types.h> +#include <stdbool.h> + +pid_t bin_pid(void); +int bin_start(struct bin_mod *m); +int bin_stop(struct bin_proc *p); +int bin_load(struct bin_mod *m); +int bin_unload(struct bin_mod *m); + +#endif diff --git a/src/bin/private_include/bin/types.h b/src/bin/private_include/bin/types.h new file mode 100644 index 0000000..2a498ed --- /dev/null +++ b/src/bin/private_include/bin/types.h @@ -0,0 +1,99 @@ +/* + * 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 <https://www.gnu.org/licenses/>. + */ + +#ifndef BIN_TYPES_H +#define BIN_TYPES_H + +#include <bin/wasi.h> +#include <caio.h> +#include <fs/fs.h> +#include <dynstr.h> +#include <nanowasm/nw.h> +#include <nanowasm/dbg.h> +#include <sys/types.h> +#include <stdbool.h> + +enum {BIN_IMPORTS = 9}; + +struct bin_dbg +{ + char b; + bool running, step; + struct nw_dbg dbg; + struct dynstr dstr; + struct aio *aio; + struct fs_fd fd; + long *bkpt, offset; + size_t n_bkpt; +}; + +struct bin_stack +{ + struct page *page; + size_t sz, pi, n; +}; + +struct bin_global +{ + void *buf; + size_t sz; +}; + +struct bin_proc +{ + const struct bin_mod *mod; + struct nw_inst instance; + union nw_value args[7]; + struct bin_dbg dbg; + struct caio *caio; + char *path, **argv; + size_t argc; + pid_t pid; + uid_t uid; + gid_t gid; + char header[sizeof "asm"]; + size_t i; + long retval; + struct bin_stack stack; + struct bin_global global; + void *import; + struct page *linear; + int *fds; + size_t n_fds; + struct bin_proc *prev, *next; +}; + +struct bin_mod +{ + char *path; + struct caio *caio; + struct nw_mod mod; + struct nw_mod_out mod_out; + struct nw_import_index import_indexes[BIN_IMPORTS]; + struct bin_mod *prev, *next; +}; + +struct bin +{ + struct bin_mod *mod_head, *mod_tail; + struct bin_proc *proc_head, *proc_tail; +}; + +extern struct bin bin_active, bin_pending, bin_locked, bin_zombie; + +#endif diff --git a/src/bin/private_include/bin/wasi.h b/src/bin/private_include/bin/wasi.h new file mode 100644 index 0000000..c22c777 --- /dev/null +++ b/src/bin/private_include/bin/wasi.h @@ -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 <https://www.gnu.org/licenses/>. + */ + +#ifndef BIN_WASI_H +#define BIN_WASI_H + +#include <nanowasm/nw.h> + +enum nw_state bin_wasi_proc_exit(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); +enum nw_state bin_wasi_fd_prestat_get(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); +enum nw_state bin_wasi_fd_prestat_dir_name(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); +enum nw_state bin_wasi_path_create_directory(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); +enum nw_state bin_wasi_fd_close(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); +enum nw_state bin_wasi_fd_fdstat_get(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); +enum nw_state bin_wasi_fd_seek(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); +enum nw_state bin_wasi_fd_write(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); + +#endif diff --git a/src/bin/private_include/bin/wasi/errno.h b/src/bin/private_include/bin/wasi/errno.h new file mode 100644 index 0000000..442e877 --- /dev/null +++ b/src/bin/private_include/bin/wasi/errno.h @@ -0,0 +1,105 @@ +/* + * 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 <https://www.gnu.org/licenses/>. + */ + +#ifndef WASI_ERRNO_H +#define WASI_ERRNO_H + +enum wasi_errno +{ + WASI_SUCCESS, + WASI_2BIG, + WASI_ACCES, + WASI_ADDRINUSE, + WASI_ADDRNOTAVAIL, + WASI_AFNOSUPPORT, + WASI_AGAIN, + WASI_ALREADY, + WASI_BADF, + WASI_BADMSG, + WASI_BUSY, + WASI_CANCELED, + WASI_CHILD, + WASI_CONNABORTED, + WASI_CONNREFUSED, + WASI_CONNRESET, + WASI_DEADLK, + WASI_DESTADDRREQ, + WASI_DOM, + WASI_DQUOT, + WASI_EXIST, + WASI_FAULT, + WASI_FBIG, + WASI_HOSTUNREACH, + WASI_IDRM, + WASI_ILSEQ, + WASI_INPROGRESS, + WASI_INTR, + WASI_INVAL, + WASI_IO, + WASI_ISCONN, + WASI_ISDIR, + WASI_LOOP, + WASI_MFILE, + WASI_MLINK, + WASI_MSGSIZE, + WASI_MULTIHOP, + WASI_NAMETOOLONG, + WASI_NETDOWN, + WASI_NETRESET, + WASI_NETUNREACH, + WASI_NFILE, + WASI_NOBUFS, + WASI_NODEV, + WASI_NOENT, + WASI_NOEXEC, + WASI_NOLCK, + WASI_NOLINK, + WASI_NOMEM, + WASI_NOMSG, + WASI_NOPROTOOPT, + WASI_NOSPC, + WASI_NOSYS, + WASI_NOTCONN, + WASI_NOTDIR, + WASI_NOTEMPTY, + WASI_NOTRECOVERABLE, + WASI_NOTSOCK, + WASI_NOTSUP, + WASI_NOTTY, + WASI_NXIO, + WASI_OVERFLOW, + WASI_OWNERDEAD, + WASI_PERM, + WASI_PIPE, + WASI_PROTO, + WASI_PROTONOSUPPORT, + WASI_PROTOTYPE, + WASI_RANGE, + WASI_ROFS, + WASI_SPIPE, + WASI_SRCH, + WASI_STALE, + WASI_TIMEDOUT, + WASI_TXTBSY, + WASI_XDEV, + WASI_NOTCAPABLE +}; + +int wasi_errno(int error, enum wasi_errno *out); + +#endif diff --git a/src/bin/private_include/bin/wnix.h b/src/bin/private_include/bin/wnix.h new file mode 100644 index 0000000..07e7131 --- /dev/null +++ b/src/bin/private_include/bin/wnix.h @@ -0,0 +1,37 @@ +/* + * 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 <https://www.gnu.org/licenses/>. + */ + +#ifndef BIN_WNIX_H +#define BIN_WNIX_H + +#include <nanowasm/nw.h> + +enum nw_state bin_wnix_exit(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); +enum nw_state bin_wnix_argc(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); +enum nw_state bin_wnix_arglen(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); +enum nw_state bin_wnix_argcopy(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); +enum nw_state bin_wnix_mkdir(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); +enum nw_state bin_wnix_mount(const union nw_value *params, + union nw_value *ret, void *user, struct nw_next *next); + +#endif diff --git a/src/bin/private_include/bin/wnix/routines.h b/src/bin/private_include/bin/wnix/routines.h new file mode 100644 index 0000000..aa488fb --- /dev/null +++ b/src/bin/private_include/bin/wnix/routines.h @@ -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 <https://www.gnu.org/licenses/>. + */ + +#ifndef BIN_WNIX_ROUTINES_H +#define BIN_WNIX_ROUTINES_H + +#include <bin.h> +#include <bin/types.h> +#include <nanowasm/nw.h> + +int bin_wnix_set_errno(struct bin_proc *p, int error, unsigned long addr, + struct nw_next *next); + +#endif |
