this repo has no description
1
fork

Configure Feed

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

Merge pull request #1062 from trungnt2910/dev/trungnt2910/run-dotnet/misc

fix: Various kernel fixes

authored by

Ariel Abreu and committed by
GitHub
7399bb19 1e7b4ce3

+400 -14
+3
src/frameworks/CoreServices/CMakeLists.txt
··· 66 66 reexport(CoreServices SharedFileList ${SharedFileList_BUILD}) 67 67 reexport(CoreServices OSServices ${OSServices_BUILD}) 68 68 69 + set_property(TARGET CoreServices APPEND_STRING PROPERTY 70 + LINK_FLAGS " -Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/reexport.exp") 71 + 69 72 install(FILES SystemVersion.plist DESTINATION "libexec/darling/System/Library/CoreServices")
+32
src/frameworks/CoreServices/reexport.exp
··· 1 + __FE_DFL_DISABLE_SSE_DENORMS_ENV 2 + __FE_DFL_ENV 3 + ___inf 4 + _exp2 5 + _exp2$fenv_access_off 6 + _fdim 7 + _fdim$fenv_access_off 8 + _feclearexcept 9 + _fegetenv 10 + _fegetexcept 11 + _fegetround 12 + _feholdexcept 13 + _feraiseexcept 14 + _fesetenv 15 + _fesetexcept 16 + _fesetround 17 + _fetestexcept 18 + _feupdateenv 19 + _fmax 20 + _fmax$fenv_access_off 21 + _fmin 22 + _fmin$fenv_access_off 23 + _log2 24 + _log2$fenv_access_off 25 + _modff 26 + _modff$fenv_access_off 27 + _nan 28 + _nanf 29 + _nextafterd 30 + _nextafterf 31 + _remquo 32 + _remquo$fenv_access_off
+7
src/kernel/emulation/linux/elfcalls_wrapper.c
··· 26 26 _elfcalls->exit(ec); 27 27 } 28 28 29 + long native_sysconf(int name) 30 + { 31 + if (_elfcalls) 32 + return _elfcalls->sysconf(name); 33 + return -1; 34 + } 35 + 29 36 void* __darling_thread_create(unsigned long stack_size, unsigned long pthobj_size, 30 37 void* entry_point, uintptr_t arg3, 31 38 uintptr_t arg4, uintptr_t arg5, uintptr_t arg6,
+2
src/kernel/emulation/linux/elfcalls_wrapper.h
··· 15 15 16 16 void native_exit(int ec); 17 17 18 + long native_sysconf(int name); 19 + 18 20 // Native thread wrapping 19 21 void* __darling_thread_create(unsigned long stack_size, unsigned long pthobj_size, 20 22 void* entry_point, uintptr_t arg3,
+12
src/kernel/emulation/linux/mach/mach_traps.c
··· 214 214 } 215 215 else 216 216 { 217 + // XNU returns KERN_INVALID_ARGUMENT for address overflow, 218 + // and allows NULL address if size is 0. 219 + if (address + size < address) 220 + { 221 + return KERN_INVALID_ARGUMENT; 222 + } 223 + 224 + if (size == (mach_vm_offset_t)0) 225 + { 226 + return KERN_SUCCESS; 227 + } 228 + 217 229 ret = munmap(address, size); 218 230 219 231 if (ret == -1)
+231 -3
src/kernel/emulation/linux/misc/proc_info.c
··· 6 6 #include <sys/errno.h> 7 7 #include <sys/proc_info.h> 8 8 #include <mach/vm_prot.h> 9 + #include "../dirent/getdirentries.h" 9 10 #include "../ext/syslog.h" 10 11 #include "../fcntl/open.h" 11 12 #include "../unistd/close.h" ··· 22 23 #include <lkm/api.h> 23 24 #include "../mach/lkm.h" 24 25 #include "sysctl_proc.h" 26 + #include <stddef.h> 27 + #include "../elfcalls_wrapper.h" 25 28 26 29 #define LINUX_PR_SET_NAME 15 27 30 ··· 32 35 extern void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n); 33 36 extern char *strcpy(char *dest, const char *src); 34 37 extern char *strncpy(char *dest, const char *src, __SIZE_TYPE__ n); 38 + extern int strncmp (const char * str1, const char * str2, __SIZE_TYPE__ num); 39 + extern char *strchr(char *str, int character); 35 40 36 41 long sys_proc_info(uint32_t callnum, int32_t pid, uint32_t flavor, 37 42 uint64_t arg, void* buffer, int32_t bufsize) ··· 98 103 static long _proc_pidinfo_pidthreadinfo(int32_t pid, uint64_t thread_handle, void* buffer, int32_t bufsize); 99 104 static long _proc_pidinfo_pathinfo(int32_t pid, void* buffer, int32_t bufsize); 100 105 static long _proc_pidinfo_regionpath(int32_t pid, uint64_t arg, void* buffer, int32_t buffer_size); 106 + static long _proc_pidinfo_taskinfo(int32_t pid, void* buffer, int32_t bufsize); 107 + static long _proc_pidinfo_taskallinfo(int32_t pid, void* buffer, int32_t bufsize); 108 + static long _proc_pidinfo_listthreads(int32_t pid, void* buffer, int32_t bufsize); 101 109 102 110 long _proc_pidinfo(int32_t pid, uint32_t flavor, uint64_t arg, void* buffer, int32_t bufsize) 103 111 { ··· 135 143 { 136 144 return _proc_pidinfo_regionpath(pid, arg, buffer, bufsize); 137 145 } 146 + case PROC_PIDTASKINFO: 147 + { 148 + return _proc_pidinfo_taskinfo(pid, buffer, bufsize); 149 + } 150 + case PROC_PIDTASKALLINFO: 151 + { 152 + return _proc_pidinfo_taskallinfo(pid, buffer, bufsize); 153 + } 154 + case PROC_PIDLISTTHREADS: 155 + { 156 + return _proc_pidinfo_listthreads(pid, buffer, bufsize); 157 + } 138 158 default: 139 159 { 140 160 __simple_printf("sys_proc_info(): Unsupported pidinfo flavor: %d\n", ··· 215 235 return 1; 216 236 } 217 237 238 + // glibc bits/confname.h 239 + #define _SC_CLK_TCK 2 240 + 218 241 static long _proc_pidinfo_tbsdinfo(int32_t pid, void* buffer, int32_t bufsize) 219 242 { 220 243 struct proc_bsdinfo* info = (struct proc_bsdinfo*) buffer; ··· 241 264 info->pbi_svuid = shortinfo.pbsi_svuid; 242 265 info->pbi_svgid = shortinfo.pbsi_svgid; 243 266 info->pbi_pgid = shortinfo.pbsi_pgid; 244 - // info->pbi_nice 245 - // info->pbi_start 267 + 268 + char path[64], stat[4096]; 269 + char *statptr; 270 + const char* elem; 271 + 272 + __simple_sprintf(path, "/proc/%d/stat", pid); 273 + if (!read_string(path, stat, sizeof(stat))) 274 + return -ESRCH; 275 + 276 + #define READELEM() elem = next_stat_elem(&statptr); if (!elem) goto reterr 277 + 278 + statptr = stat; 279 + skip_stat_elems(&statptr, 18); // skip until ppid 280 + 281 + READELEM(); 282 + info->pbi_nice = elem[0] == '-' ? -__simple_atoi(elem + 1, NULL) : __simple_atoi(elem, NULL); 283 + 284 + skip_stat_elems(&statptr, 2); // skip until starttime 285 + READELEM(); 286 + 287 + uint64_t starttime = __simple_atoi(elem, NULL); 288 + 289 + if (!read_string("/proc/stat", stat, sizeof(stat))) 290 + return -ESRCH; 291 + 292 + statptr = stat; 293 + 294 + uint64_t btime; 295 + 296 + while (statptr < stat + sizeof(stat)) 297 + { 298 + if (strncmp(statptr, "btime ", 6) == 0) 299 + { 300 + statptr += 6; 301 + btime = __simple_atoi(statptr, NULL); 302 + break; 303 + } 304 + 305 + char* next = strchr(statptr, '\n'); 306 + if (!next) 307 + return -ESRCH; 308 + 309 + statptr = next + 1; 310 + } 311 + 312 + long ticks_per_sec = native_sysconf(_SC_CLK_TCK); 313 + uint64_t starttime_secs = starttime / ticks_per_sec; 314 + uint64_t starttime_usecs = (starttime % ticks_per_sec) * 1000000 / ticks_per_sec; 315 + 316 + info->pbi_start_tvsec = btime + starttime_secs; 317 + info->pbi_start_tvusec = starttime_usecs; 246 318 247 319 memcpy(info->pbi_comm, shortinfo.pbsi_comm, sizeof(info->pbi_comm)); 248 320 249 - return err; 321 + return sizeof(struct proc_bsdinfo); 322 + reterr: 323 + return -EINVAL; 250 324 } 251 325 252 326 static long _proc_pidinfo_pidthreadinfo(int32_t pid, uint64_t thread_handle, void* buffer, int32_t bufsize) ··· 583 657 strncpy(buffer, args.path, bufsize); 584 658 return strlen(args.path); 585 659 } 660 + 661 + static long _proc_pidinfo_taskinfo(int32_t pid, void* buffer, int32_t bufsize) 662 + { 663 + if (!buffer) 664 + return -EFAULT; 665 + if (bufsize < sizeof(struct proc_taskinfo)) 666 + return -ENOSPC; 667 + 668 + char path[64], stat[1024]; 669 + char *statptr; 670 + const char* elem; 671 + 672 + memset(buffer, 0, bufsize); 673 + struct proc_taskinfo* ti = (struct proc_taskinfo*) buffer; 674 + 675 + __simple_sprintf(path, "/proc/%d/stat", pid); 676 + if (!read_string(path, stat, sizeof(stat))) 677 + return -ESRCH; 678 + 679 + #define READELEM() elem = next_stat_elem(&statptr); if (!elem) goto reterr 680 + 681 + statptr = stat; 682 + skip_stat_elems(&statptr, 9); // skip until minflt 683 + READELEM(); 684 + int32_t minflt = __simple_atoi(elem, NULL); 685 + 686 + skip_stat_elems(&statptr, 1); // skip until majflt 687 + READELEM(); 688 + int32_t majflt = __simple_atoi(elem, NULL); 689 + 690 + skip_stat_elems(&statptr, 1); // skip until utime 691 + READELEM(); 692 + uint64_t utime = __simple_atoi(elem, NULL); 693 + 694 + READELEM(); 695 + uint64_t stime = __simple_atoi(elem, NULL); 696 + 697 + skip_stat_elems(&statptr, 2); // skip until priority 698 + READELEM(); 699 + // Can be negative, according to docs. 700 + int32_t priority = (elem[0] == '-') ? -__simple_atoi(elem + 1, NULL) : __simple_atoi(elem, NULL); 701 + 702 + skip_stat_elems(&statptr, 1); // skip until num_threads 703 + READELEM(); 704 + int32_t num_threads = __simple_atoi(elem, NULL); 705 + 706 + skip_stat_elems(&statptr, 2); // skip until vsize 707 + READELEM(); 708 + uint64_t vsize = __simple_atoi(elem, NULL); 709 + 710 + READELEM(); 711 + uint64_t rss = __simple_atoi(elem, NULL); 712 + 713 + ti->pti_virtual_size = vsize; 714 + ti->pti_resident_size = rss; 715 + ti->pti_total_user = utime; 716 + ti->pti_total_system = stime; 717 + // ti->pti_threads_user 718 + // ti->pti_threads_system 719 + // ti->pti_policy 720 + ti->pti_faults = minflt + majflt; 721 + // ti->pti_pageins 722 + // ti->pti_cow_faults 723 + // ti->pti_messages_sent 724 + // ti->pti_messages_received 725 + // ti->pti_syscalls_mach 726 + // ti->pti_syscalls_unix 727 + // ti->pti_csw 728 + ti->pti_threadnum = num_threads; 729 + // ti->pti_numrunning 730 + ti->pti_priority = priority; 731 + 732 + return sizeof(struct proc_taskinfo); 733 + reterr: 734 + return -EINVAL; 735 + } 736 + 737 + static long _proc_pidinfo_taskallinfo(int32_t pid, void* buffer, int32_t bufsize) 738 + { 739 + if (!buffer) 740 + return -EFAULT; 741 + if (bufsize < sizeof(struct proc_taskallinfo)) 742 + return -ENOSPC; 743 + 744 + long err = _proc_pidinfo_tbsdinfo(pid, buffer + offsetof(struct proc_taskallinfo, pbsd), sizeof(struct proc_bsdinfo)); 745 + 746 + if (err < 0) 747 + return err; 748 + 749 + err = _proc_pidinfo_taskinfo(pid, buffer + offsetof(struct proc_taskallinfo, ptinfo), sizeof(struct proc_taskinfo)); 750 + 751 + if (err < 0) 752 + return err; 753 + 754 + return sizeof(struct proc_taskallinfo); 755 + } 756 + 757 + #ifndef isdigit 758 + # define isdigit(c) (c >= '0' && c <= '9') 759 + #endif 760 + #ifndef DT_DIR 761 + # define DT_DIR 4 762 + #endif 763 + 764 + static long _proc_pidinfo_listthreads(int32_t pid, void* buffer, int32_t bufsize) 765 + { 766 + if (!buffer) 767 + return -EFAULT; 768 + 769 + uint64_t* threads = (uint64_t*)buffer; 770 + int32_t maxCount = bufsize / sizeof(uint64_t); 771 + int32_t count = 0; 772 + int fd, ret; 773 + long basep = 0; 774 + char dents[256]; 775 + char path[64]; 776 + 777 + __simple_sprintf(path, "/proc/%d/task", pid); 778 + 779 + fd = sys_open_nocancel(path, BSD_O_RDONLY | BSD_O_DIRECTORY, 0); 780 + if (fd < 0) 781 + return -ESRCH; 782 + 783 + while ((ret = sys_getdirentries(fd, (char*) dents, sizeof(dents), &basep)) > 0) 784 + { 785 + int pos = 0; 786 + 787 + while (pos < ret) 788 + { 789 + struct bsd_dirent* dent = (struct bsd_dirent*) &dents[pos]; 790 + 791 + if (dent->d_type != DT_DIR || !isdigit(dent->d_name[0])) 792 + { 793 + pos += dent->d_reclen; 794 + continue; 795 + } 796 + 797 + threads[count] = __simple_atoi(dent->d_name, NULL); 798 + ++count; 799 + 800 + if (count >= maxCount) 801 + { 802 + goto bail; 803 + return -ENOSPC; 804 + } 805 + 806 + pos += dent->d_reclen; 807 + } 808 + } 809 + 810 + bail: 811 + close_internal(fd); 812 + return count * sizeof(uint64_t); 813 + }
+19 -4
src/kernel/emulation/linux/process/waitid.c
··· 6 6 #include <linux-syscalls/linux.h> 7 7 #include <stddef.h> 8 8 9 - long sys_waitid(int idtype, int id, struct simple_siginfo* si, int options) 9 + static void siginfo_linux_to_bsd(const linux_siginfo_t* linux_si, siginfo_t* si); 10 + 11 + long sys_waitid(int idtype, int id, siginfo_t* si, int options) 10 12 { 11 13 int ret, linux_options; 12 14 13 15 linux_options = waitopts_bsd_to_linux(options); 14 16 15 - ret = LINUX_SYSCALL(__NR_waitid, idtype, id, si, linux_options); 17 + linux_siginfo_t linux_si; 18 + ret = LINUX_SYSCALL(__NR_waitid, idtype, id, &linux_si, linux_options); 16 19 if (ret < 0) 17 20 return errno_linux_to_bsd(ret); 18 21 19 22 if (si != NULL) 20 23 { 21 - si->si_signo = signum_linux_to_bsd(si->si_signo); 22 - si->si_errno = errno_linux_to_bsd(si->si_errno); 24 + siginfo_linux_to_bsd(&linux_si, si); 23 25 } 24 26 25 27 return ret; 26 28 } 27 29 30 + static void siginfo_linux_to_bsd(const linux_siginfo_t* linux_si, siginfo_t* si) 31 + { 32 + si->si_signo = signum_linux_to_bsd(linux_si->si_signo); 33 + si->si_errno = errno_linux_to_bsd(linux_si->si_errno); 34 + si->si_code = linux_si->si_code; 35 + si->si_pid = linux_si->linux_si_pid; 36 + si->si_uid = linux_si->linux_si_uid; 37 + si->si_status = linux_si->linux_si_status; 38 + si->si_addr = linux_si->linux_si_addr; 39 + si->si_value = linux_si->linux_si_value; 40 + si->si_band = linux_si->linux_si_band; 41 + } 42 +
+87 -6
src/kernel/emulation/linux/process/waitid.h
··· 1 1 #ifndef LINUX_WAITID_H 2 2 #define LINUX_WAITID_H 3 3 4 - struct simple_siginfo 4 + #include <sys/signal.h> 5 + 6 + #define LINUX_SI_MAX_SIZE 128 7 + #if __WORDSIZE == 64 8 + # define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE / sizeof (int)) - 4) 9 + #else 10 + # define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE / sizeof (int)) - 3) 11 + #endif 12 + 13 + // TODO: see when this is defind in Linux 14 + #ifndef LINUX_SI_ERRNO_THEN_CODE 15 + # define LINUX_SI_ERRNO_THEN_CODE 1 16 + #endif 17 + 18 + // This struct is heavily simplified. 19 + typedef struct 5 20 { 6 - int si_signo; 7 - int si_errno; 8 - int si_code; 9 - }; 21 + int si_signo; /* Signal number. */ 22 + #if LINUX_SI_ERRNO_THEN_CODE 23 + int si_errno; /* If non-zero, an errno value associated with 24 + this signal, as defined in <errno.h>. */ 25 + int si_code; /* Signal code. */ 26 + #else 27 + int si_code; 28 + int si_errno; 29 + #endif 30 + #if __WORDSIZE == 64 31 + int __pad0; /* Explicit padding. */ 32 + #endif 33 + union 34 + { 35 + int _pad[LINUX_SI_PAD_SIZE]; 36 + /* kill(). */ 37 + struct 38 + { 39 + pid_t si_pid; /* Sending process ID. */ 40 + uid_t si_uid; /* Real user ID of sending process. */ 41 + } _kill; 42 + /* POSIX.1b timers. */ 43 + struct 44 + { 45 + int si_tid; /* Timer ID. */ 46 + int si_overrun; /* Overrun count. */ 47 + union sigval si_sigval; /* Signal value. */ 48 + } _timer; 49 + /* POSIX.1b signals. */ 50 + struct 51 + { 52 + pid_t si_pid; /* Sending process ID. */ 53 + uid_t si_uid; /* Real user ID of sending process. */ 54 + union sigval si_sigval; /* Signal value. */ 55 + } _rt; 56 + /* SIGCHLD. */ 57 + struct 58 + { 59 + pid_t si_pid; /* Which child. */ 60 + uid_t si_uid; /* Real user ID of sending process. */ 61 + int si_status; /* Exit value or signal. */ 62 + } _sigchld; 63 + /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */ 64 + struct 65 + { 66 + void *si_addr; /* Faulting insn/memory ref. */ 67 + } _sigfault; 68 + /* SIGPOLL. */ 69 + struct 70 + { 71 + long si_band; /* Band event for SIGPOLL. */ 72 + int si_fd; 73 + } _sigpoll; 74 + /* SIGSYS. */ 75 + struct 76 + { 77 + void *_call_addr; /* Calling user insn. */ 78 + int _syscall; /* Triggering system call number. */ 79 + unsigned int _arch; /* AUDIT_ARCH_* of syscall. */ 80 + } _sigsys; 81 + } _sifields; 82 + } linux_siginfo_t; 10 83 11 - long sys_waitid(int idtype, int id, struct simple_siginfo* si, int options); 84 + // We keep only the fields defined in the BSD version. 85 + #define linux_si_pid _sifields._kill.si_pid 86 + #define linux_si_uid _sifields._kill.si_uid 87 + #define linux_si_status _sifields._sigchld.si_status 88 + #define linux_si_value _sifields._rt.si_sigval 89 + #define linux_si_addr _sifields._sigfault.si_addr 90 + #define linux_si_band _sifields._sigpoll.si_band 91 + 92 + long sys_waitid(int idtype, int id, siginfo_t* si, int options); 12 93 13 94 #endif 14 95
-1
src/kernel/emulation/linux/signal/sigaction.c
··· 19 19 void (*sa_tramp)(void*, int, int, struct bsd_siginfo*, void*) = 0; 20 20 bsd_sig_handler* sig_handlers[32] = { 21 21 [LINUX_SIGWINCH] = (bsd_sig_handler*) SIG_IGN, 22 - [LINUX_SIGCHLD] = (bsd_sig_handler*) SIG_IGN, 23 22 [LINUX_SIGURG] = (bsd_sig_handler*) SIG_IGN, 24 23 }; 25 24 int sig_flags[32];
+4
src/libelfloader/native/elfcalls.c
··· 5 5 #include <sys/mman.h> 6 6 #include <semaphore.h> 7 7 #include <locale.h> 8 + #include <unistd.h> 8 9 #include "elfcalls.h" 9 10 #include "threads.h" 10 11 ··· 67 68 68 69 calls->get_errno = get_errno; 69 70 calls->exit = exit; 71 + 72 + calls->sysconf = sysconf; 73 + 70 74 *((void**)&calls->sem_open) = sem_open; 71 75 *((void**)&calls->sem_wait) = sem_wait; 72 76 *((void**)&calls->sem_trywait) = sem_trywait;
+3
src/libelfloader/native/elfcalls.h
··· 46 46 int (*shm_unlink)(const char* name); 47 47 48 48 void (*exit)(int ec); 49 + 50 + // POSIX sysconf 51 + long (*sysconf)(int name); 49 52 }; 50 53 51 54 #endif