diff --git a/CMakeLists.txt b/CMakeLists.txt index 9933d0c..f71afc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,15 +100,7 @@ set(SRC arch/amd64/kernel.c drivers/usb/driver.c drivers/usb/device.c drivers/usb/usbkbd.c - drivers/usb/hub.c - - net/net.c - net/if.c - net/socket.c - net/util.c - net/ports.c - net/unix.c - sys/sys_net.c) + drivers/usb/hub.c) #### CFLAGS and LDFLAGS execute_process(COMMAND git describe --always @@ -152,6 +144,9 @@ set(CMAKE_ASM_FLAGS "${CFLAGS} -D__ASM__") #### Options # ... +include(etc/cmake/Options.cmake NO_POLICY_SCOPE) +set(SRC ${SRC} ${OPT_SRC}) + #### Dependencies include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/include diff --git a/arch/amd64/syscall.c b/arch/amd64/syscall.c index 7a31d62..009f3bd 100644 --- a/arch/amd64/syscall.c +++ b/arch/amd64/syscall.c @@ -1,3 +1,5 @@ +#include + #include "user/syscall.h" #include "user/errno.h" #include "user/time.h" @@ -9,7 +11,9 @@ #include "sys/sys_file.h" #include "sys/sys_sys.h" #include "sys/sys_proc.h" +#if defined(ENABLE_NET) #include "sys/sys_net.h" +#endif #include "sys/mod.h" #define MSR_IA32_STAR 0xC0000081 @@ -90,6 +94,7 @@ void *syscall_table[256] = { [SYSCALL_NRX_MODULE_LOAD] = sys_module_load, [SYSCALL_NRX_MODULE_UNLOAD] = sys_module_unload, +#if defined(ENABLE_NET) // Network [SYSCALL_NR_SOCKET] = sys_socket, [SYSCALL_NR_CONNECT] = sys_connect, @@ -99,6 +104,7 @@ void *syscall_table[256] = { [SYSCALL_NR_BIND] = sys_bind, [SYSCALL_NR_SETSOCKOPT] = sys_setsockopt, [SYSCALL_NRX_NETCTL] = sys_netctl, +#endif // Extension [SYSCALL_NRX_TRACE] = sys_debug_trace, diff --git a/config.h.in b/config.h.in index ded34fd..5cbc014 100644 --- a/config.h.in +++ b/config.h.in @@ -2,3 +2,6 @@ #define AMD64_KERNEL_STACK 32768 #define AMD64_MAX_SMP 1 + +#cmakedefine ENABLE_NET +#cmakedefine ENABLE_UNIX diff --git a/etc/cmake/Options.cmake b/etc/cmake/Options.cmake new file mode 100644 index 0000000..9945166 --- /dev/null +++ b/etc/cmake/Options.cmake @@ -0,0 +1,26 @@ +option(ENABLE_UNIX "Enable support for Unix domain sockets" ON) +option(ENABLE_NET "Enable networking support" ON) + +function(require what whom) + if (NOT ${what}) + message(FATAL_ERROR "${what} is required by ${whom}") + endif() +endfunction() + +set(OPT_SRC "") + +if (ENABLE_NET) + set(OPT_SRC ${OPT_SRC} + net/net.c + net/if.c + net/socket.c + net/util.c + net/ports.c + sys/sys_net.c) +endif() + +if (ENABLE_UNIX) + require(ENABLE_NET ENABLE_UNIX) + + set(OPT_SRC ${OPT_SRC} net/unix.c) +endif(ENABLE_UNIX) diff --git a/fs/ofile.c b/fs/ofile.c index 80daae0..0b6da19 100644 --- a/fs/ofile.c +++ b/fs/ofile.c @@ -1,3 +1,4 @@ +#include #include "sys/mem/slab.h" #include "sys/assert.h" #include "fs/ofile.h" @@ -28,9 +29,12 @@ void ofile_close(struct vfs_ioctx *ioctx, struct ofile *of) { _assert(of->refcount > 0); --of->refcount; if (of->refcount == 0) { +#if defined(ENABLE_NET) if (of->flags & OF_SOCKET) { net_close(ioctx, of); - } else { + } else +#endif + { vfs_close(ioctx, of); } ofile_destroy(of); diff --git a/sys/kernel.c b/sys/kernel.c index d8c3feb..72e699f 100644 --- a/sys/kernel.c +++ b/sys/kernel.c @@ -1,3 +1,4 @@ +#include #include "arch/amd64/syscall.h" #include "drivers/pci/pci.h" #include "drivers/usb/usb.h" @@ -18,8 +19,8 @@ void _init(void) { init_func_t *init_array = (init_func_t *) &_init_start; // Sanity checks - _assert(((uintptr_t) init_array & 0xF) == 0); - _assert(((uintptr_t) (&_init_end) & 0xF) == 0); + _assert(((uintptr_t) init_array & 0x7) == 0); + _assert(((uintptr_t) (&_init_end) & 0x7) == 0); size_t count = ((uintptr_t) &_init_end - (uintptr_t) &_init_start) / sizeof(init_func_t); for (size_t i = 0; i < count; ++i) { @@ -39,9 +40,11 @@ void main(void) { syscall_init(); sched_init(); +#if defined(ENABLE_NET) net_init(); - usb_daemon_start(); net_daemon_start(); +#endif + usb_daemon_start(); user_init_start(); sched_enter(); diff --git a/sys/sys_file.c b/sys/sys_file.c index 3e3ff29..0e4816a 100644 --- a/sys/sys_file.c +++ b/sys/sys_file.c @@ -1,3 +1,4 @@ +#include #include "user/errno.h" #include "arch/amd64/hw/timer.h" #include "arch/amd64/cpu.h" @@ -346,9 +347,12 @@ int sys_mknod(const char *filename, int mode, unsigned int dev) { } static int sys_select_get_ready(struct ofile *fd) { +#if defined(ENABLE_NET) if (fd->flags & OF_SOCKET) { return socket_has_data(&fd->socket); - } else { + } else +#endif + { struct vnode *vn = fd->file.vnode; _assert(vn);