Program entry function and _security_init_cookie__ function in Windows

Source: Internet
Author: User

The Win32 program is divided into two types:

1. Console (/subsystem:console)

2.GUI (/subsystem:windows)


First look at the console version:

Write a paragraph that is the simplest, or simply use the default main function of the compiler parameter, as follows:

[CPP] view plain copy//EntryFunction.cpp: Defines the entry point for a console application.   #include "stdafx.h" int _tmain (int argc, _tchar* argv[]) {return 0; }

1. Using the/MD option

F9 down to the tag of the main function, F11 back to _tmaincrtstartup () in call stack, and the current file is crtexe.c. As follows:



2. Using the/MT option

F9 down to the tag of the main function, F11 back to _tmaincrtstartup () in call stack, and the current file is crt0.c. As follows:



That is, different runtime links, the implementation of the code is also different. But the name of the entry point function is the same, it is _tmaincrtstartup. This is the startup function (the real entry function) under Windows.


Let's discuss separately what the two do in the entry function.

First look at the _security_init_cookie, this function is the same in the two implementation files, the code is as follows:

[CPP]  View Plain  copy  /***  *__security_init_cookie (cookie)  - init buffer  overrun security cookie.  *  *purpose:  *        initialize the global buffer overrun security cookie which is  used by  *       the /gs compile switch to  detect overwrites to local array variables  *        the potentially corrupt the return address.  this routine  is called  *       at exe/dll startup.  *   *entry:  *  *exit:  *  *exceptions:  *  **************************************** /      Void __cdecl __security_init_cookie ( void)    {       UINT_PTR cookie;       FT  systime={0};       LARGE_INTEGER perfctr;           /*       * do nothing if the global  cookie has already been initialized.  On x86,        * reinitialize the cookie if it has been previously  initialized to a       * value with the high  word 0x0000.  some versions of windows will init        * the cookie in the loader, but using an older  mechanism which forced the       * high word  to zero.&nbsp      */     

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.