os/ossrv/genericopenlibs/cstdlib/UCRT/MCRT0.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 GLDEF_C TInt E32Main()
    37 	{     
    38 	CTrapCleanup::New();
    39 
    40 	SpawnPosixServerThread();		// arrange for multi-threaded operation
    41 
    42 	int argc=0;
    43 	char ** argv=0;
    44 	char ** envp=0;
    45 
    46 
    47 	__crt0(argc,argv,envp);			// get args & environment from somewhere
    48 
    49 	int ret=CALLMAIN(argc, argv, envp);		// go
    50 
    51 	// no need to explicitly delete the cleanup stack here as all memory used by
    52 	// the process will be released by RProcess::Terminate(), called from inside exit().
    53 
    54 	exit(ret);				// finish with atexit processing
    55 
    56 	return(KErrNone);
    57 	}
    58 
    59 
    60 #if defined __GCC32__ && !defined __X86GCC__
    61 
    62 /* stub function inserted into main() by GCC */
    63 extern "C" void __gccmain (void) {}
    64 
    65 /* Default GCC entrypoint */
    66 extern "C" TInt _mainCRTStartup (void) 
    67     {
    68     extern TInt _E32Startup();
    69     return _E32Startup();
    70     }
    71 
    72 #endif /* __GCC32__ */
    73 
    74 // X86GCC uses def files derived from EABI
    75 #if (defined (__EABI__)) || (defined (__X86GCC__))
    76 
    77 // standard entrypoint for C runtime, expected by some linkers
    78 // Symbian OS does not currently use this function
    79 extern "C" void __main() {}
    80 #endif