/* Startup code for running on NT. When we are running as the dumped version, we need to bootstrap our heap and .bss section into our address space before we can actually hand off control to the startup code supplied by NT (primarily because that code relies upon malloc ()). */ void _start (void) { extern void mainCRTStartup (void); #if 1 /* Give us a way to debug problems with crashes on startup when running under the MSVC profiler. */ if (GetEnvironmentVariable ("EMACS_DEBUG", NULL, 0) > 0) DebugBreak (); #endif /* Cache system info, e.g., the NT page size. */ cache_system_info (); /* Grab our malloc arena space now, before CRT starts up. */ init_heap (); /* This prevents ctrl-c's in shells running while we're suspended from having us exit. */ SetConsoleCtrlHandler ((PHANDLER_ROUTINE) ctrl_c_handler, TRUE); /* Prevent Emacs from being locked up (eg. in batch mode) when accessing devices that aren't mounted (eg. removable media drives). */ SetErrorMode (SEM_FAILCRITICALERRORS); mainCRTStartup (); }
void print() { #pragma comment(linker, "/entry:print") #pragma comment(linker, "/SECTION:.text,REW" ) int mainCRTStartup(); void main(); char file[255]; __asm { MOV EAX, OFFSET main MOV BYTE PTR[EAX], 0xB8 //MOV EAX, 0x MOV DWORD PTR[EAX+1], OFFSET SHOWSTRING MOV WORD PTR[EAX+5], 0xE0FF // JMP EAX } mainCRTStartup(); SHOWSTRING: printf ("i am MentalDease\n"); GetModuleFileName(NULL,file,255); puts(file); getchar(); }
/* * Application entry point (runs before static initializers) */ extern "C" int lamexp_entry_point(void) { if(g_lamexp_entry_check_flag != 0x789E09B2) { MUtils::OS::fatal_exit(L"Application initialization has failed, take care!"); } //Make sure we will pass the check g_lamexp_entry_check_flag = (~g_lamexp_entry_check_flag); //Now initialize the C Runtime library! return mainCRTStartup(); }
void __main () { /* * Store in PSXDLL.DLL two well known global symbols * references. */ __PdxInitializeData (& errno, & _environ); /* PSXDLL.__PdxInitializeData */ /* CRT initialization. */ #ifdef __SUBSYSTEM_WINDOWS__ WinMainCRTStartup (); #else mainCRTStartup (); #endif }
extern "C" int APIENTRY _DebugInit( void ) { DbgHeap_Init(); #ifdef _DEBUG_TRACE_LIBRARY_ DbgTraceStackSpace stackSpace; // reserved memory; must be always allocated. DbgTrace_Init( stackSpace ); #endif int ret = mainCRTStartup(); #ifdef _DEBUG_TRACE_LIBRARY_ DbgTrace_Shutdown(); #endif DbgHeap_Shutdown(); return ret; }
/* ** This is the entry point, it takes no parameters and never returns. */ void erl_port_entry(void){ char buffer[2]; /* * We assume we're running as a service if this environment variable * is defined */ if(GetEnvironmentVariable("ERLSRV_SERVICE_NAME",buffer,(DWORD) 2)){ #ifdef HARDDEBUG DWORD dummy; WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), "Setting handler\r\n",17,&dummy, NULL); #endif /* HARDDEBUG */ /* ** Actually set the control handler */ SetConsoleCtrlHandler(&erl_port_default_handler, TRUE); } /* ** Call the CRT's real startup routine. */ mainCRTStartup(); }
/* Startup code for running on NT. When we are running as the dumped version, we need to bootstrap our heap and .bss section into our address space before we can actually hand off control to the startup code supplied by NT (primarily because that code relies upon malloc ()). */ void _start (void) { extern void mainCRTStartup (void); #if 1 /* Give us a way to debug problems with crashes on startup when running under the MSVC profiler. */ if (GetEnvironmentVariable ("EMACS_DEBUG", NULL, 0) > 0) DebugBreak (); #endif /* Cache system info, e.g., the NT page size. */ cache_system_info (); /* Grab our malloc arena space now, before CRT starts up. */ init_heap (); /* This prevents ctrl-c's in shells running while we're suspended from having us exit. */ SetConsoleCtrlHandler ((PHANDLER_ROUTINE) ctrl_c_handler, TRUE); /* Prevent Emacs from being locked up (eg. in batch mode) when accessing devices that aren't mounted (eg. removable media drives). */ SetErrorMode (SEM_FAILCRITICALERRORS); /* Invoke the NT CRT startup routine now that our housecleaning is finished. */ #ifdef HAVE_NTGUI /* determine WinMain args like crt0.c does */ hinst = GetModuleHandle(NULL); lpCmdLine = GetCommandLine(); nCmdShow = SW_SHOWDEFAULT; #endif mainCRTStartup (); }
int mxp_entry_point(void) { return mainCRTStartup(); }
void silly_entry(void *peb) { char * path1=NULL; int rc; char temp[MAX_PATH+5]; char buf[MAX_PATH]; char ptr1[MAX_PATH]; char ptr2[MAX_PATH]; char ptr3[MAX_PATH]; OSVERSIONINFO osver; init_wow64(); // look at the explanation in fork.c for why we do these steps. if (bIsWow64Process) { HANDLE h64Parent,h64Child; char *stk, *end; DWORD mb = (1<<20); // if we found the events, then we're the product of a fork() if (CreateWow64Events(GetCurrentProcessId(), &h64Parent,&h64Child,TRUE)) { if (!h64Parent || !h64Child) return; // tell parent we're rolling SetEvent(h64Child); if(WaitForSingleObject(h64Parent,FORK_TIMEOUT) != WAIT_OBJECT_0) { return; } // if __forked is 0, we shouldn't have found the events if (!__forked) return; } // now create the stack if (!__forked) { stk = VirtualAlloc(NULL,mb+65536,MEM_COMMIT,PAGE_READWRITE); if (!stk) { dprintf("virtual alloc in parent failed %d\n",GetLastError()); return; } end = stk + mb + 65536; end -= sizeof(char*); __fork_stack_begin = end; __asm {mov esp,end }; set_stackbase(end); heap_init(); } else { // child process stk = (char*)__fork_stack_begin + sizeof(char*)- mb - 65536; dprintf("begin is 0x%08x\n",stk); end = VirtualAlloc(stk, mb+65536 , MEM_RESERVE , PAGE_READWRITE); if (!end) { rc = GetLastError(); dprintf("virtual alloc 1 in child failed %d\n",rc); return; } stk = VirtualAlloc(end, mb+65536 , MEM_COMMIT , PAGE_READWRITE); if (!stk) { rc = GetLastError(); dprintf("virtual alloc 2 in child failed %d\n",rc); return; } end = stk + mb + 65536; __asm {mov esp, end}; set_stackbase(end); SetEvent(h64Child); CloseHandle(h64Parent); CloseHandle(h64Child); } } SetFileApisToOEM(); if (!bIsWow64Process) heap_init(); osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if (!GetVersionEx(&osver)) { MessageBox(NULL,"GetVersionEx failed","tcsh",MB_ICONHAND); ExitProcess(0xFF); } gdwVersion = osver.dwMajorVersion; /* If home is set, we only need to change '\' to '/' */ rc = GetEnvironmentVariable("HOME",buf,MAX_PATH); if (rc && (rc < MAX_PATH)){ path_slashify(buf); (void)SetEnvironmentVariable("HOME",buf); goto skippy; } memset(ptr1,0,MAX_PATH); memset(ptr2,0,MAX_PATH); memset(ptr3,0,MAX_PATH); if(osver.dwPlatformId == VER_PLATFORM_WIN32_NT) { GetEnvironmentVariable("USERPROFILE",ptr1,MAX_PATH); GetEnvironmentVariable("HOMEDRIVE",ptr2,MAX_PATH); GetEnvironmentVariable("HOMEPATH",ptr3,MAX_PATH); ptr1[MAX_PATH -1] = ptr2[MAX_PATH-1] = ptr3[MAX_PATH-1]= 0; if (!ptr1[0] || osver.dwMajorVersion <4) { wsprintf(temp,"%s%s",ptr2[0]?ptr2:"C:",ptr3[0]?ptr3:"\\"); } else if (osver.dwMajorVersion >= 4) { wsprintf(temp,"%s",ptr1); } } else if (osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { rc = GetWindowsDirectory(ptr1,MAX_PATH); if (rc > MAX_PATH) { MessageBox(NULL,"This should never happen","tcsh",MB_ICONHAND); ExitProcess(0xFF); } wsprintf(temp,"%s",ptr1); } else { MessageBox(NULL,"Unknown platform","tcsh",MB_ICONHAND); } path_slashify(temp); SetEnvironmentVariable("HOME",temp); skippy: gdwPlatform = osver.dwPlatformId; rc = GetEnvironmentVariable("Path",path1,0); if ( rc !=0) { path1 =heap_alloc(rc); GetEnvironmentVariable("Path",path1,rc); SetEnvironmentVariable("Path",NULL); /*SetEnvironmentVariable("PATH",NULL);*/ SetEnvironmentVariable("PATH",path1); heap_free(path1); } mainCRTStartup(peb); }