霍邱网站设计,地推拉新app推广怎么做,wordpress珠宝主题,wap 网站文章目录 参考gcc 内部的宏定义代码汇编调用在 SEI CERT C Coding Standard 这个标准里示例实例宏里的使用 参考
https://git.sr.ht/~gregkh/presentation-security/blob/3547183843399d693c35b502cf4a313e256d0dd8/security-stuff.pdf
gcc 内部的宏定义
宏定义#xff1a;… 文章目录 参考gcc 内部的宏定义代码汇编调用在 SEI CERT C Coding Standard 这个标准里示例实例宏里的使用 参考
https://git.sr.ht/~gregkh/presentation-security/blob/3547183843399d693c35b502cf4a313e256d0dd8/security-stuff.pdf
gcc 内部的宏定义
宏定义 使用的时builtin_va_end 宏定义。
#define va_start(v,l) __builtin_va_start(v,l)
#define va_end(v) __builtin_va_end(v)
#define va_arg(v,l) __builtin_va_arg(v,l)使用到了下列内置函数来实现va-start、end、arg相关的宏。
/* Expand EXP, a call to __builtin_va_start. */static rtx
expand_builtin_va_start (tree exp)
{rtx nextarg;tree valist;location_t loc EXPR_LOCATION (exp);
代码
int add(int first, int second, ... )
{int rfirst second;va_list va;;;va_start(va, second);while(int v va_arg(va,int)){rv;}va_end(va);return r;
}汇编 962 0000000000400c56 add(int, int, ...):963 400c56: 55 push %rbp964 400c57: 48 89 e5 mov %rsp,%rbp965 400c5a: 48 83 ec 68 sub $0x68,%rsp 申请的栈空间是 0x68但是使用的远远大于这个值。966 400c5e: 89 bd 2c ff ff ff mov %edi,-0xd4(%rbp) 六个寄存器参数都用上了967 400c64: 89 b5 28 ff ff ff mov %esi,-0xd8(%rbp) 而且将这六个参数放到超远的栈上。968 400c6a: 48 89 95 60 ff ff ff mov %rdx,-0xa0(%rbp)969 400c71: 48 89 8d 68 ff ff ff mov %rcx,-0x98(%rbp)970 400c78: 4c 89 85 70 ff ff ff mov %r8,-0x90(%rbp)971 400c7f: 4c 89 8d 78 ff ff ff mov %r9,-0x88(%rbp)972 400c86: 84 c0 test %al,%al 看着调用一直时0是否用到floating 的变量几个973 400c88: 74 20 je 400caa add(int, int, ...)0x54 如果又floating的数值将floating寄存器的值放到 栈974 400c8a: 0f 29 45 80 movaps %xmm0,-0x80(%rbp) floating的值放到floating 寄存器。975 400c8e: 0f 29 4d 90 movaps %xmm1,-0x70(%rbp)976 400c92: 0f 29 55 a0 movaps %xmm2,-0x60(%rbp)977 400c96: 0f 29 5d b0 movaps %xmm3,-0x50(%rbp)978 400c9a: 0f 29 65 c0 movaps %xmm4,-0x40(%rbp)979 400c9e: 0f 29 6d d0 movaps %xmm5,-0x30(%rbp)980 400ca2: 0f 29 75 e0 movaps %xmm6,-0x20(%rbp)981 400ca6: 0f 29 7d f0 movaps %xmm7,-0x10(%rbp)982 400caa: 8b 95 2c ff ff ff mov -0xd4(%rbp),%edx983 400cb0: 8b 85 28 ff ff ff mov -0xd8(%rbp),%eax984 400cb6: 01 d0 add %edx,%eax 第一个和第二个参数相加放到eax985 400cb8: 89 85 4c ff ff ff mov %eax,-0xb4(%rbp) 然后放到 栈986 400cbe: c7 85 30 ff ff ff 10 movl $0x10,-0xd0(%rbp) 将16 放到 栈987 400cc5: 00 00 00988 400cc8: c7 85 34 ff ff ff 30 movl $0x30,-0xcc(%rbp) 将0x30 放到栈989 400ccf: 00 00 00990 400cd2: 48 8d 45 10 lea 0x10(%rbp),%rax 将rbp 16 的值放到rax使用到了上一个函数栈。991 400cd6: 48 89 85 38 ff ff ff mov %rax,-0xc8(%rbp) 放到栈992 400cdd: 48 8d 85 50 ff ff ff lea -0xb0(%rbp),%rax 将rbp -0xb0的地址放到rax993 400ce4: 48 89 85 40 ff ff ff mov %rax,-0xc0(%rbp) 放到栈994 400ceb: 8b 85 30 ff ff ff mov -0xd0(%rbp),%eax 将rbp-0xd0的值放到eax995 400cf1: 83 f8 2f cmp $0x2f,%eax 对比0x2f 为什么比对2f996 400cf4: 77 23 ja 400d19 add(int, int, ...)0xc3997 400cf6: 48 8b 85 40 ff ff ff mov -0xc0(%rbp),%rax998 400cfd: 8b 95 30 ff ff ff mov -0xd0(%rbp),%edx999 400d03: 89 d2 mov %edx,%edx1000 400d05: 48 01 d0 add %rdx,%rax1001 400d08: 8b 95 30 ff ff ff mov -0xd0(%rbp),%edx1002 400d0e: 83 c2 08 add $0x8,%edx1003 400d11: 89 95 30 ff ff ff mov %edx,-0xd0(%rbp)1004 400d17: eb 12 jmp 400d2b add(int, int, ...)0xd51005 400d19: 48 8b 85 38 ff ff ff mov -0xc8(%rbp),%rax1006 400d20: 48 8d 50 08 lea 0x8(%rax),%rdx1007 400d24: 48 89 95 38 ff ff ff mov %rdx,-0xc8(%rbp)1008 400d2b: 8b 00 mov (%rax),%eax1009 400d2d: 89 85 48 ff ff ff mov %eax,-0xb8(%rbp)1010 400d33: 83 bd 48 ff ff ff 00 cmpl $0x0,-0xb8(%rbp)1011 400d3a: 74 0e je 400d4a add(int, int, ...)0xf41012 400d3c: 8b 85 48 ff ff ff mov -0xb8(%rbp),%eax1013 400d42: 01 85 4c ff ff ff add %eax,-0xb4(%rbp) 将 eax 加到栈里1014 400d48: eb a1 jmp 400ceb add(int, int, ...)0x951015 400d4a: 8b 85 4c ff ff ff mov -0xb4(%rbp),%eax 最终的结果放到eax1016 400d50: c9 leaveq1017 400d51: c3 retq调用
int main()
{
printf( abc%d\n, add(1,3,4,5,8,9,10);
return 1;
}0000000000400968 main:400968: 55 push %rbp400969: 48 89 e5 mov %rsp,%rbp40096c: 48 83 ec 08 sub $0x8,%rsp 按16 字节对齐。多8个字节占栈如果多出来一个参数400970: 6a 0a pushq $0xa400972: 41 b9 09 00 00 00 mov $0x9,%r9d400978: 41 b8 08 00 00 00 mov $0x8,%r8d40097e: b9 05 00 00 00 mov $0x5,%ecx400983: ba 04 00 00 00 mov $0x4,%edx400988: be 03 00 00 00 mov $0x3,%esi40098d: bf 01 00 00 00 mov $0x1,%edi400992: b8 00 00 00 00 mov $0x0,%eax 把 eax 清空400997: e8 aa fe ff ff callq 400846 add(int, int, ...)40099c: 48 83 c4 10 add $0x10,%rsp 释放栈4009a0: 89 c6 mov %eax,%esi4009a2: bf b2 0a 40 00 mov $0x400ab2,%edi4009a7: b8 00 00 00 00 mov $0x0,%eax4009ac: e8 3f fd ff ff callq 4006f0 printfplt4009b1: b8 01 00 00 00 mov $0x1,%eax4009b6: c9 leaveq4009b7: c3 retq在 SEI CERT C Coding Standard 这个标准里
提到了更安全的C定义方式。 这种方式将编程从运行时变参转移到了编译时更安全。
示例
https://en.cppreference.com/w/cpp/language/parameter_pack
#include iostreamvoid tprintf(const char* format) // base function
{std::cout format;
}
、、 这个会产生多少个函数来
templatetypename T, typename... Targs
void tprintf(const char* format, T value, Targs... Fargs) // recursive variadic function
{for ( ; *format ! \0; format ) {if ( *format % ) {std::cout value;tprintf(format1, Fargs...); // recursive callreturn;}std::cout *format;}
}int main()
{tprintf(% world% %\n,Hello,!,123);
}实例
变参传递到另一个函数里
static inline void abc(int level, const char *format, ...)
{char buff[UMAX_LOG_SIZE];int msgLen;va_list arglist;memset(buff, 0, sizeof(buff));va_start(arglist, format);msgLen vsnprintf(buff, UMAX_LOG_SIZE, format, arglist);va_end(arglist);宏里的使用
下面这个宏只包含有三个点所代表的参数不包含三个点以外有名称的参数。
__VA_ARGS__
#define _FUNC1_(tn, constness, ct, Method, ...) \
class mock_##Method { \
public:\RESULT_(tn, __VA_ARGS__) ct Method( \ // 这里__VA_ARGS__, 不包含 tnconstnessct和Method
文章转载自: http://www.morning.wbdm.cn.gov.cn.wbdm.cn http://www.morning.krkwh.cn.gov.cn.krkwh.cn http://www.morning.ktlxk.cn.gov.cn.ktlxk.cn http://www.morning.txzmy.cn.gov.cn.txzmy.cn http://www.morning.lnrhk.cn.gov.cn.lnrhk.cn http://www.morning.hbqhz.cn.gov.cn.hbqhz.cn http://www.morning.xqffq.cn.gov.cn.xqffq.cn http://www.morning.fnkcg.cn.gov.cn.fnkcg.cn http://www.morning.gediba.com.gov.cn.gediba.com http://www.morning.cnhgc.cn.gov.cn.cnhgc.cn http://www.morning.qxlhj.cn.gov.cn.qxlhj.cn http://www.morning.xdmsq.cn.gov.cn.xdmsq.cn http://www.morning.wkmpx.cn.gov.cn.wkmpx.cn http://www.morning.jpjpb.cn.gov.cn.jpjpb.cn http://www.morning.tgcw.cn.gov.cn.tgcw.cn http://www.morning.wqngt.cn.gov.cn.wqngt.cn http://www.morning.kkwbw.cn.gov.cn.kkwbw.cn http://www.morning.kfmlf.cn.gov.cn.kfmlf.cn http://www.morning.krdb.cn.gov.cn.krdb.cn http://www.morning.grpbt.cn.gov.cn.grpbt.cn http://www.morning.mfmrg.cn.gov.cn.mfmrg.cn http://www.morning.qmbpy.cn.gov.cn.qmbpy.cn http://www.morning.zwzwn.cn.gov.cn.zwzwn.cn http://www.morning.tmlhh.cn.gov.cn.tmlhh.cn http://www.morning.ccphj.cn.gov.cn.ccphj.cn http://www.morning.pcwzb.cn.gov.cn.pcwzb.cn http://www.morning.wkws.cn.gov.cn.wkws.cn http://www.morning.zsgbt.cn.gov.cn.zsgbt.cn http://www.morning.sfzwm.cn.gov.cn.sfzwm.cn http://www.morning.lzqdd.cn.gov.cn.lzqdd.cn http://www.morning.sknbb.cn.gov.cn.sknbb.cn http://www.morning.rzjfn.cn.gov.cn.rzjfn.cn http://www.morning.sthp.cn.gov.cn.sthp.cn http://www.morning.ggmls.cn.gov.cn.ggmls.cn http://www.morning.kgrwh.cn.gov.cn.kgrwh.cn http://www.morning.mxgpp.cn.gov.cn.mxgpp.cn http://www.morning.rzczl.cn.gov.cn.rzczl.cn http://www.morning.okiner.com.gov.cn.okiner.com http://www.morning.tnjff.cn.gov.cn.tnjff.cn http://www.morning.lpmdy.cn.gov.cn.lpmdy.cn http://www.morning.qtnmp.cn.gov.cn.qtnmp.cn http://www.morning.hyjpl.cn.gov.cn.hyjpl.cn http://www.morning.mqxzh.cn.gov.cn.mqxzh.cn http://www.morning.bphqd.cn.gov.cn.bphqd.cn http://www.morning.qxkcx.cn.gov.cn.qxkcx.cn http://www.morning.skmzm.cn.gov.cn.skmzm.cn http://www.morning.rfjmy.cn.gov.cn.rfjmy.cn http://www.morning.ltrz.cn.gov.cn.ltrz.cn http://www.morning.mzcrs.cn.gov.cn.mzcrs.cn http://www.morning.bctr.cn.gov.cn.bctr.cn http://www.morning.sdhmn.cn.gov.cn.sdhmn.cn http://www.morning.klyyd.cn.gov.cn.klyyd.cn http://www.morning.wpqcj.cn.gov.cn.wpqcj.cn http://www.morning.crfyr.cn.gov.cn.crfyr.cn http://www.morning.wrbnh.cn.gov.cn.wrbnh.cn http://www.morning.rmfwh.cn.gov.cn.rmfwh.cn http://www.morning.yqfdl.cn.gov.cn.yqfdl.cn http://www.morning.xfwnk.cn.gov.cn.xfwnk.cn http://www.morning.zcyxq.cn.gov.cn.zcyxq.cn http://www.morning.wzjhl.cn.gov.cn.wzjhl.cn http://www.morning.tkzrh.cn.gov.cn.tkzrh.cn http://www.morning.tqpr.cn.gov.cn.tqpr.cn http://www.morning.ryxgk.cn.gov.cn.ryxgk.cn http://www.morning.tsxg.cn.gov.cn.tsxg.cn http://www.morning.mysmz.cn.gov.cn.mysmz.cn http://www.morning.ggjlm.cn.gov.cn.ggjlm.cn http://www.morning.xrlwr.cn.gov.cn.xrlwr.cn http://www.morning.hnrpk.cn.gov.cn.hnrpk.cn http://www.morning.tgyzk.cn.gov.cn.tgyzk.cn http://www.morning.dsgdt.cn.gov.cn.dsgdt.cn http://www.morning.jmwrj.cn.gov.cn.jmwrj.cn http://www.morning.kqxwm.cn.gov.cn.kqxwm.cn http://www.morning.fprll.cn.gov.cn.fprll.cn http://www.morning.dzrcj.cn.gov.cn.dzrcj.cn http://www.morning.gwtgt.cn.gov.cn.gwtgt.cn http://www.morning.wrtsm.cn.gov.cn.wrtsm.cn http://www.morning.bpwdc.cn.gov.cn.bpwdc.cn http://www.morning.kksjr.cn.gov.cn.kksjr.cn http://www.morning.qcsbs.cn.gov.cn.qcsbs.cn http://www.morning.ykyfq.cn.gov.cn.ykyfq.cn