kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

builtin_30_frame_address.c (568B)


      1 /* __builtin_frame_address(0): the current frame pointer, never null. Level 1
      2  * names the caller's frame; since the stack grows down, the caller frame sits
      3  * at a higher address than ours. */
      4 __attribute__((noinline)) static void* fa0(void) {
      5   return __builtin_frame_address(0);
      6 }
      7 
      8 int test_main(void) {
      9   void* here = __builtin_frame_address(0);
     10   void* callee = fa0();
     11   if (here == 0 || callee == 0) return 1;
     12   /* fa0's frame is below test_main's (deeper call, lower address). */
     13   if (!((unsigned char*)callee < (unsigned char*)here)) return 2;
     14   return 42;
     15 }