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/net | |
| parent | 7fc48e9216ff809da5f8055a50b0be17628ef1df (diff) | |
| download | wnix-7861a52adf92a083bb2aed4c35f98d8035dce032.tar.gz | |
Setup project skeleton
Diffstat (limited to 'src/net')
| -rw-r--r-- | src/net/CMakeLists.txt | 20 | ||||
| -rw-r--r-- | src/net/include/net.h | 26 | ||||
| -rw-r--r-- | src/net/private_include/net/ops.h | 30 | ||||
| -rw-r--r-- | src/net/private_include/net/types.h | 39 | ||||
| -rw-r--r-- | src/net/src/CMakeLists.txt | 24 | ||||
| -rw-r--r-- | src/net/src/init.c | 78 | ||||
| -rw-r--r-- | src/net/src/net.c | 22 | ||||
| -rw-r--r-- | src/net/src/ops/CMakeLists.txt | 23 | ||||
| -rw-r--r-- | src/net/src/ops/alloc.c | 29 | ||||
| -rw-r--r-- | src/net/src/ops/free.c | 29 | ||||
| -rw-r--r-- | src/net/src/ops/read.c | 38 | ||||
| -rw-r--r-- | src/net/src/ops/realloc.c | 29 | ||||
| -rw-r--r-- | src/net/src/ops/write.c | 29 | ||||
| -rw-r--r-- | src/net/src/shutdown.c | 26 | ||||
| -rw-r--r-- | src/net/src/update.c | 31 |
15 files changed, 473 insertions, 0 deletions
diff --git a/src/net/CMakeLists.txt b/src/net/CMakeLists.txt new file mode 100644 index 0000000..e0822e7 --- /dev/null +++ b/src/net/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 <https://www.gnu.org/licenses/>. + +add_library(net) +add_subdirectory(src) +target_include_directories(net PUBLIC include PRIVATE private_include) +target_link_libraries(net PRIVATE aio loop state wip) diff --git a/src/net/include/net.h b/src/net/include/net.h new file mode 100644 index 0000000..0ae9dc1 --- /dev/null +++ b/src/net/include/net.h @@ -0,0 +1,26 @@ +/* + * 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 NET_H +#define NET_H + +int net_init(const char *dev); +int net_update(void); +int net_shutdown(void); + +#endif diff --git a/src/net/private_include/net/ops.h b/src/net/private_include/net/ops.h new file mode 100644 index 0000000..abeea39 --- /dev/null +++ b/src/net/private_include/net/ops.h @@ -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 <https://www.gnu.org/licenses/>. + */ + +#ifndef NET_OPS_H +#define NET_OPS_H + +#include <stddef.h> + +void *net_alloc(size_t n, void *user); +void *net_realloc(void *, size_t n, void *user); +void net_free(void *p, void *user); +int net_read(void *buf, size_t n, void *user); +int net_write(const void *buf, size_t n, void *user); + +#endif diff --git a/src/net/private_include/net/types.h b/src/net/private_include/net/types.h new file mode 100644 index 0000000..eab5843 --- /dev/null +++ b/src/net/private_include/net/types.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 NET_TYPES_H +#define NET_TYPES_H + +#include <aio.h> +#include <fs/fs.h> +#include <wip/wip.h> +#include <stddef.h> +#include <stdbool.h> + +struct net +{ + bool init; + size_t available; + struct aio *aio; + struct wip w; + struct fs_fd fd; +}; + +extern struct net net; + +#endif diff --git a/src/net/src/CMakeLists.txt b/src/net/src/CMakeLists.txt new file mode 100644 index 0000000..c011446 --- /dev/null +++ b/src/net/src/CMakeLists.txt @@ -0,0 +1,24 @@ +# 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/>. + +target_sources(net PRIVATE + init.c + net.c + shutdown.c + update.c +) + +add_subdirectory(ops) diff --git a/src/net/src/init.c b/src/net/src/init.c new file mode 100644 index 0000000..9e66981 --- /dev/null +++ b/src/net/src/init.c @@ -0,0 +1,78 @@ +/* + * 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/>. + */ + +#include <net.h> +#include <net/ops.h> +#include <net/types.h> +#include <aio.h> +#include <loop.h> +#include <wip/wip.h> +#include <fcntl.h> +#include <stdbool.h> + +static int open_done(const enum state state, void *const args) +{ + struct net *const n = &net; + + if (loop_rm_aio(n->aio)) + return -1; + + aio_free(n->aio); + n->aio = NULL; + n->init = true; + return 0; +} + +int net_init(const char *const dev) +{ + struct net *const n = &net; + struct aio *aio = NULL; + const struct wip_cfg cfg = + { + .alloc = net_alloc, + .realloc = net_realloc, + .free = net_free, + .read = net_read, + .write = net_write, + .user = n + }; + + const struct fs_open op = + { + .path = dev, + .fd = &n->fd, + .flags = O_RDWR + }; + + const struct aio_done d = + { + .f = open_done, + .args = n + }; + + if (!(aio = aio_open(&op, &d)) || loop_add_aio(aio)) + goto failure; + + *n = (const struct net){.aio = aio}; + wip_init(&n->w, &cfg); + return 0; + +failure: + aio_free(aio); + return -1; +} diff --git a/src/net/src/net.c b/src/net/src/net.c new file mode 100644 index 0000000..b2dbd1a --- /dev/null +++ b/src/net/src/net.c @@ -0,0 +1,22 @@ +/* + * 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/>. + */ + +#include <net.h> +#include <net/types.h> + +struct net net; diff --git a/src/net/src/ops/CMakeLists.txt b/src/net/src/ops/CMakeLists.txt new file mode 100644 index 0000000..40d4490 --- /dev/null +++ b/src/net/src/ops/CMakeLists.txt @@ -0,0 +1,23 @@ +# 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/>. + +target_sources(net PRIVATE + alloc.c + free.c + read.c + realloc.c + write.c +) diff --git a/src/net/src/ops/alloc.c b/src/net/src/ops/alloc.c new file mode 100644 index 0000000..6152a92 --- /dev/null +++ b/src/net/src/ops/alloc.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 <https://www.gnu.org/licenses/>. + */ + +#include <net.h> +#include <net/ops.h> +#include <net/types.h> +#include <wip/wip.h> +#include <stddef.h> +#include <stdlib.h> + +void *net_alloc(const size_t n, void *const user) +{ + return malloc(n); +} diff --git a/src/net/src/ops/free.c b/src/net/src/ops/free.c new file mode 100644 index 0000000..0f1f63b --- /dev/null +++ b/src/net/src/ops/free.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 <https://www.gnu.org/licenses/>. + */ + +#include <net.h> +#include <net/ops.h> +#include <net/types.h> +#include <wip/wip.h> +#include <stddef.h> +#include <stdlib.h> + +void net_free(void *const p, void *const user) +{ + free(p); +} diff --git a/src/net/src/ops/read.c b/src/net/src/ops/read.c new file mode 100644 index 0000000..1fca206 --- /dev/null +++ b/src/net/src/ops/read.c @@ -0,0 +1,38 @@ +/* + * 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/>. + */ + +#include <net.h> +#include <net/ops.h> +#include <net/types.h> +#include <aio.h> +#include <loop.h> +#include <wip/wip.h> +#include <stddef.h> + +int net_read(void *const buf, const size_t n, void *const user) +{ + struct net *const net = user; + const struct fs_read r = + { + .fd = &net->fd, + .buf = buf, + .n = n + }; + + return aio_read_nb(&r); +} diff --git a/src/net/src/ops/realloc.c b/src/net/src/ops/realloc.c new file mode 100644 index 0000000..329cbe5 --- /dev/null +++ b/src/net/src/ops/realloc.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 <https://www.gnu.org/licenses/>. + */ + +#include <net.h> +#include <net/ops.h> +#include <net/types.h> +#include <wip/wip.h> +#include <stddef.h> +#include <stdlib.h> + +void *net_realloc(void *const p, const size_t n, void *const user) +{ + return realloc(p, n); +} diff --git a/src/net/src/ops/write.c b/src/net/src/ops/write.c new file mode 100644 index 0000000..2bf9093 --- /dev/null +++ b/src/net/src/ops/write.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 <https://www.gnu.org/licenses/>. + */ + +#include <net.h> +#include <net/ops.h> +#include <net/types.h> +#include <wip/wip.h> +#include <stddef.h> + +int net_write(const void *const buf, const size_t n, void *const user) +{ + /* TODO */ + return -1; +} diff --git a/src/net/src/shutdown.c b/src/net/src/shutdown.c new file mode 100644 index 0000000..b815e2c --- /dev/null +++ b/src/net/src/shutdown.c @@ -0,0 +1,26 @@ +/* + * 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/>. + */ + +#include <net.h> +#include <net/types.h> +#include <wip/wip.h> + +int net_shutdown(void) +{ + return -1; +} diff --git a/src/net/src/update.c b/src/net/src/update.c new file mode 100644 index 0000000..b7a0954 --- /dev/null +++ b/src/net/src/update.c @@ -0,0 +1,31 @@ +/* + * 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/>. + */ + +#include <net.h> +#include <net/types.h> +#include <wip/wip.h> + +int net_update(void) +{ + struct net *const n = &net; + + if (!n->init) + return 0; + + return wip_run(&n->w) == WIP_FATAL ? -1 : 0; +} |
