genericopenlibs/cstdlib/UCRT/MCRT0.CPP
changeset 0 e4d67989cc36
child 49 e5d77a29bdca
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // EPOC32 version of crt0.c for C programs which always want multi-threaded support
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <e32base.h>
       
    20 #include <estlib.h>	// for SpawnPosixServerThread()
       
    21 #include <stdlib.h>
       
    22 
       
    23 #ifdef __ARMCC__
       
    24 __asm int CallMain(int argc, char *argv[], char *envp[])
       
    25 {
       
    26        import main
       
    27        code32
       
    28        b main
       
    29 }
       
    30 #define CALLMAIN(argc, argv, envp) CallMain(argc, argv, envp)
       
    31 #else
       
    32 extern "C" int main (int argc, char *argv[], char *envp[]);
       
    33 #define CALLMAIN(argc, argv, envp) main(argc, argv, envp)
       
    34 #endif
       
    35 
       
    36 extern "C" void exit (int ret);
       
    37 
       
    38 GLDEF_C TInt E32Main()
       
    39 	{     
       
    40 	CTrapCleanup::New();
       
    41 
       
    42 	SpawnPosixServerThread();		// arrange for multi-threaded operation
       
    43 
       
    44 	int argc=0;
       
    45 	char ** argv=0;
       
    46 	char ** envp=0;
       
    47 
       
    48 
       
    49 	__crt0(argc,argv,envp);			// get args & environment from somewhere
       
    50 
       
    51 	int ret=CALLMAIN(argc, argv, envp);		// go
       
    52 
       
    53 	// no need to explicitly delete the cleanup stack here as all memory used by
       
    54 	// the process will be released by RProcess::Terminate(), called from inside exit().
       
    55 
       
    56 	exit(ret);				// finish with atexit processing
       
    57 
       
    58 	return(KErrNone);
       
    59 	}
       
    60 
       
    61 
       
    62 #if defined __GCC32__ && !defined __X86GCC__
       
    63 
       
    64 /* stub function inserted into main() by GCC */
       
    65 extern "C" void __gccmain (void) {}
       
    66 
       
    67 /* Default GCC entrypoint */
       
    68 extern "C" TInt _mainCRTStartup (void) 
       
    69     {
       
    70     extern TInt _E32Startup();
       
    71     return _E32Startup();
       
    72     }
       
    73 
       
    74 #endif /* __GCC32__ */
       
    75 
       
    76 // X86GCC uses def files derived from EABI
       
    77 #if (defined (__EABI__)) || (defined (__X86GCC__))
       
    78 
       
    79 // standard entrypoint for C runtime, expected by some linkers
       
    80 // Symbian OS does not currently use this function
       
    81 extern "C" void __main() {}
       
    82 #endif