this repo has no description
1
fork

Configure Feed

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

Expose "simple" functions from libsystem_kernel

Some of these (like __simple_printf and __simple_kprintf) were already externally visible, but now all of the functions in the simple.h header are externally visible.

One benefit of this is that we can use these in xtrace and get rid of the redundant code in xtrace's simple.{c,h}

+26 -9
+17 -5
src/kernel/emulation/linux/simple.c
··· 4 4 #include <stddef.h> 5 5 #include <linux-syscalls/linux.h> 6 6 #include <lkm/api.h> 7 + #include "mach/lkm.h" 7 8 8 - void __simple_vsprintf(char* buf, const char* format, va_list vl); 9 + int __simple_vsprintf(char* buf, const char* format, va_list vl); 9 10 extern char* memchr(char* buf, int c, __SIZE_TYPE__ n); 10 11 12 + __attribute__ ((visibility ("default"))) 11 13 int __simple_strlen(const char* text) 12 14 { 13 15 int len = 0; ··· 21 23 return (n < 0) ? -n : n; 22 24 } 23 25 24 - void __simple_vsprintf(char* buf, const char* format, va_list vl) 26 + __attribute__ ((visibility ("default"))) 27 + int __simple_vsprintf(char* buf, const char* format, va_list vl) 25 28 { 29 + char* initial_buf = buf; 26 30 while (*format) 27 31 { 28 32 if (*format == '%') ··· 136 140 } 137 141 138 142 *buf = 0; 143 + return buf - initial_buf; 139 144 } 140 145 141 146 __attribute__ ((visibility ("default"))) ··· 164 169 lkm_call(NR_kernel_printk, buffer); 165 170 } 166 171 172 + __attribute__ ((visibility ("default"))) 167 173 void __simple_fprintf(int fd, const char* format, ...) 168 174 { 169 175 char buffer[512]; ··· 176 182 LINUX_SYSCALL3(__NR_write, fd, buffer, __simple_strlen(buffer)); 177 183 } 178 184 179 - 180 - void __simple_sprintf(char *buffer, const char* format, ...) 185 + __attribute__ ((visibility ("default"))) 186 + int __simple_sprintf(char *buffer, const char* format, ...) 181 187 { 182 188 va_list vl; 183 189 184 190 va_start(vl, format); 185 - __simple_vsprintf(buffer, format, vl); 191 + int ret = __simple_vsprintf(buffer, format, vl); 186 192 va_end(vl); 193 + 194 + return ret; 187 195 } 188 196 189 197 #ifdef isdigit ··· 205 213 return 0; 206 214 } 207 215 216 + __attribute__ ((visibility ("default"))) 208 217 unsigned long long __simple_atoi(const char* str, const char** endp) 209 218 { 210 219 unsigned long long value = 0; ··· 221 230 return value; 222 231 } 223 232 233 + __attribute__ ((visibility ("default"))) 224 234 unsigned long long __simple_atoi16(const char* str, const char** endp) 225 235 { 226 236 unsigned long long value = 0; ··· 252 262 # define min(a,b) ((a) < (b) ? (a) : (b)) 253 263 #endif 254 264 265 + __attribute__ ((visibility ("default"))) 255 266 void __simple_readline_init(struct simple_readline_buf* buf) 256 267 { 257 268 buf->used = 0; 258 269 } 259 270 271 + __attribute__ ((visibility ("default"))) 260 272 char* __simple_readline(int fd, struct simple_readline_buf* buf, char* out, int max_out) 261 273 { 262 274 char* nl = NULL;
+9 -4
src/kernel/emulation/linux/simple.h
··· 1 1 #ifndef LINUX_DEBUG_H 2 2 #define LINUX_DEBUG_H 3 3 4 + #include <stdarg.h> 5 + 6 + // everything in this header can be used outside of libsystem_kernel 7 + 4 8 #ifdef __cplusplus 5 9 extern "C" { 6 10 #endif 7 11 8 - void __simple_printf(const char* format, ...); 9 - void __simple_kprintf(const char* format, ...); 10 - void __simple_fprintf(int fd, const char* format, ...); 11 - void __simple_sprintf(char *buffer, const char* format, ...); 12 + void __simple_printf(const char* format, ...) __attribute__((format(printf, 1, 2))); 13 + void __simple_kprintf(const char* format, ...) __attribute__((format(printf, 1, 2))); 14 + void __simple_fprintf(int fd, const char* format, ...) __attribute__((format(printf, 2, 3))); 15 + int __simple_sprintf(char *buffer, const char* format, ...) __attribute__((format(printf, 2, 3))); 12 16 int __simple_strlen(const char* str); 17 + int __simple_vsprintf(char* buf, const char* format, va_list vl) __attribute__((format(printf, 2, 0))); 13 18 14 19 unsigned long long __simple_atoi(const char* str, const char** endp); 15 20 unsigned long long __simple_atoi16(const char* str, const char** endp);