Re: Avoiding _memset?
"ExitThread Function: If the thread is the last thread in the process when this function is called, the thread's process is also
terminated."[1]
windows xp sp3:
00 ntdll!NtTerminateProcess
01 kernel32!_ExitProcess+0x37
02 kernel32!ExitProcess+0x14
03 kernel32!ExitThread+0x92
04 kernel32!BaseProcessStart+0x28
When I open the GetOpenFileName Dialog Box[2], the process adds three threads (one ntdll.dll!RtlpTimerThread + two
ntdll.dll!RtlpWorkerThread). When I close the GetOpenFileName Dialog Box, the nocrt.exe!main thread exits, but the other three
threads remain. After several minutes, the two ntdll.dll!RtlpWorkerThread exit but the ntdll.dll!RtlpTimerThread remains. The
process is not terminated!
[1] http://msdn.microsoft.com/en-us/library/ms682659.aspx
[2]
#pragma comment(linker, "/entry:main")
#pragma comment(linker, "/subsystem:console")
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0'
processorArchitecture='*' publicKeyToken='6595b64144ccf1df'\"")
#pragma comment(lib, "kernel32")
#pragma comment(lib, "comdlg32")
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commdlg.h> //GetOpenFileName
#include <intrin.h> //__stosd
int __cdecl main() {
OPENFILENAME op;
char file[MAX_PATH*2];
__stosd((unsigned long *)&op, 0, sizeof(op)/4); // 88/4=22
op.lStructSize = sizeof(op);
op.lpstrFile = file;
op.nMaxFile = sizeof(file);
GetOpenFileName(&op);
return 0;
}
"Alex Blekhman" <tkfx.REMOVE@yahoo.com> wrote:
"xiaosi" wrote:
Yes, on my 32bit windows xp sp3, __tmainCRTStartupt
(tmainCRTStartup or tWinMainCRTStartup) never returns to
BaseProcessStart. Without any exception thrown,
__tmainCRTStartup calls exit(), doexit(), __crtExitProcess(),
ExitProcess(), _ExitProcess(), NtTerminateProcess(), and never
returns.
Yes, you're right. I overlooked this code. However, even without
explicitly calling ExitProcess the BaseProcessStart routine will
call it anyway. Here's the stack of CRT-less program after main
returns:
...
ntdll.dll!_KiFastSystemCall@0()
ntdll.dll!_NtTerminateProcess@8() + 0xc bytes
kernel32.dll!__ExitProcess@4() + 0x37 bytes
kernel32.dll!7c81cb26()
kernel32.dll!_ExitThread@4() + 0x63 bytes
kernel32.dll!_BaseProcessStart@4() + 0x29 bytes
Alex