this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added BSD ioctl translation infrstructure, added mkdir/rmdir and fcntl_nocancel

+208 -37
+2
src/kernel/emulation/linux/CMakeLists.txt
··· 61 61 stat/stat.c 62 62 stat/getfsstat.c 63 63 stat/statfs.c 64 + stat/mkdir.c 65 + stat/rmdir.c 64 66 stat/common.c 65 67 dirent/getdirentries.c 66 68 time/gettimeofday.c
+5
src/kernel/emulation/linux/fcntl/fcntl.c
··· 26 26 27 27 long sys_fcntl(int fd, int cmd, long arg) 28 28 { 29 + return sys_fcntl_nocancel(fd, cmd, arg); 30 + } 31 + 32 + long sys_fcntl_nocancel(int fd, int cmd, long arg) 33 + { 29 34 int ret, linux_cmd; 30 35 31 36 switch (cmd)
+1
src/kernel/emulation/linux/fcntl/fcntl.h
··· 2 2 #define LINUX_FCNTL_H 3 3 4 4 long sys_fcntl(int fd, int cmd, long arg); 5 + long sys_fcntl_nocancel(int fd, int cmd, long arg); 5 6 6 7 enum { 7 8 LINUX_F_DUPFD = 0,
+20
src/kernel/emulation/linux/stat/mkdir.c
··· 1 + #include "mkdir.h" 2 + #include "common.h" 3 + #include "../base.h" 4 + #include "../errno.h" 5 + #include <asm/unistd.h> 6 + 7 + long sys_mkdir(const char* path, unsigned int mode) 8 + { 9 + int ret; 10 + 11 + // TODO: handle case conversion 12 + 13 + ret = LINUX_SYSCALL(__NR_mkdir, path, mode); 14 + 15 + if (ret < 0) 16 + return errno_linux_to_bsd(ret); 17 + 18 + return 0; 19 + } 20 +
+7
src/kernel/emulation/linux/stat/mkdir.h
··· 1 + #ifndef LINUX_MKDIR_H 2 + #define LINUX_MKDIR_H 3 + 4 + long sys_mkdir(const char* path, unsigned int mode); 5 + 6 + #endif 7 +
+20
src/kernel/emulation/linux/stat/rmdir.c
··· 1 + #include "rmdir.h" 2 + #include "common.h" 3 + #include "../base.h" 4 + #include "../errno.h" 5 + #include <asm/unistd.h> 6 + 7 + long sys_rmdir(const char* path) 8 + { 9 + int ret; 10 + 11 + // TODO: handle case conversion 12 + 13 + ret = LINUX_SYSCALL(__NR_rmdir, path); 14 + 15 + if (ret < 0) 16 + return errno_linux_to_bsd(ret); 17 + 18 + return 0; 19 + } 20 +
+7
src/kernel/emulation/linux/stat/rmdir.h
··· 1 + #ifndef LINUX_RMDIR_H 2 + #define LINUX_RMDIR_H 3 + 4 + long sys_rmdir(const char* path); 5 + 6 + #endif 7 +
+5
src/kernel/emulation/linux/syscalls.c
··· 47 47 #include "stat/stat.h" 48 48 #include "stat/lstat.h" 49 49 #include "stat/statfs.h" 50 + #include "stat/mkdir.h" 51 + #include "stat/rmdir.h" 50 52 #include "stat/getfsstat.h" 51 53 #include "time/gettimeofday.h" 52 54 #include "wqueue/bsdthread_register.h" ··· 84 86 [121] = sys_writev, 85 87 [123] = sys_fchown, 86 88 [124] = sys_fchmod, 89 + [136] = sys_mkdir, 90 + [137] = sys_rmdir, 87 91 [147] = sys_setsid, 88 92 [153] = sys_pread, 89 93 [154] = sys_pwrite, ··· 114 118 [397] = sys_write_nocancel, 115 119 [398] = sys_open_nocancel, 116 120 [399] = sys_close_nocancel, 121 + [406] = sys_fcntl_nocancel, 117 122 [408] = sys_fsync_nocancel, 118 123 [411] = sys_readv_nocancel, 119 124 [412] = sys_writev_nocancel,
+1
src/kernel/mach_server/client/CMakeLists.txt
··· 8 8 set(mach_server_client_sources 9 9 mach_traps.c 10 10 mach_time.c 11 + lkm.c 11 12 ) 12 13 13 14 add_library(mach_server_client OBJECT ${mach_server_client_sources})
+42
src/kernel/mach_server/client/lkm.c
··· 1 + #include "lkm.h" 2 + #include "../../lkm/api.h" 3 + 4 + int driver_fd; 5 + 6 + void mach_driver_init(void) 7 + { 8 + if (driver_fd != -1) 9 + close(driver_fd); 10 + 11 + driver_fd = open("/dev/mach", O_RDWR); 12 + if (driver_fd == -1) 13 + { 14 + const char* msg = "Cannot open /dev/mach. Aborting.\nMake sure you have loaded the darling-mach kernel module.\n"; 15 + 16 + write(2, msg, strlen(msg)); 17 + abort(); 18 + } 19 + 20 + if (ioctl(driver_fd, NR_get_api_version, 0) != DARLING_MACH_API_VERSION) 21 + { 22 + const char* msg = "Darling Mach kernel module reports different API level. Aborting.\n"; 23 + 24 + write(2, msg, strlen(msg)); 25 + abort(); 26 + } 27 + } 28 + 29 + extern int __real_ioctl(int fd, int cmd, void* arg); 30 + 31 + // Emulated ioctl implementation 32 + int ioctl(int fd, int cmd, void* arg) 33 + { 34 + struct bsd_ioctl_args args = { 35 + .fd = fd, 36 + .request = cmd, 37 + .arg = arg 38 + }; 39 + 40 + return __real_ioctl(driver_fd, NR_bsd_ioctl_trap, &args); 41 + } 42 +
+8
src/kernel/mach_server/client/lkm.h
··· 1 + #ifndef _LKM_H 2 + #define _LKM_H 3 + 4 + __attribute__((hidden)) 5 + extern int driver_fd; 6 + 7 + #endif 8 +
+2 -25
src/kernel/mach_server/client/mach_traps.c
··· 1 + #define ioctl __real_ioctl 1 2 #define PRIVATE 2 3 #include <mach/mach_traps.h> 3 4 #include <mach/kern_return.h> ··· 5 6 #include <fcntl.h> 6 7 #include <unistd.h> 7 8 #include "../../lkm/api.h" 9 + #include "lkm.h" 8 10 9 11 #define UNIMPLEMENTED_TRAP() { char msg[] = "Called unimplemented Mach trap: "; write(2, msg, sizeof(msg)-1); write(2, __FUNCTION__, sizeof(__FUNCTION__)-1); write(2, "\n", 1); } 10 - 11 - static int driver_fd = -1; 12 - 13 - void mach_driver_init(void) 14 - { 15 - if (driver_fd != -1) 16 - close(driver_fd); 17 - 18 - driver_fd = open("/dev/mach", O_RDWR); 19 - if (driver_fd == -1) 20 - { 21 - const char* msg = "Cannot open /dev/mach. Aborting.\nMake sure you have loaded the darling-mach kernel module.\n"; 22 - 23 - write(2, msg, strlen(msg)); 24 - abort(); 25 - } 26 - 27 - if (ioctl(driver_fd, NR_get_api_version, 0) != DARLING_MACH_API_VERSION) 28 - { 29 - const char* msg = "Darling Mach kernel module reports different API level. Aborting.\n"; 30 - 31 - write(2, msg, strlen(msg)); 32 - abort(); 33 - } 34 - } 35 12 36 13 mach_port_name_t mach_reply_port(void) 37 14 {
+41 -5
src/lkm/bsd_ioctl.c
··· 18 18 */ 19 19 20 20 #include "bsd_ioctl.h" 21 + #include "debug.h" 22 + #include <linux/fs.h> 23 + #include <linux/dcache.h> 24 + 25 + #define D_TAPE 1 26 + #define D_DISK 2 27 + #define D_TTY 3 28 + 29 + int bsd_ioctl_xlate_socket(struct file* f, struct bsd_ioctl_args* args, long* retval) 30 + { 31 + return bsd_ioctl_xlate_generic(f, args, retval); 32 + } 21 33 22 - void bsd_ioctl_xlate_socket(struct bsd_ioctl_args* args) 34 + int bsd_ioctl_xlate_tty(struct file* f, struct bsd_ioctl_args* args, long* retval) 23 35 { 24 - 36 + return bsd_ioctl_xlate_generic(f, args, retval); 25 37 } 26 38 27 - void bsd_ioctl_xlate_tty(struct bsd_ioctl_args* args) 39 + int bsd_ioctl_xlate_pts(struct file* f, struct bsd_ioctl_args* args, long* retval) 28 40 { 29 - 41 + return bsd_ioctl_xlate_generic(f, args, retval); 30 42 } 31 43 32 - void bsd_ioctl_xlate_pts(struct bsd_ioctl_args* args) 44 + int bsd_ioctl_xlate_generic(struct file* f, struct bsd_ioctl_args* args, long* retval) 33 45 { 46 + switch (args->request) 47 + { 48 + case BSD_FIODTYPE: 49 + { 50 + char name[60]; 51 + 52 + if (d_path(&f->f_path, name, sizeof(name))) 53 + { 54 + int type; 55 + if (strncmp(name, "/dev/pts", 8) == 0 || strncmp(name, "/dev/tty", 8) == 0) 56 + type = D_TTY; 57 + else if (strncmp(name, "/dev/st", 7) == 0 || strncmp(name, "/dev/nst", 8) == 0) 58 + type = D_TAPE; 59 + else 60 + type = D_DISK; 61 + *retval = type; 62 + 63 + return 1; 64 + } 65 + 66 + break; 67 + } 68 + } 34 69 70 + return 0; 35 71 }
+39 -3
src/lkm/bsd_ioctl.h
··· 20 20 #ifndef BSD_IOCTL_H 21 21 #define BSD_IOCTL_H 22 22 #include "api.h" 23 + #include <linux/file.h> 24 + 25 + // If only translation of ioctl request number happens, 26 + // retval is untouched and 0 is returned. 27 + // If the ioctl is handled completely differently, retval contains the return 28 + // value to be returned to userspace and function returns non-zero value. 29 + 30 + int bsd_ioctl_xlate_socket(struct file* f, struct bsd_ioctl_args* args, long* retval); 31 + int bsd_ioctl_xlate_tty(struct file* f, struct bsd_ioctl_args* args, long* retval); 32 + int bsd_ioctl_xlate_pts(struct file* f, struct bsd_ioctl_args* args, long* retval); 33 + int bsd_ioctl_xlate_generic(struct file* f, struct bsd_ioctl_args* args, long* retval); 23 34 24 - void bsd_ioctl_xlate_socket(struct bsd_ioctl_args* args); 25 - void bsd_ioctl_xlate_tty(struct bsd_ioctl_args* args); 26 - void bsd_ioctl_xlate_pts(struct bsd_ioctl_args* args); 35 + #define BSD_IOCPARM_MASK 0x1fff 36 + #define BSD_IOCPARM_LEN(x) (((x) >> 16) & BSD_IOCPARM_MASK) 37 + #define BSD_IOCBASECMD(x) ((x) & ~(IBSD_OCPARM_MASK << 16)) 38 + #define BSD_IOCGROUP(x) (((x) >> 8) & 0xff) 39 + 40 + #define BSD_IOCPARM_MAX (BSD_IOCPARM_MASK + 1) 41 + #define BSD_IOC_VOID (uint32_t)0x20000000 42 + #define BSD_IOC_OUT (uint32_t)0x40000000 43 + #define BSD_IOC_IN (uint32_t)0x80000000 44 + #define BSD_IOC_INOUT (BSD_IOC_IN|BSD_IOC_OUT) 45 + #define BSD_IOC_DIRMASK (uint32_t)0xe0000000 46 + 47 + #define BSD_IOC(inout,group,num,len) \ 48 + (inout | ((len & BSD_IOCPARM_MASK) << 16) | ((group) << 8) | (num)) 49 + #define BSD_IO(g,n) BSD_IOC(BSD_IOC_VOID, (g), (n), 0) 50 + #define BSD_IOR(g,n,t) BSD_IOC(BSD_IOC_OUT, (g), (n), sizeof(t)) 51 + #define BSD_IOW(g,n,t) BSD_IOC(BSD_IOC_IN, (g), (n), sizeof(t)) 52 + #define BSD_IOWR(g,n,t) BSD_IOC(BSD_IOC_INOUT, (g), (n), sizeof(t)) 53 + 54 + 55 + #define BSD_FIOCLEX BSD_IO('f', 1) 56 + #define BSD_FIONCLEX BSD_IO('f', 2) 57 + #define BSD_FIONREAD BSD_IOR('f', 127, int) 58 + #define BSD_FIONBIO BSD_IOW('f', 126, int) 59 + #define BSD_FIOASYNC BSD_IOW('f', 125, int) 60 + #define BSD_FIOSETOWN BSD_IOW('f', 124, int) 61 + #define BSD_FIOGETOWN BSD_IOR('f', 123, int) 62 + #define BSD_FIODTYPE BSD_IOR('f', 122, int) 27 63 28 64 #endif
+8 -4
src/lkm/traps.c
··· 698 698 struct file* f; 699 699 char name[60]; 700 700 long retval = 0; 701 + int handled; 701 702 702 703 if (copy_from_user(&args, in_args, sizeof(args))) 703 704 return -EFAULT; ··· 720 721 721 722 // Perform ioctl translation based on name 722 723 if (strncmp(name, "socket:", 7) == 0) 723 - bsd_ioctl_xlate_socket(&args); 724 + handled = bsd_ioctl_xlate_socket(f, &args, &retval); 724 725 else if (strncmp(name, "/dev/tty", 8) == 0) 725 - bsd_ioctl_xlate_tty(&args); 726 + handled = bsd_ioctl_xlate_tty(f, &args, &retval); 726 727 else if (strncmp(name, "/dev/pts", 8) == 0) 727 - bsd_ioctl_xlate_pts(&args); 728 + handled = bsd_ioctl_xlate_pts(f, &args, &retval); 729 + else 730 + handled = bsd_ioctl_xlate_generic(f, &args, &retval); 728 731 729 - retval = f->f_op->unlocked_ioctl(f, args.request, args.arg); 732 + if (!handled) 733 + retval = f->f_op->unlocked_ioctl(f, args.request, args.arg); 730 734 731 735 fput(f); 732 736