|
66 | 66 | #ifdef PY_HAVE_PERF_TRAMPOLINE |
67 | 67 |
|
68 | 68 | /* Standard library includes for perf jitdump implementation */ |
69 | | -#include <elf.h> // ELF architecture constants |
| 69 | +#if defined(__linux__) |
| 70 | +# include <elf.h> // ELF architecture constants |
| 71 | +#endif |
70 | 72 | #include <fcntl.h> // File control operations |
71 | 73 | #include <stdio.h> // Standard I/O operations |
72 | 74 | #include <stdlib.h> // Standard library functions |
73 | 75 | #include <sys/mman.h> // Memory mapping functions (mmap) |
74 | 76 | #include <sys/types.h> // System data types |
75 | 77 | #include <unistd.h> // System calls (sysconf, getpid) |
76 | 78 | #include <sys/time.h> // Time functions (gettimeofday) |
77 | | -#include <sys/syscall.h> // System call interface |
| 79 | +#if defined(__linux__) |
| 80 | +# include <sys/syscall.h> // System call interface |
| 81 | +#endif |
78 | 82 |
|
79 | 83 | // ============================================================================= |
80 | 84 | // CONSTANTS AND CONFIGURATION |
|
101 | 105 | * based on the actual unwind information requirements. |
102 | 106 | */ |
103 | 107 |
|
| 108 | + |
| 109 | +/* These constants are defined inside <elf.h>, which we can't use outside of linux. */ |
| 110 | +#if !defined(__linux__) |
| 111 | +# define EM_386 3 |
| 112 | +# define EM_X86_64 62 |
| 113 | +# define EM_ARM 40 |
| 114 | +# define EM_AARCH64 183 |
| 115 | +# define EM_RISCV 243 |
| 116 | +#endif |
| 117 | + |
104 | 118 | /* Convenient access to the global trampoline API state */ |
105 | 119 | #define trampoline_api _PyRuntime.ceval.perf.trampoline_api |
106 | 120 |
|
@@ -194,7 +208,7 @@ struct BaseEvent { |
194 | 208 | typedef struct { |
195 | 209 | struct BaseEvent base; // Common event header |
196 | 210 | uint32_t process_id; // Process ID where code was generated |
197 | | - uint32_t thread_id; // Thread ID where code was generated |
| 211 | + uint64_t thread_id; // Thread ID where code was generated |
198 | 212 | uint64_t vma; // Virtual memory address where code is loaded |
199 | 213 | uint64_t code_address; // Address of the actual machine code |
200 | 214 | uint64_t code_size; // Size of the machine code in bytes |
@@ -1263,7 +1277,11 @@ static void perf_map_jit_write_entry(void *state, const void *code_addr, |
1263 | 1277 | ev.base.size = sizeof(ev) + (name_length+1) + size; |
1264 | 1278 | ev.base.time_stamp = get_current_monotonic_ticks(); |
1265 | 1279 | ev.process_id = getpid(); |
| 1280 | +#if defined(__APPLE__) |
| 1281 | + pthread_threadid_np(NULL, &ev.thread_id); |
| 1282 | +#else |
1266 | 1283 | ev.thread_id = syscall(SYS_gettid); // Get thread ID via system call |
| 1284 | +#endif |
1267 | 1285 | ev.vma = base; // Virtual memory address |
1268 | 1286 | ev.code_address = base; // Same as VMA for our use case |
1269 | 1287 | ev.code_size = size; |
|
0 commit comments