In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What this article shares with you is about how to call C++. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
There is a thorny problem when making C++ calls. Naked Call is a rare C++ calling convention that programmers are advised not to use. The compiler will not add initialization and cleaning code to this function, saving it from becoming a white labor.
Note to the caller push 1push 2call functionadd esp,8: here the C++ caller saves the ebp register in push ebp at the called function _ function on the recovery stack, which will be used to hold the top pointer of the stack. You can restore the mov ebp,esp to save the stack pointer mov eax when the function exits. Before the ebp points to the position in the [ebp + 8H] stack, ebp,cs:eip,a,b,ebp + 8 points to the aadd eax in turn, and the bmov esp,ebp recovery esppop ebpret is saved at ebp + 12 in the [ebp + 0CH] stack. Note: there is no modification to the stack.
MSDN says that this modification automatically underscores the function name with a leading underscore, so the function name is recorded as _ function in the symbol table, but I don't seem to see this change at compile time. Since the parameters are stacked from right to left, the initial parameters are closest to the top of the stack, so when using an indefinite number of parameters, the position of * parameters in the stack can be known. As long as the uncertain number of parameters can be determined according to the following explicit parameters of the latter, indefinite parameters can be used. For example, for the sprintf function in CRT, it is defined as:
Class A {public: int function1 (int arecint b); int function2 (int apene...);}; int A::function1 (int arecint b) {return aforb;} # include int A::function2 (int apene...) {va_list ap; va_start (ap,a); int i; int result = 0; for (I = 0; I < a; I + +) {result + = va_arg (ap,int) }
The * and the second DWORD parameters (or smaller) of the function are passed through ecx and edx. The other parameters are called by pressing the stack sequentially from right to left to clean up the stack function name modification rule, which is a rare calling convention, which is not recommended by general programmers.
The compiler will not add initialization and cleanup code to this function, and more specifically, you can't return the value with return, you can only use insert assembly to return the result. This is generally used in real mode driver design, assuming that a summation adder is defined, which can be defined as:
_ _ declspec (naked) int add (int aline int b) {_ _ asm mov eax,a _ _ asm add eax,b _ _ asm ret}
Note that this function does not have an explicit return return value, which is achieved by modifying the eax register, and even the ret instruction to exit the function must be explicitly inserted. The above code is translated into assembly and becomes:
Declspec (naked) int add (int aline int b) {_ _ asm mov eax,a _ _ asm add eax,b _ _ asm ret}
Because the caller does not understand the meaning of WINAPI, the above code will inevitably cause the stack to be corrupted. The checkesp function inserted by MFC at compile time will tell you that the stack is broken.
The above is how to make C++ calls. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.