zoukankan      html  css  js  c++  java
  • __builtin_return_address && _RET_IP_

      以前看互斥锁自旋锁实现的时候,看过RET_IP,只是了解到其为当前函数的返回地址;今天系统的看下这几个宏

    • __builtin_return_address(0)的含义是,得到当前函数返回地址,即此函数被别的函数调用返回时的地址。
    • __builtin_return_address(1)的含义是,得到当前函数的调用者的返回地址。
    #define _RET_IP_ (unsigned long)__builtin_return_address(0)
    #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
    /* All archs should have this, but we define it for consistency */
    #ifndef ftrace_return_address0
    # define ftrace_return_address0 __builtin_return_address(0)
    #endif
    
    /* Archs may use other ways for ADDR1 and beyond */
    #ifndef ftrace_return_address
    # ifdef CONFIG_FRAME_POINTER
    #  define ftrace_return_address(n) __builtin_return_address(n)
    # else
    #  define ftrace_return_address(n) 0UL
    # endif
    #endif
    
    #define CALLER_ADDR0 ((unsigned long)ftrace_return_address0)
    #define CALLER_ADDR1 ((unsigned long)ftrace_return_address(1))
    #define CALLER_ADDR2 ((unsigned long)ftrace_return_address(2))
    #define CALLER_ADDR3 ((unsigned long)ftrace_return_address(3))
    #define CALLER_ADDR4 ((unsigned long)ftrace_return_address(4))
    #define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
    #define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
    _THIS_IP_ :当前进程的地址;可以看到其实现使用了label 以及&& 
    & in && is necessary to make GCC lookup the name as a label, instead of as a variable.
    { __label__ __here;
     __here: 
    (unsigned long) &&__here; 
    }

    CALLER_ADDR5   __builtin_return_address (5) 这是什么鬼?

       实际上内建函数 __builtin_return_address返回当前函数或其调用者的返回地址,参数LEVEL指定在栈上搜索farme栈的个数 ;

    其具体需要编写代码试一下

    http代理服务器(3-4-7层代理)-网络事件库公共组件、内核kernel驱动 摄像头驱动 tcpip网络协议栈、netfilter、bridge 好像看过!!!! 但行好事 莫问前程 --身高体重180的胖子
  • 相关阅读:
    CodeForces 734F Anton and School
    CodeForces 733F Drivers Dissatisfaction
    CodeForces 733C Epidemic in Monstropolis
    ZOJ 3498 Javabeans
    ZOJ 3497 Mistwald
    ZOJ 3495 Lego Bricks
    CodeForces 732F Tourist Reform
    CodeForces 732E Sockets
    CodeForces 731E Funny Game
    CodeForces 731D 80-th Level Archeology
  • 原文地址:https://www.cnblogs.com/codestack/p/15097768.html
Copyright © 2011-2022 走看看