Windows下程式入口函數與_security_init_cookie__函數

來源:互聯網
上載者:User

win32程式分為兩種:

1.控制台(/SUBSYSTEM:CONSOLE )

2.GUI(/SUBSYSTEM:WINDOWS)


首先看控制台版本的:

寫一段最簡單的,或者就直接使用編譯器參數的預設main函數,如下:

[cpp]  view plain  copy   // EntryFunction.cpp : 定義控制台應用程式的進入點。   //      #include "stdafx.h"         int _tmain(int argc, _TCHAR* argv[])   {       return 0;   }  

1.使用/MD選項

F9下斷到main函數的標籤處,F11後,在Call Stack中回溯到_tmainCRTStartup(),當前檔案為crtexe.c。如下:



2.使用/MT選項

F9下斷到main函數的標籤處,F11後,在Call Stack中回溯到_tmainCRTStartup(),當前檔案為crt0.c。如下:



也就是說,不同的運行時連結方式,其實現代碼也是不同的。但是其進入點函數的名稱是相同的,都是_tmainCRTStartup。這便是Windows下的啟動函數(真正的入口函數)。


下面我們分別討論,這兩者在入口函數中都幹了些什麼。

首先看_security_init_cookie,這個函數在兩個實現檔案中是一樣的,代碼如下:

[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.       */     

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.