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

+428 -3
+8
src/kernel/emulation/linux/CMakeLists.txt
··· 25 25 errno.c 26 26 readline.c 27 27 common_at.c 28 + wrapped/shm_open.c 29 + wrapped/shm_unlink.c 30 + wrapped/sem_open.c 31 + wrapped/sem_unlink.c 32 + wrapped/sem_wait.c 33 + wrapped/sem_trywait.c 34 + wrapped/sem_close.c 35 + wrapped/sem_post.c 28 36 guarded/guarded_open_np.c 29 37 guarded/guarded_close_np.c 30 38 guarded/guarded_kqueue_np.c
+105
src/kernel/emulation/linux/ioctl/termios.c
··· 5 5 #include <stdbool.h> 6 6 #include "../simple.h" 7 7 8 + #define USE_OLD_TTY 9 + #include <sys/ioctl_compat.h> 10 + 8 11 // Speeds are stored in cflags 9 12 // http://osxr.org/glibc/source/sysdeps/unix/sysv/linux/speed.c?v=glibc-2.13 10 13 ··· 23 26 static void lflag_bsd_to_linux(unsigned long b, unsigned int* l); 24 27 static void speed_linux_to_bsd(unsigned int l, unsigned long* b); 25 28 static void speed_bsd_to_linux(unsigned long b, unsigned int* l); 29 + static void sgflag_linux_to_bsd(const struct linux_termios* tos, short* sgflags); 30 + static void sgflag_bsd_to_linux(const short sgflags, struct linux_termios* tos); 26 31 27 32 int handle_termios(int fd, unsigned int cmd, void* arg, int* retval) 28 33 { ··· 84 89 85 90 *retval = __real_ioctl(fd, op, &out); 86 91 92 + return IOCTL_HANDLED; 93 + } 94 + case BSD_TIOCGETP: 95 + { 96 + struct linux_termios in; 97 + struct sgttyb* out = (struct sgttyb*) arg; 98 + unsigned long ispeed, ospeed; 99 + 100 + *retval = __real_ioctl(fd, LINUX_TCGETS, &in); 101 + 102 + speed_linux_to_bsd(in.c_ispeed, &ispeed); 103 + speed_linux_to_bsd(in.c_ospeed, &ospeed); 104 + out->sg_ispeed = ispeed; 105 + out->sg_ospeed = ospeed; 106 + 107 + out->sg_erase = in.c_cc[LINUX_VERASE]; 108 + out->sg_kill = in.c_cc[LINUX_VKILL]; 109 + sgflag_linux_to_bsd(&in, &out->sg_flags); 110 + 111 + return IOCTL_HANDLED; 112 + } 113 + case BSD_TIOCSETP: 114 + { 115 + struct linux_termios out; 116 + const struct sgttyb* in = (struct sgttyb*) arg; 117 + 118 + // Get existing values so that we don't overwrite many 119 + // of the parameters not specified in struct sgttyb. 120 + __real_ioctl(fd, LINUX_TCGETS, &out); 121 + 122 + speed_bsd_to_linux(in->sg_ispeed, &out.c_ispeed); 123 + speed_bsd_to_linux(in->sg_ospeed, &out.c_ospeed); 124 + out.c_cc[LINUX_VERASE] = in->sg_erase; 125 + out.c_cc[LINUX_VKILL] = in->sg_kill; 126 + sgflag_bsd_to_linux(in->sg_flags, &out); 127 + 128 + *retval = __real_ioctl(fd, LINUX_TCSETS, &out); 129 + 87 130 return IOCTL_HANDLED; 88 131 } 89 132 case BSD_TIOCGWINSZ: ··· 585 628 *l = lspeed; 586 629 } 587 630 631 + // Linux provides TIOCGETP only on some architectures 632 + // and even there the support is very limited. 633 + // See http://elixir.free-electrons.com/linux/latest/source/drivers/tty/tty_ioctl.c#L712 634 + // Hence we do the translation ourselves. 635 + static void sgflag_linux_to_bsd(const struct linux_termios* tos, short* sgflags) 636 + { 637 + *sgflags = 0; 638 + 639 + if (!(tos->c_lflag & LINUX_ICANON)) 640 + { 641 + if (tos->c_lflag & LINUX_ISIG) 642 + *sgflags |= 0x2; // cbreak 643 + else 644 + *sgflags |= 0x20; // raw 645 + } 646 + 647 + if (tos->c_lflag & LINUX_ECHO) 648 + *sgflags |= 0x8; // echo 649 + 650 + if (tos->c_oflag & LINUX_OPOST) 651 + { 652 + if (tos->c_oflag & LINUX_ONLCR) 653 + *sgflags |= 0x10; // crmod 654 + } 655 + } 656 + 657 + static void sgflag_bsd_to_linux(const short sgflags, struct linux_termios* tos) 658 + { 659 + tos->c_iflag = LINUX_ICRNL | LINUX_IXON; 660 + tos->c_oflag = 0; 661 + tos->c_lflag = LINUX_ISIG | LINUX_ICANON; 662 + 663 + if (sgflags & 0x02) // cbreak 664 + { 665 + tos->c_iflag = 0; 666 + tos->c_lflag &= LINUX_ICANON; 667 + } 668 + 669 + if (sgflags & 0x08) // echo 670 + { 671 + tos->c_lflag |= LINUX_ECHO | LINUX_ECHOE | LINUX_ECHOK 672 + | LINUX_ECHOCTL | LINUX_ECHOKE | LINUX_IEXTEN; 673 + } 674 + 675 + if (sgflags & 0x10) // crmod 676 + { 677 + tos->c_oflag |= LINUX_OPOST | LINUX_ONLCR; 678 + } 679 + 680 + if (sgflags & 0x20) // raw 681 + { 682 + tos->c_iflag = 0; 683 + tos->c_lflag &= ~(LINUX_ISIG | LINUX_ICANON); 684 + } 685 + 686 + if (!(tos->c_lflag & LINUX_ICANON)) 687 + { 688 + tos->c_cc[LINUX_VMIN] = 1; 689 + tos->c_cc[LINUX_VTIME] = 0; 690 + } 691 + } 692 +
+2
src/kernel/emulation/linux/ioctl/termios.h
··· 85 85 #define BSD_TIOCIXON BSD_IO('t', 129) 86 86 #define BSD_TIOCIXOFF BSD_IO('t', 128) 87 87 #define BSD_TIOCISATTY 0x2000745E 88 + #define BSD_TIOCGETP 0x40067408 89 + #define BSD_TIOCSETP 0x80067409 88 90 89 91 #define BSD_TIOCSBRK BSD_IO('t', 123) 90 92 #define BSD_TIOCCBRK BSD_IO('t', 122)
+3
src/kernel/emulation/linux/simple.c
··· 55 55 int count = 0; 56 56 57 57 if (num < 0) 58 + { 58 59 *buf++ = '-'; 60 + num = -num; 61 + } 59 62 60 63 do 61 64 {
+16
src/kernel/emulation/linux/syscalls.c
··· 10 10 #include "guarded/guarded_open_np.h" 11 11 #include "guarded/guarded_close_np.h" 12 12 #include "guarded/guarded_kqueue_np.h" 13 + #include "wrapped/shm_open.h" 14 + #include "wrapped/shm_unlink.h" 15 + #include "wrapped/sem_open.h" 16 + #include "wrapped/sem_unlink.h" 17 + #include "wrapped/sem_close.h" 18 + #include "wrapped/sem_wait.h" 19 + #include "wrapped/sem_trywait.h" 20 + #include "wrapped/sem_post.h" 13 21 #include "mman/mman.h" 14 22 #include "mman/madvise.h" 15 23 #include "mman/msync.h" ··· 319 327 [240] = sys_listxattr, 320 328 [241] = sys_flistxattr, 321 329 [244] = sys_posix_spawn, 330 + [266] = sys_shm_open, 331 + [267] = sys_shm_unlink, 332 + [268] = sys_sem_open, 333 + [269] = sys_sem_close, 334 + [270] = sys_sem_unlink, 335 + [271] = sys_sem_wait, 336 + [272] = sys_sem_trywait, 337 + [273] = sys_sem_post, 322 338 [274] = sys_sysctlbyname, 323 339 [282] = sys_chmod_extended, 324 340 [283] = sys_fchmod_extended,
+24
src/kernel/emulation/linux/wrapped/sem_close.c
··· 1 + #include "sem_close.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include <sys/errno.h> 5 + #include <linux-syscalls/linux.h> 6 + #include <elfcalls.h> 7 + 8 + extern struct elf_calls* _elfcalls; 9 + 10 + long sys_sem_close(int sem) 11 + { 12 + #ifndef VARIANT_DYLD 13 + int ret; 14 + 15 + ret = _elfcalls->sem_close(sem); 16 + if (ret == -1) 17 + ret = -errno_linux_to_bsd(_elfcalls->get_errno()); 18 + 19 + return ret; 20 + #else 21 + return -ENOSYS; 22 + #endif 23 + } 24 +
+7
src/kernel/emulation/linux/wrapped/sem_close.h
··· 1 + #ifndef LINUX_SEM_CLOSE_H 2 + #define LINUX_SEM_CLOSE_H 3 + 4 + long sys_sem_close(int sem); 5 + 6 + #endif 7 +
+33
src/kernel/emulation/linux/wrapped/sem_open.c
··· 1 + #include "sem_open.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include "../fcntl/open.h" 5 + #include <sys/errno.h> 6 + #include <linux-syscalls/linux.h> 7 + #include <elfcalls.h> 8 + 9 + extern struct elf_calls* _elfcalls; 10 + 11 + long sys_sem_open(const char* name, int oflag, int mode, int value) 12 + { 13 + #ifndef VARIANT_DYLD 14 + int ret; 15 + int* ptr; 16 + 17 + // __simple_printf("sem_open %s, %d, %d, %d\n", name, oflag, mode, value); 18 + 19 + ptr = _elfcalls->sem_open(name, oflags_bsd_to_linux(oflag), mode, value); 20 + //__simple_printf("sem_open -> %p\n", ptr); 21 + 22 + if (!ptr) 23 + { 24 + // __simple_printf("errno: %d\n", _elfcalls->get_errno()); 25 + return -errno_linux_to_bsd(_elfcalls->get_errno()); 26 + } 27 + 28 + return (long) ptr; 29 + #else 30 + return -ENOSYS; 31 + #endif 32 + } 33 +
+7
src/kernel/emulation/linux/wrapped/sem_open.h
··· 1 + #ifndef LINUX_SEM_OPEN_H 2 + #define LINUX_SEM_OPEN_H 3 + 4 + long sys_sem_open(const char* name, int oflag, int mode, int value); 5 + 6 + #endif 7 +
+25
src/kernel/emulation/linux/wrapped/sem_post.c
··· 1 + #include "sem_post.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include <sys/errno.h> 5 + #include <linux-syscalls/linux.h> 6 + #include <elfcalls.h> 7 + 8 + extern struct elf_calls* _elfcalls; 9 + 10 + long sys_sem_post(int* sem) 11 + { 12 + #ifndef VARIANT_DYLD 13 + int ret; 14 + 15 + // __simple_printf("sem_post(%p)\n", sem); 16 + ret = _elfcalls->sem_post(sem); 17 + if (ret == -1) 18 + ret = -errno_linux_to_bsd(_elfcalls->get_errno()); 19 + 20 + return ret; 21 + #else 22 + return -ENOSYS; 23 + #endif 24 + } 25 +
+7
src/kernel/emulation/linux/wrapped/sem_post.h
··· 1 + #ifndef LINUX_SEM_POST_H 2 + #define LINUX_SEM_POST_H 3 + 4 + long sys_sem_post(int* sem); 5 + 6 + #endif 7 +
+24
src/kernel/emulation/linux/wrapped/sem_trywait.c
··· 1 + #include "sem_trywait.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include <sys/errno.h> 5 + #include <linux-syscalls/linux.h> 6 + #include <elfcalls.h> 7 + 8 + extern struct elf_calls* _elfcalls; 9 + 10 + long sys_sem_trywait(int* sem) 11 + { 12 + #ifndef VARIANT_DYLD 13 + int ret; 14 + 15 + ret = _elfcalls->sem_trywait(sem); 16 + if (ret == -1) 17 + ret = -errno_linux_to_bsd(_elfcalls->get_errno()); 18 + 19 + return ret; 20 + #else 21 + return -ENOSYS; 22 + #endif 23 + } 24 +
+7
src/kernel/emulation/linux/wrapped/sem_trywait.h
··· 1 + #ifndef LINUX_SEM_TRYWAIT_H 2 + #define LINUX_SEM_TRYWAIT_H 3 + 4 + long sys_sem_trywait(int* sem); 5 + 6 + #endif 7 +
+24
src/kernel/emulation/linux/wrapped/sem_unlink.c
··· 1 + #include "sem_unlink.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include <sys/errno.h> 5 + #include <linux-syscalls/linux.h> 6 + #include <elfcalls.h> 7 + 8 + extern struct elf_calls* _elfcalls; 9 + 10 + long sys_sem_unlink(const char* name) 11 + { 12 + #ifndef VARIANT_DYLD 13 + int ret; 14 + 15 + ret = _elfcalls->sem_unlink(name); 16 + if (ret == -1) 17 + ret = -errno_linux_to_bsd(_elfcalls->get_errno()); 18 + 19 + return ret; 20 + #else 21 + return -ENOSYS; 22 + #endif 23 + } 24 +
+7
src/kernel/emulation/linux/wrapped/sem_unlink.h
··· 1 + #ifndef LINUX_SEM_UNLINK_H 2 + #define LINUX_SEM_UNLINK_H 3 + 4 + long sys_sem_unlink(const char* name); 5 + 6 + #endif 7 +
+24
src/kernel/emulation/linux/wrapped/sem_wait.c
··· 1 + #include "sem_wait.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include <sys/errno.h> 5 + #include <linux-syscalls/linux.h> 6 + #include <elfcalls.h> 7 + 8 + extern struct elf_calls* _elfcalls; 9 + 10 + long sys_sem_wait(int* sem) 11 + { 12 + #ifndef VARIANT_DYLD 13 + int ret; 14 + 15 + ret = _elfcalls->sem_wait(sem); 16 + if (ret == -1) 17 + ret = -errno_linux_to_bsd(_elfcalls->get_errno()); 18 + 19 + return ret; 20 + #else 21 + return -ENOSYS; 22 + #endif 23 + } 24 +
+7
src/kernel/emulation/linux/wrapped/sem_wait.h
··· 1 + #ifndef LINUX_SEM_WAIT_H 2 + #define LINUX_SEM_WAIT_H 3 + 4 + long sys_sem_wait(int* sem); 5 + 6 + #endif 7 +
+25
src/kernel/emulation/linux/wrapped/shm_open.c
··· 1 + #include "shm_open.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include "../fcntl/open.h" 5 + #include <sys/errno.h> 6 + #include <linux-syscalls/linux.h> 7 + #include <elfcalls.h> 8 + 9 + extern struct elf_calls* _elfcalls; 10 + 11 + long sys_shm_open(const char* name, int oflag, int mode) 12 + { 13 + #ifndef VARIANT_DYLD 14 + int ret; 15 + 16 + ret = _elfcalls->shm_open(name, oflags_bsd_to_linux(oflag), mode); 17 + if (ret == -1) 18 + ret = -errno_linux_to_bsd(_elfcalls->get_errno()); 19 + 20 + return ret; 21 + #else 22 + return -ENOSYS; 23 + #endif 24 + } 25 +
+7
src/kernel/emulation/linux/wrapped/shm_open.h
··· 1 + #ifndef LINUX_SHM_OPEN_H 2 + #define LINUX_SHM_OPEN_H 3 + 4 + long sys_shm_open(const char* name, int oflag, int mode); 5 + 6 + #endif 7 +
+24
src/kernel/emulation/linux/wrapped/shm_unlink.c
··· 1 + #include "shm_unlink.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include <sys/errno.h> 5 + #include <linux-syscalls/linux.h> 6 + #include <elfcalls.h> 7 + 8 + extern struct elf_calls* _elfcalls; 9 + 10 + long sys_shm_unlink(const char* name) 11 + { 12 + #ifndef VARIANT_DYLD 13 + int ret; 14 + 15 + ret = _elfcalls->shm_unlink(name); 16 + if (ret == -1) 17 + ret = -errno_linux_to_bsd(_elfcalls->get_errno()); 18 + 19 + return ret; 20 + #else 21 + return -ENOSYS; 22 + #endif 23 + } 24 +
+7
src/kernel/emulation/linux/wrapped/shm_unlink.h
··· 1 + #ifndef LINUX_SHM_UNLINK_H 2 + #define LINUX_SHM_UNLINK_H 3 + 4 + long sys_shm_unlink(const char* name); 5 + 6 + #endif 7 +
+2 -2
src/startup/CMakeLists.txt
··· 26 26 elfcalls.c 27 27 ) 28 28 add_executable(mldr ${mldr_sources}) 29 - target_link_libraries(mldr pthread dl) 29 + target_link_libraries(mldr pthread dl rt) 30 30 31 31 add_executable(mldr32 ${mldr_sources}) 32 - target_link_libraries(mldr32 pthread dl) 32 + target_link_libraries(mldr32 pthread dl rt) 33 33 set_target_properties(mldr32 34 34 PROPERTIES 35 35 COMPILE_FLAGS "-m32"
+19
src/startup/elfcalls.c
··· 1 1 #include <dlfcn.h> 2 2 #include <stdio.h> 3 3 #include <stdlib.h> 4 + #include <errno.h> 5 + #include <semaphore.h> 6 + #include <sys/mman.h> 4 7 #include "elfcalls.h" 5 8 #include "threads.h" 6 9 ··· 56 59 *all_image_length = dyld_all_image_size; 57 60 } 58 61 62 + static int get_errno(void) 63 + { 64 + return errno; 65 + } 66 + 59 67 char* elfcalls_make(void) 60 68 { 61 69 static char param[32]; ··· 76 84 77 85 calls.exe_uuid = get_exe_uuid; 78 86 calls.dyld_info = get_dyld_info; 87 + 88 + calls.get_errno = get_errno; 89 + *((void**)&calls.sem_open) = sem_open; 90 + *((void**)&calls.sem_wait) = sem_wait; 91 + *((void**)&calls.sem_trywait) = sem_trywait; 92 + *((void**)&calls.sem_post) = sem_post; 93 + *((void**)&calls.sem_close) = sem_close; 94 + *((void**)&calls.sem_unlink) = sem_unlink; 95 + 96 + *((void**)&calls.shm_open) = shm_open; 97 + *((void**)&calls.shm_unlink) = shm_unlink; 79 98 80 99 sprintf(param, "elf_calls=%p", &calls); 81 100 return param;
+14 -1
src/startup/elfcalls.h
··· 4 4 5 5 struct elf_calls 6 6 { 7 - // ELF synamic loader access 7 + // ELF dynamic loader access 8 8 void* (*dlopen)(const char* name); 9 9 int (*dlclose)(void* lib); 10 10 void* (*dlsym)(void* lib, const char* name); ··· 29 29 30 30 // Get data for TASK_DYLD_INFO (struct task_dyld_info) 31 31 void (*dyld_info)(uintptr_t* all_image_location, __SIZE_TYPE__* all_image_length); 32 + 33 + // POSIX semaphore APIs 34 + int (*get_errno)(void); 35 + int* (*sem_open)(const char* name, int oflag, unsigned short mode, unsigned int value); 36 + int (*sem_wait)(int* sem); 37 + int (*sem_trywait)(int* sem); 38 + int (*sem_post)(int* sem); 39 + int (*sem_close)(int* sem); 40 + int (*sem_unlink)(const char* name); 41 + 42 + // POSIX SHM APIs 43 + int (*shm_open)(const char* name, int oflag, unsigned short mode); 44 + int (*shm_unlink)(const char* name); 32 45 }; 33 46 34 47 #endif