@@ -36,11 +36,10 @@ struct luajit_procs_t {
3636 __val; \
3737 })
3838
39- #define L_PART_OFFSET 0x10
40- #define CFRAME_SIZE_JIT 0x60
39+ #define L_PART_OFFSET 0x10
4140// (gdb) p/x sizeof(GCproto)
4241// $4 = 0x68
43- #define GCPROTO_SIZE 0x68
42+ #define GCPROTO_SIZE 0x68
4443
4544// This is L offset into interpreter stack frames.
4645#define L_STACK_OFFSET 0x10
@@ -116,7 +115,7 @@ enum { LJ_CONT_TAILCALL, LJ_CONT_FFI_CALLBACK }; /* Special continuations. */
116115
117116///////// END code copied from luajit2 sources.
118117
119- static inline __attribute__(( __always_inline__ )) TValue * frame_prevl (TValue * f , TValue frame_val )
118+ static EBPF_INLINE TValue * frame_prevl (TValue * f , TValue frame_val )
120119{
121120 // This is the EBPF version of the frame_prevl macro.
122121 // #define frame_prevl(f) ((f) - (1+LJ_FR2+bc_a(frame_pc(f)[-1])))
@@ -131,7 +130,7 @@ static inline __attribute__((__always_inline__)) TValue *frame_prevl(TValue *f,
131130// there's a bunch of places the return address is stored depending on the frame
132131// type.
133132// https://github.com/openresty/luajit2/blob/7952882d/src/lj_debug.c#L53
134- static inline __attribute__(( __always_inline__ )) ErrorCode
133+ static EBPF_INLINE ErrorCode
135134lj_debug_framepc (PerCPURecord * record , void * fn , u32 * startpc , TValue * prevframe , u32 * pc )
136135{
137136 LJFuncPart * func = & record -> luajitUnwindScratch .f ;
@@ -252,7 +251,7 @@ lj_debug_framepc(PerCPURecord *record, void *fn, u32 *startpc, TValue *prevframe
252251// bytecode which we will walk backwards in userland to figure out a name for the
253252// callee. The callee_pc is for information purposes only, so the user can see where
254253// execution was.
255- static inline __attribute__(( __always_inline__ )) ErrorCode lj_push_frame (
254+ static EBPF_INLINE ErrorCode lj_push_frame (
256255 UnwindState * state , Trace * trace , u64 callee_pt , u64 caller_pt , u32 callee_pc , u32 caller_pc )
257256{
258257 u64 * data =
@@ -265,7 +264,7 @@ static inline __attribute__((__always_inline__)) ErrorCode lj_push_frame(
265264 return ERR_OK ;
266265}
267266
268- static inline __attribute__(( __always_inline__ )) ErrorCode
267+ static EBPF_INLINE ErrorCode
269268lj_record_frame (PerCPURecord * record , TValue * frame , TValue frame_value , TValue * prevframe )
270269{
271270 LJScratchSpace * scr = & record -> luajitUnwindScratch ;
@@ -331,8 +330,7 @@ lj_record_frame(PerCPURecord *record, TValue *frame, TValue frame_value, TValue
331330
332331// See:
333332// https://github.com/openresty/luajit2/blob/7952882d/src/lj_frame.h#L33
334- static inline __attribute__((__always_inline__ )) ErrorCode
335- lj_prev_frame (PerCPURecord * record , TValue frame_val )
333+ static EBPF_INLINE ErrorCode lj_prev_frame (PerCPURecord * record , TValue frame_val )
336334{
337335 TValue * frame = record -> luajitUnwindState .frame ;
338336 if (frame_islua (frame_val )) {
@@ -350,18 +348,12 @@ lj_prev_frame(PerCPURecord *record, TValue frame_val)
350348 return ERR_OK ;
351349}
352350
353- #if defined(__x86_64__ )
354- #define CFRAME_SPACE 80
355- #elif defined(__aarch64__ )
356- #define CFRAME_SPACE 208
357- #endif
358-
359351// Unwind a frame of native code; for example,
360352// a CFRAME at the C/Lua boundary.
361353//
362354// `is_jit`should be true if there is JITted code anywhere in the Lua code corresponding to this
363355// cframe.
364- static inline __attribute__(( __always_inline__ )) ErrorCode
356+ static EBPF_INLINE ErrorCode
365357unwind_native_frame (const LuaJITProcInfo * info , UnwindState * state , bool is_jit )
366358{
367359 /* Interpreter frames unwind naturally, we need to poke sp/pc for JIT frames */
@@ -375,7 +367,7 @@ unwind_native_frame(const LuaJITProcInfo *info, UnwindState *state, bool is_jit)
375367 spadjust = info -> cframe_size_jit ;
376368 }
377369 } else {
378- spadjust = CFRAME_SPACE ;
370+ spadjust = LUAJIT_CFRAME_SPACE ;
379371 }
380372
381373 state -> sp += spadjust ;
@@ -404,7 +396,7 @@ unwind_native_frame(const LuaJITProcInfo *info, UnwindState *state, bool is_jit)
404396// and finding ones that indicate a function call frame. Code inspired by
405397// lj_debug_frame.
406398// https://github.com/openresty/luajit2/blob/7952882d/src/lj_debug.c#L25
407- static inline __attribute__(( __always_inline__ )) ErrorCode
399+ static EBPF_INLINE ErrorCode
408400walk_luajit_stack (PerCPURecord * record , const LuaJITProcInfo * info , int * next_unwinder )
409401{
410402 bool exitToNative = false;
@@ -434,7 +426,7 @@ walk_luajit_stack(PerCPURecord *record, const LuaJITProcInfo *info, int *next_un
434426 // BASE must always be two elements above the bottom of the stack,
435427 // even when the stack is logically empty. So whenever a new Lua state is created
436428 // (e.g. via luaL_newstate() or lua_newthread()), the interpreter
437- // pushes two dummy values.
429+ // pushes two dummy values (see https://github.com/luajit/luajit/blob/659a6169/src/lj_state.c#L168-L180) .
438430 //
439431 // Thus, when `diff` (set below) is <= 2, we've actually unwound past the logical
440432 // root of the stack, which should never happen...
@@ -554,7 +546,7 @@ walk_luajit_stack(PerCPURecord *record, const LuaJITProcInfo *info, int *next_un
554546 return ERR_OK ;
555547}
556548
557- static inline __attribute__(( __always_inline__ )) ErrorCode
549+ static EBPF_INLINE ErrorCode
558550find_context (struct pt_regs * ctx , PerCPURecord * record , const LuaJITProcInfo * info )
559551{
560552 bool reportG = false;
@@ -662,7 +654,7 @@ find_context(struct pt_regs *ctx, PerCPURecord *record, const LuaJITProcInfo *in
662654 return ERR_OK ;
663655}
664656
665- static inline __attribute__(( __always_inline__ )) int unwind_luajit (struct pt_regs * ctx )
657+ static EBPF_INLINE int unwind_luajit (struct pt_regs * ctx )
666658{
667659 PerCPURecord * record = get_per_cpu_record ();
668660 if (!record )
0 commit comments