this repo has no description
1
fork

Configure Feed

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

Handle hw.pagesize correctly

It *is* supposed to always be an `int` (and Apple's XNU code treats it
as such), but we need to zero out the rest of the buffer we get to make
libc's sysconf happy.

+14 -5
+14 -5
src/kernel/emulation/linux/misc/sysctl_hw.c
··· 7 7 #include "sysctl_proc.h" 8 8 #include "../ext/sys/utsname.h" 9 9 #include "../simple.h" 10 + #include "../string.h" 10 11 11 12 extern kern_return_t mach_port_deallocate(ipc_space_t task, mach_port_name_t name); 12 13 extern kern_return_t host_info(mach_port_name_t host, int itype, void* hinfo, mach_msg_type_number_t* count); ··· 46 47 { .oid = _HW_LOGICAL_CPU, .type = CTLTYPE_INT, .exttype = "", .name = "logicalcpu", .handler = handle_logicalcpu }, 47 48 { .oid = _HW_LOGICAL_CPU_MAX, .type = CTLTYPE_INT, .exttype = "", .name = "logicalcpu_max", .handler = handle_logicalcpu_max }, 48 49 { .oid = HW_MEMSIZE, .type = CTLTYPE_QUAD, .exttype = "U", .name = "memsize", .handler = handle_memsize }, 49 - { .oid = HW_PAGESIZE, .type = CTLTYPE_INT, .exttype = "", .name = "pagesize", .handler = handle_pagesize }, 50 + { .oid = HW_PAGESIZE, .type = CTLTYPE_INT, .exttype = "I", .name = "pagesize", .handler = handle_pagesize }, 50 51 { .oid = _HW_CPUTYPE, .type = CTLTYPE_INT, .exttype = "", .name = "cputype", .handler = handle_cputype }, 51 52 { .oid = _HW_CPUSUBTYPE, .type = CTLTYPE_INT, .exttype = "", .name = "cpusubtype", .handler = handle_cpusubtype }, 52 53 { .oid = _HW_CPUTHREADTYPE, .type = CTLTYPE_INT, .exttype = "", .name = "cputhreadtype", .handler = handle_cputhreadtype }, ··· 118 119 119 120 sysctl_handler(handle_pagesize) 120 121 { 121 - //sysctl_handle_size(sizeof(int)); 122 - // TODO: maybe should be int64_t (long long) all the time, keeping compatability with int for now 123 122 if (old == NULL) 124 123 { 125 124 *oldlen = sizeof(int); 126 125 return 0; 127 126 } 128 - else if (*oldlen == sizeof(long long)) 127 + else if (*oldlen < sizeof(int)) 129 128 { 130 - *((long long*) old) = 4096; // true on all Darling platforms 129 + return -EINVAL; 131 130 } 132 131 else 133 132 { 134 133 *((int*) old) = 4096; // true on all Darling platforms 134 + 135 + // libc's sysconf passes in a `long` for the argument. 136 + // Apple's code is actually wrong there because it doesn't check the returned size. 137 + // to deal with this (since apparently it works on real macOS), what we do is zero out 138 + // the rest of the buffer so the upper half won't be garbage. 139 + // 140 + // note that this only works on little endian systems, 141 + // but that's okay; that's what all Darling platforms are. 142 + memset((char*)old + sizeof(int), 0, *oldlen - sizeof(int)); 143 + 135 144 *oldlen = sizeof(int); 136 145 } 137 146 return 0;