aboutsummaryrefslogtreecommitdiff
path: root/programs
diff options
context:
space:
mode:
Diffstat (limited to 'programs')
-rw-r--r--programs/CMakeLists.txt57
-rw-r--r--programs/env/CMakeLists.txt19
-rw-r--r--programs/env/imports1
-rw-r--r--programs/env/include/sys/mount.h25
-rw-r--r--programs/env/private_include/env.h25
-rw-r--r--programs/env/src/CMakeLists.txt19
-rw-r--r--programs/env/src/mount.c27
-rw-r--r--programs/initd/CMakeLists.txt31
-rw-r--r--programs/initd/initd.c30
-rw-r--r--programs/wasi-sdk-toolchain.cmake20
-rw-r--r--programs/yes/CMakeLists.txt21
-rw-r--r--programs/yes/yes.c34
12 files changed, 309 insertions, 0 deletions
diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt
new file mode 100644
index 0000000..2065e64
--- /dev/null
+++ b/programs/CMakeLists.txt
@@ -0,0 +1,57 @@
+# 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/>.
+
+set(programs
+ initd
+ yes
+)
+
+include(ExternalProject)
+file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+
+foreach(p ${programs})
+ set(cflags " \
+ -g \
+ "
+ )
+
+ set(ldflags " \
+ -Wl,--allow-undefined-file=${CMAKE_CURRENT_LIST_DIR}/env/imports \
+ -Wl,--threads=1 \
+ ")
+
+ ExternalProject_Add(${p}_project_wasi
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/${p}
+ BUILD_ALWAYS ON
+ CMAKE_ARGS
+ -D CMAKE_C_FLAGS=${cflags}
+ -D CMAKE_EXE_LINKER_FLAGS=${ldflags}
+ -D CMAKE_BUILD_TYPE=Release
+ -D CMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_LIST_DIR}/wasi-sdk-toolchain.cmake
+ -D CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}
+ -D CMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}
+ -D WNIX_ENV=${CMAKE_CURRENT_LIST_DIR}/env
+ )
+
+ add_custom_target(${p}_project ALL
+ ${TOOLS_PREFIX}/bin/nwc
+ ${CMAKE_CURRENT_BINARY_DIR}/bin/${p} ${CMAKE_BINARY_DIR}/bin/${p}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ BYPRODUCTS ${CMAKE_BINARY_DIR}/bin/${p}
+ )
+
+ add_dependencies(${p}_project ${p}_project_wasi tools)
+endforeach()
diff --git a/programs/env/CMakeLists.txt b/programs/env/CMakeLists.txt
new file mode 100644
index 0000000..5d2e650
--- /dev/null
+++ b/programs/env/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 <https://www.gnu.org/licenses/>.
+
+add_library(wnix_env)
+add_subdirectory(src)
+target_include_directories(wnix_env PUBLIC include PRIVATE private_include)
diff --git a/programs/env/imports b/programs/env/imports
new file mode 100644
index 0000000..f82bd6e
--- /dev/null
+++ b/programs/env/imports
@@ -0,0 +1 @@
+wnix_mount
diff --git a/programs/env/include/sys/mount.h b/programs/env/include/sys/mount.h
new file mode 100644
index 0000000..eae6d63
--- /dev/null
+++ b/programs/env/include/sys/mount.h
@@ -0,0 +1,25 @@
+/*
+ * 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 _SYS_MOUNT_H
+#define _SYS_MOUNT_H
+
+int mount(const char *__src, const char *__tgt, const char *__type,
+ unsigned long __flags, const void *__args);
+
+#endif
diff --git a/programs/env/private_include/env.h b/programs/env/private_include/env.h
new file mode 100644
index 0000000..5f78d51
--- /dev/null
+++ b/programs/env/private_include/env.h
@@ -0,0 +1,25 @@
+/*
+ * 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 ENV_H
+#define ENV_H
+
+int wnix_mount(const char *src, const char *tgt, const char *type,
+ unsigned long flags, const void *args, int *error);
+
+#endif
diff --git a/programs/env/src/CMakeLists.txt b/programs/env/src/CMakeLists.txt
new file mode 100644
index 0000000..644c2f0
--- /dev/null
+++ b/programs/env/src/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 <https://www.gnu.org/licenses/>.
+
+target_sources(wnix_env PRIVATE
+ mount.c
+)
diff --git a/programs/env/src/mount.c b/programs/env/src/mount.c
new file mode 100644
index 0000000..8cd63f8
--- /dev/null
+++ b/programs/env/src/mount.c
@@ -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 <https://www.gnu.org/licenses/>.
+ */
+
+#include <sys/mount.h>
+#include <env.h>
+#include <errno.h>
+
+int mount(const char *const src, const char *const tgt, const char *const type,
+ const unsigned long flags, const void *const args)
+{
+ return wnix_mount(src, tgt, type, flags, args, &errno);
+}
diff --git a/programs/initd/CMakeLists.txt b/programs/initd/CMakeLists.txt
new file mode 100644
index 0000000..63c95e4
--- /dev/null
+++ b/programs/initd/CMakeLists.txt
@@ -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/>.
+
+cmake_minimum_required(VERSION 3.13)
+include(GNUInstallDirs)
+project(initd C)
+add_subdirectory(${WNIX_ENV} ${CMAKE_CURRENT_BINARY_DIR}/env)
+add_executable(${PROJECT_NAME} initd.c)
+target_link_libraries(${PROJECT_NAME} PRIVATE wnix_env)
+# 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})
diff --git a/programs/initd/initd.c b/programs/initd/initd.c
new file mode 100644
index 0000000..1568995
--- /dev/null
+++ b/programs/initd/initd.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 <https://www.gnu.org/licenses/>.
+ */
+
+#include <sys/mount.h>
+#include <errno.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+int main(void)
+{
+ if (mount("/dev/mc0", "/home", "ps1mcfs", 0, NULL))
+ return errno;
+
+ return 1;
+}
diff --git a/programs/wasi-sdk-toolchain.cmake b/programs/wasi-sdk-toolchain.cmake
new file mode 100644
index 0000000..5e277af
--- /dev/null
+++ b/programs/wasi-sdk-toolchain.cmake
@@ -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/>.
+
+find_package(WASI_SDK REQUIRED)
+set(CMAKE_C_COMPILER ${WASI_SDK_CLANG})
+set(CMAKE_C_COMPILER_WORKS 1)
+set(CMAKE_STRIP ${WASI_SDK_STRIP})
diff --git a/programs/yes/CMakeLists.txt b/programs/yes/CMakeLists.txt
new file mode 100644
index 0000000..a8d0a89
--- /dev/null
+++ b/programs/yes/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 <https://www.gnu.org/licenses/>.
+
+cmake_minimum_required(VERSION 3.13)
+include(GNUInstallDirs)
+project(yes C)
+add_executable(${PROJECT_NAME} yes.c)
+install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
diff --git a/programs/yes/yes.c b/programs/yes/yes.c
new file mode 100644
index 0000000..99473e2
--- /dev/null
+++ b/programs/yes/yes.c
@@ -0,0 +1,34 @@
+/*
+ * 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/>.
+ */
+
+#if 0
+#include <stdio.h>
+#include <stdlib.h>
+#endif
+
+int main(void)
+{
+#if 0
+ for (;;)
+ puts("y");
+
+ return EXIT_SUCCESS;
+#else
+return 0;
+#endif
+}