genericopenlibs/cstdlib/UCRT/ECRT0.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 pure C programs
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <e32base.h>
       
    20 #include <estlib.h>
       
    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 	int argc=0;
       
    43 	char** argv=0;
       
    44 	char** envp=0;
       
    45 
       
    46 	__crt0(argc,argv,envp);			// get args & environment from somewhere
       
    47 	int ret=CALLMAIN(argc, argv, envp);		// go
       
    48 
       
    49 	// no need to explicitly delete the cleanup stack here as all memory used by
       
    50 	// the process will be released by RProcess::Terminate(), called from inside exit().
       
    51 
       
    52 	exit(ret);				// finish with atexit processing
       
    53 
       
    54 	return(KErrNone);
       
    55 	}
       
    56 
       
    57 
       
    58 #if defined __GCC32__ && !defined __X86GCC__
       
    59 
       
    60 /* stub function inserted into main() by GCC */
       
    61 extern "C" void __gccmain (void) {}
       
    62 
       
    63 /* Default GCC entrypoint */
       
    64 extern "C" TInt _mainCRTStartup (void) 
       
    65     {
       
    66     extern TInt _E32Startup();
       
    67     return _E32Startup();
       
    68     }
       
    69 
       
    70 #endif /* __GCC32__ */
       
    71 
       
    72 // X86GCC uses def files derived from EABI
       
    73 #if (defined (__EABI__) || defined (__X86GCC__))
       
    74 
       
    75 // standard entrypoint for C runtime, expected by some linkers
       
    76 // Symbian OS does not currently use this function
       
    77 extern "C" void __main() {}
       
    78 #endif
       
    79 
       
    80 
       
    81