├── CMakeLists.txt ├── COPYING ├── COPYING.LIB ├── README.md ├── Uninstall.cmake ├── cmd ├── CMakeLists.txt ├── vu_insmod.c ├── vu_lsmod.c ├── vu_rmmod.c ├── vudebug.c ├── vumount.c ├── vuname.c ├── vustack.c ├── vusu.c └── vuumount.c ├── include ├── CMakeLists.txt ├── config.h.in ├── libvumod.h ├── vudev.h ├── vulib.h ├── vumisc.h ├── vumodule.h └── vunet.h ├── libvumod ├── CMakeLists.txt └── vu_mod_pseudofile.c ├── man ├── CMakeLists.txt ├── Makefile ├── fusenull.1 ├── fusenull.1.md ├── fusereal.1 ├── fusereal.1.md ├── umvu.1 ├── umvu.1.md ├── vu_insmod.1 ├── vu_insmod.1.md ├── vu_lsmod.1 ├── vu_lsmod.1.md ├── vu_rmmod.1 ├── vu_rmmod.1.md ├── vudebug.1 ├── vudebug.1.md ├── vumount.1 ├── vumount.1.md ├── vuname.1 ├── vuname.1.md ├── vustack.1 ├── vustack.1.md ├── vusu.1 ├── vusu.1.md ├── vuumount.1 └── vuumount.1.md ├── scripts ├── CMakeLists.txt ├── archtable_gen.py ├── r_table_gen.py ├── r_table_gen.sh ├── syscall_defs_gen.py ├── syscall_deps.sh ├── syscall_names_gen.py ├── syscall_names_gen.sh ├── syscall_nr_compat_gen.py └── syscall_table_gen.py ├── test_modules ├── CMakeLists.txt ├── mountreal.c ├── netlinkdump.c ├── unreal.c ├── unrealcap.c ├── unrealinfofs.c ├── unrealprw.c ├── unrealsock.c └── unrealuidgid.c ├── umvu ├── CMakeLists.txt ├── include │ ├── arch_table.h │ ├── canonicalize.h │ ├── carrot.h │ ├── epoch.h │ ├── hashtable.h │ ├── linux_32_64.h │ ├── mountflags.h │ ├── path_utils.h │ ├── ptrace_defs.h │ ├── r_table_compat.h │ ├── service.h │ ├── syscall_names.h │ ├── syscall_table.h │ ├── umvu_peekpoke.h │ ├── umvu_tracer.h │ ├── vu_access_emu.h │ ├── vu_chroot_exec.h │ ├── vu_execute.h │ ├── vu_fd_table.h │ ├── vu_file_table.h │ ├── vu_fnode_copy.h │ ├── vu_fs.h │ ├── vu_inheritance.h │ ├── vu_initfini.h │ ├── vu_log.h │ ├── vu_mmap_table.h │ ├── vu_mod_inheritance.h │ ├── vu_modutils.h │ ├── vu_name.h │ ├── vu_nesting.h │ ├── vu_pushpop.h │ ├── vu_slow_calls.h │ ├── vu_thread_sd.h │ ├── vu_tmpdir.h │ ├── vu_uidgid.h │ ├── vu_vnode.h │ ├── vu_wrap_rw_multiplex.h │ ├── vu_wrapper_utils.h │ ├── xcommon.h │ └── xstat.h └── src │ ├── canonicalize.c │ ├── carrot.c │ ├── epoch.c │ ├── hashtable.c │ ├── linux_32_64.c │ ├── mountflags.c │ ├── path_utils.c │ ├── r_table.c │ ├── service.c │ ├── umvu_main.c │ ├── umvu_peekpoke.c │ ├── umvu_tracer.c │ ├── vu_access_emu.c │ ├── vu_choice.c │ ├── vu_chroot_exec.c │ ├── vu_execute.c │ ├── vu_fd_table.c │ ├── vu_file_table.c │ ├── vu_fnode_copy.c │ ├── vu_fs.c │ ├── vu_inheritance.c │ ├── vu_initfini.c │ ├── vu_log.c │ ├── vu_mmap_table.c │ ├── vu_mod_inheritance.c │ ├── vu_modutils.c │ ├── vu_name.c │ ├── vu_nesting.c │ ├── vu_pthreads.c │ ├── vu_pushpop.c │ ├── vu_slow_calls.c │ ├── vu_thread_sd.c │ ├── vu_tmpdir.c │ ├── vu_uidgid.c │ ├── vu_vnode.c │ ├── vu_vwrap_vumgmt.c │ ├── vu_wrap_cap.c │ ├── vu_wrap_cwd.c │ ├── vu_wrap_execve.c │ ├── vu_wrap_file.c │ ├── vu_wrap_fs.c │ ├── vu_wrap_ioctl.c │ ├── vu_wrap_mmap.c │ ├── vu_wrap_mount.c │ ├── vu_wrap_poll.c │ ├── vu_wrap_rw_multiplex.c │ ├── vu_wrap_socket.c │ ├── vu_wrap_time.c │ ├── vu_wrap_uid_gid.c │ └── vu_wrap_xattr.c ├── vu_syscalls.conf ├── vubinfmt ├── CMakeLists.txt └── vubinfmt.c ├── vudev ├── CMakeLists.txt └── vudev.c ├── vudev_modules ├── CMakeLists.txt ├── vudevnull.c ├── vudevpartx.c ├── vudevramdisk.c └── vudevvdi.c ├── vudevfuse ├── CMakeLists.txt ├── devfuse.c ├── devfuse.h ├── eventsem.h ├── fusenode.c ├── fusenode.h ├── fusereqq.c ├── fusereqq.h ├── listx.h ├── vudevfuse.c ├── vudevfuse.h └── vudevfuse_ops.c ├── vufs ├── CMakeLists.txt ├── vufs.c ├── vufs.h ├── vufs_getdents.c ├── vufs_getdents.h ├── vufs_path.c ├── vufs_path.h ├── vufsa.c ├── vufsa.h ├── vufsops.c ├── vufstat.c └── vufstat.h ├── vufuse ├── CMakeLists.txt ├── fuse_opt.c ├── vufuse.c ├── vufuse.h ├── vufuse_compat.c ├── vufuse_default_ops.c ├── vufuse_default_ops.h ├── vufuse_node.c ├── vufuse_node.h ├── vufuse_startmain.c ├── vufuse_startmain.h └── vufuseop.c ├── vufuse_modules ├── CMakeLists.txt ├── vufusenull.c └── vufusereal.c ├── vumisc ├── CMakeLists.txt └── vumisc.c ├── vumisc_modules ├── CMakeLists.txt └── vumisctime.c ├── vunet ├── CMakeLists.txt ├── vunet.c └── vunet_ioctl.c └── vunet_modules ├── CMakeLists.txt ├── vunetnull.c ├── vunetreal.c └── vunetvdestack.c /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | project("vuos" 3 | VERSION 0.9.2 4 | DESCRIPTION "" 5 | HOMEPAGE_URL "https://github.com/virtualsquare/vuos" 6 | LANGUAGES C) 7 | 8 | include(GNUInstallDirs) 9 | include(CheckIncludeFile) 10 | include(CheckSymbolExists) 11 | 12 | set(LIBS_REQUIRED stropt volatilestream execs vdeplug fuse3) 13 | set(HEADERS_REQUIRED stropt.h strcase.h volatilestream.h execs.h libvdeplug.h fuse3/fuse.h pthread.h) 14 | # DFUSE_USE_VERSION 300 is just to test fuse3-dev availability 15 | set(CMAKE_REQUIRED_DEFINITIONS -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=300) 16 | 17 | foreach(THISLIB IN LISTS LIBS_REQUIRED) 18 | find_library(LIB${THISLIB}_OK ${THISLIB}) 19 | if(NOT LIB${THISLIB}_OK) 20 | message(FATAL_ERROR "library lib${THISLIB} not found") 21 | endif() 22 | endforeach(THISLIB) 23 | 24 | foreach(HEADER IN LISTS HEADERS_REQUIRED) 25 | check_include_file(${HEADER} ${HEADER}_OK) 26 | if(NOT ${HEADER}_OK) 27 | message(FATAL_ERROR "header file ${HEADER} not found") 28 | endif() 29 | endforeach(HEADER) 30 | unset(CMAKE_REQUIRED_DEFINITIONS) 31 | 32 | set(CMAKE_C_FLAGS 33 | "-ggdb -Wall -Wextra -pedantic -std=gnu11 -Wno-unused-parameter -O2 -D_FORTIFY_SOURCE=2") 34 | add_definitions(-D_GNU_SOURCE) 35 | 36 | set(MODULES_INSTALL_PATH ${CMAKE_INSTALL_FULL_LIBDIR}/vu/modules) 37 | set(CONFIGURATION_DIR_PATH ${CMAKE_INSTALL_FULL_SYSCONFDIR}) 38 | set(HEADERS_INSTALL_PATH ${CMAKE_INSTALL_FULL_INCLUDEDIR}) 39 | set(VU_HEADERS ${PROJECT_SOURCE_DIR}/include) 40 | set(VU_DYN_SOURCE_PATH ${CMAKE_BINARY_DIR}/umvu_dynsrc) 41 | set(VU_DYN_HEADER_PATH ${CMAKE_BINARY_DIR}/include) 42 | 43 | set(VU_SYSCALL_DEFS ${VU_DYN_HEADER_PATH}/syscall_defs.h) 44 | set(R_TABLE_H ${VU_DYN_HEADER_PATH}/r_table.h) 45 | set(SYSCALL_NR_COMPAT_H ${VU_DYN_HEADER_PATH}/syscall_nr_compat.h) 46 | set(VU_SYSNAMES ${VU_DYN_SOURCE_PATH}/syscall_names.c) 47 | set(VU_ARCHTABLE ${VU_DYN_SOURCE_PATH}/arch_table.c) 48 | set(VU_SYSTABLE ${VU_DYN_SOURCE_PATH}/syscall_table.c) 49 | set(VU_DYN_SOURCES ${VU_SYSNAMES} ${VU_ARCHTABLE} ${VU_SYSTABLE}) 50 | 51 | execute_process(COMMAND mkdir -p ${VU_DYN_SOURCE_PATH}) 52 | 53 | foreach(DYN ${VU_DYN_SOURCES}) 54 | execute_process(COMMAND touch -d 20000101 ${DYN}) 55 | endforeach(DYN) 56 | 57 | configure_file( ${VU_HEADERS}/config.h.in ${VU_DYN_HEADER_PATH}/config.h ) 58 | 59 | add_subdirectory(scripts) 60 | add_subdirectory(umvu) 61 | add_subdirectory(cmd) 62 | add_subdirectory(test_modules) 63 | add_subdirectory(libvumod) 64 | add_subdirectory(vufuse) 65 | add_subdirectory(vudev) 66 | add_subdirectory(vudevfuse) 67 | add_subdirectory(include) 68 | add_subdirectory(vunet) 69 | add_subdirectory(vufs) 70 | add_subdirectory(vubinfmt) 71 | add_subdirectory(vumisc) 72 | add_subdirectory(vunet_modules) 73 | add_subdirectory(vufuse_modules) 74 | add_subdirectory(vudev_modules) 75 | add_subdirectory(vumisc_modules) 76 | add_subdirectory(man) 77 | 78 | add_custom_target(uninstall 79 | "${CMAKE_COMMAND}" -P "${PROJECT_SOURCE_DIR}/Uninstall.cmake") 80 | -------------------------------------------------------------------------------- /Uninstall.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | set(MANIFEST "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt") 3 | 4 | if(NOT EXISTS ${MANIFEST}) 5 | message(FATAL_ERROR "Cannot find install manifest: '${MANIFEST}'") 6 | endif() 7 | 8 | file(STRINGS ${MANIFEST} files) 9 | foreach(file ${files}) 10 | if(EXISTS ${file} OR IS_SYMLINK ${file}) 11 | message(STATUS "Removing: ${file}") 12 | 13 | execute_process( 14 | COMMAND rm -f ${file} 15 | RESULT_VARIABLE retcode 16 | ) 17 | 18 | if(NOT "${retcode}" STREQUAL "0") 19 | message(WARNING "Failed to remove: ${file}") 20 | endif() 21 | endif() 22 | endforeach(file) 23 | -------------------------------------------------------------------------------- /cmd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include_directories(${VU_HEADERS}) 4 | set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) 5 | set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) 6 | 7 | file(GLOB VU_CMDS ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 8 | 9 | foreach(VU_CMD ${VU_CMDS}) 10 | string(REPLACE ".c" "" VU_CMD_FILE ${VU_CMD}) 11 | get_filename_component(VU_CMD_TARGET ${VU_CMD_FILE} NAME) 12 | add_executable(${VU_CMD_TARGET} ${VU_CMD}) 13 | install(TARGETS ${VU_CMD_TARGET} RUNTIME DESTINATION bin) 14 | endforeach(VU_CMD) 15 | 16 | target_link_libraries(vumount stropt) 17 | target_link_libraries(vustack stropt) 18 | -------------------------------------------------------------------------------- /cmd/vu_insmod.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | static char *progname; 29 | void usage() 30 | { 31 | fprintf(stderr, 32 | "Usage:\n" 33 | " %s OPTIONS vu_module [vu_module] ...\n" 34 | " OPTIONS:\n" 35 | " -p --permanent: rmmod forbidden\n\n" 36 | " -h --help: print this help message\n\n", progname); 37 | 38 | exit(2); 39 | } 40 | 41 | static const char *short_options = "p"; 42 | static const struct option long_options[] = { 43 | {"permanent",0,0,'p'}, 44 | {"help",0,0,'h'}, 45 | {0,0,0,0} 46 | }; 47 | 48 | int main(int argc, char *argv[]) 49 | { 50 | int c; 51 | int permanent=0; 52 | progname = basename(argv[0]); 53 | if (vu_check() < 0) { 54 | fprintf(stderr,"This is a VUOS command." 55 | "It works only inside a vuos virtual namespace\n"); 56 | usage(); 57 | } 58 | while (1) { 59 | c=getopt_long(argc, argv, 60 | short_options, long_options, NULL); 61 | if (c == -1) break; 62 | switch (c) { 63 | case 'p': permanent=1; 64 | break; 65 | case 'h': usage(); 66 | break; 67 | } 68 | } 69 | if (argc - optind < 1) 70 | usage(); 71 | else { 72 | int rv=0; 73 | int i; 74 | for (i = optind; i < argc; i++) { 75 | if (vu_insmod(argv[i], permanent) < 0) { 76 | perror(argv[i]); 77 | rv=1; 78 | } 79 | } 80 | return rv; 81 | } 82 | return 0; 83 | } 84 | 85 | -------------------------------------------------------------------------------- /cmd/vu_lsmod.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | static char *progname; 29 | void usage() 30 | { 31 | fprintf(stderr, 32 | "Usage:\n" 33 | " %s OPTIONS\n" 34 | " OPTIONS:\n" 35 | " -h --help: print this help message\n\n", progname); 36 | exit(2); 37 | } 38 | 39 | static const char *short_options = "p"; 40 | static const struct option long_options[] = { 41 | {"help",0,0,'h'}, 42 | {0,0,0,0} 43 | }; 44 | 45 | int main(int argc, char *argv[]) 46 | { 47 | int c; 48 | progname = basename(argv[0]); 49 | size_t bufsize; 50 | if (vu_check() < 0) { 51 | fprintf(stderr,"This is a VUOS command." 52 | "It works only inside a vuos virtual namespace\n"); 53 | usage(); 54 | } 55 | while (1) { 56 | c=getopt_long(argc, argv, 57 | short_options, long_options, NULL); 58 | if (c == -1) break; 59 | switch (c) { 60 | case 'h': usage(); 61 | break; 62 | } 63 | } 64 | if (argc - optind > 0) 65 | usage(); 66 | if ((bufsize = vu_lsmod(NULL, 0)) > 0) { 67 | char buf[bufsize]; 68 | if (vu_lsmod(buf, bufsize) < 0) 69 | perror(progname); 70 | else 71 | printf("%s", buf); 72 | } 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /cmd/vu_rmmod.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | static char *progname; 29 | void usage() 30 | { 31 | fprintf(stderr, 32 | "Usage:\n" 33 | " %s OPTIONS vu_module [vu_module] ...\n" 34 | " OPTIONS:\n" 35 | " -h --help: print this help message\n\n", progname); 36 | exit(2); 37 | } 38 | 39 | static const char *short_options = "p"; 40 | static const struct option long_options[] = { 41 | {"help",0,0,'h'}, 42 | {0,0,0,0} 43 | }; 44 | 45 | int main(int argc, char *argv[]) 46 | { 47 | int c; 48 | progname = basename(argv[0]); 49 | if (vu_check() < 0) { 50 | fprintf(stderr,"This is a VUOS command." 51 | "It works only inside a vuos virtual namespace\n"); 52 | usage(); 53 | } 54 | while (1) { 55 | c=getopt_long(argc, argv, 56 | short_options, long_options, NULL); 57 | if (c == -1) break; 58 | switch (c) { 59 | case 'h': usage(); 60 | break; 61 | } 62 | } 63 | if (argc - optind < 1) 64 | usage(); 65 | else { 66 | int rv=0; 67 | int i; 68 | for (i = optind; i < argc; i++) { 69 | if (vu_rmmod(argv[i]) < 0) { 70 | perror(argv[i]); 71 | rv=1; 72 | } 73 | } 74 | return rv; 75 | } 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /cmd/vuumount.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2019 Renzo Davoli 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | void usage(char *argv0) 30 | { 31 | char *name=basename(argv0); 32 | fprintf(stderr, 33 | "Usage:\n" 34 | " %s [options] \n\n" 35 | "Unmount a filesystem.\n\n" 36 | "Options:\n" 37 | " -f, --force force unmount (in case of an unreachable NFS system)\n" 38 | " -d, --detach-loop if mounted loop device, also free this loop device\n" 39 | " -h, --help display this help\n" 40 | "\n", 41 | name); 42 | 43 | exit(1); 44 | } 45 | 46 | int main(int argc, char *argv[]) 47 | { 48 | char *progname = basename(argv[0]); 49 | char *target = NULL; 50 | int flags = 0; 51 | 52 | int c; 53 | static char *short_options = "hfd"; 54 | static struct option long_options[] = { 55 | {"force", no_argument, 0, 'f'}, 56 | {"detach-loop", no_argument, 0, 'd'}, 57 | {"help", no_argument, 0, 'h'}, 58 | {0, 0, 0, 0} 59 | }; 60 | 61 | while (1) { 62 | int option_index = 0; 63 | c = getopt_long(argc, argv, short_options, 64 | long_options, &option_index); 65 | if (c == -1) 66 | break; 67 | switch (c) { 68 | case 'f': 69 | flags |= MNT_FORCE; 70 | break; 71 | case 'd': 72 | flags |= MNT_DETACH; 73 | break; 74 | case 'h': 75 | default: 76 | usage(progname); 77 | break; 78 | } 79 | } 80 | if ((optind + 1) != argc) 81 | usage(progname); // this implies exit 82 | 83 | target = argv[optind]; 84 | 85 | if (umount2(target, flags) < 0) 86 | perror(progname); 87 | return 0; 88 | } 89 | -------------------------------------------------------------------------------- /include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | file(GLOB VU_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | install(FILES ${VU_HEADERS} DESTINATION ${HEADERS_INSTALL_PATH}) 5 | -------------------------------------------------------------------------------- /include/config.h.in: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H 2 | #define CONFIG_H 3 | 4 | #define VUOS_VERSION "@CMAKE_PROJECT_VERSION@" 5 | 6 | #define MODULES_INSTALL_PATH "@MODULES_INSTALL_PATH@" 7 | 8 | #define VURC "vurc" 9 | 10 | #define ETC_VURC "@CONFIGURATION_DIR_PATH@/" VURC 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /include/libvumod.h: -------------------------------------------------------------------------------- 1 | #ifndef VUMODLIB_H 2 | #define VUMODLIB_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /* pseudo file mgmt */ 13 | 14 | #define PSEUDOFILE_LOAD_CONTENTS 1 15 | #define PSEUDOFILE_STORE_CLOSE 2 16 | #define PSEUDOFILE_LOAD_DIRENTS 3 17 | 18 | /* upcall: this is the prototype upcall function registered by pseudofile_open, 19 | tag == PSEUDOFILE_LOAD_CONTENTS: upload the contents f-writing the file f 20 | (this happens at first read/write/lseek) 21 | tag == PSEUDOFILE_STORE_CLOSE: store/use the contents (and free any dynamic memory 22 | allocated for pseudoprivate). f can be NULL if the file has been never read or written. 23 | tag == PSEUDOFILE_LOAD_DIRENTS: populate the dir for getdents using pseudofile_filldir. 24 | (this appens at first getdents64) 25 | */ 26 | typedef int (* pseudo_upcall)(int tag, FILE *f, int openflags, void *pseudoprivate); 27 | 28 | /* helper function: convert struct stat's st_mode to struct dirent's d_type */ 29 | int pseudofile_mode2type(mode_t mode); 30 | 31 | /* helper function: use path to fill in the buf of bufsiz bytes for readlink. 32 | it returns -1/EINVAL if path is NULL */ 33 | ssize_t pseudofile_readlink_fill(char *path, char *buf, size_t bufsiz); 34 | 35 | /* add an entry to the dir for getdents */ 36 | int pseudofile_filldir(FILE *f, char *name, ino_t ino, char type); 37 | 38 | /* open a pseudofile: pseudoprivate is an opaque arg forwarded to the upcall. 39 | *private value must be stored and passed to all the other function here below. 40 | (e.g. using the private arg of the module's open syscall implementation */ 41 | int pseudofile_open(pseudo_upcall upcall, void *pseudoprivate, int flags, void **private); 42 | 43 | /* syscall implementation for pseudofiles. The signature of these function has been 44 | designed to be a drop in replacement for your module's functions. e.g. in yourmodule_init: 45 | struct vu_service_t *s = vu_mod_getservice(); 46 | vu_syscall_handler(s, close) = pseudofile_close; 47 | */ 48 | int pseudofile_close(int fd, void *private); 49 | 50 | int pseudofile_read(int fd, void *buf, size_t count, void *private); 51 | 52 | int pseudofile_write(int fd, const void *buf, size_t count, void *private); 53 | 54 | int pseudofile_lseek(int fd, off_t offset, int whence, void *private); 55 | 56 | int pseudofile_getdents64(int fd, struct dirent64 *dirp, unsigned int count, void *private); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/vudev.h: -------------------------------------------------------------------------------- 1 | #ifndef VUDEV_H 2 | #define VUDEV_H 3 | #include 4 | 5 | /* header file for vudev submodules */ 6 | 7 | /* A vudev submodule must define a global non-static variable: 8 | 9 | struct vudev_operations_t vudev_ops = { 10 | .... 11 | } 12 | */ 13 | 14 | struct vudev_t; 15 | 16 | struct vudevfd_t { 17 | dev_t subdev; 18 | off_t offset; /* unused always 0 */ 19 | int flags; 20 | void *fdprivate; 21 | struct vudev_t *vudev; 22 | }; 23 | 24 | /* get the private data of the driver (return value of "init") */ 25 | void *vudev_get_private_data(struct vudev_t *vudev); 26 | 27 | /* set the device type (S_IFBLK or S_IFCHR) 28 | S_IFCHR is the default value */ 29 | void vudev_set_devtype(struct vudev_t *vudev, mode_t devtype); 30 | 31 | struct vudev_operations_t { 32 | /* confirm_function for devices with trailing numbers (e.g. hda1, hda2 etc) 33 | return 1 if this submodule manages that subdevice */ 34 | int (*confirm_subdev) (int subdev, struct vudev_t *vudev); 35 | int (*open) (const char *pathname, mode_t mode, struct vudevfd_t *vudevfd); 36 | int (*close) (int fd, struct vudevfd_t *vudevfd); 37 | /* when pread/pwrite are defined, read/write can be omitted. umdev translates 38 | read/write/seek and keeps track ofthe file position */ 39 | /* pread/pwrite are for block devices (seekable) 40 | read/write for char devices */ 41 | ssize_t (*read) (int fd, void *buf, size_t count, struct vudevfd_t *vudevfd); 42 | ssize_t (*write) (int fd, const void *buf, size_t count, struct vudevfd_t *vudevfd); 43 | ssize_t (*pread) (int fd, void *buf, size_t count, off_t offset, struct vudevfd_t *vudevfd); 44 | ssize_t (*pwrite) (int fd, const void *buf, size_t count, off_t offset, struct vudevfd_t *vudevfd); 45 | off_t (*lseek) (int fd, off_t offset, int whence, struct vudevfd_t *vudevfd); 46 | /* ioctl: 47 | * when fd == -1: return -1 if request already encodes dir and size (_IO/_IOR/_IOW/_IORX in ioctl.h. 48 | * otherwise return a fake request with the right dir and size 49 | * when fd >= 0: run the ioctl */ 50 | int (*ioctl) (int fd, unsigned long request, void *addr, struct vudevfd_t *vudevfd); 51 | /* management of poll/select/blocking requests */ 52 | int (*epoll_ctl) (int epfd, int op, int fd, struct epoll_event *event, struct vudevfd_t *vudevfd); 53 | /* constructor/destructor of the driver. 54 | * the return value of init: 55 | * - can be retrieved by vudev_get_private_data() 56 | * - is the private_data argument of fini */ 57 | void * (*init) (const char *source, unsigned long flags, const char *args, struct vudev_t *vudev); 58 | int (*fini) (void *private_data); 59 | }; 60 | 61 | #endif 62 | 63 | 64 | -------------------------------------------------------------------------------- /include/vulib.h: -------------------------------------------------------------------------------- 1 | #ifndef _VULIB_H 2 | #define _VULIB_H 3 | #include 4 | #include 5 | 6 | /* header file of libvulib. 7 | This library is for programs running in VUOS virtual machines. 8 | it provides access to the syscalls added by VUOS, 9 | if defines constants and structs for the syscalls */ 10 | 11 | /* Virtual System call numbers */ 12 | #define __VVU_insmod -1 13 | #define __VVU_rmmod -2 14 | #define __VVU_lsmod -3 15 | #define __VVU_vuctl -4 16 | #define __VVU_msocket -5 17 | 18 | #define __NR_vu_insmod __VVU_insmod 19 | #define __NR_vu_rmmod __VVU_rmmod 20 | #define __NR_vu_lsmod __VVU_lsmod 21 | #define __NR_vuctl __VVU_vuctl 22 | #define __NR_msocket __VVU_msocket 23 | 24 | /* constants for vuctl */ 25 | #define VUCTL_GETINFO 1 26 | #define VUCTL_SETNAME 2 27 | #define VUCTL_GET_DEBUGTAGS 3 28 | #define VUCTL_ADD_DEBUGTAGS 4 29 | #define VUCTL_DEL_DEBUGTAGS 5 30 | #define VUCTL_GET_DEBUGTAGNAME 6 31 | #define VUCTL_SET_DEBUGCOLOR 7 32 | #if 0 33 | /* not yet implemented */ 34 | #define VUCTL_ATTACH 35 | #endif 36 | 37 | /* in VUOS network stacks can be "mounted" in the file system. 38 | S_IFSTACK is the file type of a network stack */ 39 | #ifndef S_IFSTACK 40 | #define S_IFSTACK 0160000 41 | #endif 42 | /* 0 is not a valid socket type, it is used by msocket 43 | to define the default stack for a give family: 44 | msocket("/dev/net/mystack", AF_INET, SOCK_DEFAULT, 0); 45 | sets the default stack for ipv4 socket to "/dev/net/mystack" */ 46 | #ifndef SOCK_DEFAULT 47 | #define SOCK_DEFAULT 0 48 | #endif 49 | 50 | /* debug tags for vuctl VUCTL_*_DEBUGTAGS */ 51 | #define DEBUG_ALLTAGS " ABCDEFGHIJKLMNOPQRSTUVWXYZ_01234abcdefghijklmnopqrstuvwxyz56789" 52 | #define DEBUG_NTAGS sizeof(DEBUG_ALLTAGS) 53 | 54 | /* struct for vuctl VUCTL_GETINFO */ 55 | struct vu_info { 56 | struct utsname uname; 57 | char vu_serverid[_UTSNAME_LENGTH]; 58 | char vu_name[_UTSNAME_LENGTH]; 59 | }; 60 | 61 | #ifndef _VU_HYPERVISOR 62 | 63 | static inline long vu_insmod(char *module, int permanent) { 64 | return syscall(__NR_vu_insmod, module, permanent); 65 | } 66 | 67 | static inline long vu_rmmod(char *modname) { 68 | return syscall(__NR_vu_rmmod, modname); 69 | } 70 | 71 | static inline long vu_lsmod(char *buf, size_t len) { 72 | return syscall(__NR_vu_lsmod, buf, len); 73 | } 74 | 75 | static inline long vu_getinfo(struct vu_info *info) { 76 | return syscall(__NR_vuctl, VUCTL_GETINFO, info); 77 | } 78 | 79 | static inline long vu_check(void) { 80 | return syscall(__NR_vuctl, VUCTL_GETINFO, NULL); 81 | } 82 | 83 | static inline long vu_setname(char *vuname) { 84 | return syscall(__NR_vuctl, VUCTL_SETNAME, vuname); 85 | } 86 | 87 | static inline long vu_get_debugtags(char *debugtags, size_t len, int local) { 88 | return syscall(__NR_vuctl, VUCTL_GET_DEBUGTAGS, debugtags, len, local); 89 | } 90 | 91 | static inline long vu_add_debugtags(char *debugtags, int local) { 92 | return syscall(__NR_vuctl, VUCTL_ADD_DEBUGTAGS, debugtags, local); 93 | } 94 | 95 | static inline long vu_del_debugtags(char *debugtags, int local) { 96 | return syscall(__NR_vuctl, VUCTL_DEL_DEBUGTAGS, debugtags, local); 97 | } 98 | 99 | static inline long vu_get_debugtagname(int tag, char *string, size_t len) { 100 | return syscall(__NR_vuctl, VUCTL_GET_DEBUGTAGNAME, tag, string, len); 101 | } 102 | 103 | static inline long vu_set_debugcolor(char *debugcolor) { 104 | return syscall(__NR_vuctl, VUCTL_SET_DEBUGCOLOR, debugcolor); 105 | } 106 | 107 | static inline long msocket(char *stack, int domain, int type, int protocol) { 108 | return syscall(__NR_msocket, stack, domain, type, protocol); 109 | } 110 | 111 | #endif 112 | #endif 113 | -------------------------------------------------------------------------------- /include/vumisc.h: -------------------------------------------------------------------------------- 1 | #ifndef VUMISC_H 2 | #define VUMISC_H 3 | #include 4 | #include 5 | 6 | struct vumisc_info { 7 | char *path; 8 | struct vu_stat stat; 9 | void *upcall_private; 10 | }; 11 | 12 | /* get the private data (return value of "init") */ 13 | void *vumisc_get_private_data(void); 14 | 15 | struct vumisc_operations_t { 16 | struct vumisc_info *infotree; 17 | pseudo_upcall infocontents; 18 | /* constructor/destructor of the submodule. 19 | * the return value of init: 20 | * - can be retrieved by vudev_get_private_data() 21 | * - is the private_data argument of fini */ 22 | void * (*init) (const char *source); 23 | int (*fini) (void *private_data); 24 | }; 25 | 26 | #define VUMISC_SYSNAME(name, syscall) name ## _ ## syscall 27 | 28 | #define VUMISC_PROTOTYPES(name) \ 29 | int VUMISC_SYSNAME(name, clock_getres) (clockid_t clk_id, struct timespec *res); \ 30 | int VUMISC_SYSNAME(name, clock_gettime) (clockid_t clk_id, struct timespec *tp); \ 31 | int VUMISC_SYSNAME(name, clock_settime) (clockid_t clk_id, const struct timespec *tp); \ 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/vunet.h: -------------------------------------------------------------------------------- 1 | #ifndef _VUNET_H 2 | #define _VUNET_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | /* header file for vunet submodules */ 11 | 12 | /* A vunet submodule must define a global non-static variable: 13 | 14 | struct vunet_operations_t vunet_ops = { 15 | .... 16 | } 17 | */ 18 | 19 | #ifndef S_IFSTACK 20 | #define S_IFSTACK 0160000 21 | #endif 22 | #ifndef SOCK_DEFAULT 23 | #define SOCK_DEFAULT 0 24 | #endif 25 | 26 | /* set and get private data of a fd */ 27 | void *vunet_get_fdprivate(void); 28 | void vunet_set_fdprivate(void *fdprivate); 29 | /* get the private_data of the stack (set by init below) */ 30 | void *vunet_get_private_data(void); 31 | 32 | struct vunet_operations { 33 | int (*socket) (int, int, int); 34 | int (*bind) (int, const struct sockaddr *, socklen_t); 35 | int (*connect) (int, const struct sockaddr *, socklen_t); 36 | int (*listen) (int, int); 37 | int (*accept4) (int, struct sockaddr *, socklen_t *, int flags); 38 | int (*getsockname) (int, struct sockaddr *, socklen_t *); 39 | int (*getpeername) (int, struct sockaddr *, socklen_t *); 40 | /* read, recv, recvfrom, recvmsg are all converted in recvmsg */ 41 | ssize_t (*recvmsg)(int, struct msghdr *, int); 42 | /* write, send, sendto, sendmsg are all converted in sendmsg */ 43 | ssize_t (*sendmsg)(int, const struct msghdr *, int); 44 | int (*setsockopt) (int, int, int, const void *, socklen_t); 45 | int (*getsockopt) (int, int, int, void *, socklen_t *); 46 | int (*shutdown) (int, int); 47 | /* ioctl: 48 | * when fd == -1: return -1 if request already encodes dir and size (_IO/_IOR/_IOW/_IORX in ioctl.h. 49 | * otherwise return a fake request with the right dir and size 50 | * when fd >= 0: run the ioctl */ 51 | int (*ioctl) (int, unsigned long, void *); 52 | int (*close) (int); 53 | int (*fcntl) (int, int, long); 54 | 55 | /* management of poll/select/blocking requests */ 56 | int (*epoll_ctl) (int epfd, int op, int fd, struct epoll_event *event); 57 | 58 | /* return 1 if the submodule supports the address family, 0 otherwise */ 59 | int (*supported_domain) (int domain); 60 | /* return 1 if the submodule supports the ioctl request, 0 otherwise */ 61 | int (*supported_ioctl) (unsigned long request); 62 | 63 | /* constructor/destructor of the stack. 64 | * *private_data in init: 65 | * - can be retrieved by vunet_get_private_data() 66 | * - is the private_data argument of fini */ 67 | int (*init) (const char *source, unsigned long flags, const char *args, void **private_data); 68 | int (*fini) (void *private_data); 69 | }; 70 | 71 | /* helper functions for ioctl: 72 | * vunet_is_netdev_ioctl returns a boolean: 1 (true) if the request is a netdevice ioctl (see netdevice(7)). 73 | * vunet_ioctl_parms convert network related requests in dir/size. 74 | * (netdevice ioctl, FIONREAD, FIONBIO use an old ancoding which do not encode dir/size. */ 75 | int vunet_is_netdev_ioctl(unsigned long request); 76 | long vunet_ioctl_parms(unsigned long request); 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /libvumod/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | set(VUMODLIB_VERSION_STRING 0.0.1) 3 | set(VUMODLIB_VERSION_MAJOR 0) 4 | 5 | include_directories(${VU_HEADERS}) 6 | set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) 7 | 8 | file(GLOB VUMODLIB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 9 | add_library(vumod SHARED ${VUMODLIB_SOURCES}) 10 | target_link_libraries(vumod volatilestream) 11 | 12 | set_target_properties(vumod PROPERTIES VERSION ${VUMODLIB_VERSION_STRING} 13 | SOVERSION ${VUMODLIB_VERSION_MAJOR}) 14 | 15 | install(TARGETS vumod LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) 16 | -------------------------------------------------------------------------------- /man/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | set(PANDOC_ORG "VirtualSquare-VUOS") 4 | 5 | # ### pandoc pages 6 | 7 | file(GLOB VU_PANDOC_PAGES ${CMAKE_CURRENT_SOURCE_DIR}/*.[1-8].md) 8 | set(VU_MAN_FILES) 9 | foreach(VU_PANDOC_PATH IN LISTS VU_PANDOC_PAGES) 10 | # VU_PANDOCPAGE: basename of VU_PANDOC_PATH 11 | get_filename_component(VU_PANDOCPAGE ${VU_PANDOC_PATH} NAME) 12 | # VU_MANPAGE: VU_PANDOCPAGE without the suffix 13 | string(REGEX REPLACE "\.md$" "" VU_MANPAGE ${VU_PANDOCPAGE}) 14 | list(APPEND VU_MAN_FILES ${VU_MANPAGE}) 15 | endforeach(VU_PANDOC_PATH) 16 | 17 | add_custom_target(${PROJECT_NAME}_manpages ALL make PANDOC_ORG="${PANDOC_ORG}" ${VU_MAN_FILES} 18 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 19 | 20 | ### man pages 21 | file(GLOB VU_MAN_PAGES ${CMAKE_CURRENT_SOURCE_DIR}/*.[1-8]) 22 | foreach(VU_MAN_PATH IN LISTS VU_MAN_PAGES) 23 | get_filename_component(VU_MANPAGE ${VU_MAN_PATH} NAME) 24 | string(REGEX REPLACE ".*\\." "" MAN_CHAPTER ${VU_MANPAGE}) 25 | install(FILES ${VU_MAN_PATH} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_CHAPTER}) 26 | endforeach(VU_MAN_PATH) 27 | -------------------------------------------------------------------------------- /man/Makefile: -------------------------------------------------------------------------------- 1 | MAKEFLAGS += --silent 2 | PANDOC=pandoc 3 | PANDOCOK := $(shell command -v ${PANDOC} 2> /dev/null) 4 | PANDOCMINVER=3.1.7 5 | 6 | ifdef PANDOCOK 7 | PANDOCVER := $(shell ${PANDOC} -v | head -1 | cut -d ' ' -f 2) 8 | PANDOCVEROK := $(shell printf '%s\n' ${PANDOCMINVER} ${PANDOCVER} | sort -C -V; echo $$?) 9 | endif 10 | 11 | none: 12 | 13 | % : %.md 14 | ifdef PANDOCOK 15 | ifeq (${PANDOCVEROK}, 1) 16 | echo "${PANDOC} ${PANDOCVER} < ${PANDOCMINVER}. $@ can create font warnings with man/groff" >&2 17 | endif 18 | # copy copyright notice 19 | grep "^\.\\\\\"" $< > $@ || true 20 | # run pandoc 21 | $(eval SECTION := $(subst .,,$(suffix $@))) 22 | $(eval BASENAME := $(basename $@)) 23 | $(eval TITLE := $(shell echo "${BASENAME}\(${SECTION}\)" | tr [:lower:] [:upper:])) 24 | $(eval HEADER := "$(shell man ${SECTION} intro | head -1 | sed -e 's/^[^[:blank:]]*[[:blank:]]*//' -e 's/[[:blank:]]*[^[:blank:]]*$$//' )") 25 | $(PANDOC) -standalone -M title=${TITLE} -M section=${SECTION} -M header=${HEADER} -M footer=${PANDOC_ORG} -M "date=`date +\"%B %Y\"`" --to man $< >> $@ 26 | # workaround for boldface rendering 27 | sed -i -e 's/\\f\[CR\]/\\f\[CB\]/g' $@ || true 28 | echo "$@ manpage updated" >&2 29 | else 30 | echo "${PANDOC} is not available. Manpage $@ cannot be updated" >&2 31 | endif 32 | -------------------------------------------------------------------------------- /man/fusenull.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2023 VirtualSquare. Project Leader: Renzo Davoli 2 | .\" 3 | .\" This is free documentation; you can redistribute it and/or 4 | .\" modify it under the terms of the GNU General Public License, 5 | .\" as published by the Free Software Foundation, either version 2 6 | .\" of the License, or (at your option) any later version. 7 | .\" 8 | .\" The GNU General Public License's references to "object code" 9 | .\" and "executables" are to be interpreted as the output of any 10 | .\" document formatting or typesetting system, including 11 | .\" intermediate and printed output. 12 | .\" 13 | .\" This manual is distributed in the hope that it will be useful, 14 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | .\" GNU General Public License for more details. 17 | .\" 18 | .\" You should have received a copy of the GNU General Public 19 | .\" License along with this manual; if not, write to the Free 20 | .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 21 | .\" MA 02110-1301 USA. 22 | .\" 23 | .\" Automatically generated by Pandoc 3.1.11 24 | .\" 25 | .TH "FUSENULL" "1" "January 2024" "VirtualSquare\-VUOS" "General Commands Manual" 26 | .SH NAME 27 | fusenull, vufusenull \- mount a null file system using FUSE and vufuse 28 | .SH SYNOPSIS 29 | \f[CB]fusenull\f[R] [\f[CB]\-hVdfs\f[R]] [\f[CB]\-o\f[R] 30 | \f[I]options\f[R] ] \f[I]dir\f[R] 31 | .PP 32 | in a \f[CB]umvu\f[R] session: 33 | .PP 34 | \f[CB]mount \-t vufusenull\f[R] [\f[CB]\-o\f[R] \f[I]options\f[R] ] 35 | \f[I]dir\f[R] 36 | .SH DESCRIPTION 37 | \f[CB]fusenull\f[R] mounts a null filesystem on \f[I]dir\f[R]. 38 | A null file system appears as an empty directory, any operation on it 39 | fails. 40 | It is generally used as a minimal FUSE module for testing. 41 | .PP 42 | \f[CB]vufusenull\f[R] is the VUOS/vufuse submodule of 43 | \f[CB]fusenull\f[R] 44 | .SH OPTIONS 45 | \f[CB]fusenull\f[R] is build upon FUSE (Filesystem in Userspace) 46 | library. 47 | the complete set of available options depends upon the specific FUSE 48 | installed. 49 | Execute \f[CB]fusenull \-h\f[R] to retrieve the actual complete list. 50 | .SS general options 51 | .TP 52 | \f[CB]\-o\f[R] opt,[opt\&...] 53 | FUSE and file specific mount options. 54 | .TP 55 | \f[CB]\-h\f[R] 56 | display a usage and options summary 57 | .TP 58 | \f[CB]\-V\f[R] \ \f[CB]\-\-version\f[R] 59 | display version 60 | .SS main FUSE mount options 61 | These options are not valid in VUOS/vufuse. 62 | .TP 63 | \f[CB]\-d\f[R] \ \f[CB]\-o debug\f[R] 64 | enable debug output (implies \-f) 65 | .TP 66 | \f[CB]\-f\f[R] 67 | foreground operation 68 | .TP 69 | \f[CB]\-s\f[R] 70 | disable multi\-threaded operation 71 | .SH SEE ALSO 72 | \f[CB]fuse\f[R](8), \f[CB]umvu\f[R](1) 73 | .SH AUTHOR 74 | VirtualSquare. 75 | Project leader: Renzo Davoli. 76 | -------------------------------------------------------------------------------- /man/fusenull.1.md: -------------------------------------------------------------------------------- 1 | 25 | 26 | # NAME 27 | 28 | fusenull, vufusenull - mount a null file system using FUSE and vufuse 29 | 30 | # SYNOPSIS 31 | 32 | `fusenull` [`-hVdfs`] [`-o` _options_ ] *dir* 33 | 34 | in a `umvu` session: 35 | 36 | `mount -t vufusenull` [`-o` _options_ ] *dir* 37 | 38 | # DESCRIPTION 39 | 40 | `fusenull` mounts a null filesystem on *dir*. 41 | A null file system appears as an empty directory, any operation on it fails. 42 | It is generally used as a minimal FUSE module for testing. 43 | 44 | `vufusenull` is the VUOS/vufuse submodule of `fusenull` 45 | 46 | # OPTIONS 47 | 48 | `fusenull` is build upon FUSE (Filesystem in Userspace) library. 49 | the complete set of available options depends upon the specific 50 | FUSE installed. Execute `fusenull -h` to retrieve the actual complete 51 | list. 52 | 53 | ### general options 54 | 55 | `-o` opt,[opt...] 56 | : FUSE and file specific mount options. 57 | 58 | `-h` 59 | : display a usage and options summary 60 | 61 | `-V`   `--version` 62 | : display version 63 | 64 | ### main FUSE mount options 65 | 66 | These options are not valid in VUOS/vufuse. 67 | 68 | `-d`   `-o debug` 69 | : enable debug output (implies -f) 70 | 71 | `-f` 72 | : foreground operation 73 | 74 | `-s` 75 | : disable multi-threaded operation 76 | 77 | # SEE ALSO 78 | `fuse`(8), `umvu`(1) 79 | 80 | # AUTHOR 81 | VirtualSquare. Project leader: Renzo Davoli. 82 | 83 | -------------------------------------------------------------------------------- /man/fusereal.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2023 VirtualSquare. Project Leader: Renzo Davoli 2 | .\" 3 | .\" This is free documentation; you can redistribute it and/or 4 | .\" modify it under the terms of the GNU General Public License, 5 | .\" as published by the Free Software Foundation, either version 2 6 | .\" of the License, or (at your option) any later version. 7 | .\" 8 | .\" The GNU General Public License's references to "object code" 9 | .\" and "executables" are to be interpreted as the output of any 10 | .\" document formatting or typesetting system, including 11 | .\" intermediate and printed output. 12 | .\" 13 | .\" This manual is distributed in the hope that it will be useful, 14 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | .\" GNU General Public License for more details. 17 | .\" 18 | .\" You should have received a copy of the GNU General Public 19 | .\" License along with this manual; if not, write to the Free 20 | .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 21 | .\" MA 02110-1301 USA. 22 | .\" 23 | .\" Automatically generated by Pandoc 3.1.11 24 | .\" 25 | .TH "FUSEREAL" "1" "January 2024" "VirtualSquare\-VUOS" "General Commands Manual" 26 | .SH NAME 27 | fusereal, vufusereal \- mount a file system tree to another place using 28 | FUSE and vufuse 29 | .SH SYNOPSIS 30 | \f[CB]fusereal\f[R] [\f[CB]\-hVdfs\f[R]] [\f[CB]\-o\f[R] 31 | \f[I]options\f[R] ] \f[I]olddir\f[R] \f[I]newdir\f[R] 32 | .PP 33 | in a \f[CB]umvu\f[R] session: 34 | .PP 35 | \f[CB]mount \-t vufusereal\f[R] [\f[CB]\-o\f[R] \f[I]options\f[R] ] 36 | \f[I]olddir\f[R] \f[I]newdir\f[R] 37 | .SH DESCRIPTION 38 | \f[CB]fusereal\f[R] causes the contents of \f[I]olddir\f[R] to be 39 | accessible (also) under \f[I]newdir\f[R]. 40 | .PP 41 | \f[CB]vufusereal\f[R] is the VUOS/vufuse submodule of 42 | \f[CB]fusereal\f[R] 43 | .SH OPTIONS 44 | \f[CB]fusereal\f[R] is build upon FUSE (Filesystem in Userspace) 45 | library. 46 | the complete set of available options depends upon the specific FUSE 47 | installed. 48 | Execute \f[CB]fusereal \-h\f[R] to retrieve the actual complete list. 49 | .SS general options 50 | .TP 51 | \f[CB]\-o\f[R] opt,[opt\&...] 52 | FUSE and file specific mount options. 53 | .TP 54 | \f[CB]\-h\f[R] 55 | display a usage and options summary 56 | .TP 57 | \f[CB]\-V\f[R] \ \f[CB]\-\-version\f[R] 58 | display version 59 | .SS main FUSE mount options 60 | These options are not valid in VUOS/vufuse. 61 | .TP 62 | \f[CB]\-d\f[R] \ \f[CB]\-o debug\f[R] 63 | enable debug output (implies \-f) 64 | .TP 65 | \f[CB]\-f\f[R] 66 | foreground operation 67 | .TP 68 | \f[CB]\-s\f[R] 69 | disable multi\-threaded operation 70 | .SH SEE ALSO 71 | \f[CB]fuse\f[R](8), \f[CB]umvu\f[R](1) 72 | .SH AUTHOR 73 | VirtualSquare. 74 | Project leader: Renzo Davoli. 75 | -------------------------------------------------------------------------------- /man/fusereal.1.md: -------------------------------------------------------------------------------- 1 | 25 | 26 | # NAME 27 | 28 | fusereal, vufusereal - mount a file system tree to another place using FUSE and vufuse 29 | 30 | # SYNOPSIS 31 | 32 | `fusereal` [`-hVdfs`] [`-o` _options_ ] *olddir* *newdir* 33 | 34 | in a `umvu` session: 35 | 36 | `mount -t vufusereal` [`-o` _options_ ] *olddir* *newdir* 37 | 38 | # DESCRIPTION 39 | 40 | `fusereal` 41 | causes the contents of *olddir* to be accessible (also) under *newdir*. 42 | 43 | `vufusereal` is the VUOS/vufuse submodule of `fusereal` 44 | 45 | # OPTIONS 46 | 47 | `fusereal` is build upon FUSE (Filesystem in Userspace) library. 48 | the complete set of available options depends upon the specific 49 | FUSE installed. Execute `fusereal -h` to retrieve the actual complete 50 | list. 51 | 52 | ### general options 53 | 54 | `-o` opt,[opt...] 55 | : FUSE and file specific mount options. 56 | 57 | `-h` 58 | : display a usage and options summary 59 | 60 | `-V`   `--version` 61 | : display version 62 | 63 | ### main FUSE mount options 64 | 65 | These options are not valid in VUOS/vufuse. 66 | 67 | `-d`   `-o debug` 68 | : enable debug output (implies -f) 69 | 70 | `-f` 71 | : foreground operation 72 | 73 | `-s` 74 | : disable multi-threaded operation 75 | 76 | # SEE ALSO 77 | `fuse`(8), `umvu`(1) 78 | 79 | # AUTHOR 80 | VirtualSquare. Project leader: Renzo Davoli. 81 | 82 | -------------------------------------------------------------------------------- /man/vu_insmod.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2019 VirtualSquare. Project Leader: Renzo Davoli 2 | .\" 3 | .\" This is free documentation; you can redistribute it and/or 4 | .\" modify it under the terms of the GNU General Public License, 5 | .\" as published by the Free Software Foundation, either version 2 6 | .\" of the License, or (at your option) any later version. 7 | .\" 8 | .\" The GNU General Public License's references to "object code" 9 | .\" and "executables" are to be interpreted as the output of any 10 | .\" document formatting or typesetting system, including 11 | .\" intermediate and printed output. 12 | .\" 13 | .\" This manual is distributed in the hope that it will be useful, 14 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | .\" GNU General Public License for more details. 17 | .\" 18 | .\" You should have received a copy of the GNU General Public 19 | .\" License along with this manual; if not, write to the Free 20 | .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 21 | .\" MA 02110-1301 USA. 22 | .\" 23 | .\" Automatically generated by Pandoc 3.1.11 24 | .\" 25 | .TH "VU_INSMOD" "1" "January 2024" "VirtualSquare\-VUOS" "General Commands Manual" 26 | .SH NAME 27 | \f[CB]vu_insmod\f[R] \[en] user\-mode implementation of VUOS 28 | .SH SYNOPSIS 29 | \f[CB]vu_insmod\f[R] [\f[I]options\f[R] \&...] 30 | \f[I]vu_module\f[R] [\f[I]vu_module\f[R]] 31 | .SH DESCRIPTION 32 | \f[I]This is a VUOS command. 33 | It works only inside a vuos virtual namespace\f[R] see 34 | \f[CB]umvu\f[R](1). 35 | .PP 36 | This command adds one or more modules to umvu. 37 | .SH OPTIONS 38 | .TP 39 | \f[CB]\-h\f[R], \f[CB]\-\-help\f[R] 40 | Print a short help message and exit. 41 | .TP 42 | \f[CB]\-p\f[R], \f[CB]\-\-permanent\f[R] 43 | permanently inserted modules cannot be removed. 44 | .SH EXAMPLE 45 | The following command adds vufuse (file system virtualization), vudev 46 | (virtual devices) and vunet (virtual networking). 47 | .IP 48 | .EX 49 | vu_insmod vufuse vudev vunet 50 | .EE 51 | .SH SEE ALSO 52 | umvu(1), vu_lsmod(1), vu_rmmod(1) 53 | .SH AUTHOR 54 | VirtualSquare. 55 | Project leader: Renzo Davoli 56 | -------------------------------------------------------------------------------- /man/vu_insmod.1.md: -------------------------------------------------------------------------------- 1 | 25 | # NAME 26 | 27 | `vu_insmod` -- user-mode implementation of VUOS 28 | 29 | # SYNOPSIS 30 | 31 | `vu_insmod` [*options* ...] *vu_module* [*vu_module*] 32 | 33 | # DESCRIPTION 34 | 35 | *This is a VUOS command. It works only inside a vuos virtual namespace* see `umvu`(1). 36 | 37 | This command adds one or more modules to umvu. 38 | 39 | # OPTIONS 40 | 41 | `-h`, `--help` 42 | : Print a short help message and exit. 43 | 44 | `-p`, `--permanent` 45 | : permanently inserted modules cannot be removed. 46 | 47 | # EXAMPLE 48 | 49 | The following command adds vufuse (file system virtualization), vudev (virtual devices) and vunet (virtual networking). 50 | 51 | ``` 52 | vu_insmod vufuse vudev vunet 53 | ``` 54 | 55 | # SEE ALSO 56 | umvu(1), vu_lsmod(1), vu_rmmod(1) 57 | 58 | # AUTHOR 59 | 60 | VirtualSquare. Project leader: Renzo Davoli 61 | 62 | -------------------------------------------------------------------------------- /man/vu_lsmod.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2019 VirtualSquare. Project Leader: Renzo Davoli 2 | .\" 3 | .\" This is free documentation; you can redistribute it and/or 4 | .\" modify it under the terms of the GNU General Public License, 5 | .\" as published by the Free Software Foundation, either version 2 6 | .\" of the License, or (at your option) any later version. 7 | .\" 8 | .\" The GNU General Public License's references to "object code" 9 | .\" and "executables" are to be interpreted as the output of any 10 | .\" document formatting or typesetting system, including 11 | .\" intermediate and printed output. 12 | .\" 13 | .\" This manual is distributed in the hope that it will be useful, 14 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | .\" GNU General Public License for more details. 17 | .\" 18 | .\" You should have received a copy of the GNU General Public 19 | .\" License along with this manual; if not, write to the Free 20 | .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 21 | .\" MA 02110-1301 USA. 22 | .\" 23 | .\" Automatically generated by Pandoc 3.1.11 24 | .\" 25 | .TH "VU_LSMOD" "1" "January 2024" "VirtualSquare\-VUOS" "General Commands Manual" 26 | .SH NAME 27 | \f[CB]vu_lsmod\f[R] \[en] user\-mode implementation of VUOS 28 | .SH SYNOPSIS 29 | \f[CB]vu_lsmod\f[R] [\f[I]options\f[R] \&...] 30 | \f[I]vu_module\f[R] [\f[I]vu_module\f[R]] 31 | .SH DESCRIPTION 32 | \f[I]This is a VUOS command. 33 | It works only inside a vuos virtual namespace\f[R] see 34 | \f[CB]umvu\f[R](1). 35 | .PP 36 | This command lists the modules currently loaded. 37 | .SH OPTIONS 38 | .TP 39 | \f[CB]\-h\f[R], \f[CB]\-\-help\f[R] 40 | Print a short help message and exit. 41 | .SH EXAMPLE 42 | .IP 43 | .EX 44 | $ vu_lsmod vufuse 45 | vufuse: vu virtual file systems (user level FUSE) 46 | vudev: vu virtual devices 47 | vunet: vu virtual networking 48 | .EE 49 | .SH SEE ALSO 50 | umvu(1), vu_insmod(1), vu_rmmod(1) 51 | .SH AUTHOR 52 | VirtualSquare. 53 | Project leader: Renzo Davoli 54 | -------------------------------------------------------------------------------- /man/vu_lsmod.1.md: -------------------------------------------------------------------------------- 1 | 25 | # NAME 26 | 27 | `vu_lsmod` -- user-mode implementation of VUOS 28 | 29 | # SYNOPSIS 30 | 31 | `vu_lsmod` [*options* ...] *vu_module* [*vu_module*] 32 | 33 | # DESCRIPTION 34 | 35 | *This is a VUOS command. It works only inside a vuos virtual namespace* see `umvu`(1). 36 | 37 | This command lists the modules currently loaded. 38 | 39 | # OPTIONS 40 | 41 | `-h`, `--help` 42 | : Print a short help message and exit. 43 | 44 | 45 | # EXAMPLE 46 | 47 | ``` 48 | $ vu_lsmod vufuse 49 | vufuse: vu virtual file systems (user level FUSE) 50 | vudev: vu virtual devices 51 | vunet: vu virtual networking 52 | ``` 53 | 54 | # SEE ALSO 55 | umvu(1), vu_insmod(1), vu_rmmod(1) 56 | 57 | # AUTHOR 58 | 59 | VirtualSquare. Project leader: Renzo Davoli 60 | 61 | -------------------------------------------------------------------------------- /man/vu_rmmod.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2019 VirtualSquare. Project Leader: Renzo Davoli 2 | .\" 3 | .\" This is free documentation; you can redistribute it and/or 4 | .\" modify it under the terms of the GNU General Public License, 5 | .\" as published by the Free Software Foundation, either version 2 6 | .\" of the License, or (at your option) any later version. 7 | .\" 8 | .\" The GNU General Public License's references to "object code" 9 | .\" and "executables" are to be interpreted as the output of any 10 | .\" document formatting or typesetting system, including 11 | .\" intermediate and printed output. 12 | .\" 13 | .\" This manual is distributed in the hope that it will be useful, 14 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | .\" GNU General Public License for more details. 17 | .\" 18 | .\" You should have received a copy of the GNU General Public 19 | .\" License along with this manual; if not, write to the Free 20 | .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 21 | .\" MA 02110-1301 USA. 22 | .\" 23 | .\" Automatically generated by Pandoc 3.1.11 24 | .\" 25 | .TH "VU_RMMOD" "1" "January 2024" "VirtualSquare\-VUOS" "General Commands Manual" 26 | .SH NAME 27 | \f[CB]vu_rmmod\f[R] \[en] user\-mode implementation of VUOS 28 | .SH SYNOPSIS 29 | \f[CB]vu_rmmod\f[R] [\f[I]options\f[R] \&...] 30 | \f[I]vu_module\f[R] [\f[I]vu_module\f[R]] 31 | .SH DESCRIPTION 32 | \f[I]This is a VUOS command. 33 | It works only inside a vuos virtual namespace\f[R] see 34 | \f[CB]umvu\f[R](1). 35 | .PP 36 | This command removes one or more modules currently loaded in umvu. 37 | .SH OPTIONS 38 | .TP 39 | \f[CB]\-h\f[R], \f[CB]\-\-help\f[R] 40 | Print a short help message and exit. 41 | .SH EXAMPLE 42 | The following command removes vudev (virtual devices) and vunet (virtual 43 | networking). 44 | .IP 45 | .EX 46 | vu_rmmod vudev vunet 47 | .EE 48 | .SH SEE ALSO 49 | umvu(1), vu_insmod(1), vu_lsmod(1) 50 | .SH AUTHOR 51 | VirtualSquare. 52 | Project leader: Renzo Davoli 53 | -------------------------------------------------------------------------------- /man/vu_rmmod.1.md: -------------------------------------------------------------------------------- 1 | 25 | 26 | # NAME 27 | 28 | `vu_rmmod` -- user-mode implementation of VUOS 29 | 30 | # SYNOPSIS 31 | 32 | `vu_rmmod` [*options* ...] *vu_module* [*vu_module*] 33 | 34 | # DESCRIPTION 35 | 36 | *This is a VUOS command. It works only inside a vuos virtual namespace* see `umvu`(1). 37 | 38 | This command removes one or more modules currently loaded in umvu. 39 | 40 | # OPTIONS 41 | 42 | `-h`, `--help` 43 | : Print a short help message and exit. 44 | 45 | # EXAMPLE 46 | 47 | The following command removes vudev (virtual devices) and vunet (virtual networking). 48 | 49 | ``` 50 | vu_rmmod vudev vunet 51 | ``` 52 | 53 | # SEE ALSO 54 | umvu(1), vu_insmod(1), vu_lsmod(1) 55 | 56 | # AUTHOR 57 | 58 | VirtualSquare. Project leader: Renzo Davoli 59 | 60 | -------------------------------------------------------------------------------- /man/vumount.1.md: -------------------------------------------------------------------------------- 1 | 25 | # NAME 26 | 27 | `vumount` -- mount a filesystem or a resource 28 | 29 | # SYNOPSIS 30 | 31 | `vumount` [*options* ...] *source* *destination* 32 | 33 | # DESCRIPTION 34 | 35 | Everything is (or can be seen) as a file. It is part of the philosophy 36 | of UNIX. The file hierarchy is the global naming facility. 37 | 38 | VUOS follows this principle: VUOS modules use `mount`(2) not only to 39 | mount virtual filesystems but also to activate other virtual services. 40 | The mountpoint, *destination* in the synopsis, is the name 41 | that will be used to identify the virtual entity/service. 42 | 43 | For example, in `vudev` it is possible to mount devices, in `vunet` the 44 | mountpoint is the name of the networking stack, `vustack`(1) uses the path 45 | of the mountpoint to set the current stack for processes. 46 | 47 | `vumount` is just a command interface to `mount`(2). 48 | The `mount`(8) command is a complex tool which includes several features like 49 | the management of /etc/fstab and /etc/mtab. `mount`(8) is a 50 | root setuid executable and performs security checks before the actual 51 | `mount`(2) syscall request. `mount`(8) can be used in VUOS 52 | in place of `vumount` but it requires the (virtual) real uid of the 53 | executing process to be 0 (root). e.g. `vusu`(1) can be used to 54 | set the virtual real uid to 0. 55 | `vumount` has been designed for VUOS but can be used to run the `mount` 56 | system call directly, without all the other management actions provided by 57 | `mount`(8). `vumount` is not setuid root. 58 | 59 | # OPTIONS 60 | 61 | `-h`, `--help` 62 | : Print a short help message and exit. 63 | 64 | `-o` *list*, `--options` *list* 65 | : comma-separated list of mount options 66 | 67 | `-t` *fstype*, `--types` *fstype* 68 | : define the filesystem type 69 | 70 | `-r`, `--read-only` 71 | : mount the filesystem read-only (same as -o ro) 72 | 73 | `-w`, `--rw`, `--read-write` 74 | : mount the filesystem read-write (default) 75 | 76 | `-B`, `--bind` 77 | : mount a subtree somewhere else (same as -o bind) 78 | 79 | `-M`, `--move` 80 | : move a subtree to some other place 81 | 82 | `-R`, `--rbind` 83 | : mount a subtree and all submounts somewhere else 84 | 85 | # SEE ALSO 86 | umvu(1), vu_insmod(1), vu_lsmod(1), vu_rmmod(1), vuumount(1), vudebug(1) 87 | 88 | # AUTHOR 89 | 90 | VirtualSquare. Project leader: Renzo Davoli 91 | -------------------------------------------------------------------------------- /man/vuname.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2019 VirtualSquare. Project Leader: Renzo Davoli 2 | .\" 3 | .\" This is free documentation; you can redistribute it and/or 4 | .\" modify it under the terms of the GNU General Public License, 5 | .\" as published by the Free Software Foundation, either version 2 6 | .\" of the License, or (at your option) any later version. 7 | .\" 8 | .\" The GNU General Public License's references to "object code" 9 | .\" and "executables" are to be interpreted as the output of any 10 | .\" document formatting or typesetting system, including 11 | .\" intermediate and printed output. 12 | .\" 13 | .\" This manual is distributed in the hope that it will be useful, 14 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | .\" GNU General Public License for more details. 17 | .\" 18 | .\" You should have received a copy of the GNU General Public 19 | .\" License along with this manual; if not, write to the Free 20 | .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 21 | .\" MA 02110-1301 USA. 22 | .\" 23 | .\" Automatically generated by Pandoc 3.1.11 24 | .\" 25 | .TH "VUNAME" "1" "January 2024" "VirtualSquare\-VUOS" "General Commands Manual" 26 | .SH NAME 27 | \f[CB]vuname\f[R] \[en] print system/view information \- set view name. 28 | .SH SYNOPSIS 29 | \f[CB]vuname\f[R] [\f[I]options\f[R] \&...] 30 | .PP 31 | or 32 | .PP 33 | \f[CB]vuname\f[R] \f[I]newname\f[R] 34 | .SH DESCRIPTION 35 | Print certain system/view information. 36 | With no options, and no arguments, same as \-s. 37 | With no options and exactly one argument: set the VUOS view name. 38 | .PP 39 | This tool extends \f[CB]uname\f[R](1). 40 | It should provide the same output of \f[CB]uname\f[R] except when it 41 | runs as a VUOS process (or if \f[CB]\-\-x\f[R]/\f[CB]\-\-nouname\f[R] 42 | disables this feature). 43 | In VUOS the system information is extended with view information. 44 | .SH OPTIONS 45 | .TP 46 | \f[CB]\-a\f[R], \f[CB]\-\-all\f[R] 47 | print all information, in the following order, except omit 48 | \f[CB]\-p\f[R] and \f[CB]\-i\f[R] if unknown. 49 | .TP 50 | \f[CB]\-s\f[R], \f[CB]\-\-kernel\-name\f[R] 51 | print the kernel name 52 | .TP 53 | \f[CB]\-n\f[R], \f[CB]\-\-nodename\f[R] 54 | print the network node hostname 55 | .TP 56 | \f[CB]\-r\f[R], \f[CB]\-\-kernel\-release\f[R] 57 | print the kernel release 58 | .TP 59 | \f[CB]\-v\f[R], \f[CB]\-\-kernel\-version\f[R] 60 | print the kernel version 61 | .TP 62 | \f[CB]\-m\f[R], \f[CB]\-\-machine\f[R] 63 | print the machine hardware name 64 | .TP 65 | \f[CB]\-p\f[R], \f[CB]\-\-processor\f[R] 66 | print the processor type or \[lq]unknown\[rq] 67 | .TP 68 | \f[CB]\-i\f[R], \f[CB]\-\-hardware\-platform\f[R] 69 | print the hardware platform or \[lq]unknown\[rq] 70 | .TP 71 | \f[CB]\-o\f[R], \f[CB]\-\-operating\-system\f[R] 72 | print the operating system 73 | .TP 74 | \f[CB]\-U\f[R], \f[CB]\-\-serverid\f[R] 75 | print the VUOS server id (it is the process id of the hypervisor) 76 | .TP 77 | \f[CB]\-V\f[R], \f[CB]\-\-viewname\f[R] 78 | print the view name 79 | .TP 80 | \f[CB]\-P\f[R], \f[CB]\-\-prompt\f[R] 81 | return a suitable (shell) command prompt: the nodename (\f[CB]\-n\f[R]) 82 | if \f[CB]vuname\f[R] runs outside VUOS else the view name 83 | (\f[CB]\-V\f[R]) if it has been defined otherwise the nodename 84 | followedby the server id enclosed in square brackets (something like 85 | \f[I]host[42]\f[R]). 86 | .TP 87 | \f[CB]\-x\f[R], \f[CB]\-\-nouname\f[R] 88 | do not use uname (without this flag the command behaves like uname when 89 | it runs on a non VUOS enabled environment). 90 | .TP 91 | \f[CB]\-q\f[R], \f[CB]\-\-quiet\f[R] 92 | quiet mode: error messages suppressed 93 | .TP 94 | \f[CB]\-\-help\f[R] 95 | display a help message and exit 96 | .TP 97 | \f[CB]\-\-version\f[R] 98 | output version information and exit 99 | -------------------------------------------------------------------------------- /man/vuname.1.md: -------------------------------------------------------------------------------- 1 | 25 | # NAME 26 | 27 | `vuname` -- print system/view information - set view name. 28 | 29 | # SYNOPSIS 30 | 31 | `vuname` [*options* ...] 32 | 33 | or 34 | 35 | `vuname` *newname* 36 | 37 | 38 | # DESCRIPTION 39 | 40 | Print certain system/view information. With no options, and no arguments, same as -s. 41 | With no options and exactly one argument: set the VUOS view name. 42 | 43 | This tool extends `uname`(1). It should provide the same output of `uname` except when 44 | it runs as a VUOS process (or if `--x`/`--nouname` disables this feature). 45 | In VUOS the system information is extended with view information. 46 | 47 | # OPTIONS 48 | 49 | `-a`, `--all` 50 | : print all information, in the following order, except omit `-p` and `-i` if unknown. 51 | 52 | `-s`, `--kernel-name` 53 | : print the kernel name 54 | 55 | `-n`, `--nodename` 56 | : print the network node hostname 57 | 58 | `-r`, `--kernel-release` 59 | : print the kernel release 60 | 61 | `-v`, `--kernel-version` 62 | : print the kernel version 63 | 64 | `-m`, `--machine` 65 | : print the machine hardware name 66 | 67 | `-p`, `--processor` 68 | : print the processor type or "unknown" 69 | 70 | `-i`, `--hardware-platform` 71 | : print the hardware platform or "unknown" 72 | 73 | `-o`, `--operating-system` 74 | : print the operating system 75 | 76 | `-U`, `--serverid` 77 | : print the VUOS server id (it is the process id of the hypervisor) 78 | 79 | `-V`, `--viewname` 80 | : print the view name 81 | 82 | `-P`, `--prompt` 83 | : return a suitable (shell) command prompt: the nodename (`-n`) if `vuname` runs outside VUOS else the view name (`-V`) if 84 | it has been defined otherwise the nodename followedby the server id enclosed in square brackets (something like *host[42]*). 85 | 86 | `-x`, `--nouname` 87 | : do not use uname (without this flag the command behaves like uname when it runs on a non VUOS enabled environment). 88 | 89 | `-q`, `--quiet` 90 | : quiet mode: error messages suppressed 91 | 92 | `--help` 93 | : display a help message and exit 94 | 95 | `--version` 96 | : output version information and exit 97 | 98 | -------------------------------------------------------------------------------- /man/vustack.1.md: -------------------------------------------------------------------------------- 1 | 25 | # NAME 26 | 27 | `vustack` -- set the default networking stack 28 | 29 | # SYNOPSIS 30 | 31 | `vustack` [*options* ...] *stack* *command* [*args*] 32 | 33 | # DESCRIPTION 34 | 35 | `vunet` is the VUOS module for networking virtualization. Networking 36 | stacks can be loaded using `vumount`(1) and are identified by a pathname: 37 | the mount point. `vustack` selects the stack to use among those available; 38 | *command* runs using the stack selected `vustack`. 39 | 40 | # OPTIONS 41 | 42 | `-h`, `--help` 43 | : Print a short help message and exit. If combined with `-v` print also 44 | : the list of protocol family names. 45 | 46 | `-s`, `--supported` 47 | : select the stack only for the protocol families supported by *stack*. 48 | 49 | `-f` *list*, `--family` *list*, `--families` *list* 50 | : select the stack for the protocol families in *list*. *list* is a 51 | : comma separated list of protocol names or numbers. 52 | 53 | `-v`, `--verbose` 54 | : print the list of protocol families object of the stack selection. 55 | 56 | # EXAMPLES 57 | 58 | Load `vunet` and mount a stack: 59 | 60 | ``` 61 | $ vu_insmod vunet 62 | $ vumount -t vunetvdestack vde:// /dev/net/vde 63 | ``` 64 | 65 | Run *ip link* using the stack mounted in /dev/net/vde: 66 | 67 | ``` 68 | $ vustack /dev/net/vde ip link 69 | 1: lo: *LOOPBACK* mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 70 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 71 | 2: vde0: *BROADCAST,MULTICAST* mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 72 | link/ether 5a:1e:97:fa:ab:a3 brd ff:ff:ff:ff:ff:ff 73 | ``` 74 | 75 | Run *ip link set vde0 up* selecting /dev/net/vde only for the families supported by vunetvdestack: 76 | 77 | ``` 78 | $ vustack -s -v /dev/net/vde ip link set vde0 up 79 | Using /dev/net/vde for the following address families: 80 | inet(2) inet6(10) netlink(16) packet(17) 81 | ``` 82 | 83 | mount a null stack and use it to disable netlink: 84 | 85 | ``` 86 | $ vumount -t vunetnull vde:// /dev/net/null 87 | $ exec vustack -f netlink -v /dev/net/null bash 88 | Using /dev/net/null for the following address families: 89 | netlink(16) 90 | $ ip addr 91 | Cannot open netlink socket: Address family not supported by protocol 92 | ``` 93 | 94 | # SEE ALSO 95 | umvu(1), vumount(1) 96 | 97 | # AUTHOR 98 | VirtualSquare. Project leader: Renzo Davoli 99 | -------------------------------------------------------------------------------- /man/vusu.1.md: -------------------------------------------------------------------------------- 1 | 25 | # NAME 26 | 27 | `vusu` -- set the default networking stack 28 | 29 | # SYNOPSIS 30 | 31 | `vusu` [*options*] [-] [*user* [*argment...]] 32 | 33 | # DESCRIPTION 34 | 35 | `vusu` allows one to run commands with a substitute user and group ID (in VUOS). 36 | It requires a module loaded in VUOS able to redefine uid/gid, e.g. `unrealuidgid`. 37 | 38 | When called without arguments, `vusu` defaults to running an interactive shell as 39 | (virtual) *root*. 40 | 41 | For compatibility with `su`(1), `vusu` defaults to not change the current 42 | directory and to only set the environment variables `HOME` and `SHELL` (plus 43 | `USER` and `LOGNAME` if the target user is not root). It is recommended to 44 | always use the `--login` option (instead of its shortcut -) to avoid side 45 | effects caused by mixing environments. 46 | 47 | # OPTIONS 48 | `-c` *command*, `--command` *command* 49 | : Pass command to the shell with the `-c` option. 50 | 51 | `-`, `-l`, `--login` 52 | : Start the shell as a login shell with an environment similar to a real login:\ 53 | 54 | ` ` 55 | : \- clears all the environment variables except `TERM`\ 56 | 57 | ` ` 58 | : \- initializes the environment variables `HOME`, `SHELL`, `USER`, `LOGNAME`, and `PATH`\ 59 | 60 | ` ` 61 | : \- changes to the target user's home directory\ 62 | 63 | ` ` 64 | : \- sets argv[0] of the shell to '-' in order to make the shell a login shell 65 | 66 | `-m`, `-p`, `--preserve-environment` 67 | : Preserve the entire environment, i.e. it does not set `HOME`, `SHELL`, `USER` nor `LOGNAME`. 68 | : This option is ignored if the option `--login` is specified. 69 | 70 | `-s` *shell*, `--shell` *shell* 71 | : Run the specified shell instead of the default. The shell to run is selected according to the following 72 | : rules, in order: 73 | 74 | ` ` 75 | : \- the shell specified with `--shell`\ 76 | 77 | ` ` 78 | : \- the shell specified in the environment variable `SHELL`, if the `--preserve-environment` option is used\ 79 | 80 | ` ` 81 | : \- the shell listed in the passwd entry of the target user\ 82 | 83 | ` ` 84 | : \- /bin/sh 85 | 86 | `-h`, `--help` 87 | : Display a short help message and exit. 88 | 89 | # SEE ALSO 90 | umvu(1), su(1) 91 | 92 | # AUTHOR 93 | VirtualSquare. Project leader: Renzo Davoli. 94 | (most of this man page is a derivative work from `su`(1) man page) 95 | -------------------------------------------------------------------------------- /man/vuumount.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2019 VirtualSquare. Project Leader: Renzo Davoli 2 | .\" 3 | .\" This is free documentation; you can redistribute it and/or 4 | .\" modify it under the terms of the GNU General Public License, 5 | .\" as published by the Free Software Foundation, either version 2 6 | .\" of the License, or (at your option) any later version. 7 | .\" 8 | .\" The GNU General Public License's references to "object code" 9 | .\" and "executables" are to be interpreted as the output of any 10 | .\" document formatting or typesetting system, including 11 | .\" intermediate and printed output. 12 | .\" 13 | .\" This manual is distributed in the hope that it will be useful, 14 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | .\" GNU General Public License for more details. 17 | .\" 18 | .\" You should have received a copy of the GNU General Public 19 | .\" License along with this manual; if not, write to the Free 20 | .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 21 | .\" MA 02110-1301 USA. 22 | .\" 23 | .\" Automatically generated by Pandoc 3.1.11 24 | .\" 25 | .TH "VUUMOUNT" "1" "January 2024" "VirtualSquare\-VUOS" "General Commands Manual" 26 | .SH NAME 27 | \f[CB]vuumount\f[R] \[en] unmount a filesystem or a resource 28 | .SH SYNOPSIS 29 | \f[CB]vuumount\f[R] [\f[I]options\f[R] \&...] 30 | \f[I]source\f[R] \f[I]destination\f[R] 31 | .SH DESCRIPTION 32 | \f[CB]vuumount\f[R] is just a command interface to \f[CB]umount\f[R](2). 33 | It has been designed for VUOS but can be used to run the 34 | \f[CB]umount\f[R] system call directly, without all the other management 35 | actions provided by \f[CB]umount\f[R](8). 36 | \f[CB]vuumount\f[R] is not setuid root (viceversa \f[CB]umount\f[R] is 37 | setuid root). 38 | .SH OPTIONS 39 | .TP 40 | \f[CB]\-h\f[R], \f[CB]\-\-help\f[R] 41 | Print a short help message and exit. 42 | .TP 43 | \f[CB]\-f\f[R], \f[CB]\-\-force\f[R] 44 | force unmount (e.g.\ in case of an unreachable NFS system) 45 | .TP 46 | \f[CB]\-d\f[R], \f[CB]\-\-detach\-loop\f[R] 47 | if mounted loop device, also free this loop device 48 | .SH SEE ALSO 49 | umvu(1), vu_insmod(1), vu_lsmod(1), vu_rmmod(1), vumount(1), udebug(1) 50 | .SH AUTHOR 51 | VirtualSquare. 52 | Project leader: Renzo Davoli 53 | -------------------------------------------------------------------------------- /man/vuumount.1.md: -------------------------------------------------------------------------------- 1 | 25 | # NAME 26 | 27 | `vuumount` -- unmount a filesystem or a resource 28 | 29 | # SYNOPSIS 30 | 31 | `vuumount` [*options* ...] *source* *destination* 32 | 33 | # DESCRIPTION 34 | 35 | `vuumount` is just a command interface to `umount`(2). 36 | It has been designed for VUOS but can be used to run the `umount` 37 | system call directly, without all the other management actions provided by 38 | `umount`(8). `vuumount` is not setuid root (viceversa `umount` is setuid root). 39 | 40 | # OPTIONS 41 | 42 | `-h`, `--help` 43 | : Print a short help message and exit. 44 | 45 | `-f`, `--force` 46 | : force unmount (e.g. in case of an unreachable NFS system) 47 | 48 | `-d`, `--detach-loop` 49 | : if mounted loop device, also free this loop device 50 | 51 | 52 | # SEE ALSO 53 | umvu(1), vu_insmod(1), vu_lsmod(1), vu_rmmod(1), vumount(1), udebug(1) 54 | 55 | # AUTHOR 56 | 57 | VirtualSquare. Project leader: Renzo Davoli 58 | -------------------------------------------------------------------------------- /scripts/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | set(VU_SYSCALL_CONF ${PROJECT_SOURCE_DIR}/vu_syscalls.conf) 4 | set(VU_SCRIPT_PATH ${PROJECT_SOURCE_DIR}/scripts) 5 | 6 | add_custom_target(Dynamic_Sources ALL 7 | DEPENDS ${VU_SYSCALL_DEFS} ${VU_ARCHTABLE} ${SYSCALL_NR_COMPAT_H} ${VU_SYSNAMES} ${VU_SYSTABLE} ${R_TABLE_H}) 8 | add_custom_command(OUTPUT ${VU_DYN_HEADER_PATH} 9 | COMMAND mkdir ${VU_DYN_HEADER_PATH}) 10 | add_custom_command(OUTPUT ${VU_DYN_SOURCE_PATH} 11 | COMMAND mkdir ${VU_DYN_SOURCE_PATH}) 12 | 13 | execute_process(COMMAND ${VU_SCRIPT_PATH}/syscall_deps.sh ${CMAKE_C_COMPILER} 14 | OUTPUT_VARIABLE SYSCALL_DEPS) 15 | 16 | # syscall_defs.h 17 | add_custom_command(OUTPUT ${VU_SYSCALL_DEFS} 18 | COMMAND ${VU_SCRIPT_PATH}/syscall_defs_gen.py ${VU_SYSCALL_CONF} > ${VU_SYSCALL_DEFS} 19 | COMMENT "Populating VU syscall list" 20 | DEPENDS ${VU_SYSCALL_CONF} ${VU_DYN_HEADER_PATH}) 21 | 22 | # r_table.h 23 | add_custom_command(OUTPUT ${R_TABLE_H} 24 | COMMAND ${VU_SCRIPT_PATH}/r_table_gen.sh ${CMAKE_C_COMPILER} ${VU_SCRIPT_PATH} > ${R_TABLE_H} 25 | COMMENT "Generating r_table" 26 | DEPENDS ${VU_DYN_HEADER_PATH} ${SYSCALL_DEPS}) 27 | 28 | # syscall_nr_compat_gen.h 29 | add_custom_command(OUTPUT ${SYSCALL_NR_COMPAT_H} 30 | COMMAND ${VU_SCRIPT_PATH}/syscall_nr_compat_gen.py ${VU_SYSCALL_CONF} > ${SYSCALL_NR_COMPAT_H} 31 | COMMENT "Generating syscall NR compat list" 32 | DEPENDS ${VU_SYSCALL_CONF} ${VU_DYN_HEADER_PATH}) 33 | 34 | # syscall_names.c 35 | add_custom_command(OUTPUT ${VU_SYSNAMES} 36 | COMMAND ${VU_SCRIPT_PATH}/syscall_names_gen.sh ${CMAKE_C_COMPILER} ${VU_SCRIPT_PATH} > ${VU_SYSNAMES} 37 | COMMENT "Generating syscall names table" 38 | DEPENDS ${VU_DYN_SOURCE_PATH} ${SYSCALL_DEPS}) 39 | 40 | # arch_table.c 41 | add_custom_command(OUTPUT ${VU_ARCHTABLE} 42 | COMMAND ${VU_SCRIPT_PATH}/archtable_gen.py ${ARCH} ${VU_SYSCALL_CONF} > ${VU_ARCHTABLE} 43 | COMMENT "Generating architecture table" 44 | DEPENDS ${VU_SYSCALL_CONF} ${VU_DYN_SOURCE_PATH}) 45 | 46 | # syscall_table.c 47 | add_custom_command(OUTPUT ${VU_SYSTABLE} 48 | COMMAND ${VU_SCRIPT_PATH}/syscall_table_gen.py ${VU_SYSCALL_CONF} > ${VU_SYSTABLE} 49 | COMMENT "Generating VU syscall table" 50 | DEPENDS ${VU_SYSCALL_CONF} ${VU_DYN_SOURCE_PATH}) 51 | 52 | -------------------------------------------------------------------------------- /scripts/archtable_gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | from os import path, chdir 4 | 5 | def usage(): 6 | print(f"{sys.argv[0]}: the input should be vu_syscalls.conf") 7 | 8 | if len(sys.argv) < 2 or not path.isfile(sys.argv[1]): 9 | usage() 10 | sys.exit(1) 11 | 12 | # Parse vu_syscalls.conf 13 | vu_syscalls = dict() 14 | vu_sysargs = dict() 15 | vvu_sysargs = dict() 16 | with open(sys.argv[1]) as f: 17 | for line in f: 18 | line = line.strip() 19 | if not line.startswith('#'): 20 | um_syscall_list = line.split(':') 21 | if len(um_syscall_list) > 1: 22 | um_syscall = um_syscall_list[0].split(',') 23 | value = um_syscall[0].strip() 24 | value = value.split('/')[0].strip() 25 | if value.startswith('-'): 26 | value = value[1:].strip() 27 | for s in um_syscall: 28 | sys_arg = s.split('/') 29 | vsysname = sys_arg[0].strip() 30 | if vsysname.startswith('-'): 31 | vsysname = vsysname[1:].strip() 32 | if len(sys_arg) > 1: 33 | vvu_sysargs[vsysname] = sys_arg[1].strip() 34 | else: 35 | for s in um_syscall: 36 | vu_syscalls[s.split('/')[0].strip()] = value 37 | for s in um_syscall: 38 | sys_arg = s.split('/') 39 | if len(sys_arg) > 1: 40 | vu_sysargs[sys_arg[0].strip()] = sys_arg[1].strip() 41 | 42 | # Parse and output 43 | footer = "};\n" 44 | print ('''#include 45 | #include 46 | 47 | /*This table has been autogenerated! */ 48 | const uint16_t vu_arch_table[SYSCALL_NR_OVERESTIMATION] = {''') 49 | for syscall in sorted(vu_syscalls): 50 | print(f"\t#ifdef __NR_{syscall}") 51 | print(f"\t\t[__NR_{syscall}] = __VU_{vu_syscalls[syscall]},") 52 | print("\t#endif") 53 | print(footer); 54 | 55 | print('const uint8_t vu_arch_args[SYSCALL_NR_OVERESTIMATION] = {') 56 | for syscall in sorted(vu_sysargs): 57 | print(f"\t#ifdef __NR_{syscall}") 58 | print(f"\t\t[__NR_{syscall}] = 0{vu_sysargs[syscall]},") 59 | print("\t#endif") 60 | print(footer); 61 | 62 | print('''const uint8_t vvu_arch_args[VVU_NR_SYSCALLS] = { 63 | \t[0] = 0,''') 64 | for syscall in sorted(vvu_sysargs): 65 | print(f"\t[-__VVU_{syscall}] = 0{vvu_sysargs[syscall]},") 66 | print(footer); 67 | 68 | -------------------------------------------------------------------------------- /scripts/r_table_gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | import os 4 | 5 | syscall_names = [] 6 | for line in sys.stdin: 7 | fields = line.split() 8 | if len(fields) == 2 and fields[0] == '#define': 9 | name = fields[1] 10 | if name[:5] == '__NR_': 11 | syscall_names.append(name[5:]) 12 | 13 | print( 14 | '''#ifndef R_TABLE_H 15 | #define R_TABLE_H 16 | 17 | /* THIS FILE HAS BEEN AUTOMATICALLY GENERATED, DO NOT EDIT */ 18 | 19 | #include 20 | #include 21 | 22 | extern long (*native_syscall)(); 23 | ''') 24 | 25 | for f in sorted(syscall_names): 26 | print(f'#define r_{f}(...) native_syscall(__NR_{f}, ## __VA_ARGS__)') 27 | 28 | print( 29 | ''' 30 | #include 31 | #include 32 | 33 | #endif'''); 34 | 35 | -------------------------------------------------------------------------------- /scripts/r_table_gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "#include" | $1 -dN -E - | $2/r_table_gen.py 4 | -------------------------------------------------------------------------------- /scripts/syscall_defs_gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | import os.path 4 | 5 | if len(sys.argv) < 2 or not os.path.isfile(sys.argv[1]): 6 | print(f"{sys.argv[0]}: the input should be 'vu_syscalls.conf'") 7 | sys.exit(1) 8 | 9 | # Parse and output 10 | 11 | code = '''#ifndef __VU_SYSCALL_DEFS__ 12 | #define __VU_SYSCALL_DEFS__ 13 | 14 | /* Arch independent definitions */ 15 | 16 | ''' 17 | vu_syscall_max_namelen = 0 18 | vvu_syscall_max_namelen = 0 19 | 20 | with open(sys.argv[1]) as f: 21 | counter = 0 22 | vcounter = 1 23 | mcounter = 0 24 | for line in f: 25 | line = line.strip() 26 | if line == "BUILTIN": 27 | mcounter = counter 28 | elif not line.startswith('#'): 29 | syscall_line = line.split(':') 30 | if len(syscall_line) > 1: 31 | syscall = syscall_line[0].strip() 32 | if len(syscall) > 1: 33 | syscall = syscall.split(',')[0].strip() 34 | syscall = syscall.split('/')[0] 35 | if syscall.startswith('-'): 36 | syscall = syscall[1:].strip() 37 | syscall_len = len(syscall) 38 | if syscall_len > vvu_syscall_max_namelen: 39 | vvu_syscall_max_namelen = syscall_len 40 | code += f"#define __VVU_{syscall} {-vcounter}\n" 41 | vcounter += 1 42 | else: 43 | syscall_len = len(syscall) 44 | if syscall_len > vu_syscall_max_namelen: 45 | vu_syscall_max_namelen = syscall_len 46 | code += f"#define __VU_{syscall} {counter}\n" 47 | counter += 1 48 | if mcounter == 0: 49 | mcounter = counter 50 | code += f"\n#define VU_NR_SYSCALLS {counter}" 51 | code += f"\n#define VU_NR_MODULE_SYSCALLS {mcounter}" 52 | code += f"\n#define VVU_NR_SYSCALLS {vcounter}" 53 | code += f"\n#define VU_SYSCALL_MAX_NAMELEN {vu_syscall_max_namelen}" 54 | code += f"\n#define VVU_SYSCALL_MAX_NAMELEN {vvu_syscall_max_namelen}" 55 | code += "\n\n#endif" 56 | print(code) 57 | -------------------------------------------------------------------------------- /scripts/syscall_deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # compute and print on stdout all the (nested_ dependencies of "#include" 4 | 5 | echo "#include" | gcc -M -E - | \ 6 | sed ':a; N; s/\n/ /; ta' | sed 's/^-: *//;s/ *$//;s/\\//g;s/ */;/g' 7 | 8 | # sed magics: first sed=join all the lines 9 | # second sed: delete leading -: and trailing spaces, delete all \ and change any sequence of spaces to ; 10 | -------------------------------------------------------------------------------- /scripts/syscall_names_gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | import os 4 | 5 | syscall_names = [] 6 | for line in sys.stdin: 7 | fields = line.split() 8 | if len(fields) == 3 and fields[0] == '#define': 9 | name = fields[1] 10 | if name[:5] == '__NR_': 11 | syscall_names.insert(0, name[5:]) 12 | 13 | print('''#include 14 | #include 15 | struct syscallname { 16 | int sysno; 17 | char *syscall_name; 18 | struct syscallname *next; 19 | }; 20 | 21 | static struct syscallname syscallname_table[] = {''') 22 | for name in syscall_names: 23 | print(f'''#ifdef __NR_{name} 24 | {{__NR_{name}, "{name}", NULL}}, 25 | #endif''') 26 | print('};') 27 | print(''' 28 | #define SYSCALLNAME_TABLE_LEN (sizeof(syscallname_table) / sizeof(*syscallname_table)) 29 | #define SYSCALLNAME_HASHMASK 255 30 | static struct syscallname *syscall_name_hash[SYSCALLNAME_HASHMASK + 1]; 31 | 32 | const char *syscallname(int sysno) { 33 | int key = sysno & SYSCALLNAME_HASHMASK; 34 | struct syscallname *scan; 35 | for (scan = syscall_name_hash[key]; scan != NULL; scan = scan->next) 36 | if (sysno == scan->sysno) 37 | return scan->syscall_name; 38 | return "unknown"; 39 | } 40 | 41 | __attribute__((constructor)) 42 | static void init (void) { 43 | unsigned int i; 44 | for (i = 0; i < SYSCALLNAME_TABLE_LEN; i++) { 45 | int key = syscallname_table[i].sysno & SYSCALLNAME_HASHMASK; 46 | syscallname_table[i].next = syscall_name_hash[key]; 47 | syscall_name_hash[key] = &syscallname_table[i]; 48 | } 49 | }''') 50 | -------------------------------------------------------------------------------- /scripts/syscall_names_gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "#include" | $1 -dD -E - | $2/syscall_names_gen.py 4 | -------------------------------------------------------------------------------- /scripts/syscall_nr_compat_gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | import os 4 | 5 | ''' 6 | generate fake __NR_xxxx constants for syscalls not defined in the current arch 7 | so that code like: 8 | if (... == __NR_xxxx) 9 | or 10 | switch (...) { 11 | case __NR_xxxx 12 | is just skipped. No arch #ifdef are required. 13 | ''' 14 | __NR__first = 1000000000 15 | 16 | if len(sys.argv) < 2 or not os.path.isfile(sys.argv[1]): 17 | print(f"{sys.argv[0]}: the input should be 'vu_syscalls.conf'") 18 | sys.exit(1) 19 | 20 | # Parse and output 21 | 22 | def acceptable(string): 23 | if string.startswith('#') or \ 24 | string.startswith('-') or \ 25 | string.startswith('null') or \ 26 | string.startswith('BUILTIN'): 27 | return False 28 | else: 29 | return True 30 | 31 | def get_syscall_names(string): 32 | syscall_list = [] 33 | s = string.rpartition(':') 34 | if ':' == s[1]: 35 | seq = s[0].split(', ') 36 | for syscall in seq: 37 | parts = syscall.rpartition('/') 38 | if parts[1] == '/': 39 | syscall_list.append(parts[0]) 40 | else: 41 | syscall_list.append(parts[2]) 42 | return syscall_list 43 | 44 | syscall_list = [] 45 | with open(sys.argv[1]) as f: 46 | for line in f: 47 | if acceptable(line): 48 | syscall_list += get_syscall_names(line) 49 | 50 | print('''#ifndef __SYSCALL_NR_COMPAT_H 51 | #define __SYSCALL_NR_COMPAT_H 52 | 53 | /* Generate compat __NR for missing system calls */ 54 | 55 | ''') 56 | 57 | for syscall_nr,syscall_def in enumerate(syscall_list, start = __NR__first): 58 | print(f'''#ifndef __NR_{syscall_def} 59 | # define __NR_{syscall_def} {syscall_nr} 60 | #endif\n''') 61 | 62 | print(f'#define __NR__first {__NR__first}') 63 | print(f'#define __NR__last {__NR__first + len(syscall_list) - 1}') 64 | print('#define __NR__is_unsupp(X) ((X) >= __NR__first && (X) <= __NR__last)'); 65 | print('\n\n#endif') 66 | 67 | -------------------------------------------------------------------------------- /scripts/syscall_table_gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | import os.path 4 | 5 | 6 | def usage(): 7 | print(f"{sys.argv[0]}: the input should be 'vu_syscalls.conf'") 8 | 9 | if len(sys.argv) < 2 or not os.path.isfile(sys.argv[1]): 10 | usage() 11 | sys.exit(1) 12 | 13 | # Parse and output 14 | header = ''' 15 | #include 16 | #include 17 | 18 | /* Architecture INdependent table, 19 | * this is unique and stable for UMView reference */ 20 | 21 | /*This table has been autogenerated from vu_syscalls.conf */ 22 | 23 | ''' 24 | print(header) 25 | 26 | cset = set() 27 | wiset = set() 28 | wdset = set() 29 | woset = set() 30 | vwset = set() 31 | 32 | table = "const struct syscall_tab_entry vu_syscall_table[] = {\n" 33 | vtable = "const struct vsyscall_tab_entry vvu_syscall_table[] = {\n" 34 | ntable = "const char *vu_syscall_names[] = {\n" 35 | vntable = "const char *vvu_syscall_names[] = {\n" 36 | with open(sys.argv[1]) as f: 37 | for line in f: 38 | line = line.strip() 39 | if not line.startswith('#'): 40 | linesplit = line.split(':', maxsplit = 1) 41 | if len(linesplit) > 1: 42 | s, args = linesplit 43 | s = s.split(',')[0].strip() 44 | s = s.split('/')[0].strip() 45 | if s.startswith('-'): 46 | s = s[1:].strip() 47 | stag = "__VVU_" + s 48 | args = args.split(',') 49 | c = "choice_" + args[0].strip() 50 | w = "vw_" + args[1].strip() 51 | vtable += f"\t[-{stag}] = {{{c}, {w}}},\n" 52 | vntable += f"\t[-{stag}] = \"{s}\",\n" 53 | cset.add(c) 54 | vwset.add(w) 55 | else: 56 | stag = "__VU_" + s 57 | args = args.split(',') 58 | while len(args) < 6: 59 | args.append("NULL") 60 | c = "choice_" + args[0].strip() 61 | win = "wi_" + args[1].strip() 62 | wd = "wd_" + args[2].strip() 63 | wout = "wo_" +args[3].strip() 64 | table += f"\t[{stag}] = {{{c}, {win}, {wd}, {wout}}},\n" 65 | ntable += f"\t[{stag}] = \"{s}\",\n" 66 | cset.add(c) 67 | wiset.add(win) 68 | wdset.add(wd) 69 | woset.add(wout) 70 | table += "};\n" 71 | vtable += "};\n" 72 | ntable += "};\n" 73 | vntable += "};\n" 74 | 75 | for f in sorted(cset): 76 | print(f"choicef_t {f};") 77 | for f in sorted(wiset): 78 | print(f"wrapf_t {f};") 79 | for f in sorted(wdset): 80 | print(f"wrapf_t {f};") 81 | for f in sorted(woset): 82 | print(f"wrapf_t {f};") 83 | for f in sorted(vwset): 84 | print(f"wrapf_t {f};") 85 | print() 86 | print(table) 87 | print(ntable) 88 | print(vtable) 89 | print(vntable) 90 | -------------------------------------------------------------------------------- /test_modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include_directories(${VU_HEADERS}) 4 | set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) 5 | 6 | file(GLOB VU_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 7 | 8 | foreach(VU_MOD ${VU_MODULES}) 9 | string(REPLACE ".c" "" VU_MOD_FILE ${VU_MOD}) 10 | get_filename_component(VU_MOD_TARGET ${VU_MOD_FILE} NAME) 11 | add_library(${VU_MOD_TARGET} SHARED ${VU_MOD}) 12 | set_target_properties(${VU_MOD_TARGET} PROPERTIES PREFIX "") 13 | install(TARGETS ${VU_MOD_TARGET} LIBRARY DESTINATION ${MODULES_INSTALL_PATH}) 14 | endforeach(VU_MOD) 15 | 16 | target_link_libraries(unrealinfofs vumod) 17 | -------------------------------------------------------------------------------- /test_modules/unrealsock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | VU_PROTOTYPES(unrealsock) 35 | 36 | struct vu_module_t vu_module = { 37 | .name = "unrealsock", 38 | .description = "tcp-ip stack server side" 39 | }; 40 | 41 | static struct vuht_entry_t *ht[3]; 42 | static int afs[3] = {AF_INET, AF_INET6, AF_NETLINK}; 43 | 44 | void *vu_unrealsock_init(void) { 45 | struct vu_service_t *s = vu_mod_getservice(); 46 | int i; 47 | 48 | #pragma GCC diagnostic push 49 | #pragma GCC diagnostic ignored "-Wincompatible-pointer-types" 50 | vu_syscall_handler(s, socket) = socket; 51 | vu_syscall_handler(s, bind) = bind; 52 | vu_syscall_handler(s, connect) = connect; 53 | vu_syscall_handler(s, listen) = listen; 54 | vu_syscall_handler(s, accept4) = accept4; 55 | vu_syscall_handler(s, getsockname) = getsockname; 56 | vu_syscall_handler(s, getpeername) = getpeername; 57 | vu_syscall_handler(s, sendto) = sendto; 58 | vu_syscall_handler(s, recvfrom) = recvfrom; 59 | vu_syscall_handler(s, shutdown) = shutdown; 60 | vu_syscall_handler(s, setsockopt) = setsockopt; 61 | vu_syscall_handler(s, getsockopt) = getsockopt; 62 | vu_syscall_handler(s, epoll_ctl) = epoll_ctl; 63 | vu_syscall_handler(s, close) = close; 64 | #pragma GCC diagnostic pop 65 | 66 | for (i = 0; i < 3; i++) 67 | ht[i] = vuht_add(CHECKSOCKET, &afs[i], sizeof(int), s, 0, NULL, NULL); 68 | return NULL; 69 | } 70 | 71 | int vu_unrealsock_fini(void *private) { 72 | int i; 73 | for (i = 0; i < 3; i++) { 74 | if (ht[i] && vuht_del(ht[i], MNT_FORCE) == 0) 75 | ht[i] = NULL; 76 | } 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /umvu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | set(UMVU_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src) 4 | set(UMVU_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include) 5 | 6 | set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) 7 | set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) 8 | 9 | file(GLOB_RECURSE UMVU_SOURCES ${UMVU_SOURCES}/*.c) 10 | list(APPEND UMVU_SOURCES ${VU_DYN_SOURCES}) 11 | 12 | include_directories(${UMVU_HEADERS} ${VU_DYN_HEADER_PATH} ${VU_HEADERS}) 13 | add_executable(umvu ${UMVU_SOURCES}) 14 | set_property(TARGET umvu PROPERTY ENABLE_EXPORTS 1) 15 | target_link_libraries(umvu pthread dl) 16 | 17 | install(TARGETS umvu 18 | RUNTIME DESTINATION bin) 19 | -------------------------------------------------------------------------------- /umvu/include/arch_table.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_TABLE_H 2 | #define _ARCH_TABLE_H 3 | #include 4 | #include 5 | 6 | /* header file for the file arch_table.c which is automatically generated 7 | during the building/compilation process. The source file to generate 8 | arch_table.c is vu_syscall.conf */ 9 | 10 | #define SYSCALL_NR_OVERESTIMATION 512 11 | 12 | /* This is the mapping between the system calls numbers as defined 13 | by the kernel for the current architecure and the correspondant 14 | vuos system call number. 15 | Several *real* system calls can be unified, processed and handled by 16 | modules as one vuos systems call. 17 | e.g. stat, lstat, fstat, fstatat, newfstatat: all are handled as __VU_lstat */ 18 | extern const uint16_t vu_arch_table[]; 19 | 20 | /* vu_arch_args defines for each system call provided by the architecure: 21 | * i) the number of arguments 22 | * ii) if the syscall has a pathname arg, and which is the index of the path arg 23 | * iii) it if is a l- symbolic link opaque call (like lchown lstat) 24 | * iv) if it is a -at system call (including a dirfd arg, e.g. openat, fstatat) 25 | * 26 | * all this information is stored in a single byte: 27 | * +-+-+-+-+-+-+-+-+ 28 | * |typ|path |nargs| 29 | * +-+-+-+-+-+-+-+-+ 30 | * 31 | * typ = 01 l-call 32 | * 02 -at call 33 | * 03 *special* cases e.g. -at calls supporting AT_SYMLINK_NOFOLLOW 34 | * path = index of the path arg (of dirfd if this is a -at call) 35 | * nargs = numebr of args. 36 | * 37 | * Writing this value in octal the first digit is typ, the second is path and the third is nargs. 38 | * vu_arch_table[__NR_write] = 03; // 3 args, no path 39 | * vu_arch_table[__NR_stat] = 012; // 2 args, the first is the path 40 | * vu_arch_table[__NR_lstat] = 0112; // 2 args, the first is the path, do not follow links 41 | * vu_arch_table[__NR_mkdirat] = 0212; // 2 args, at-type, the first is the dirfd, so the second is the path 42 | * vu_arch_table[__NR_faccessat] = 314; // 2 args, at-type, the first is dirfd, 43 | * AT_SYMLINK_NOFOLLOW is a supported flag 44 | */ 45 | 46 | extern const uint8_t vu_arch_args[]; 47 | 48 | /* virtual system calls are those provided by vuos for its services. 49 | e.g. insmod, rmmod, vuctl, msocket. umvu uses negative syscall numbers for virtual system calls */ 50 | /* vvu_arch_args provides for each *virtual* system call the same information 51 | as vu_arch_table. The elements of vvu_arch_args has the same structure of vu_arch_table. */ 52 | extern const uint8_t vvu_arch_args[]; 53 | 54 | #define ARCH_TYPE_SYMLINK_NOFOLLOW 1 55 | #define ARCH_TYPE_IS_AT 2 56 | #define ARCH_TYPE_IS_EXCEPTION 3 57 | 58 | /* utility functions to read the (bit)fields of vu_arch_args and vvu_arch_args elements */ 59 | 60 | static inline int vu_arch_table_nargs(int syscall_number) { 61 | int argstag = vu_arch_args[syscall_number]; 62 | return (argstag & 0x7); 63 | } 64 | 65 | static inline int vu_arch_table_type(int syscall_number) { 66 | int argstag = vu_arch_args[syscall_number]; 67 | return argstag >> 6; 68 | } 69 | 70 | static inline int vu_arch_table_patharg(int syscall_number) { 71 | int argstag = vu_arch_args[syscall_number]; 72 | return ((argstag >> 3) & 0x7) - 1; 73 | } 74 | 75 | static inline int vvu_arch_table_nargs(int syscall_number) { 76 | int argstag = vvu_arch_args[syscall_number]; 77 | return (argstag & 0x7); 78 | } 79 | 80 | static inline int vvu_arch_table_type(int syscall_number) { 81 | int argstag = vvu_arch_args[syscall_number]; 82 | return argstag >> 6; 83 | } 84 | 85 | static inline int vvu_arch_table_patharg(int syscall_number) { 86 | int argstag = vvu_arch_args[syscall_number]; 87 | return ((argstag >> 3) & 0x7) - 1; 88 | } 89 | #endif 90 | -------------------------------------------------------------------------------- /umvu/include/canonicalize.h: -------------------------------------------------------------------------------- 1 | #ifndef CANONICALIZE_H 2 | #define CANONICALIZE_H 3 | 4 | #include 5 | #include 6 | 7 | /* canonicalize provides extended (and optimized) implementations of 8 | realpath(3) and canonicalize_file_name(3). 9 | 10 | canon_realpath can used in place of realpath, the argument named flags 11 | can configure the behavior as explained for the constants here below 12 | 13 | canon_realpath_dup provides the same extensions with respect to 14 | canonicalize_file_name. 15 | */ 16 | 17 | char *canon_realpath(const char *path, char *resolved_path, int flags, void *private); 18 | 19 | char *canon_realpath_dup(const char *path, int flags, void *private); 20 | 21 | /* if FOLLOWLINK == 0 and pathname is a symlink then it returns 22 | the realpath of the link itself instead of the realpath of 23 | the file it refers to */ 24 | #define FOLLOWLINK 1 25 | /* if PERMIT_NONEXISTENT_LEAF == 1 the pathname may refer to a non-existent 26 | file (inside an existing directory) */ 27 | #define PERMIT_NONEXISTENT_LEAF 2 28 | /* if PERMIT_EMPTY_PATH == 1 and pathname is an empty string it returns the 29 | cwd (or what the getcwd helper function returns). 30 | if PERMIT_EMPTY_PATH == 0 and pathname is an empty string realpath returns -1/ENOENT */ 31 | #define PERMIT_EMPTY_PATH 4 32 | /* if CHECK_S_IXGRP_ON_DIRS == 1 canon_realpath returns -1/EACCES if S_IXGRP is 33 | not set in the return value of lmode for one of the directories in the path 34 | (unsupported) */ 35 | #define CHECK_S_IXALL_ON_DIRS 8 36 | 37 | #define S_IXALL (S_IXUSR | S_IXGRP | S_IXOTH) 38 | 39 | /* canonicalize in virtual environments: 40 | virtual-world consistent re-definition of functions needed for canonicalize */ 41 | 42 | struct canon_ops { 43 | /* link opaque (lstat) mode_t definition of file type, 0 for non-existent file */ 44 | /* when CHECK_S_IXALL_ON_DIRS == 1, S_IXALL means search permission on directories. 45 | if CHECK_S_IXALL_ON_DIRS == 1 and at least one of S_IXALL bits is unset for lmode's 46 | return value then any further path-resolution step inside that directory is forbidden 47 | and realpath returns -1/EACCES */ 48 | mode_t (*lmode) (const char *pathname, void *private); 49 | 50 | /* same as readlink(2) */ 51 | ssize_t (*readlink) (const char *pathname, char *buf, size_t bufsiz, void *private); 52 | 53 | /* load in pathname the current pwd, return 0 upon success */ 54 | int (*getcwd) (char *pathname, size_t size, void *private); 55 | 56 | /* load in pathname the current root relative to /, return 0 upon success */ 57 | int (*getroot) (char *pathname, size_t size, void *private); 58 | }; 59 | 60 | void canon_setops(struct canon_ops *ops); 61 | #endif 62 | 63 | -------------------------------------------------------------------------------- /umvu/include/carrot.h: -------------------------------------------------------------------------------- 1 | #ifndef CARROT_H 2 | #define CARROT_H 3 | 4 | #include 5 | 6 | /* this is a helper module for hashtable. 7 | Hashtable try to match incrementally the right module/service. 8 | a match can be more specific (e.g. a subdirectory) 9 | can have a more recent epoch and may have exceptions. 10 | Checking for exceptions can be computationally expensive. 11 | It is useless if the match is then overridden by a more specific, 12 | more recent match. 13 | So, the incremental matching process stores in a "carrot" the list of matches 14 | that can have exceptions. 15 | When the incremental matching process completes, the carrot contains all 16 | the possible matches if the exceptions are confirmed or not. */ 17 | 18 | struct vuht_entry_t; 19 | struct carrot_t; 20 | 21 | /* Functions */ 22 | void carrot_free(struct carrot_t *old); 23 | /* Create the list of possible ht elements to be returned. The list is created according to the timestamp. */ 24 | struct carrot_t *carrot_insert(struct carrot_t *head, struct vuht_entry_t *elem, epoch_t time, 25 | int (*has_exception)(struct vuht_entry_t *elem)); 26 | 27 | /* Delete a specific element from the "carrot" */ 28 | struct carrot_t *carrot_delete(struct carrot_t *head, struct vuht_entry_t *elem); 29 | 30 | /* Choose the ht element to be returned, the first confirmed match is returned.*/ 31 | struct vuht_entry_t *carrot_check(struct carrot_t *head, 32 | int (*confirm)(struct vuht_entry_t *elem, void *opaque), void *opaque); 33 | 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /umvu/include/epoch.h: -------------------------------------------------------------------------------- 1 | #ifndef _EPOCH_H 2 | #define _EPOCH_H 3 | #include 4 | 5 | /* 6 | * Each node is timestamped with its starting epoch. 7 | * After each relevant operation the timestamp is updated. 8 | * 9 | * Epoch is the key concept for layered virtualization. 10 | * each system call request generated inside the hypervisor 11 | * (guardian angels, helper threads) happens at the epoch 12 | * when that virtualization was activated (e.g. the epoch 13 | * when a file system was mounted). In this way these system 14 | * calls see the world at that time, and cen be further 15 | * virtualized. 16 | * 17 | * e.g. mount a file system in /mnt at epoch 42 18 | * mount the file system image /mnt/image on /mnt at epoch 44 19 | * open (/mnt/myfile) at epoch 50. 20 | * /mnt/myfile is in the subtree virtualized by the mount at epoch 44. 21 | * the virtualization module (e.g. vufuse) processing the 'open' request 22 | * runs at epoch 44, so if it needs to run a system call (say 23 | * lstat("/mnt/test"...), the request is managed by the virtualization 24 | * aptivated by the "mount" at epoch 42 (at epoch 44 the second "mount" 25 | * did not exist). 26 | */ 27 | 28 | typedef uint64_t epoch_t; 29 | 30 | /* function definitions */ 31 | 32 | /* a relevant event happened. epoch is incremented by one tick */ 33 | void update_vepoch(void); 34 | 35 | /* define a new working/virtual epoch for the current thread, 36 | it returns the previous epoch (to restore the value in a second time */ 37 | epoch_t set_vepoch(epoch_t e); 38 | 39 | /* return the working/virtual epoch for the current thread, */ 40 | epoch_t get_vepoch(void); 41 | 42 | /* return the current (global) epoch, the *now* epoch */ 43 | epoch_t get_epoch(void); 44 | 45 | /* set the current (global) epoch, to the current/global/ *now* epoch */ 46 | epoch_t update_epoch(void); 47 | 48 | /* return the service_epoch if it is consistent with the current 49 | working/virtual epoch of calling thread. 50 | It returns 0 if service_epoch is too new, so this 51 | 'service'/virtualization did not exist at the current/working/virtual epoch */ 52 | epoch_t matching_epoch(epoch_t service_epoch); 53 | 54 | #endif 55 | 56 | -------------------------------------------------------------------------------- /umvu/include/linux_32_64.h: -------------------------------------------------------------------------------- 1 | #ifndef LINUX_32_64_H 2 | #define LINUX_32_64_H 3 | #include 4 | 5 | /* 32/64 compatibility issues. 6 | vuos always uses the 64bits system calls. 7 | vu_* and r_vu_* refer to the 64 bit implementation */ 8 | 9 | /* blame glibc for this */ 10 | #if __WORDSIZE == 32 11 | #define vu_stat stat64 12 | #define vu_lstat lstat64 13 | #define vu_fstat fstat64 14 | #define vu_lstat lstat64 15 | #define vu_fstat fstat64 16 | #define vu_statfs statfs64 17 | #define vu_fstatfs fstatfs64 18 | #define vu_fstatat fstatat64 19 | #define r_vu_stat r_stat64 20 | #define r_vu_lstat r_lstat64 21 | #define r_vu_fstat r_fstat64 22 | #define r_vu_lstat r_lstat64 23 | #define r_vu_fstat r_fstat64 24 | #define r_vu_statfs r_statfs64 25 | #define r_vu_fstatfs r_fstatfs64 26 | #define r_vu_fstatat r_fstatat64 27 | #else 28 | /* 64 bit architectures */ 29 | #define vu_stat stat 30 | #define vu_lstat lstat 31 | #define vu_fstat fstat 32 | #define vu_lstat lstat 33 | #define vu_fstat fstat 34 | #define vu_statfs statfs 35 | #define vu_fstatfs fstatfs 36 | #define vu_fstatat fstatat 37 | #define r_vu_stat r_stat 38 | #define r_vu_lstat r_lstat 39 | #define r_vu_fstat r_fstat 40 | #define r_vu_lstat r_lstat 41 | #define r_vu_fstat r_fstat 42 | #define r_vu_statfs r_statfs 43 | #define r_vu_fstatfs r_fstatfs 44 | #define r_vu_fstatat r_fstatat 45 | #endif 46 | 47 | /* for 32 bit hosts missing in standard include files */ 48 | struct linux_dirent { 49 | unsigned long d_ino; /* Inode number */ 50 | unsigned long d_off; /* Offset to next linux_dirent */ 51 | unsigned short d_reclen; /* Length of this linux_dirent */ 52 | char d_name[]; /* Filename (null-terminated) */ 53 | /* length is actually (d_reclen - 2 - 54 | offsetof(struct linux_dirent, d_name)) */ 55 | /* 56 | char pad; // Zero padding byte 57 | char d_type; // File type (only since Linux 58 | // 2.6.4); offset is (d_reclen - 1) 59 | */ 60 | }; 61 | 62 | void dirent64_to_dirent(void* buf, int count); 63 | #endif 64 | -------------------------------------------------------------------------------- /umvu/include/mountflags.h: -------------------------------------------------------------------------------- 1 | #ifndef MOUNTFLAGS_H 2 | #define MOUNTFLAGS_H 3 | 4 | /* translate all mount flags into options so that modules can parse options only */ 5 | /* currently used by hashtable to set up the mount line (a' la /proc/mounts) */ 6 | 7 | /* opts == NULL: return the length of the char array required 8 | else: translate mountflags as a comma separated string of options in opts */ 9 | 10 | size_t mountflags2opts(unsigned long mountflags, char *opts, size_t optslen); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /umvu/include/path_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef PATH_UTILS_H 2 | #define PATH_UTILS_H 3 | 4 | /* helper function to get a canonicalized path arguemnts from the user process. 5 | return values, if not NULL, are dynamically allocated strings, so their memory must be 6 | deallocated by free(3) */ 7 | 8 | char *get_path(int dirfd, syscall_arg_t addr, struct stat *buf, int flags, uint8_t *need_rewrite, int nested); 9 | 10 | /* get the canonicalized path of the system call described is sd. It uses arch_table to 11 | process -at calls, to decide if the system call follow synbolic links or not etc. */ 12 | char *get_syspath(struct syscall_descriptor_t *sd, struct stat *buf, uint8_t *need_rewrite); 13 | /* the same as above for nested syscalls */ 14 | char *get_nested_syspath(int syscall_number, syscall_arg_t *args, struct stat *buf, uint8_t *need_rewrite); 15 | 16 | /* the same as above for virtual syscalls */ 17 | char *get_vsyspath(struct syscall_descriptor_t *sd, struct stat *buf, uint8_t *need_rewrite); 18 | 19 | /* change the path of a system call: rewrite the path in the user process memory. 20 | The hosting kernel receives the system call request using the modified path. 21 | The new path string is stored on the stack, just below the stack pointer */ 22 | void rewrite_syspath(struct syscall_descriptor_t *sd, char *newpath); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /umvu/include/r_table_compat.h: -------------------------------------------------------------------------------- 1 | /* r_xxx compat defs for arch unsupported syscalls */ 2 | 3 | #ifndef R_TABLE_H 4 | #error "do no include r_table_compat.h, use r_table.h instead" 5 | #endif 6 | 7 | #if !defined(r_fork) && defined(__NR_clone) 8 | # define r_fork() native_syscall(__NR_clone, SIGCHLD, NULL) 9 | #endif 10 | 11 | #if !defined(r_open) && defined(__NR_openat) 12 | # define r_open(...) native_syscall(__NR_openat, AT_FDCWD, ## __VA_ARGS__) 13 | #endif 14 | 15 | #if !defined(r_lstat) 16 | # if defined(__NR_fstatat) 17 | # define r_lstat(path, buf) native_syscall(__NR_fstatat, AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW) 18 | # elif defined(__NR3264_fstatat) 19 | # define r_lstat(path, buf) native_syscall(__NR3264_fstatat, AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW) 20 | # endif 21 | #endif 22 | 23 | #if !defined(r_readlink) && defined(__NR_readlinkat) 24 | # define r_readlink(...) native_syscall(__NR_readlinkat, AT_FDCWD, ## __VA_ARGS__) 25 | #endif 26 | 27 | #if !defined(r_unlink) && defined(__NR_unlinkat) 28 | # define r_unlink(pathname) native_syscall(__NR_unlinkat, AT_FDCWD, pathname, 0) 29 | #endif 30 | 31 | #if !defined(r_rmdir) && defined(__NR_unlinkat) 32 | # define r_rmdir(pathname) native_syscall(__NR_unlinkat, AT_FDCWD, pathname, AT_REMOVEDIR) 33 | #endif 34 | 35 | #if !defined(r_dup2) && defined(__NR_dup3) 36 | # define r_dup2(oldfd, newfd) (oldfd == newfd) ? newfd : native_syscall(__NR_dup3, oldfd, newfd, 0) 37 | #endif 38 | 39 | #if !defined(r_poll) && defined(__NR_ppoll) 40 | # define r_poll(fds, nfds, timeout) \ 41 | native_syscall(__NR_ppoll, fds, nfds, &(struct timespec){.tv_sec = timeout}, NULL) 42 | #endif 43 | 44 | #if !defined(r_epoll_wait) && defined(__NR_epoll_pwait) 45 | # define r_epoll_wait(epfd, events, maxevents, timeout) \ 46 | native_syscall(__NR_epoll_pwait, epfd, events, maxevents, timeout, NULL) 47 | #endif 48 | -------------------------------------------------------------------------------- /umvu/include/service.h: -------------------------------------------------------------------------------- 1 | #ifndef SERVICE_H 2 | #define SERVICE_H 3 | 4 | #include 5 | #include 6 | 7 | /* each module define a service. 8 | services are registered in the hashtable (he key is the module name */ 9 | 10 | struct vuht_entry_t; 11 | typedef long (*syscall_t)(); 12 | 13 | struct vu_service_t { 14 | // pointer to a static structure named "vu_module" defined in the module 15 | // this structure defines the name and a short description of the module 16 | // the presence of such a structure is used as a test (that the module 17 | // has been designed for vuos). 18 | struct vu_module_t *mod; 19 | // modules are loaded as dynamic library plug-ins. 20 | // this is the handle returned by dl_open 21 | void *dlhandle; 22 | // the hash table pointer of the service itself 23 | struct vuht_entry_t *service_ht; 24 | // private data of the module (modules can use this pointer as they please. 25 | void *private; 26 | // table of vu_syscalls implementation. 27 | syscall_t module_syscall[]; 28 | }; 29 | 30 | struct vuht_entry_t *vu_mod_getht(void); 31 | 32 | /* A static thread variable records the module hash table element chosen by the hypervisor, 33 | so that the module can access it */ 34 | void vu_mod_setht(struct vuht_entry_t *ht); 35 | 36 | /* hash table and epoch wrapper: 37 | * set the ht and epoch to run a service_syscall and then 38 | * restore the previous value. 39 | * usage: 40 | * VU_HTWRAP(ht, ret_value = service_syscall(ht, __VU_xxxx)(arg0, arg1...)); 41 | */ 42 | 43 | #define VU_HTWRAP(HT, X) \ 44 | do { \ 45 | struct vuht_entry_t *__sht = vu_mod_getht(); \ 46 | epoch_t __e = get_vepoch(); \ 47 | vu_mod_setht(HT); \ 48 | set_vepoch(vuht_get_vepoch(HT)); \ 49 | (X); \ 50 | set_vepoch(__e); \ 51 | vu_mod_setht(__sht); \ 52 | } while(0) 53 | 54 | 55 | /* inline function: it is here for performance. 56 | it returns the pointer of the syscall implementation.... 57 | an example of this inline usage is: 58 | retval = service_syscall(ht, __VU_read)(fd, buf, buflen); 59 | */ 60 | __attribute__((always_inline)) 61 | static inline syscall_t service_syscall(struct vuht_entry_t *ht, int vu_syscall_number) { 62 | struct vu_service_t *service = vuht_get_service(ht); 63 | return service->module_syscall[vu_syscall_number]; 64 | } 65 | 66 | /* inline function: it is here for performance. 67 | it returns the flags of the module */ 68 | __attribute__((always_inline)) 69 | static inline uint64_t service_getflags(struct vuht_entry_t *ht) { 70 | return ht ? vuht_get_service(ht)->mod->flags : 0; 71 | } 72 | #endif 73 | 74 | -------------------------------------------------------------------------------- /umvu/include/syscall_names.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSCALL_NAMES_H 2 | #define SYSCALL_NAMES_H 3 | 4 | /* header file for the file syscall_names.c which is automatically generated 5 | during the building/compilation process. The header file 6 | is pre-processed to get the names of the the system calls provided by the 7 | kernel for the current architecture. */ 8 | 9 | const char *syscallname(int sysno); 10 | #endif 11 | -------------------------------------------------------------------------------- /umvu/include/syscall_table.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYSCALL_TABLE_H_ 2 | #define _SYSCALL_TABLE_H_ 3 | /* header file for the file syscall_table.c which is automatically generated 4 | during the building/compilation process. The source file to generate 5 | arch_table.c is vu_syscall.conf */ 6 | 7 | struct syscall_descriptor_t; 8 | struct vuht_entry_t; 9 | 10 | /* a choice function processes the actual arguments of a system call request 11 | and returns the pointer to the hash table entry which is responsible to handle 12 | the request. When a choice function returns NULL it means that the request 13 | is not to be virtualized, so it is forwarded to the kernel */ 14 | typedef struct vuht_entry_t *choicef_t(struct syscall_descriptor_t *); 15 | typedef void wrapf_t(struct vuht_entry_t *, struct syscall_descriptor_t *); 16 | 17 | /* vu_syscall_table defines for each _VU_ system call: 18 | the choice function, 19 | the system call pre-processing wrapper 20 | it is evaluated before the kernel gets the system call. 21 | the system call co-processing wrapper 22 | it is evaluated while the kernel is processing the request 23 | the system call post-processing wrapper 24 | it runs when the kernel has completed the system call request 25 | */ 26 | 27 | struct syscall_tab_entry{ 28 | choicef_t *choicef; 29 | wrapf_t *wrapinf; 30 | wrapf_t *wrapduringf; 31 | wrapf_t *wrapoutf; 32 | }; 33 | 34 | struct vsyscall_tab_entry{ 35 | choicef_t *choicef; 36 | wrapf_t *wrapf; 37 | }; 38 | 39 | extern const struct syscall_tab_entry vu_syscall_table[]; 40 | extern const struct vsyscall_tab_entry vvu_syscall_table[]; 41 | 42 | /* these arrays provide the names of _VU_ system calls (for debugging purposes) */ 43 | extern const char *vu_syscall_names[]; 44 | extern const char *vvu_syscall_names[]; 45 | #endif 46 | -------------------------------------------------------------------------------- /umvu/include/umvu_tracer.h: -------------------------------------------------------------------------------- 1 | #ifndef UMVU_TRACER_H 2 | #define UMVU_TRACER_H 3 | #include 4 | #include 5 | 6 | /* tracer: this is the lowest layer of virtualization */ 7 | /* legacy implementation. 8 | umvu_tracer_seccomp uses seccomp (BPF) to speedup the tracing */ 9 | 10 | typedef void (*syscall_handler_t)(syscall_state_t, struct syscall_descriptor_t *); 11 | 12 | /* test if seccomp is available on the hosting system */ 13 | int umvu_tracer_test_seccomp(void); 14 | 15 | /* the tracer must be used as follows: 16 | * int wstatus; 17 | * switch(childpid = umvu_tracer_fork()) { 18 | * case 0: .... root of the virtualized processes 19 | * exit(...) 20 | * default: .... init the tracer 21 | * wstatus = umvu_tracepid(childpid, syscall_hangler, 1); 22 | * .... cleanup tracer 23 | * exit(WEXITSTATUS(wstatus)) 24 | * case -1: 25 | * .... error management 26 | */ 27 | int umvu_tracer_fork(int seccomp); 28 | int umvu_tracepid(pid_t childpid, syscall_handler_t syscall_handler_arg, int main); 29 | #endif 30 | -------------------------------------------------------------------------------- /umvu/include/vu_access_emu.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_ACCESS_EMU_H 2 | #define VU_ACCESS_EMU_H 3 | 4 | #include 5 | 6 | /* this emulates 'access' given a stat buffer. 7 | use getuid (or geteuid if AT_EACCESS), getgid (or getegid if AT_EACCESS) 8 | and getgroups. 9 | return 0 or -errno 10 | AT_SYMLINK_NOFOLLOW is handled by canonicalize/path-utils 11 | */ 12 | int vu_access_emu(struct vu_stat *statbuf, int mode, int flags); 13 | #endif 14 | -------------------------------------------------------------------------------- /umvu/include/vu_chroot_exec.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_CHROOT_EXEC_H 2 | #define VU_CHROOT_EXEC_H 3 | 4 | void exec_chroot_rewrite_interpreter(struct vuht_entry_t *ht, struct binfmt_req_t *req); 5 | #endif 6 | -------------------------------------------------------------------------------- /umvu/include/vu_execute.h: -------------------------------------------------------------------------------- 1 | #ifndef _VU_EXECUTE_H 2 | #define _VU_EXECUTE_H 3 | #include 4 | #include 5 | #include 6 | 7 | /* second layer of virtualization, just above the tracer. 8 | this module gets the system call requests, 9 | calls the chice functions to decide if the request must be virtualized or not, 10 | and dispatches them to the right wrappers */ 11 | 12 | #define VU_NESTED 1 13 | #define VU_NOT_NESTED 0 14 | 15 | /* extension of syscall state_t, field added for execute */ 16 | struct syscall_extra_t { 17 | /* the pathname of the syscall. 18 | always canonicalized. 19 | syscall using file descriptors: the canonicalized path used to open the file*/ 20 | char *path; 21 | /* module path: path relative to the mountpoint of the module */ 22 | const char *mpath; 23 | /* stat of the file: st_mode == 0 means that the file does not exist */ 24 | struct vu_stat statbuf; 25 | /* errno returned during the path resolution */ 26 | int path_errno; 27 | /* nested == 1 means self virtualization */ 28 | uint8_t nested; 29 | /* if path_rewrite == 1, the pathname will be rewritten */ 30 | uint8_t path_rewrite; 31 | /* latest syscall was a successful exec: no "out phase", cleanup needed */ 32 | uint8_t isexec; 33 | /* hash table element of the module managing this system call. 34 | NULL means not virtualized syscall */ 35 | struct vuht_entry_t *ht; 36 | /* the epoch of the module match */ 37 | epoch_t epoch; 38 | }; 39 | 40 | void vu_syscall_execute(syscall_state_t state, struct syscall_descriptor_t *sd); 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /umvu/include/vu_fd_table.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_FD_TABLE_H 2 | #define VU_FD_TABLE_H 3 | #include 4 | 5 | /* This module keeps track of the file descriptors of the 6 | * corresponding user-thread (or the fd of the hypervisor itself if nested == 1). 7 | * 8 | * NB there are three layers of data structures: 9 | * fd_table (this), file_table (whose elements are named fnodes), vnode. 10 | * more elements of fd_table may point to the same fnode, several fnodes to the same vnode. 11 | * 12 | * clone/fork/exec are automatically handled: 13 | * in case of fork/clone. if CLONE_FILES the mapping is shared, copied otherwise. 14 | * in case of exec. the CLOEXEC entries are deleted. 15 | * 16 | * This module perform locking to support multithreading access 17 | */ 18 | 19 | struct vu_fnode_t; 20 | struct vuht_entry_t; 21 | 22 | /* store the mapping between fd and fnode */ 23 | void vu_fd_set_fnode(int fd, int nested, struct vu_fnode_t *fnode, int fdflags); 24 | 25 | /* delete the mapping about fd */ 26 | int vu_fd_close(int fd, int nested); 27 | 28 | /* manage a dup, copy the mapping */ 29 | void vu_fd_dup(int fd, int nested, int oldfd, int fdflags); 30 | 31 | /* helper functions to get/set specific info*/ 32 | struct vu_fnode_t *vu_fd_get_fnode(int fd, int nested); 33 | 34 | struct vuht_entry_t *vu_fd_get_ht(int fd, int nested); 35 | 36 | void vu_fd_get_path(int fd, int nested, char *dest, size_t n); 37 | 38 | mode_t vu_fd_get_mode(int fd, int nested); 39 | 40 | int vu_fd_get_fdflags(int fd, int nested); 41 | 42 | void vu_fd_set_fdflags(int fd, int nested, int flags); 43 | 44 | int vu_fd_get_flflags(int fd, int nested); 45 | 46 | void vu_fd_set_flflags(int fd, int nested, int flags); 47 | 48 | int vu_fd_get_sfd(int fd, void **pprivate, int nested); 49 | 50 | /* VU_USE_PRW */ 51 | void vu_fd_get_possize_lock(int fd, int nested, off_t *pos, off_t *size); 52 | void vu_fd_set_possize_unlock(int fd, int nested, off_t pos, off_t size); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /umvu/include/vu_file_table.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_FILE_TABLE_H 2 | #define VU_FILE_TABLE_H 3 | #include 4 | #include 5 | #include 6 | 7 | /* This if the table of open files. 8 | * 9 | * NB there are three layers of data structures: 10 | * fd_table, file_table (this, whose elements are named fnodes), vnode. 11 | * more elements of fd_table may point to the same fnode, several fnodes to the same vnode. 12 | * 13 | * dup/inherited file descriptors from fd_table point the same fnode element. 14 | * 15 | * fnodes point to the same vnode element if they refer to the same file. 16 | * 17 | * This module perform locking to support multithreading access 18 | */ 19 | 20 | struct vuht_entry_t; 21 | struct vu_fnode_t; 22 | 23 | /* set the "close" upcall. (one for each file type (see umvu/include/xstat.h) */ 24 | typedef int (* close_upcall_t)(struct vuht_entry_t *ht, int sfd, void *private); 25 | void vu_fnode_set_close_upcall(mode_t mode, close_upcall_t close_upcall); 26 | 27 | #define VU_FNODE_CLOSED ((void *) -1) 28 | /* create an f-node: 29 | * sfd is the service fd, the file descriptor used by the module to identify the file 30 | * (private == VU_FNODE_CLOSED) means that the tmp file has no corresponding 31 | * open file. e.g. tmp file for execve 32 | */ 33 | struct vu_fnode_t *vu_fnode_create( 34 | struct vuht_entry_t *ht, 35 | const char *path, 36 | struct vu_stat *stat, 37 | int flags, 38 | int sfd, 39 | void *private); 40 | 41 | /* close an fnode: delete the fnodeis the usage counter becomes 0 */ 42 | int vu_fnode_close(struct vu_fnode_t *fnode); 43 | 44 | /* increment the usage count */ 45 | void vu_fnode_dup(struct vu_fnode_t *v); 46 | 47 | /* helper functions */ 48 | 49 | struct vuht_entry_t *vu_fnode_get_ht(struct vu_fnode_t *v); 50 | 51 | void vu_fnode_get_path(struct vu_fnode_t *v, char *dest, size_t n); 52 | 53 | char *vu_fnode_get_vpath(struct vu_fnode_t *v); 54 | 55 | mode_t vu_fnode_get_mode(struct vu_fnode_t *v); 56 | 57 | int vu_fnode_get_flags(struct vu_fnode_t *v); 58 | 59 | void vu_fnode_set_flags(struct vu_fnode_t *v, int flags); 60 | 61 | int vu_fnode_get_sfd(struct vu_fnode_t *v, void **pprivate); 62 | 63 | /* a local copy of the file is required. copyinout calls the callback in 'cp' 64 | with the right arguments and opportune locking */ 65 | typedef int (*copyfun) (struct vuht_entry_t *ht, char *path, char *tmp_path); 66 | int vu_fnode_copyinout (struct vu_fnode_t *v, copyfun cp); 67 | 68 | /* VU_USE_PRW */ 69 | void vu_fnode_get_possize_lock(struct vu_fnode_t *v, off_t *pos, off_t *size); 70 | void vu_fnode_set_possize_unlock(struct vu_fnode_t *v, off_t pos, off_t size); 71 | off_t vu_fnode_getset_size(struct vuht_entry_t *ht, struct vu_stat *stat, off_t size); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /umvu/include/vu_fnode_copy.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_FNODE_COPY_H 2 | #define VU_FNODE_COPY_H 3 | 4 | struct vu_fnode_t; 5 | /* get a local copy or the filei corresponding to fnode */ 6 | int vu_fnode_copyin(struct vu_fnode_t *fnode); 7 | /* use the local copy to update the file corresponding to fnode */ 8 | int vu_fnode_copyout(struct vu_fnode_t *fnode); 9 | 10 | /* this functions use vu_fnode_copyinout */ 11 | #endif 12 | -------------------------------------------------------------------------------- /umvu/include/vu_fs.h: -------------------------------------------------------------------------------- 1 | #ifndef FS_H 2 | #define FS_H 3 | 4 | /* file system module. This module keep track of: 5 | * current working directory 6 | * chroot 7 | * umask 8 | * it automatically manages: clone/fork, termination of user-threads and hypervisor threads. 9 | * (info are shared if clone has the flag CLONE_FS set). 10 | */ 11 | 12 | /* change the working directory */ 13 | void vu_fs_set_cwd(char *wd); 14 | /* change the root directory */ 15 | void vu_fs_set_rootdir(char *dir); 16 | /* change the umask directory: return the previous mask */ 17 | mode_t vu_fs_set_umask(mode_t mask); 18 | 19 | /* helper functions */ 20 | 21 | void vu_fs_get_rootdir(char *dest, size_t n); 22 | int vu_fs_is_chroot(void); 23 | void vu_fs_get_cwd(char *dest, size_t n); 24 | mode_t vu_fs_get_umask(void); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /umvu/include/vu_inheritance.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_INHERITANCE_H 2 | #define VU_INHERITANCE_H 3 | 4 | /* inheritance management: 5 | hypervisor modules can register a callback upcall that will be called 6 | in case of the event listed in inheritance_state_t. 7 | It is used by core sections (or modules) which need to initialize and maintain 8 | thread private data structures. */ 9 | 10 | /* Warning: vu_inheritance_upcall_register is *NOT* thread safe. It has been designed 11 | for __attribute__((constructor)) functions (so the call happens before 12 | going multi-threading. A thread safe implementation for modules as 13 | an upper layer is provided by vu_mod_inheritance.c */ 14 | 15 | /* CLONE/START is the pair of events to manage a new process/thread: 16 | CLONE is an event of the parent process/creating thread 17 | START is the first event if the newborn process/thread. 18 | It is possible cor CLONE to pass data to START */ 19 | 20 | /* INH_CLONE, INH_START, INH_EXEC, INH_TERMINATE report event of user-processes 21 | INH_PTHREAD_CLONE, INH_PTHREAD_START, INH_PTHREAD_TERMINATE are about 22 | threads of the hypervisor */ 23 | 24 | typedef enum inheritance_state_t { 25 | INH_CLONE = 0, 26 | INH_START = 1, 27 | INH_EXEC = 2, 28 | INH_TERMINATE = 3, 29 | INH_PTHREAD_CLONE = 10, 30 | INH_PTHREAD_START = 11, 31 | INH_PTHREAD_TERMINATE = 13 32 | } inheritance_state_t; 33 | 34 | typedef void *(*inheritance_upcall_t)(inheritance_state_t state, void *ioarg, void *arg); 35 | /* register an upcall handler */ 36 | void vu_inheritance_upcall_register(inheritance_upcall_t upcall); 37 | 38 | /* 39 | call all the registered handlers. 40 | 41 | vu_inheritance_call(INH_SOMETHING, NULL, commonarg): 42 | >>> all the handlers get commonarg as their arg 43 | >>> the return values of the handlers are discarded 44 | vu_inheritance_call(INH_SOMETHING, inoutarg, commonarg): 45 | >>> all the handlers get commonarg as their arg 46 | >>> each handler gets its element in inoutarg as its ioarg. 47 | >>> the return value of each handler updates its element in inoutarg. 48 | >>> inoutargs must point to a memory area vu_inheritance_inout_size() bytes wide 49 | >>> (START / CLONE events use this) 50 | */ 51 | 52 | void vu_inheritance_call(inheritance_state_t state, void **inout, void *arg); 53 | size_t vu_inheritance_inout_size(void); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /umvu/include/vu_initfini.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_INITFINI_H 2 | #define VU_INITFINI_H 3 | 4 | /* hypervisor constructors/destructors. 5 | vu_init calls all the upcalls registered by vu_constructor_register. 6 | vu_fini calls all the upcalls registered by vu_destructor_register. 7 | 8 | umvu_main calls vu_init just before starting the tracer and vu_fini 9 | as soon as the tracer terminates. 10 | 11 | Warning: these functions are *NOT* thread safe. They have been designed 12 | for __attribute__((constructor)) functions (so the call happens before 13 | going multi-threading) 14 | 15 | */ 16 | 17 | typedef void (*voidfun_t)(void); 18 | 19 | /* register a constructor/destructor */ 20 | void vu_constructor_register(voidfun_t upcall); 21 | void vu_destructor_register(voidfun_t upcall); 22 | 23 | /* this functions are for main: start all the constructors (init), 24 | and run all the destructors (fini) */ 25 | void vu_init(void); 26 | void vu_fini(void); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /umvu/include/vu_mmap_table.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_MMAP_TABLE_H 2 | #define VU_MMAP_TABLE_H 3 | #include 4 | 5 | /* keep track of mmapped regions. 6 | CLONE/EXEC/TERMINATE are processed automatically. 7 | 8 | The fnode is kept alive as long as there are mapped regions */ 9 | 10 | struct fnode; 11 | void vu_mmap_mmap(uintptr_t addr, size_t length, struct vu_fnode_t *fnode, off_t offset); 12 | void vu_mmap_munmap(uintptr_t addr, size_t length); 13 | void vu_mmap_mremap(uintptr_t addr, size_t length, uintptr_t newaddr, size_t newlength); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /umvu/include/vu_mod_inheritance.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_MOD_INHERITANCE_H 2 | #define VU_MOD_INHERITANCE_H 3 | #include 4 | 5 | /* it manages inheritance for modules */ 6 | 7 | /* the interface to modules is in include/vumodule.h */ 8 | 9 | 10 | /* vu_exec_setuid, vu_exec_setgid are used by vu_wrap_exec to 11 | request setuid/setgid to uid/gid virtualization modules */ 12 | 13 | void vu_exec_setuid(uid_t uid); 14 | void vu_exec_setgid(gid_t gid); 15 | #endif 16 | -------------------------------------------------------------------------------- /umvu/include/vu_modutils.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_MODUTILS_H 2 | #define VU_MODUTILS_H 3 | 4 | /* loading/unloading of modules */ 5 | /* vu_syscall_handler_pointer is used in vumodule.h 6 | by "vu_syscall_handler" macro */ 7 | 8 | typedef void (* voidfun)(void); 9 | 10 | struct vu_service_t; 11 | 12 | typedef long (*syscall_t)(); 13 | 14 | struct vu_service_t *module_load(const char *modname); 15 | syscall_t *vu_syscall_handler_pointer(struct vu_service_t *service, char *name); 16 | void module_unload(struct vu_service_t *service); 17 | 18 | voidfun *module_getsym(struct vu_service_t *service, char *symbol); 19 | void module_run_init(struct vu_service_t *service); 20 | int module_run_fini(struct vu_service_t *service); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /umvu/include/vu_name.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_NAME_H 2 | #define VU_NAME_H 3 | 4 | /* manage the hypervisor's name */ 5 | 6 | void set_vu_name(char *name); 7 | 8 | void get_vu_name(char *name, size_t len); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /umvu/include/vu_nesting.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_NESTING_H 2 | #define VU_NESTING_H 3 | 4 | /* enable and disable nested virtualization */ 5 | void vu_nesting_enable(void); 6 | void vu_nesting_disable(void); 7 | 8 | /* vu_nesting_init enables the self virtualization using libpurelibc. 9 | vuos supports nested virtualization using self virtualization. 10 | This function execs and then restarts the entire hypervisor 11 | to enable LD_PRELOAD of libpurelibc */ 12 | 13 | /* If libpurelibc.so is not preloaded, this function add it to LD_PRELOAD and 14 | umvu re-execute itself. 15 | The nested virtualization is enabled during the "second execution". In this 16 | way purelibc is loaded at the top of the library hierarchy allowing its 17 | functions implementation to prevail over the other libraries functions.*/ 18 | 19 | 20 | void vu_nesting_init(int argc, char **argv); 21 | 22 | #endif 23 | 24 | -------------------------------------------------------------------------------- /umvu/include/vu_pushpop.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_PUSHPOP_H 2 | #define VU_PUSHPOP_H 3 | #include 4 | 5 | /* push and pop data on the user process stack. */ 6 | 7 | /* The area above the stack pointer of the process is used to store data 8 | (pathnames, memory structures) nededed by the kernel 9 | to run the system call. This method does not generate conflicts because the 10 | kernel uses a different stack area to process the system call and when the 11 | syscall returns, the values stored above the SP aren't used anymore. */ 12 | 13 | 14 | syscall_arg_t vu_push(struct syscall_descriptor_t *sd, void *buf, size_t datalen); 15 | 16 | void vu_pop(struct syscall_descriptor_t *sd, void *buf, size_t datalen); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /umvu/include/vu_slow_calls.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_SLOW_CALLS_H 2 | #define VU_SLOW_CALLS_H 3 | 4 | /* management of slow syscalls: those who may block. */ 5 | 6 | #include 7 | struct vuht_entry_t; 8 | struct slowcall; 9 | 10 | /* This syscall requires 'events' to run, use this in the IN wrapper */ 11 | struct slowcall *vu_slowcall_in(struct vuht_entry_t *ht, int fd, uint32_t events, int nested); 12 | 13 | /* suspend until the slowcall can succeed. the return value must be assigned to sd->waiting_pid */ 14 | /* this function is for the DURING wrapper */ 15 | pid_t vu_slowcall_during(struct slowcall *sc); 16 | 17 | /* this function is forthe OUT wrapper. 18 | undo what vu_slowcall_in did and free the struct slowcall */ 19 | void vu_slowcall_out(struct slowcall *sc, struct vuht_entry_t *ht, int fd, uint32_t events, int nested); 20 | 21 | /* test if the syscall can run (it is an optimization)*/ 22 | int vu_slowcall_test(struct slowcall *sc); 23 | #endif 24 | -------------------------------------------------------------------------------- /umvu/include/vu_thread_sd.h: -------------------------------------------------------------------------------- 1 | #ifndef _VU_THREAD_SD_H 2 | #define _VU_THREAD_SD_H 3 | 4 | /* get/set the syscall_descriptor of the current thread, 5 | mainly for modules */ 6 | 7 | /* set the new value of thread_sd and return the previous, 8 | so that it can be used later to restore the old value */ 9 | struct syscall_descriptor_t *set_thread_sd(struct syscall_descriptor_t *sd); 10 | /* get the current thread_sd */ 11 | struct syscall_descriptor_t *get_thread_sd(void); 12 | 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /umvu/include/vu_tmpdir.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_TMPDIR_h 2 | #define VU_TMPDIR_h 3 | 4 | /* Each umvu instance uses a hidden directory in /tmp to store temporary files. 5 | This function returns the path of that directory */ 6 | char *vu_tmpdirpath(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /umvu/include/vu_uidgid.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_UIDGID_H 2 | #define VU_UIDGID_H 3 | 4 | 5 | #include 6 | 7 | void vu_uidgid_getresfuid(uid_t *ruid, uid_t *euid, uid_t *suid, uid_t *fsuid); 8 | void vu_uidgid_setresfuid(const uid_t ruid, const uid_t euid, const uid_t suid, const uid_t fsuid); 9 | void vu_uidgid_getresfgid(gid_t *rgid, gid_t *egid, gid_t *sgid, gid_t *fsgid); 10 | void vu_uidgid_setresfgid(const gid_t rgid, const gid_t egid, const gid_t sgid, const gid_t fsgid); 11 | int vu_uidgid_getgroups(int size, gid_t list[]); 12 | int vu_uidgid_setgroups(int size, gid_t list[]); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /umvu/include/vu_vnode.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_VNODE_H 2 | #define VU_VNODE_H 3 | 4 | /* This if the table of vnodes. 5 | * 6 | * NB there are three layers of data structures: 7 | * fd_table, file_table (whose elements are named fnodes), vnode (this). 8 | * more elements of fd_table may point to the same fnode, several fnodes to the same vnode. 9 | * 10 | * dup/inherited file descriptors from fd_table point the same fnode element. 11 | * fnodes point to the same vnode element if they refer to the same file. 12 | * 13 | * This module perform locking to support multithreading access 14 | */ 15 | 16 | 17 | struct vu_node_t; 18 | struct vuht_entry_t; 19 | 20 | /* open/close a vnode element ht+dev+inode together are the unique identifier 21 | of a vnode, open creates a new element if that file has not been opened yet, 22 | otherwise it returns the pointer to the corresponding vnode (and increment 23 | the usage counter) 24 | */ 25 | struct vu_vnode_t *vu_vnode_open(struct vuht_entry_t *ht, ino_t dev, ino_t inode, off_t size, 26 | int trunc); 27 | /* close decrements the usage counter, delete the local copy and free the vnode when 28 | the counter becomes zero) */ 29 | void vu_vnode_close(struct vu_vnode_t *vnode); 30 | 31 | /* this is the pathname of a real file, local "image" of a virtual file. 32 | it is often an empty file used to open "something" in the user process to 33 | allocate a file descriptor. 34 | The original contents of the file is loaded to support mmap or execve */ 35 | char *vu_vnode_getvpath(struct vu_vnode_t *vnode); 36 | 37 | typedef int (*copyfun) (struct vuht_entry_t *ht, char *path, char *tmp_path); 38 | 39 | int vu_vnode_copyinout (struct vu_vnode_t *vnode, char *path, copyfun cp); 40 | 41 | /* VU_USE_PRW: get and set size + locking */ 42 | off_t vu_vnode_get_size_lock(struct vu_vnode_t *vnode); 43 | void vu_vnode_set_size_unlock(struct vu_vnode_t *vnode, off_t size); 44 | off_t vu_vnode_getset_size(struct vuht_entry_t *ht, ino_t dev, ino_t inode, off_t size); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /umvu/include/vu_wrap_rw_multiplex.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_WRAP_RW_MULTIPLEX_H 2 | #define VU_WRAP_RW_MULTIPLEX_H 3 | #include 4 | #include 5 | 6 | /* this hypervisor module defines the wrappers for read and write and 7 | dispatch the requests to specific wrappersdepending on the file types. 8 | 9 | e.g. read and write have different implementations when operating 10 | on regular files, block or char devices. 11 | read/write are mapped to recvmsg/sendmsg if the file is a socket. 12 | 13 | The following functions permits the definition of specific handlers 14 | per file type */ 15 | 16 | void multiplex_read_wrappers(mode_t mode, 17 | wrapf_t wrapin, wrapf_t wrapduring, wrapf_t wrapout); 18 | void multiplex_write_wrappers(mode_t mode, 19 | wrapf_t wrapin, wrapf_t wrapduring, wrapf_t wrapout); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /umvu/include/xcommon.h: -------------------------------------------------------------------------------- 1 | #ifndef XCOMMON_H 2 | #define XCOMMON_H 3 | 4 | /* xfree and xstrdup does not break if the argument is NULL */ 5 | 6 | #define xfree(ptr) do { \ 7 | if (ptr) \ 8 | free(ptr); \ 9 | } while(0) 10 | 11 | #define xstrdup(ptr) \ 12 | (ptr ? strdup(ptr) : NULL) 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /umvu/include/xstat.h: -------------------------------------------------------------------------------- 1 | #ifndef VU_XSTAT_H 2 | #define VU_XSTAT_H 3 | #include 4 | 5 | /* define arrays having one element per file type */ 6 | #define S_MODE2TYPE(X) (((X) >> 12) & 0xf) 7 | #define S_TYPES 16 8 | #define S_TYPES_INIT(X) (X),(X),(X),(X),(X),(X),(X),(X),(X),(X),(X),(X),(X),(X),(X),(X) 9 | 10 | /* Table of file types: 11 | * 0 0000000 the file does not exist 12 | * 1 0010000 S_IFIFO 13 | * 2 0020000 S_IFCHR 14 | * 3 0030000 not assigned 15 | * 4 0040000 S_IFDIR 16 | * 5 0050000 not assigned 17 | * 6 0060000 S_IFBLK 18 | * 7 0070000 not assigned 19 | * 8 0100000 S_IFREG 20 | * 9 0110000 S_IFSIGNALFD 21 | * 10 0120000 S_IFLNK 22 | * 11 0130000 S_IFEVENTFD 23 | * 13 0150000 S_IFTIMERFD 24 | * 12 0140000 S_IFSOCK 25 | * 14 0160000 S_IFSTACK 26 | * 15 0170000 S_IFEPOLL 27 | */ 28 | 29 | /* define file types not currently handled in inodes */ 30 | #define S_IFEPOLL __S_IFEPOLL 31 | #define S_IFSTACK __S_IFSTACK 32 | #define S_IFSIGNALFD __S_IFSIGNALFD 33 | #define S_IFTIMERFD __S_IFTIMERFD 34 | #define S_IFEVENTFD __S_IFEVENTFD 35 | 36 | #define __S_IFEPOLL 0170000 /* Epoll */ 37 | #define __S_IFSTACK 0160000 /* Stack */ 38 | #define __S_IFSIGNALFD 0110000 /* Signalfd */ 39 | #define __S_IFTIMERFD 0150000 /* Timerfd */ 40 | #define __S_IFEVENTFD 0130000 /* Eventfd */ 41 | 42 | #define S_ISEPOLL __S_ISTYPE((mode), __S_IFEPOLL) 43 | #define S_ISSTACK __S_ISTYPE((mode), __S_IFSTACK) 44 | #define S_ISESIGNALFD __S_ISTYPE((mode), __S_IFESIGNALFD) 45 | #define S_ISETIMERFD __S_ISTYPE((mode), __S_IFETIMERFD) 46 | #define S_ISEEVENTFD __S_ISTYPE((mode), __S_IFEEVENTFD) 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /umvu/src/epoch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | /* per thread time keeping */ 27 | __thread epoch_t virtual_epoch; 28 | 29 | /* epoch now is a (uint64_t) counter, it is used to timestamp all the state changes in the system 30 | * This global counter is incremented at each operation which modifies the "view". 31 | * Each value of the eposh is like a virtualization layer, this approach allows the support of 32 | * nested virtualization. See comments in epoch.h */ 33 | static epoch_t epoch_now = 2; 34 | 35 | /* one tick of the global timestamp clock epoch_now */ 36 | epoch_t update_epoch(void) 37 | { 38 | return __sync_fetch_and_add(&epoch_now, 1); 39 | } 40 | 41 | epoch_t set_vepoch(epoch_t e) 42 | { 43 | epoch_t tmp = virtual_epoch; 44 | virtual_epoch = e; 45 | return tmp; 46 | } 47 | 48 | epoch_t get_epoch(void) 49 | { 50 | return __sync_fetch_and_add(&epoch_now, 0); 51 | } 52 | 53 | void update_vepoch(void) 54 | { 55 | virtual_epoch = __sync_fetch_and_add(&epoch_now, 0); 56 | } 57 | 58 | epoch_t get_vepoch(void) 59 | { 60 | return virtual_epoch; 61 | } 62 | 63 | /* it is > 0 if the operation time is consistent with the service time. 64 | * in such a case it returns the epoch of the matching */ 65 | epoch_t matching_epoch(epoch_t service_epoch) 66 | { 67 | if (service_epoch < virtual_epoch) 68 | return service_epoch; 69 | else 70 | return 0; 71 | } 72 | 73 | static void *epoch_upcall(inheritance_state_t state, void *ioarg, void *arg) { 74 | void *ret_value = NULL; 75 | switch (state) { 76 | case INH_PTHREAD_CLONE: 77 | ret_value = &virtual_epoch; 78 | break; 79 | case INH_PTHREAD_START: 80 | virtual_epoch = *(epoch_t *) ioarg; 81 | break; 82 | default: 83 | break; 84 | } 85 | return ret_value; 86 | } 87 | 88 | 89 | __attribute__((constructor)) 90 | static void init(void) { 91 | vu_inheritance_upcall_register(epoch_upcall); 92 | } 93 | 94 | -------------------------------------------------------------------------------- /umvu/src/linux_32_64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | /* convert dirent64 to dirent: 27 | VUOS modules handle 64bit dirents, this conversion is needed to 28 | support 32bit dirent (on 32bit architectures) */ 29 | void dirent64_to_dirent(void* buf, int count){ 30 | struct linux_dirent *dirp=buf; 31 | struct dirent64 *dirp64=buf; 32 | int counter=0; 33 | unsigned short int buf_len; 34 | 35 | /* Actually the conversion is a bit tricky. 36 | * dirent is always shorter then dirent64. 37 | * copy the corresponding fields 38 | * keep the record length (there will be some unused bytes) */ 39 | for( counter=0; counterd_ino = (unsigned long) dirp64->d_ino; 42 | dirp->d_off = (unsigned long) dirp64->d_off; 43 | buf_len = dirp->d_reclen = dirp64->d_reclen; 44 | tmptype = dirp64->d_type; 45 | memmove(dirp->d_name,dirp64->d_name,strlen(dirp64->d_name)+1); 46 | *((char *) dirp + buf_len - 1)=tmptype; 47 | counter= counter + dirp->d_reclen; //bad... 48 | dirp = (struct linux_dirent *) ((char*)dirp + buf_len); 49 | dirp64 = (struct dirent64 *) ((char*)dirp64 + buf_len); 50 | } 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /umvu/src/mountflags.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2018 Renzo Davoli 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | /* translate all mount flags into options so that modules can parse options only */ 30 | 31 | char *mountflag_strings[32] = { 32 | "ro", // 1 33 | "nosuid", // 2 34 | "nodev", // 4 35 | "noexec", // 8 36 | "sync", // 16 37 | "remount", // 32 38 | "mand", // 64 39 | "dirsync", // 128 40 | NULL, // 256 41 | NULL, // 512 42 | "noatime", // 1024 43 | "nodiratime", // 2048 44 | "bind", // 4096 45 | "move", // 8192 46 | "rec", // 16384 47 | "silent", // 32768 48 | "acl", // 1 << 16 49 | "unbindable", // 1 << 17 50 | NULL, // 1 << 18 (MS_PRIVATE) 51 | NULL, // 1 << 19 (MS_SLAVE) 52 | NULL, // 1 << 20 (MS_SHARED) 53 | "relatime", // 1 << 21 54 | NULL, // 1 << 22 (MS_KERNMOUNT) 55 | "iversion", // 1 << 23 (MS_IVERSION) 56 | "strictatime", // 1 << 24 57 | "lazytime", // 1 << 25 58 | NULL, // 1 << 26 59 | NULL, // 1 << 27 60 | NULL, // 1 << 28 61 | NULL, // 1 << 29 62 | NULL, // 1 << 30 (MS_ACTIVE) 63 | "nouser", // 1 << 31 (MS_NOUSER) 64 | }; 65 | 66 | static char *strlpcpy(char *dst, char *src, char *limit) { 67 | while (*src && dst < limit - 1) 68 | *dst++ = *src++; 69 | *dst = 0; 70 | return dst; 71 | } 72 | 73 | size_t mountflags2opts(unsigned long mountflags, char *opts, size_t optslen) { 74 | int i; 75 | if (opts) { 76 | char *limit = opts + optslen; 77 | char *nextopt = opts; 78 | *nextopt = 0; 79 | if (mountflags & 1) 80 | nextopt = strlpcpy(nextopt, mountflag_strings[0], limit); 81 | else 82 | nextopt = strlpcpy(nextopt, "rw", limit); 83 | for (i = 1; i < 32; i++) { 84 | if ((mountflags & (1UL << i)) && (mountflag_strings[i])) { 85 | nextopt = strlpcpy(nextopt, ",", limit); 86 | nextopt = strlpcpy(nextopt, mountflag_strings[i], limit); 87 | } 88 | } 89 | return (nextopt - opts) + 1; 90 | } else { 91 | size_t retval = 3; 92 | for (i = 1; i < 32; i++) { 93 | if ((mountflags & (1UL << i)) && (mountflag_strings[i])) 94 | retval += strlen(mountflag_strings[i]) + 1; 95 | } 96 | return retval; 97 | } 98 | } 99 | 100 | #if 0 101 | int main() { 102 | unsigned long flags = 0; //0xffffffff; 103 | size_t len = mountflags2opts(flags, NULL, 0); 104 | char str[len]; 105 | printf("%d %d\n", len, mountflags2opts(flags, str, len)); 106 | printf("%s %d\n", str, strlen(str)); 107 | } 108 | #endif 109 | -------------------------------------------------------------------------------- /umvu/src/r_table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | /* r_table.h is automatically generated during the build process. 25 | * r_ stands for real system calls. 26 | * All the system call requestsgenerated by the hypervisor can be further 27 | * virtualized ***unless** they are real r_ system calls. 28 | * e.g. open(path ... ), may be processed by a module 29 | * r_open(path ...) always refers to the file "path" in the hosting operating system */ 30 | 31 | #pragma GCC diagnostic push 32 | #pragma GCC diagnostic ignored "-Wincompatible-pointer-types" 33 | long (*native_syscall)() = syscall; 34 | #pragma GCC diagnostic pop 35 | -------------------------------------------------------------------------------- /umvu/src/vu_access_emu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2020 Renzo Davoli 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | static int _is_group_member(gid_t gid) { 28 | int len = getgroups(0, NULL); 29 | gid_t list[len]; 30 | int i; 31 | len = getgroups(len, list); 32 | for (i = 0; i < len; i++) { 33 | if (gid == list[i]) 34 | return 1; 35 | } 36 | return 0; 37 | } 38 | 39 | int vu_access_emu(struct vu_stat *statbuf, int mode, int flags) { 40 | if (flags & ~(AT_EACCESS | AT_SYMLINK_NOFOLLOW)) 41 | return -EINVAL; 42 | 43 | if (statbuf->st_mode == 0) 44 | return -ENOENT; 45 | 46 | if (mode == F_OK) 47 | return 0; 48 | 49 | uid_t uid = (flags & AT_EACCESS) ? geteuid() : getuid(); 50 | 51 | if (uid == 0) { // it is root 52 | if ((mode & X_OK) == 0) // RW are always allowed 53 | return 0; 54 | // X OK is X is okay for someone 55 | if (statbuf->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) 56 | return 0; 57 | } 58 | 59 | int granted; 60 | 61 | if (uid == statbuf->st_uid) 62 | // user permissions 63 | granted = (int) ((statbuf->st_mode >> 6) & mode); 64 | else { 65 | gid_t gid = (flags & AT_EACCESS) ? getegid() : getgid(); 66 | if (statbuf->st_gid == gid || _is_group_member(statbuf->st_gid)) 67 | // group permissions 68 | granted = (int) ((statbuf->st_mode >> 3) & mode); 69 | else 70 | // other permissions 71 | granted = statbuf->st_mode & mode; 72 | } 73 | 74 | if (granted == mode) 75 | return 0; 76 | 77 | return -EACCES; 78 | } 79 | -------------------------------------------------------------------------------- /umvu/src/vu_inheritance.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2018 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | struct inheritance_elem_t { 26 | inheritance_upcall_t upcall; 27 | struct inheritance_elem_t *next; 28 | }; 29 | 30 | static struct inheritance_elem_t *inheritance_upcall_list_h = NULL; 31 | static struct inheritance_elem_t *inheritance_upcall_list_t = NULL; 32 | static int inheritance_upcall_list_count; 33 | 34 | void vu_inheritance_upcall_register(inheritance_upcall_t upcall) { 35 | struct inheritance_elem_t *new; 36 | new = malloc(sizeof(struct inheritance_elem_t)); 37 | fatal(new); 38 | new->upcall = upcall; 39 | new->next = NULL; 40 | if (inheritance_upcall_list_t == NULL) 41 | inheritance_upcall_list_h = new; 42 | else 43 | inheritance_upcall_list_t->next = new; 44 | inheritance_upcall_list_t = new; 45 | inheritance_upcall_list_count++; 46 | } 47 | 48 | void vu_inheritance_call(inheritance_state_t state, void **inout, void *arg) { 49 | struct inheritance_elem_t *scan; 50 | for (scan = inheritance_upcall_list_h; scan != NULL; scan = scan->next) { 51 | if (inout == NULL) 52 | (void) scan->upcall(state, NULL, arg); 53 | else { 54 | *inout = scan->upcall(state, *inout, arg); 55 | inout++; 56 | } 57 | } 58 | } 59 | 60 | size_t vu_inheritance_inout_size(void) { 61 | return inheritance_upcall_list_count * sizeof(void *); 62 | } 63 | -------------------------------------------------------------------------------- /umvu/src/vu_initfini.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | struct voidfun_elem_t { 29 | voidfun_t upcall; 30 | struct voidfun_elem_t *next; 31 | }; 32 | 33 | /* constructor and destructor list head/tail pointers */ 34 | static struct voidfun_elem_t *constructor_list_h = NULL; 35 | static struct voidfun_elem_t *constructor_list_t = NULL; 36 | static struct voidfun_elem_t *destructor_list_h = NULL; 37 | static struct voidfun_elem_t *destructor_list_t = NULL; 38 | 39 | static struct voidfun_elem_t *umvu_voidfun_list_new(voidfun_t upcall) { 40 | struct voidfun_elem_t *new = malloc(sizeof(struct voidfun_elem_t)); 41 | fatal(new); 42 | new->upcall = upcall; 43 | new->next = NULL; 44 | return new; 45 | } 46 | 47 | void vu_constructor_register(voidfun_t upcall) { 48 | struct voidfun_elem_t *new = umvu_voidfun_list_new(upcall); 49 | if (constructor_list_t == NULL) 50 | constructor_list_h = new; 51 | else 52 | constructor_list_t->next = new; 53 | constructor_list_t = new; 54 | } 55 | 56 | void vu_destructor_register(voidfun_t upcall) { 57 | struct voidfun_elem_t *new = umvu_voidfun_list_new(upcall); 58 | if (destructor_list_t == NULL) 59 | destructor_list_h = new; 60 | else 61 | destructor_list_t->next = new; 62 | destructor_list_t = new; 63 | } 64 | 65 | static void umvu_voidfun_list_run(struct voidfun_elem_t *list) { 66 | struct voidfun_elem_t *scan; 67 | for (scan = list; scan != NULL; scan = scan->next) 68 | scan->upcall(); 69 | } 70 | 71 | static void sig_handler(int sig) { 72 | signal(sig, SIG_DFL); 73 | vu_fini(); 74 | if (sig == SIGTERM) 75 | r_exit(0); 76 | else 77 | r_kill(-getpgrp(), sig); 78 | } 79 | 80 | static void setsighandlers(void) { 81 | struct sigaction sa = { 82 | .sa_handler = sig_handler, 83 | .sa_flags = 0, 84 | .sa_restorer = NULL}; 85 | sigfillset(&sa.sa_mask); 86 | sigaction(SIGHUP, &sa, NULL); 87 | sigaction(SIGINT, &sa, NULL); 88 | sigaction(SIGTERM, &sa, NULL); 89 | signal(SIGPIPE, SIG_IGN); 90 | signal(SIGALRM, SIG_IGN); 91 | signal(SIGUSR1, SIG_IGN); 92 | signal(SIGUSR2, SIG_IGN); 93 | signal(SIGPOLL, SIG_IGN); 94 | signal(SIGPROF, SIG_IGN); 95 | signal(SIGVTALRM, SIG_IGN); 96 | } 97 | 98 | void vu_init(void) { 99 | setsighandlers(); 100 | umvu_voidfun_list_run(constructor_list_h); 101 | } 102 | 103 | void vu_fini(void) { 104 | umvu_voidfun_list_run(destructor_list_h); 105 | } 106 | -------------------------------------------------------------------------------- /umvu/src/vu_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | static pthread_mutex_t vu_name_mutex = PTHREAD_MUTEX_INITIALIZER; 28 | static char vu_name[_UTSNAME_LENGTH]; 29 | 30 | void set_vu_name(char *name) { 31 | pthread_mutex_lock(&vu_name_mutex); 32 | vu_name[_UTSNAME_LENGTH - 1 ] = 0; 33 | strncpy(vu_name, name, _UTSNAME_LENGTH - 1); 34 | pthread_mutex_unlock(&vu_name_mutex); 35 | } 36 | 37 | void get_vu_name(char *name, size_t len) { 38 | if (len > _UTSNAME_LENGTH) 39 | len = _UTSNAME_LENGTH; 40 | pthread_mutex_lock(&vu_name_mutex); 41 | memcpy(name, vu_name, len); 42 | pthread_mutex_unlock(&vu_name_mutex); 43 | } 44 | -------------------------------------------------------------------------------- /umvu/src/vu_pthreads.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2018 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | static int (*libc_pthread_create)(); 28 | 29 | struct _pthread_arg { 30 | void *(*start_routine) (void *); 31 | void *start_arg; 32 | void *inherited_args[]; 33 | }; 34 | 35 | void cleanup(void *arg) { 36 | //printk("cleanup \n"); 37 | vu_inheritance_call(INH_PTHREAD_TERMINATE, NULL, NULL); 38 | } 39 | 40 | void *_pthread_wrapper(void *arg) { 41 | struct _pthread_arg *ptarg = arg; 42 | 43 | void *(*start_routine) (void *) = ptarg->start_routine; 44 | void *start_arg = ptarg->start_arg; 45 | 46 | vu_inheritance_call(INH_PTHREAD_START, ptarg->inherited_args, NULL); 47 | free(ptarg); 48 | pthread_cleanup_push(cleanup, NULL); 49 | //printk("start_routine \n"); 50 | start_arg = start_routine(start_arg); 51 | //printk("start_routine DONE\n"); 52 | pthread_cleanup_pop(1); 53 | 54 | return start_arg; 55 | } 56 | 57 | int pthread_create(pthread_t *thread, const pthread_attr_t *attr, 58 | void *(*start_routine) (void *), void *arg) { 59 | //printk("pthread_create\n"); 60 | struct _pthread_arg *ptarg = malloc(sizeof(struct _pthread_arg) + vu_inheritance_inout_size()); 61 | fatal(ptarg); 62 | ptarg->start_routine = start_routine; 63 | ptarg->start_arg = arg; 64 | 65 | vu_inheritance_call(INH_PTHREAD_CLONE, ptarg->inherited_args, (void *) -1); 66 | 67 | return libc_pthread_create(thread, attr, _pthread_wrapper, ptarg); 68 | } 69 | 70 | __attribute__((constructor)) 71 | static void init(void) { 72 | #pragma GCC diagnostic push 73 | #pragma GCC diagnostic ignored "-Wpedantic" 74 | libc_pthread_create = dlsym (RTLD_NEXT, "pthread_create"); 75 | #pragma GCC diagnostic pop 76 | } 77 | -------------------------------------------------------------------------------- /umvu/src/vu_pushpop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | /* push and pop data on the user process stack */ 25 | #define __WORDMASK ((__WORDSIZE / 8) - 1) 26 | #define WORDALIGN(X) (((X) + __WORDMASK) & ~__WORDMASK) 27 | 28 | syscall_arg_t vu_push(struct syscall_descriptor_t *sd, void *buf, size_t datalen) { 29 | sd->stack_pointer -= WORDALIGN(datalen); 30 | umvu_poke_data(sd->stack_pointer, buf, datalen); 31 | return sd->stack_pointer; 32 | } 33 | 34 | void vu_pop(struct syscall_descriptor_t *sd, void *buf, size_t datalen) { 35 | umvu_peek_data(sd->stack_pointer, buf, datalen); 36 | sd->stack_pointer += WORDALIGN(datalen); 37 | } 38 | -------------------------------------------------------------------------------- /umvu/src/vu_slow_calls.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #define STACKSIZE 4096 39 | 40 | struct slowcall { 41 | int epfd; 42 | //char stack[STACKSIZE]; 43 | }; 44 | static int (*libc_clone)(); 45 | 46 | int vu_slowcall_test(struct slowcall *sc) { 47 | struct pollfd pfd = {sc->epfd, POLLIN, 0}; 48 | return poll(&pfd, 1, 0); 49 | } 50 | 51 | struct slowcall *vu_slowcall_in(struct vuht_entry_t *ht, int fd, uint32_t events, int nested) { 52 | if (vu_fd_get_flflags(fd, nested) & O_NONBLOCK) 53 | return NULL; 54 | else { 55 | void *private = NULL; 56 | int sfd = vu_fd_get_sfd(fd, &private, nested); 57 | int epfd = r_epoll_create1(EPOLL_CLOEXEC); 58 | struct epoll_event event = {.events = events, .data.fd = fd}; 59 | int ret_value = service_syscall(ht, __VU_epoll_ctl)(epfd, EPOLL_CTL_ADD, sfd, &event, private); 60 | //printk("vu_slowcall_in... %d (add %d)\n", epfd, ret_value); 61 | if (ret_value < 0) { 62 | r_close(epfd); 63 | return NULL; 64 | } else { 65 | struct slowcall *sc = malloc(sizeof(struct slowcall)); 66 | sc->epfd = epfd; 67 | return sc; 68 | } 69 | } 70 | } 71 | 72 | static int slow_thread(void *arg) { 73 | struct slowcall *sc = arg; 74 | struct pollfd pfd = {sc->epfd, POLLIN, 0}; 75 | //printk("vu_slowcall_during... %d\n", pfd); 76 | poll(&pfd, 1, -1); 77 | //printk("vu_slowcall_wakeup %d %d\n", errno); 78 | return 0; 79 | } 80 | 81 | pid_t vu_slowcall_during(struct slowcall *sc) { 82 | //printk(">>>>>>>>>%lu\n", pthread_self()); 83 | #if 0 84 | return libc_clone(slow_thread, sc->stack + STACKSIZE, 85 | CLONE_FILES | CLONE_VM | CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID | SIGCHLD, 86 | sc); 87 | #endif 88 | pid_t pid; 89 | if ((pid = r_fork()) == 0) 90 | r_exit(slow_thread(sc)); 91 | return pid; 92 | } 93 | 94 | void vu_slowcall_out(struct slowcall *sc, struct vuht_entry_t *ht, int fd, uint32_t events, int nested) { 95 | void *private = NULL; 96 | int sfd = vu_fd_get_sfd(fd, &private, nested); 97 | struct epoll_event event = {.events = events, .data.fd = fd}; 98 | //printk("vu_slowcall_wakeup...\n"); 99 | service_syscall(ht, __VU_epoll_ctl)(sc->epfd, EPOLL_CTL_DEL, sfd, &event, private); 100 | r_close(sc->epfd); 101 | free(sc); 102 | } 103 | 104 | __attribute__((constructor)) 105 | static void init(void) { 106 | /* init the libc_clone pointer */ 107 | #pragma GCC diagnostic push 108 | #pragma GCC diagnostic ignored "-Wpedantic" 109 | libc_clone = dlsym (RTLD_NEXT, "clone"); 110 | #pragma GCC diagnostic pop 111 | } 112 | -------------------------------------------------------------------------------- /umvu/src/vu_thread_sd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | /* safe default value */ 29 | static struct syscall_extra_t default_extra; 30 | static struct syscall_descriptor_t default_sd = {.extra = &default_extra}; 31 | 32 | /* per thread syscall descriptor */ 33 | __thread struct syscall_descriptor_t *thread_sd = &default_sd; 34 | 35 | /* set the new value of sd and return the previous, 36 | so that it can be used later to restore the old value */ 37 | struct syscall_descriptor_t *set_thread_sd(struct syscall_descriptor_t *sd) { 38 | struct syscall_descriptor_t *tmp = thread_sd; 39 | printkdebug(t, "set_thread_sd %p->%p\n", tmp, sd); 40 | thread_sd = sd; 41 | return tmp; 42 | } 43 | 44 | struct syscall_descriptor_t *get_thread_sd(void) { 45 | printkdebug(t, "get_thread_sd %p\n", thread_sd); 46 | return thread_sd; 47 | } 48 | 49 | static void *thread_sd_upcall(inheritance_state_t state, void *ioarg, void *arg) { 50 | void *ret_value = NULL; 51 | switch (state) { 52 | case INH_PTHREAD_CLONE: 53 | ret_value = thread_sd; 54 | printkdebug(t, "thread_sd_upcall CLONE %p", thread_sd); 55 | break; 56 | case INH_PTHREAD_START: 57 | thread_sd = ioarg; 58 | printkdebug(t, "thread_sd_upcall START %p\n", thread_sd); 59 | break; 60 | default: 61 | break; 62 | } 63 | return ret_value; 64 | } 65 | 66 | __attribute__((constructor)) 67 | static void init(void) { 68 | vu_inheritance_upcall_register(thread_sd_upcall); 69 | debug_set_name(t, "THREADS"); 70 | } 71 | 72 | -------------------------------------------------------------------------------- /umvu/src/vu_tmpdir.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #define TMP_PATTERN "/tmp/.vu_%010lu_XXXXXX" 31 | #define TMP_PATTERN_EXAMPLE "/tmp/.vu_0123456789_XXXXXX" 32 | static char dirpath[sizeof(TMP_PATTERN_EXAMPLE)+1]; 33 | 34 | char *vu_tmpdirpath(void) { 35 | return dirpath; 36 | } 37 | 38 | static void dirpath_init(void) { 39 | snprintf(dirpath, sizeof(TMP_PATTERN_EXAMPLE)+1, TMP_PATTERN, (unsigned long) getpid()); 40 | fatal(mkdtemp(dirpath)); 41 | r_chdir(dirpath); 42 | } 43 | 44 | static void dirpath_fini(void) { 45 | r_rmdir(dirpath); 46 | } 47 | 48 | __attribute__((constructor)) 49 | static void init (void) { 50 | vu_constructor_register(dirpath_init); 51 | vu_destructor_register(dirpath_fini); 52 | } 53 | -------------------------------------------------------------------------------- /umvu/src/vu_wrap_cap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | void wi_capget(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { 39 | int nested = sd->extra->nested; 40 | uintptr_t hdrp = sd->syscall_args[0]; 41 | uintptr_t datap = sd->syscall_args[1]; 42 | cap_user_header_t hdr; 43 | cap_user_data_t data; 44 | sd->action = SKIPIT; 45 | if (hdrp == 0) { 46 | sd->ret_value = -EFAULT; 47 | return; 48 | } 49 | vu_alloc_peek_local_arg(hdrp, hdr, sizeof(*hdr), nested); 50 | if (hdr->version != _LINUX_CAPABILITY_VERSION_3) { 51 | sd->ret_value = -EFAULT; 52 | hdr->version = _LINUX_CAPABILITY_VERSION_3; 53 | vu_poke_arg(hdrp, hdr, sizeof(*hdr), nested); 54 | return; 55 | } 56 | if (datap == 0) { 57 | sd->ret_value = 0; 58 | return; 59 | } 60 | vu_alloc_local_arg(datap, data, 61 | sizeof(*data) * _LINUX_CAPABILITY_U32S_3, nested); 62 | if (ht) { 63 | sd->ret_value = service_syscall(ht, __VU_capget)(hdr, data); 64 | } else { 65 | sd->ret_value = capget(hdr, data); 66 | } 67 | if (sd->ret_value == 0) 68 | vu_poke_arg(datap, data, 69 | sizeof(*data) * _LINUX_CAPABILITY_U32S_3, nested); 70 | else 71 | sd->ret_value = -errno; 72 | } 73 | 74 | void wi_capset(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { 75 | if (ht) { 76 | int nested = sd->extra->nested; 77 | uintptr_t hdrp = sd->syscall_args[0]; 78 | uintptr_t datap = sd->syscall_args[1]; 79 | cap_user_header_t hdr; 80 | cap_user_data_t data; 81 | sd->action = SKIPIT; 82 | if (hdrp == 0) { 83 | sd->ret_value = -EFAULT; 84 | return; 85 | } 86 | vu_alloc_peek_local_arg(hdrp, hdr, sizeof(*hdr), nested); 87 | if (hdr->version != _LINUX_CAPABILITY_VERSION_3) { 88 | sd->ret_value = -EFAULT; 89 | hdr->version = _LINUX_CAPABILITY_VERSION_3; 90 | vu_poke_arg(hdrp, hdr, sizeof(*hdr), nested); 91 | return; 92 | } 93 | if (datap == 0) { 94 | sd->ret_value = 0; 95 | return; 96 | } 97 | if (hdr->pid == 0) 98 | hdr->pid = umvu_gettid(); 99 | else if (hdr->pid != umvu_gettid()) { 100 | sd->ret_value = -EPERM; 101 | return; 102 | } 103 | vu_alloc_peek_local_arg(datap, data, 104 | sizeof(*data) * _LINUX_CAPABILITY_U32S_3, nested); 105 | sd->ret_value = service_syscall(ht, __VU_capset)(hdr, data); 106 | if (sd->ret_value != 0) 107 | sd->ret_value = -errno; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /umvu/src/vu_wrap_ioctl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | /* TODO XXX ioctl can be a blocking syscall. 45 | ioctl should be changed to poll(NULL, 0, -1), 46 | the call of module's ioctl should be in the "during" phase, 47 | sending a PTRACE_INTERRUPT when done, and 48 | the results must be stored in the "out" phase */ 49 | void wi_ioctl(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { 50 | if (ht) { 51 | /* standard args */ 52 | int nested = sd->extra->nested; 53 | int ret_value; 54 | /* args */ 55 | int fd = sd->syscall_args[0]; 56 | unsigned long request = sd->syscall_args[1]; 57 | uintptr_t addr = sd->syscall_args[2]; 58 | unsigned long reqargs; 59 | int sfd; 60 | void *private = NULL; 61 | void *buf = NULL; 62 | int len; 63 | sd->action = SKIPIT; 64 | if (fd < 0) { 65 | sd->ret_value = -EBADF; 66 | return; 67 | } 68 | sfd = vu_fd_get_sfd(fd, &private, nested); 69 | /* module's ioctl returns the encoding of size and direction of the parameter i 70 | if fd == -1 */ 71 | /* modern ioctls have already size and direction encoded in their request argument, 72 | so if the modules' call fails, reqargs gets the value of request */ 73 | reqargs = service_syscall(ht, __VU_ioctl)(-1, request, NULL, addr, private); 74 | if (reqargs == (unsigned long) -1) 75 | reqargs = request; 76 | len = _IOC_SIZE(reqargs); 77 | if (len > 0) 78 | vu_alloc_arg(addr, buf, len, nested); 79 | if (reqargs & IOC_OUT) 80 | vu_peek_arg(addr, buf, len, nested); 81 | ret_value = service_syscall(ht, __VU_ioctl)(sfd, request, buf, addr, private); 82 | if (ret_value < 0) 83 | sd->ret_value = -errno; 84 | else { 85 | sd->ret_value = ret_value; 86 | if (reqargs & IOC_IN) 87 | vu_poke_arg(addr, buf, len, nested); 88 | } 89 | if (buf) 90 | vu_free_arg(buf, nested); 91 | } 92 | } 93 | 94 | -------------------------------------------------------------------------------- /umvu/src/vu_wrap_mount.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2017 Renzo Davoli , Antonio Cardace 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | void wi_mount(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { 40 | int nested = sd->extra->nested; 41 | if (ht && !nested) { 42 | /* standard args */ 43 | int ret_value; 44 | /* args */ 45 | char *source = umvu_peekdup_path(sd->syscall_args[0]); 46 | char *target = sd->extra->path; 47 | char *filesystemtype = umvu_peekdup_path(sd->syscall_args[2]); 48 | unsigned long mountflags = sd->syscall_args[3]; 49 | char *data = NULL; 50 | if (sd->syscall_args[4] != 0) 51 | data = umvu_peekdup_path(sd->syscall_args[4]); 52 | /* fetch args */ 53 | /* call */ 54 | sd->action = SKIPIT; 55 | ret_value = service_syscall(ht, __VU_mount)(source, target, filesystemtype, mountflags, data); 56 | xfree(source); 57 | xfree(filesystemtype); 58 | xfree(data); 59 | /* store results */ 60 | if (ret_value < 0) 61 | sd->ret_value = -errno; 62 | else 63 | sd->ret_value = ret_value; 64 | } 65 | } 66 | 67 | void wi_umount2(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { 68 | int nested = sd->extra->nested; 69 | if (ht && !nested) { 70 | /* standard args */ 71 | int syscall_number = sd->syscall_number; 72 | int ret_value; 73 | /* args */ 74 | char *target = sd->extra->path; 75 | int flags; 76 | /* fetch args */ 77 | switch (syscall_number) { 78 | default: 79 | case __NR_umount: flags = 0; 80 | break; 81 | case __NR_umount2: flags = sd->syscall_args[1]; 82 | break; 83 | } 84 | sd->action = SKIPIT; 85 | ret_value = service_syscall(ht, __VU_umount2)(target, flags); 86 | if (ret_value < 0) 87 | sd->ret_value = -errno; 88 | else 89 | sd->ret_value = ret_value; 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /vubinfmt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include_directories(${VU_HEADERS}) 4 | 5 | set(VU_MOD_TARGET vubinfmt) 6 | file(GLOB_RECURSE VUBINFMT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 7 | 8 | add_library(${VU_MOD_TARGET} SHARED ${VUBINFMT_SOURCES}) 9 | set_target_properties(${VU_MOD_TARGET} PROPERTIES PREFIX "") 10 | target_link_libraries(${VU_MOD_TARGET} stropt vumod) 11 | 12 | install(TARGETS ${VU_MOD_TARGET} LIBRARY DESTINATION ${MODULES_INSTALL_PATH}) 13 | -------------------------------------------------------------------------------- /vudev/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include_directories(${VU_HEADERS}) 4 | 5 | set(VU_MOD_TARGET vudev) 6 | file(GLOB_RECURSE VUDEV_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 7 | 8 | add_library(${VU_MOD_TARGET} SHARED ${VUDEV_SOURCES}) 9 | set_target_properties(${VU_MOD_TARGET} PROPERTIES PREFIX "") 10 | target_link_libraries(${VU_MOD_TARGET} stropt) 11 | 12 | install(TARGETS ${VU_MOD_TARGET} LIBRARY DESTINATION ${MODULES_INSTALL_PATH}) 13 | -------------------------------------------------------------------------------- /vudev_modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include_directories(${VU_HEADERS} ${VU_DYN_HEADER_PATH}) 4 | set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) 5 | 6 | file(GLOB VUDEV_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 7 | 8 | foreach(VUDEV_MOD ${VUDEV_MODULES}) 9 | string(REGEX REPLACE "\.c$" "" VUDEV_MOD_FILE ${VUDEV_MOD}) 10 | get_filename_component(VUDEV_MOD_TARGET ${VUDEV_MOD_FILE} NAME) 11 | add_library(${VUDEV_MOD_TARGET} SHARED ${VUDEV_MOD}) 12 | set_target_properties(${VUDEV_MOD_TARGET} PROPERTIES PREFIX "") 13 | install(TARGETS ${VUDEV_MOD_TARGET} LIBRARY DESTINATION ${MODULES_INSTALL_PATH}) 14 | endforeach(VUDEV_MOD) 15 | -------------------------------------------------------------------------------- /vudev_modules/vudevnull.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2018 Renzo Davoli 4 | * with contributions by Alessio Volpe 5 | * VirtualSquare team. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | static int null_open(const char *pathname, mode_t mode, struct vudevfd_t *vudevfd) { 29 | printkdebug(D,"null_open [%s]", pathname); 30 | return 0; 31 | } 32 | 33 | static int null_close(int fd, struct vudevfd_t *vudevfd) { 34 | printkdebug(D,"null_close", NULL); 35 | return 0; 36 | } 37 | 38 | static ssize_t null_read (int fd, void *buf, size_t count, struct vudevfd_t *vudevfd) { 39 | printkdebug(D,"null_read: [%d]", count); 40 | return 0; 41 | } 42 | 43 | static ssize_t null_write(int fd, const void *buf, size_t count, struct vudevfd_t *vudevfd) { 44 | printkdebug(D,"null_write: [%d]", count); 45 | return count; 46 | } 47 | 48 | struct vudev_operations_t vudev_ops = { 49 | .open = null_open, 50 | .close = null_close, 51 | .read = null_read, 52 | .write= null_write, 53 | }; 54 | 55 | -------------------------------------------------------------------------------- /vudevfuse/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include_directories(${VU_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}) 4 | 5 | set(VU_MOD_TARGET fuse) 6 | file(GLOB_RECURSE VUDEV_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 7 | 8 | add_library(${VU_MOD_TARGET} SHARED ${VUDEV_SOURCES}) 9 | set_target_properties(${VU_MOD_TARGET} PROPERTIES PREFIX "") 10 | target_link_libraries(${VU_MOD_TARGET} stropt volatilestream) 11 | 12 | install(TARGETS ${VU_MOD_TARGET} LIBRARY DESTINATION ${MODULES_INSTALL_PATH}) 13 | -------------------------------------------------------------------------------- /vudevfuse/devfuse.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEVFUSE_H 2 | #define _DEVFUSE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define FUSE_INT_REQ_BIT (1ULL << 0) 9 | #define FUSE_REQ_ID_STEP (1ULL << 1) 10 | 11 | #define FUSE_NOREPLY (-1) 12 | 13 | int vu_devfuse_lstat(char *pathname, struct vu_stat *buf, int flags, int sfd, void *fdprivate); 14 | int vu_devfuse_open(const char *pathname, int flags, mode_t mode, void **fdprivate); 15 | int vu_devfuse_close(int fd, void *fdprivate); 16 | int vu_devfuse_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event, void *fdprivate); 17 | ssize_t vu_devfuse_read(int fd, void *buf, size_t count, void *fdprivate); 18 | ssize_t vu_devfuse_write(int fd, const void *buf, size_t count, void *fdprivate); 19 | #define vu_devfuse_nosys(...) (errno = ENOSYS, -1) 20 | 21 | 22 | int32_t vu_devfuse_conversation(struct fusemount_t *fusemount, 23 | uint32_t opcode, uint64_t nodeid, 24 | struct iovec *reqiov, int reqcnt, 25 | struct iovec *replyiov, int replycnt, 26 | size_t *return_len); 27 | 28 | void fusemount_free(struct fusemount_t *fusemount); 29 | 30 | #define IOV0 NULL, 0 31 | #define IOV_NOREPLY NULL, FUSE_NOREPLY 32 | #define IOV1(BASE, LEN) (struct iovec []) {{(void *) (BASE), (LEN)}}, 1 33 | #define IOV2(BASE0, LEN0, BASE1, LEN1) \ 34 | (struct iovec []) {{(void *) (BASE0), (LEN0)}, {(void *) (BASE1), (LEN1)}}, 2 35 | #define IOV3(BASE0, LEN0, BASE1, LEN1, BASE2, LEN2) \ 36 | (struct iovec []) { \ 37 | {(void *) (BASE0), (LEN0)}, \ 38 | {(void *) (BASE1), (LEN1)}, \ 39 | {(void *) (BASE2), (LEN2)}}, 3 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /vudevfuse/eventsem.h: -------------------------------------------------------------------------------- 1 | #ifndef _EVENT_SEM_H 2 | #define _EVENT_SEM_H 3 | #include 4 | #include 5 | 6 | static inline int sem_open(int init) { 7 | return eventfd(init, EFD_SEMAPHORE | EFD_CLOEXEC); 8 | } 9 | 10 | static inline size_t sem_P(int fd) { 11 | uint64_t dummy; 12 | return read(fd, &dummy, sizeof(dummy)); 13 | } 14 | 15 | static inline size_t sem_V(int fd) { 16 | static const uint64_t one = 1LL; 17 | return write(fd, &one, sizeof(one)); 18 | } 19 | 20 | static inline int sem_close(int fd) { 21 | return close(fd); 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /vudevfuse/fusenode.h: -------------------------------------------------------------------------------- 1 | #ifndef _FUSENODE_H 2 | #define _FUSENODE_H 3 | 4 | #include 5 | #include 6 | 7 | struct fusenode_buf; 8 | 9 | uint64_t fn_get(struct fusenode_buf *ht, 10 | const char *path, struct fuse_attr *attr); 11 | 12 | void fn_add(struct fusenode_buf *ht, 13 | const char *path, struct fuse_entry_out *entry); 14 | 15 | uint64_t fn_getnode(struct fusenode_buf *ht, 16 | uint64_t nodeid, struct fuse_attr *attr); 17 | 18 | void fn_updatenode(struct fusenode_buf *ht, 19 | uint64_t nodeid, struct fuse_attr_out *entry); 20 | 21 | uint64_t fn_delnode(struct fusenode_buf *ht, 22 | uint64_t nodeid, uint64_t *nlookup); 23 | 24 | uint64_t fn_forgetlru(struct fusenode_buf *ht, uint64_t *nlookup); 25 | 26 | struct fusenode_buf *fn_init(int maxlru); 27 | 28 | void fn_fini(struct fusenode_buf *ht); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /vudevfuse/fusereqq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * vudevfuse: /dev/fuse - virtual fuse kernel support 3 | * Copyright 2022 Renzo Davoli 4 | * Virtualsquare & University of Bologna 5 | * 6 | * fusereqq.c: manage request queues: 7 | * store pending requests to the user level daemon 8 | * and match replies 9 | * 10 | * This program is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU General Public License 12 | * as published by the Free Software Foundation; either version 2 13 | * of the License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; If not, see . 22 | * 23 | */ 24 | 25 | #include 26 | 27 | void fusereq_enqueue(struct fusereq *req, struct fusereq **tail) { 28 | struct fusereq *last = *tail; 29 | if (last == NULL) 30 | req->next = req; 31 | else { 32 | req->next = last->next; 33 | last->next = req; 34 | } 35 | *tail = req; 36 | } 37 | 38 | struct fusereq *fusereq_dequeue(struct fusereq **tail) { 39 | struct fusereq *last = *tail; 40 | if (last == NULL) 41 | return NULL; 42 | struct fusereq *first = last->next; 43 | if (last == first) 44 | *tail = NULL; 45 | else 46 | last->next = first->next; 47 | first->next = NULL; 48 | return first; 49 | } 50 | 51 | struct fusereq *fusereq_outqueue(uint64_t unique, struct fusereq **tail) { 52 | struct fusereq *prev, *this; 53 | for (prev = *tail, this = prev->next; 54 | this != *tail; 55 | prev = this, this = prev->next) 56 | if (this->reqh.unique == unique) 57 | break; 58 | if (this->reqh.unique == unique) { 59 | if (this == *tail) 60 | *tail = (prev == *tail) ? NULL : prev; 61 | prev->next = this->next; 62 | return this; 63 | } else 64 | return NULL; 65 | } 66 | -------------------------------------------------------------------------------- /vudevfuse/fusereqq.h: -------------------------------------------------------------------------------- 1 | #ifndef _FUSEREQQ_H 2 | #define _FUSEREQQ_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | struct fusereq { 9 | struct fusereq *next; 10 | int sem; 11 | struct fuse_in_header reqh; 12 | uint32_t error; 13 | struct iovec *reqiov; 14 | int reqcnt; 15 | struct iovec *replyiov; 16 | int replycnt; 17 | size_t replydatalen; 18 | }; 19 | 20 | void fusereq_enqueue(struct fusereq *req, struct fusereq **tail); 21 | struct fusereq *fusereq_dequeue(struct fusereq **tail); 22 | struct fusereq *fusereq_outqueue(uint64_t unique, struct fusereq **tail); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /vudevfuse/listx.h: -------------------------------------------------------------------------------- 1 | /* Doubly linked list macros compatible with Linux kernel's version */ 2 | #ifndef _LISTX_H 3 | #define _LISTX_H 4 | 5 | #include // NULL + offsetof 6 | #define container_of(ptr, type, member) \ 7 | ((type *)(((char *)(ptr)) - offsetof(type,member))) 8 | 9 | struct list_head { 10 | struct list_head *next, *prev; 11 | }; 12 | 13 | #define LIST_HEAD_INIT(name) { &(name), &(name) } 14 | 15 | #define LIST_HEAD(name) \ 16 | struct list_head name = LIST_HEAD_INIT(name) 17 | 18 | static inline void INIT_LIST_HEAD(struct list_head *list) 19 | { 20 | list->next = list; 21 | list->prev = list; 22 | } 23 | 24 | static inline void __list_add(struct list_head *new, 25 | struct list_head *prev, 26 | struct list_head *next) 27 | { 28 | next->prev = new; 29 | new->next = next; 30 | new->prev = prev; 31 | prev->next = new; 32 | } 33 | 34 | static inline void list_add(struct list_head *new, struct list_head *head) 35 | { 36 | __list_add(new, head, head->next); 37 | } 38 | 39 | static inline void list_add_tail(struct list_head *new, struct list_head *head) 40 | { 41 | __list_add(new, head->prev, head); 42 | } 43 | 44 | static inline void __list_del(struct list_head * prev, struct list_head * next) 45 | { 46 | next->prev = prev; 47 | prev->next = next; 48 | } 49 | 50 | static inline void list_del(struct list_head *entry) 51 | { 52 | __list_del(entry->prev, entry->next); 53 | } 54 | 55 | static inline int list_is_last(const struct list_head *list, 56 | const struct list_head *head) 57 | { 58 | return list->next == head; 59 | } 60 | 61 | static inline int list_empty(const struct list_head *head) 62 | { 63 | return head->next == head; 64 | } 65 | 66 | static inline struct list_head *list_next(const struct list_head *current) 67 | { 68 | if (list_empty(current)) 69 | return NULL; 70 | else 71 | return current->next; 72 | } 73 | 74 | static inline struct list_head *list_prev(const struct list_head *current) 75 | { 76 | if (list_empty(current)) 77 | return NULL; 78 | else 79 | return current->prev; 80 | } 81 | 82 | #define list_for_each(pos, head) \ 83 | for (pos = (head)->next; pos != (head); pos = pos->next) 84 | 85 | #define list_for_each_prev(pos, head) \ 86 | for (pos = (head)->prev; pos != (head); pos = pos->prev) 87 | 88 | #define list_for_each_entry(pos, head, member) \ 89 | for (pos = container_of((head)->next, typeof(*pos), member); \ 90 | &pos->member != (head); \ 91 | pos = container_of(pos->member.next, typeof(*pos), member)) 92 | 93 | #define list_for_each_entry_reverse(pos, head, member) \ 94 | for (pos = container_of((head)->prev, typeof(*pos), member); \ 95 | &pos->member != (head); \ 96 | pos = container_of(pos->member.prev, typeof(*pos), member)) 97 | 98 | #define list_first_entry(head, type, member) \ 99 | ((list_empty(head)) ? NULL : container_of((head)->next, type, member)) 100 | 101 | #define list_last_entry(head, type, member) \ 102 | ((list_empty(head)) ? NULL : container_of((head)->prev, type, member)) 103 | #endif 104 | -------------------------------------------------------------------------------- /vudevfuse/vudevfuse.h: -------------------------------------------------------------------------------- 1 | #ifndef _VUDEVFUSE_H 2 | #define _VUDEVFUSE_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define VUDEVFUSE_MODULE_FLAGS (VU_USE_PRW) 11 | #define FUSENODE_BUFSIZE 256 12 | 13 | extern struct vuht_entry_t *devfuse_ht; 14 | 15 | #ifndef FUSE_SUPER_MAGIC 16 | #define FUSE_SUPER_MAGIC 0x65735546 17 | #endif 18 | 19 | struct fusemount_t { 20 | struct vuht_entry_t *ht; 21 | pthread_mutex_t mutex; 22 | int sem; // < 0 if fd is closed 23 | unsigned long mountflags; 24 | mode_t rootmode; // unsupported 25 | uid_t uid; 26 | uid_t gid; 27 | uint64_t last_unique; 28 | struct fuse_init_out initdata; 29 | struct fusereq *reqq; 30 | struct fusereq *replyq; 31 | struct fusenode_buf *fnbuf; 32 | // mountflags 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /vufs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include_directories(${VU_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}) 4 | 5 | set(VU_MOD_TARGET vufs) 6 | file(GLOB_RECURSE VUFS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 7 | 8 | add_library(${VU_MOD_TARGET} SHARED ${VUFS_SOURCES}) 9 | set_target_properties(${VU_MOD_TARGET} PROPERTIES PREFIX "") 10 | target_link_libraries(${VU_MOD_TARGET} stropt volatilestream) 11 | 12 | install(TARGETS ${VU_MOD_TARGET} LIBRARY DESTINATION ${MODULES_INSTALL_PATH}) 13 | -------------------------------------------------------------------------------- /vufs/vufs.h: -------------------------------------------------------------------------------- 1 | #ifndef VUFS_H 2 | #define VUFS_H 3 | #include 4 | #include 5 | 6 | VU_PROTOTYPES(vufs) 7 | 8 | #define O_UNLINK (O_PATH | O_EXCL) 9 | 10 | #define VUFS_TYPEMASK 0x7 11 | #define VUFS_BIND 0x0 12 | #define VUFS_MERGE 0x1 13 | #define VUFS_COW 0x2 14 | #define VUFS_MINCOW 0x4 15 | #define VUFS_NOCHCOPY 0x100 16 | 17 | struct vufs_t { 18 | pthread_mutex_t mutex; 19 | 20 | char *source; 21 | char *target; 22 | int rdirfd; 23 | int vdirfd; 24 | int ddirfd; 25 | int flags; 26 | 27 | char *except[]; 28 | }; 29 | 30 | struct vufs_fdprivate { 31 | FILE *getdentsf; 32 | char path[]; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /vufs/vufs_getdents.h: -------------------------------------------------------------------------------- 1 | #ifndef VUFS_GETDENTS_H 2 | #define VUFS_GETDENTS_H 3 | 4 | struct vufs_t; 5 | 6 | int vufs_enotempty_ck(struct vufs_t *vufs, const char *path); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /vufs/vufs_path.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2018 Renzo Davoli 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | void vufs_create_path(int dirfd, const char *path, create_path_cb_t callback, void *arg) { 33 | int pathlen = strlen(path); 34 | char tpath[pathlen]; 35 | int i; 36 | for (i = 0; i < pathlen; i++) { 37 | if (path[i] == '/') { 38 | tpath[i] = 0; 39 | if (mkdirat(dirfd, tpath, 0700) == 0 && callback) 40 | callback(arg, dirfd, tpath); 41 | } 42 | tpath[i] = path[i]; 43 | } 44 | } 45 | 46 | void vufs_destroy_path(int dirfd, const char *path) { 47 | int pathlen = strlen(path); 48 | char tpath[pathlen + 1]; 49 | int i; 50 | strcpy(tpath, path); 51 | for (i = pathlen - 1; i >= 0; i--) { 52 | if (tpath[i] == '/') { 53 | tpath[i] = 0; 54 | if (unlinkat(dirfd, tpath, AT_REMOVEDIR) < 0) 55 | break; 56 | } 57 | } 58 | } 59 | 60 | static int skipdir(const char *name) { 61 | if (name[0] == 0 || name[0] != '.') 62 | return 0; 63 | if (name[1] == 0) 64 | return 1; 65 | if (name[1] == '.' && name[2] == 0) 66 | return 1; 67 | return 0; 68 | } 69 | 70 | void vufs_destroy_tree(int dirfd, const char *path, int recursive) { 71 | int retval = unlinkat(dirfd, path, 0); 72 | if (retval < 0 && errno == EISDIR) { 73 | retval = unlinkat(dirfd, path, AT_REMOVEDIR); 74 | if (retval < 0 && (errno == ENOTEMPTY || errno == EEXIST)) { 75 | int fd = openat(dirfd, path, O_RDONLY | O_DIRECTORY); 76 | if (fd >= 0) { 77 | DIR *dir; 78 | struct dirent *de; 79 | dir = fdopendir(fd); 80 | if (dir) { 81 | while ((de = readdir(dir)) != NULL) { 82 | if (skipdir(de->d_name) == 0) { 83 | if (recursive) 84 | vufs_destroy_tree(fd, de->d_name, recursive); 85 | else 86 | unlinkat(fd, de->d_name, 0); 87 | } 88 | } 89 | closedir(dir); 90 | } 91 | } 92 | unlinkat(dirfd, path, AT_REMOVEDIR); 93 | } 94 | } 95 | } 96 | 97 | int vufs_whiteout(int dirfd, const char *path) { 98 | if (dirfd >= 0) { 99 | vufs_destroy_tree(dirfd, path, 0); 100 | vufs_create_path(dirfd, path, NULL, NULL); 101 | return mknodat(dirfd, path, S_IFREG | 0644, 0); 102 | } else 103 | return 0; 104 | } 105 | 106 | void vufs_dewhiteout(int dirfd, const char *path) { 107 | if (dirfd >= 0) { 108 | if (unlinkat(dirfd, path, 0) == 0) 109 | vufs_destroy_path(dirfd, path); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /vufs/vufs_path.h: -------------------------------------------------------------------------------- 1 | #ifndef VUFS_PATH_H 2 | #define VUFS_PATH_H 3 | 4 | typedef void (*create_path_cb_t)(void *arg, int dirfd, const char *path); 5 | 6 | void vufs_create_path(int dirfd, const char *path, create_path_cb_t callback, void *arg); 7 | void vufs_destroy_path(int dirfd, const char *path); 8 | void vufs_destroy_tree(int dirfd, const char *path, int recursive); 9 | int vufs_whiteout(int dirfd, const char *path); 10 | void vufs_dewhiteout(int dirfd, const char *path); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /vufs/vufsa.h: -------------------------------------------------------------------------------- 1 | #ifndef VUFSA_H 2 | #define VUFSA_H 3 | 4 | struct vufs_t; 5 | 6 | typedef int8_t vufsa_status; 7 | 8 | /* type of FSA next function */ 9 | typedef vufsa_status (*vufsa_next)(vufsa_status status, struct vufs_t *vufs, const char *path, int rv); 10 | 11 | /* select the right FSA depending upon the mount mode and open flags */ 12 | vufsa_next vufsa_select(struct vufs_t *vufs, int open_flags); 13 | 14 | #define VUFSA_ERR -1 15 | #define VUFSA_EXIT 0 16 | #define VUFSA_START 1 17 | #define VUFSA_FINAL 2 18 | #define VUFSA_DOREAL 3 19 | #define VUFSA_DOVIRT 4 20 | #define VUFSA_DOCOPY 5 21 | #define VUFSA_VUNLINK 5 22 | 23 | #if 0 24 | /* usage: */ 25 | int rv; 26 | vufsa_status status = VUFSA_START; 27 | vufsa_next vufsa_next = vufsa_select(vufs, openflag); 28 | while ((status = vufsa_next(status, vufs, path, openflag, 0, rv)) != VUFSA_EXIT) { 29 | switch (status) { 30 | case VUFSA_DOREAL: 31 | rv = /* implementation of do_real for this syscall */ 32 | break; 33 | case VUFSA_DOVIRT: 34 | rv = /* implementation of do_virtual for this syscall */ 35 | break; 36 | case VUFSA_DOCOPY: 37 | rv = /* implementation of do_copy for this syscall */ 38 | break; 39 | case VUFSA_ERR: 40 | rv = -1; 41 | break; 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /vufs/vufstat.h: -------------------------------------------------------------------------------- 1 | #ifndef VUFSTAT_H 2 | #define VUFSTAT_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define VUFSTAT_TYPE 0x00001 11 | #define VUFSTAT_MODE 0x00002 12 | #define VUFSTAT_UID 0x00010 13 | #define VUFSTAT_GID 0x00020 14 | #define VUFSTAT_RDEV 0x00100 15 | #define VUFSTAT_DEV 0x00200 16 | #define VUFSTAT_CTIME 0x01000 17 | #define VUFSTAT_COPYMASK (VUFSTAT_MODE | VUFSTAT_UID | VUFSTAT_GID) 18 | 19 | uint32_t vufstat_merge(int dirfd, const char *path, struct vu_stat *statbuf); 20 | uint32_t vufstat_cmpstat(struct vu_stat *statbuf1, struct vu_stat *statbuf2); 21 | void vufstat_write(int dirfd, const char *path, struct vu_stat *statbuf, uint32_t mask); 22 | void vufstat_update(int dirfd, const char *path, struct vu_stat *statbuf, uint32_t mask, mode_t creat); 23 | 24 | #if 0 25 | void vufstat_chmod(int dirfd, const char *path, mode_t mode); 26 | void vufstat_chown(int dirfd, const char *path, uid_t owner, gid_t group); 27 | void vufstat_mknod(int dirfd, const char *path, dev_t dev); 28 | void vufstat_settype(int dirfd, const char *path, mode_t mode); 29 | #endif 30 | void vufstat_unlink(int dirfd, const char *path); 31 | int vufstat_link(int dirfd, const char *oldpath, const char *newpath); 32 | int vufstat_rename(int dirfd, const char *oldpath, const char *newpath, int flags); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /vufuse/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=314") 4 | 5 | include_directories(${VU_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}) 6 | 7 | set(VU_MOD_TARGET vufuse) 8 | file(GLOB_RECURSE VUFUSE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 9 | 10 | add_library(${VU_MOD_TARGET} SHARED ${VUFUSE_SOURCES}) 11 | set_target_properties(${VU_MOD_TARGET} PROPERTIES PREFIX "") 12 | target_link_libraries(${VU_MOD_TARGET} stropt volatilestream execs) 13 | 14 | install(TARGETS ${VU_MOD_TARGET} LIBRARY DESTINATION ${MODULES_INSTALL_PATH}) 15 | -------------------------------------------------------------------------------- /vufuse/vufuse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2018 Renzo Davoli 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef VUFUSE_H 22 | #define VUFUSE_H 23 | 24 | #include 25 | 26 | /** Enable hard remove */ 27 | #define FUSE_HARDREMOVE (1 << 0) 28 | 29 | struct fuse { 30 | void *dlhandle; 31 | struct fuse_operations fops; 32 | 33 | pthread_mutex_t mutex; 34 | 35 | pthread_t thread; 36 | pthread_cond_t startloop; 37 | pthread_cond_t endloop; 38 | 39 | int inuse; 40 | int fake_chan_fd; 41 | unsigned long mountflags; 42 | unsigned long fuseflags; 43 | void *private_data; 44 | }; 45 | 46 | struct fileinfo { 47 | //char *path; 48 | struct fuse_node *node; 49 | off_t pos; /* file offset */ 50 | struct fuse_file_info ffi; /* includes open flags, file handle and page_write mode */ 51 | FILE *dirf; 52 | }; 53 | 54 | struct fuse_context *fuse_push_context(struct fuse_context *new); 55 | void fuse_pop_context(struct fuse_context *old); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /vufuse/vufuse_compat.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct fuse_operations; 3 | struct fuse_args; 4 | struct libfuse_version; 5 | 6 | int __fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, 7 | size_t op_size, void *user_data); 8 | int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, 9 | size_t op_size, void *user_data) { 10 | return __fuse_main_real(argc, argv, op, op_size, user_data); 11 | } 12 | int fuse_main_real_versioned(int argc, char *argv[], 13 | const struct fuse_operations *op, size_t op_size, 14 | struct libfuse_version *version, void *user_data) { 15 | return __fuse_main_real(argc, argv, op, op_size, user_data); 16 | } 17 | 18 | struct fuse *__fuse_new(struct fuse_args *args, 19 | const struct fuse_operations *op, size_t op_size, 20 | void *user_data); 21 | struct fuse *fuse_new(struct fuse_args *args, 22 | const struct fuse_operations *op, size_t op_size, 23 | void *user_data) { 24 | return __fuse_new(args, op, op_size, user_data); 25 | } 26 | struct fuse *_fuse_new_30(struct fuse_args *args, 27 | const struct fuse_operations *op, size_t op_size, 28 | struct libfuse_version *version, void *user_data) { 29 | return __fuse_new(args, op, op_size, user_data); 30 | } 31 | struct fuse *_fuse_new_31(struct fuse_args *args, 32 | const struct fuse_operations *op, size_t op_size, 33 | struct libfuse_version *version, void *user_data) { 34 | return __fuse_new(args, op, op_size, user_data); 35 | } 36 | -------------------------------------------------------------------------------- /vufuse/vufuse_default_ops.h: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2018 Renzo Davoli 4 | * VirtualSquare team. 5 | * (inherited from umfuse Copyright 2005 Renzo Davoli) 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | * 20 | */ 21 | 22 | #ifndef VUFUSE_DEFAULT_OPS_H 23 | #define VUFUSE_DEFAULT_OPS_H 24 | 25 | #include 26 | 27 | extern struct fuse_operations vufuse_default_ops; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /vufuse/vufuse_node.h: -------------------------------------------------------------------------------- 1 | #ifndef VUFUSE_NODE_H 2 | #define VUFUSE_NODE_H 3 | 4 | struct fuse; 5 | struct fuse_node; 6 | 7 | char *vufuse_node_path(struct fuse_node *node); 8 | struct fuse_node *vufuse_node_add(struct fuse *fuse, const char *path); 9 | char *vufuse_node_del(struct fuse_node *node); 10 | char *vufuse_node_rename(struct fuse *fuse, const char *path, const char *newpath); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /vufuse/vufuse_startmain.h: -------------------------------------------------------------------------------- 1 | #ifndef VUFUSE_STARTMAIN_H 2 | #define VUFUSE_STARTMAIN_H 3 | 4 | struct main_params { 5 | int (*pmain)(int argc, char **argv); 6 | const char *filesystemtype; 7 | const char *source; 8 | const char *target; 9 | unsigned long *pmountflags; 10 | unsigned long *pfuseflags; 11 | char *opts; 12 | }; 13 | 14 | int fusestartmain(struct main_params *mntp); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /vufuse_modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include_directories(${VU_HEADERS} ${VU_DYN_HEADER_PATH}) 4 | set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) 5 | set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) 6 | 7 | file(GLOB VUFUSE_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/vu*.c) 8 | 9 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64") 10 | 11 | foreach(VUFUSE_MOD ${VUFUSE_MODULES}) 12 | string(REGEX REPLACE "\.c$" "" VUFUSE_MOD_FILE ${VUFUSE_MOD}) 13 | get_filename_component(VUFUSE_MOD_TARGET ${VUFUSE_MOD_FILE} NAME) 14 | add_library(${VUFUSE_MOD_TARGET} SHARED ${VUFUSE_MOD}) 15 | set_target_properties(${VUFUSE_MOD_TARGET} PROPERTIES PREFIX "") 16 | target_compile_definitions(${VUFUSE_MOD_TARGET} PUBLIC PROGNAME="${VUFUSE_MOD_TARGET}") 17 | install(TARGETS ${VUFUSE_MOD_TARGET} LIBRARY DESTINATION ${MODULES_INSTALL_PATH}) 18 | endforeach(VUFUSE_MOD) 19 | 20 | foreach(VUFUSE_MOD ${VUFUSE_MODULES}) 21 | string(REGEX REPLACE "\.c$" "" VUFUSE_MOD_FILE ${VUFUSE_MOD}) 22 | get_filename_component(VUFUSE_MOD_EXE ${VUFUSE_MOD_FILE} NAME) 23 | string(REGEX REPLACE "^vu" "" VUFUSE_MOD_EXE ${VUFUSE_MOD_EXE}) 24 | set(VUFUSE_MOD_TARGET ${VUFUSE_MOD_EXE}) 25 | add_executable(${VUFUSE_MOD_TARGET} ${VUFUSE_MOD}) 26 | set_target_properties(${VUFUSE_MOD_TARGET} PROPERTIES OUTPUT_NAME ${VUFUSE_MOD_EXE}) 27 | target_compile_definitions(${VUFUSE_MOD_TARGET} PUBLIC PROGNAME="${VUFUSE_MOD_TARGET}") 28 | target_link_libraries(${VUFUSE_MOD_TARGET} -lfuse3) 29 | install(TARGETS ${VUFUSE_MOD_TARGET} RUNTIME DESTINATION bin) 30 | endforeach(VUFUSE_MOD) 31 | -------------------------------------------------------------------------------- /vufuse_modules/vufusenull.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018 Renzo Davoli 3 | * Leonardo Frioli 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program (in the main directory of the vuos 17 | * distribution in the file COPYING); if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 19 | */ 20 | 21 | #define FUSE_USE_VERSION FUSE_MAKE_VERSION(3, 14) 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #ifndef PATH_MAX 43 | #define PATH_MAX 4096 44 | #endif 45 | 46 | int fuse_reentrant_tag = 0; 47 | 48 | int op_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi){ 49 | if (strcmp(path, "/") == 0) { 50 | memset(stbuf, 0, sizeof(*stbuf)); 51 | stbuf->st_mode = 0755 | S_IFDIR; 52 | stbuf->st_nlink = 2; 53 | return 0; 54 | } else 55 | return -ENOENT; 56 | } 57 | int op_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, 58 | struct fuse_file_info *fi, enum fuse_readdir_flags flags){ 59 | filler(buf, ".", NULL, 0, 0); 60 | filler(buf, "..", NULL, 0, 0); 61 | return 0; 62 | } 63 | 64 | static const struct fuse_operations null_ops = { 65 | .getattr = op_getattr, 66 | .readdir = op_readdir, 67 | }; 68 | 69 | int main(int argc, char *argv[]) 70 | { 71 | return fuse_main(argc, argv, &null_ops, NULL); 72 | } 73 | -------------------------------------------------------------------------------- /vumisc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include_directories(${VU_HEADERS}) 4 | 5 | set(VU_MOD_TARGET vumisc) 6 | file(GLOB_RECURSE VUMISC_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 7 | 8 | add_library(${VU_MOD_TARGET} SHARED ${VUMISC_SOURCES}) 9 | set_target_properties(${VU_MOD_TARGET} PROPERTIES PREFIX "") 10 | 11 | target_link_libraries(${VU_MOD_TARGET} vumod) 12 | 13 | install(TARGETS ${VU_MOD_TARGET} LIBRARY DESTINATION ${MODULES_INSTALL_PATH}) 14 | -------------------------------------------------------------------------------- /vumisc_modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include_directories(${VU_HEADERS} ${VU_DYN_HEADER_PATH}) 4 | set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) 5 | 6 | file(GLOB VUMISC_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 7 | 8 | foreach(VUMISC_MOD ${VUMISC_MODULES}) 9 | string(REGEX REPLACE "\.c$" "" VUMISC_MOD_FILE ${VUMISC_MOD}) 10 | get_filename_component(VUMISC_MOD_TARGET ${VUMISC_MOD_FILE} NAME) 11 | add_library(${VUMISC_MOD_TARGET} SHARED ${VUMISC_MOD}) 12 | set_target_properties(${VUMISC_MOD_TARGET} PROPERTIES PREFIX "") 13 | install(TARGETS ${VUMISC_MOD_TARGET} LIBRARY DESTINATION ${MODULES_INSTALL_PATH}) 14 | endforeach(VUMISC_MOD) 15 | 16 | # target_link_libraries(vumiscmod modlib) 17 | -------------------------------------------------------------------------------- /vunet/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include_directories(${VU_HEADERS}) 4 | 5 | set(VU_MOD_TARGET vunet) 6 | file(GLOB_RECURSE VUNET_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 7 | 8 | add_library(${VU_MOD_TARGET} SHARED ${VUNET_SOURCES}) 9 | set_target_properties(${VU_MOD_TARGET} PROPERTIES PREFIX "") 10 | 11 | install(TARGETS ${VU_MOD_TARGET} LIBRARY DESTINATION ${MODULES_INSTALL_PATH}) 12 | -------------------------------------------------------------------------------- /vunet/vunet_ioctl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VUOS: view OS project 3 | * Copyright (C) 2018 Renzo Davoli 4 | * VirtualSquare team. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | long vunet_ioctl_parms(unsigned long request) { 26 | switch (request) { 27 | case FIONREAD: 28 | return _IOW(' ', 0, int); 29 | case FIONBIO: 30 | return _IOR(' ', 0, int); 31 | case SIOCGIFCONF: 32 | return _IOWR(' ', 0, struct ifconf); 33 | #ifdef SIOCGSTAMP 34 | case SIOCGSTAMP: 35 | return _IOW(' ', 0, struct timeval); 36 | #endif 37 | case SIOCGIFNAME: 38 | case SIOCGIFFLAGS: 39 | case SIOCGIFADDR: 40 | case SIOCGIFDSTADDR: 41 | case SIOCGIFBRDADDR: 42 | case SIOCGIFNETMASK: 43 | case SIOCGIFMETRIC: 44 | case SIOCGIFMEM: 45 | case SIOCGIFMTU: 46 | case SIOCGIFHWADDR: 47 | case SIOCGIFINDEX: 48 | case SIOCGIFTXQLEN: 49 | return _IOWR(' ', 0, struct ifreq); 50 | case SIOCSIFNAME: 51 | case SIOCSIFFLAGS: 52 | case SIOCSIFADDR: 53 | case SIOCSIFDSTADDR: 54 | case SIOCSIFBRDADDR: 55 | case SIOCSIFNETMASK: 56 | case SIOCSIFMETRIC: 57 | case SIOCSIFMEM: 58 | case SIOCSIFMTU: 59 | case SIOCSIFHWADDR: 60 | case SIOCSIFTXQLEN: 61 | case SIOCSIFHWBROADCAST: 62 | return _IOR(' ', 0, struct ifreq); 63 | case SIOCGIFMAP: 64 | return _IOWR(' ', 0, struct ifmap); 65 | case SIOCSIFMAP: 66 | return _IOR(' ', 0, struct ifmap); 67 | default: 68 | return 0; 69 | } 70 | } 71 | 72 | int vunet_is_netdev_ioctl(unsigned long request) { 73 | switch (request) { 74 | case SIOCGIFCONF: 75 | #ifdef SIOCGSTAMP 76 | case SIOCGSTAMP: 77 | #endif 78 | case SIOCGIFNAME: 79 | case SIOCGIFFLAGS: 80 | case SIOCGIFADDR: 81 | case SIOCGIFDSTADDR: 82 | case SIOCGIFBRDADDR: 83 | case SIOCGIFNETMASK: 84 | case SIOCGIFMETRIC: 85 | case SIOCGIFMEM: 86 | case SIOCGIFMTU: 87 | case SIOCGIFHWADDR: 88 | case SIOCGIFINDEX: 89 | case SIOCGIFTXQLEN: 90 | case SIOCSIFNAME: 91 | case SIOCSIFFLAGS: 92 | case SIOCSIFADDR: 93 | case SIOCSIFDSTADDR: 94 | case SIOCSIFBRDADDR: 95 | case SIOCSIFNETMASK: 96 | case SIOCSIFMETRIC: 97 | case SIOCSIFMEM: 98 | case SIOCSIFMTU: 99 | case SIOCSIFHWADDR: 100 | case SIOCSIFTXQLEN: 101 | case SIOCSIFHWBROADCAST: 102 | case SIOCGIFMAP: 103 | case SIOCSIFMAP: 104 | return 1; 105 | default: 106 | return 0; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /vunet_modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include_directories(${VU_HEADERS} ${VU_DYN_HEADER_PATH}) 4 | set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) 5 | 6 | file(GLOB VUNET_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 7 | 8 | foreach(VUNET_MOD ${VUNET_MODULES}) 9 | string(REGEX REPLACE "\.c$" "" VUNET_MOD_FILE ${VUNET_MOD}) 10 | get_filename_component(VUNET_MOD_TARGET ${VUNET_MOD_FILE} NAME) 11 | add_library(${VUNET_MOD_TARGET} SHARED ${VUNET_MOD}) 12 | set_target_properties(${VUNET_MOD_TARGET} PROPERTIES PREFIX "") 13 | install(TARGETS ${VUNET_MOD_TARGET} LIBRARY DESTINATION ${MODULES_INSTALL_PATH}) 14 | endforeach(VUNET_MOD) 15 | 16 | target_link_libraries(vunetvdestack vdeplug) 17 | -------------------------------------------------------------------------------- /vunet_modules/vunetnull.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static int supported_domain (int domain) { 5 | switch (domain) { 6 | case AF_INET: 7 | case AF_INET6: 8 | case AF_NETLINK: 9 | case AF_PACKET: 10 | return 1; 11 | default: 12 | return 0; 13 | } 14 | } 15 | 16 | static int null_socket(int domain, int type, int protocol) { 17 | errno = EAFNOSUPPORT; 18 | return -1; 19 | } 20 | 21 | struct vunet_operations vunet_ops = { 22 | .socket = null_socket, 23 | 24 | .supported_domain = supported_domain, 25 | }; 26 | -------------------------------------------------------------------------------- /vunet_modules/vunetreal.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int supported_domain (int domain) { 4 | switch (domain) { 5 | case AF_INET: 6 | case AF_INET6: 7 | case AF_NETLINK: 8 | case AF_PACKET: 9 | return 1; 10 | default: 11 | return 0; 12 | } 13 | } 14 | 15 | static int netreal_ioctl (int fd, unsigned long request, void *addr) { 16 | return ioctl(fd, request, addr); 17 | } 18 | 19 | struct vunet_operations vunet_ops = { 20 | .socket = socket, 21 | .bind = bind, 22 | .connect = connect, 23 | .listen = listen, 24 | .accept4 = accept4, 25 | .getsockname = getsockname, 26 | .getpeername = getpeername, 27 | .recvmsg = recvmsg, 28 | .sendmsg = sendmsg, 29 | .getsockopt = getsockopt, 30 | .setsockopt = setsockopt, 31 | .shutdown = shutdown, 32 | .ioctl = netreal_ioctl, 33 | .close = close, 34 | 35 | .epoll_ctl = epoll_ctl, 36 | 37 | .supported_domain = supported_domain, 38 | }; 39 | --------------------------------------------------------------------------------