this repo has no description
1
fork

Configure Feed

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

Merge branch 'master' of github.com:darlinghq/darling into broken

+198 -27
+2
src/kernel/emulation/linux/CMakeLists.txt
··· 38 38 unistd/readv.c 39 39 unistd/writev.c 40 40 unistd/flock.c 41 + mount/unmount.c 41 42 mman/mman.c 42 43 mman/madvise.c 43 44 mman/msync.c ··· 197 198 ioctl/ioctl.c 198 199 ioctl/termios.c 199 200 ioctl/filio.c 201 + ioctl/socket.c 200 202 ext/sysinfo.c 201 203 ext/uname.c 202 204 ext/epoll_create.c
+3
src/kernel/emulation/linux/ioctl/ioctl.c
··· 5 5 #include <stdbool.h> 6 6 #include "termios.h" 7 7 #include "filio.h" 8 + #include "termios.h" 9 + #include "socket.h" 8 10 9 11 #define IOCTL_STEP(x) { int state, retval; state = (x); \ 10 12 if (state == IOCTL_HANDLED) return retval; } ··· 13 15 long sys_ioctl(int fd, int cmd, void* arg) 14 16 { 15 17 IOCTL_STEP(handle_filio(fd, cmd, arg, &retval)); 18 + IOCTL_STEP(handle_socket(fd, cmd, arg, &retval)); 16 19 IOCTL_STEP(handle_termios(fd, cmd, arg, &retval)); 17 20 18 21 run_ioctl:
+25
src/kernel/emulation/linux/ioctl/socket.c
··· 1 + #include "socket.h" 2 + #include <sys/errno.h> 3 + #include <sys/socket.h> 4 + #include <ifaddrs.h> 5 + #include <net/if.h> 6 + #include <netinet/in.h> 7 + #include <sys/sockio.h> 8 + #include <netinet6/in6_var.h> 9 + 10 + int handle_socket(int fd, unsigned int cmd, void* arg, int* retval) 11 + { 12 + switch (cmd) 13 + { 14 + // TODO: This has to be implemented for container with separate networking 15 + case SIOCGIFFLAGS: 16 + case SIOCSIFFLAGS: 17 + case SIOCAIFADDR: // set IPv4 address 18 + case SIOCAIFADDR_IN6: // set IPv6 address 19 + *retval = -ENOTSUP; 20 + return IOCTL_HANDLED; 21 + } 22 + return IOCTL_PASS; 23 + } 24 + 25 +
+8
src/kernel/emulation/linux/ioctl/socket.h
··· 1 + #ifndef EMU_SOCKET_H 2 + #define EMU_SOCKET_H 3 + #include "ioctl.h" 4 + 5 + int handle_socket(int fd, unsigned int cmd, void* arg, int* retval); 6 + 7 + #endif 8 +
+2 -1
src/kernel/emulation/linux/ioctl/termios.c
··· 214 214 return IOCTL_HANDLED; 215 215 } 216 216 default: 217 + { 217 218 __simple_printf("Passing thru unhandled ioctl 0x%x on fd %d\n", cmd, fd); 218 - __builtin_trap(); 219 219 return IOCTL_PASS; 220 + } 220 221 } 221 222 } 222 223
+62
src/kernel/emulation/linux/misc/sysctl_kern.c
··· 8 8 #include "../time/gettimeofday.h" 9 9 #include "darling-config.h" 10 10 #include "../errno.h" 11 + #include "../simple.h" 12 + #include "../fcntl/open.h" 13 + #include "../unistd/read.h" 14 + #include "../unistd/close.h" 11 15 #include <sys/errno.h> 12 16 13 17 enum { ··· 24 28 static sysctl_handler(handle_domainname); 25 29 static sysctl_handler(handle_osrelease); 26 30 static sysctl_handler(handle_version); 31 + static sysctl_handler(handle_maxproc); 32 + static sysctl_handler(handle_netboot); 33 + static sysctl_handler(handle_safeboot); 27 34 28 35 extern int _sysctl_proc(int what, int flag, struct kinfo_proc* out, unsigned long* buflen); 29 36 extern int _sysctl_procargs(int pid, char* buf, unsigned long* buflen); ··· 35 42 { .oid = KERN_PROC, .type = CTLTYPE_STRUCT, .exttype = "", .name = "proc", .handler = handle_proc }, 36 43 { .oid = KERN_PROCARGS2, .type = CTLTYPE_STRUCT, .exttype = "", .name = "procargs2", .handler = handle_procargs32 }, 37 44 { .oid = KERN_ARGMAX, .type = CTLTYPE_INT, .exttype = "I", .name = "argmax", .handler = handle_argmax }, 45 + { .oid = KERN_MAXPROC, .type = CTLTYPE_INT, .exttype = "I", .name = "maxproc", .handler = handle_maxproc }, 46 + { .oid = KERN_NETBOOT, .type = CTLTYPE_INT, .exttype = "I", .name = "netboot", .handler = handle_netboot }, 47 + { .oid = KERN_SAFEBOOT, .type = CTLTYPE_INT, .exttype = "I", .name = "safeboot", .handler = handle_safeboot }, 38 48 { .oid = KERN_BOOTTIME, .type = CTLTYPE_STRUCT, .exttype = "S,timeval", .name = "boottime", .handler = handle_boottime }, 39 49 { .oid = KERN_OSTYPE, .type = CTLTYPE_STRING, .exttype = "S", .name = "ostype", .handler = handle_ostype }, 40 50 { .oid = KERN_HOSTNAME, .type = CTLTYPE_STRING, .exttype = "S", .name = "hostname", .handler = handle_hostname }, ··· 192 202 return rv; 193 203 } 194 204 205 + sysctl_handler(handle_maxproc) 206 + { 207 + char buf[16]; 208 + int fd = sys_open("/proc/sys/kernel/pid_max", BSD_O_RDONLY, 0); 209 + int value = 1024; 210 + int* ovalue = (int*) old; 211 + 212 + if (!oldlen || *oldlen < sizeof(int)) 213 + return -EINVAL; 214 + 215 + if (fd >= 0) 216 + { 217 + int rd = sys_read(fd, buf, sizeof(buf) - 1); 218 + sys_close(fd); 219 + 220 + if (rd > 0) 221 + { 222 + buf[rd] = '\0'; 223 + value = __simple_atoi(buf, NULL); 224 + } 225 + } 226 + 227 + if (ovalue != NULL) 228 + *ovalue = value; 229 + *oldlen = sizeof(int); 230 + 231 + return 0; 232 + } 233 + 234 + sysctl_handler(handle_netboot) 235 + { 236 + int* ovalue = (int*) old; 237 + 238 + if (!oldlen || *oldlen < sizeof(int)) 239 + return -EINVAL; 240 + *ovalue = 0; 241 + 242 + return 0; 243 + } 244 + 245 + sysctl_handler(handle_safeboot) 246 + { 247 + int* ovalue = (int*) old; 248 + 249 + if (!oldlen || *oldlen < sizeof(int)) 250 + return -EINVAL; 251 + *ovalue = 0; 252 + 253 + return 0; 254 + } 255 + 256 +
+11
src/kernel/emulation/linux/mount/unmount.c
··· 1 + #include "unmount.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include <linux-syscalls/linux.h> 5 + #include <sys/errno.h> 6 + 7 + long sys_unmount(const char* path, int flags) 8 + { 9 + return -EBUSY; 10 + } 11 +
+7
src/kernel/emulation/linux/mount/unmount.h
··· 1 + #ifndef LINUX_UMOUNT_H 2 + #define LINUX_UMOUNT_H 3 + 4 + long sys_unmount(const char* path, int flags); 5 + 6 + #endif 7 +
+14 -2
src/kernel/emulation/linux/network/getsockopt.c
··· 3 3 #include "../errno.h" 4 4 #include <linux-syscalls/linux.h> 5 5 #include <stddef.h> 6 - #include "../../../../../platform-include/sys/errno.h" 6 + #include <sys/errno.h> 7 7 #include "duct.h" 8 + #include <sys/ucred.h> 9 + #include <sys/un.h> 8 10 9 11 #define LINGER_TICKS_PER_SEC 100 // Is this the right number of ticks per sec? 10 12 13 + extern void* memset(void*, int, __SIZE_TYPE__); 14 + 11 15 long sys_getsockopt(int fd, int level, int optname, void* optval, int* optlen) 12 16 { 13 17 int ret, linux_level, linux_optname; ··· 15 19 linux_level = level; 16 20 linux_optname = optname; 17 21 18 - ret = sockopt_bsd_to_linux(&linux_level, &linux_optname, NULL, NULL); 22 + ret = sockopt_bsd_to_linux(&linux_level, &linux_optname, NULL, optval); 19 23 20 24 if (ret != 0 || !linux_optname) 21 25 return ret; ··· 47 51 48 52 int sockopt_bsd_to_linux(int* level, int* optname, void** optval, void* optbuf) 49 53 { 54 + if (*optname == LOCAL_PEERCRED) 55 + { 56 + struct xucred* c = (struct xucred*) optbuf; 57 + // Simulate euid 0 58 + memset(c, 0, sizeof(*c)); 59 + *optname = 0; 60 + return 0; 61 + } 50 62 if (*level == BSD_SOL_SOCKET) 51 63 { 52 64 *level = LINUX_SOL_SOCKET;
+13
src/kernel/emulation/linux/simple.c
··· 127 127 LINUX_SYSCALL3(__NR_write, 1, buffer, __simple_strlen(buffer)); 128 128 } 129 129 130 + void __simple_fprintf(int fd, const char* format, ...) 131 + { 132 + char buffer[512]; 133 + va_list vl; 134 + 135 + va_start(vl, format); 136 + __simple_vsprintf(buffer, format, vl); 137 + va_end(vl); 138 + 139 + LINUX_SYSCALL3(__NR_write, fd, buffer, __simple_strlen(buffer)); 140 + } 141 + 142 + 130 143 void __simple_sprintf(char *buffer, const char* format, ...) 131 144 { 132 145 va_list vl;
+1
src/kernel/emulation/linux/simple.h
··· 2 2 #define LINUX_DEBUG_H 3 3 4 4 void __simple_printf(const char* format, ...); 5 + void __simple_fprintf(int fd, const char* format, ...); 5 6 void __simple_sprintf(char *buffer, const char* format, ...); 6 7 int __simple_strlen(const char* str); 7 8
+2
src/kernel/emulation/linux/syscalls.c
··· 6 6 #include "kqueue/kevent_qos.h" 7 7 #include "unistd/write.h" 8 8 #include "unistd/read.h" 9 + #include "mount/unmount.h" 9 10 #include "guarded/guarded_open_np.h" 10 11 #include "guarded/guarded_close_np.h" 11 12 #include "guarded/guarded_kqueue_np.h" ··· 275 276 [154] = sys_pwrite, 276 277 [157] = sys_statfs, 277 278 [158] = sys_fstatfs, 279 + [159] = sys_unmount, 278 280 [173] = sys_waitid, 279 281 [181] = sys_setgid, 280 282 [182] = sys_setegid,
+48 -24
src/startup/darling.c
··· 82 82 prefix = defaultPrefixPath(); 83 83 if (!prefix) 84 84 return 1; 85 + if (strlen(prefix) > 255) 86 + { 87 + fprintf(stderr, "Prefix path too long\n"); 88 + return 1; 89 + } 85 90 unsetenv("DPREFIX"); 86 91 87 92 if (!checkPrefixDir()) ··· 570 575 fprintf(stderr, "Cannot set gid_map for the init process: %s\n", strerror(errno)); 571 576 } 572 577 */ 578 + 579 + // This is for development only! 580 + if (getenv("TRY_LAUNCHD") != NULL) 581 + { 582 + int status = 0; 583 + waitpid(pid, &status, 0); 584 + } 573 585 574 586 // Here's where we resume the child 575 587 // if we enable user namespaces ··· 607 619 void darlingPreInit(void) 608 620 { 609 621 // TODO: Run /usr/libexec/makewhatis 610 - 622 + 623 + // This is for development only! 624 + if (getenv("TRY_LAUNCHD") != NULL) 625 + { 626 + // putenv("KQUEUE_DEBUG=1"); 627 + execl("/bin/mldr", "mldr!/sbin/launchd", "launchd", NULL); 628 + 629 + fprintf(stderr, "Failed to exec launchd: %s\n", strerror(errno)); 630 + abort(); 631 + } 632 + 611 633 // TODO: this is where we will exec() launchd in future. 612 634 // Instead, we just reap zombies. 613 635 while (1) ··· 714 736 void setupPrefix() 715 737 { 716 738 char path[4096]; 739 + size_t plen; 740 + 741 + const char* dirs[] = { 742 + "/Volumes", 743 + "/Applications", 744 + "/usr", 745 + "/usr/local", 746 + "/usr/local/share", 747 + "/private", 748 + "/private/var", 749 + "/private/var/db", 750 + "/var", 751 + "/var/run", 752 + "/var/tmp" 753 + }; 717 754 718 755 fprintf(stderr, "Setting up a new Darling prefix at %s\n", prefix); 719 756 ··· 721 758 setegid(g_originalGid); 722 759 723 760 createDir(prefix); 724 - 725 - // The user needs to be able to create mountpoints, 726 - snprintf(path, sizeof(path), "%s/Volumes", prefix); 727 - createDir(path); 728 - // ... to install applications, 729 - snprintf(path, sizeof(path), "%s/Applications", prefix); 730 - createDir(path); 731 - 732 - // ... to put stuff in /usr/local, 733 - snprintf(path, sizeof(path), "%s/usr", prefix); 734 - createDir(path); 735 - snprintf(path, sizeof(path), "%s/usr/local", prefix); 736 - createDir(path); 737 - snprintf(path, sizeof(path), "%s/usr/local/share", prefix); 738 - createDir(path); 739 - 740 - // ... and to install plists to /var/db 741 - snprintf(path, sizeof(path), "%s/private", prefix); 742 - createDir(path); 743 - snprintf(path, sizeof(path), "%s/private/var", prefix); 744 - createDir(path); 745 - snprintf(path, sizeof(path), "%s/private/var/db", prefix); 746 - createDir(path); 761 + strcpy(path, prefix); 762 + strcat(path, "/"); 763 + plen = strlen(path); 747 764 765 + for (size_t i = 0; i < sizeof(dirs)/sizeof(dirs[0]); i++) 766 + { 767 + path[plen] = '\0'; 768 + strcat(path, dirs[i]); 769 + createDir(path); 770 + } 771 + 748 772 seteuid(0); 749 773 setegid(0); 750 774 }