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
102
106
*/
103
107
#define PERF_JIT_CODE_PADDING 0x100
104
108
109
+
110
+ /* These constants are defined inside <elf.h>, which we can't use outside of linux. */
111
+ #if !defined(__linux__ )
112
+ # define EM_386 3
113
+ # define EM_ARM 40
114
+ # define EM_AARCH64 183
115
+ # define EM_RISCV 243
116
+ #endif
117
+
105
118
/* Convenient access to the global trampoline API state */
106
119
#define trampoline_api _PyRuntime.ceval.perf.trampoline_api
107
120
@@ -195,7 +208,7 @@ struct BaseEvent {
195
208
typedef struct {
196
209
struct BaseEvent base ; // Common event header
197
210
uint32_t process_id ; // Process ID where code was generated
198
- uint32_t thread_id ; // Thread ID where code was generated
211
+ uint64_t thread_id ; // Thread ID where code was generated
199
212
uint64_t vma ; // Virtual memory address where code is loaded
200
213
uint64_t code_address ; // Address of the actual machine code
201
214
uint64_t code_size ; // Size of the machine code in bytes
@@ -1166,7 +1179,11 @@ static void perf_map_jit_write_entry(void *state, const void *code_addr,
1166
1179
ev .base .size = sizeof (ev ) + (name_length + 1 ) + size ;
1167
1180
ev .base .time_stamp = get_current_monotonic_ticks ();
1168
1181
ev .process_id = getpid ();
1182
+ #if defined(__APPLE__ )
1183
+ pthread_threadid_np (NULL , & ev .thread_id );
1184
+ #else
1169
1185
ev .thread_id = syscall (SYS_gettid ); // Get thread ID via system call
1186
+ #endif
1170
1187
ev .vma = base ; // Virtual memory address
1171
1188
ev .code_address = base ; // Same as VMA for our use case
1172
1189
ev .code_size = size ;
@@ -1262,4 +1279,4 @@ _PyPerf_Callbacks _Py_perfmap_jit_callbacks = {
1262
1279
& perf_map_jit_fini , // Cleanup function
1263
1280
};
1264
1281
1265
- #endif /* PY_HAVE_PERF_TRAMPOLINE */
1282
+ #endif /* PY_HAVE_PERF_TRAMPOLINE */
0 commit comments