Exemplo n.º 1
2
int _LibMain( int hdll, int reason, void *reserved )
{
    thread_data             *tdata;
    int                     rc = 0;

    switch( reason ) {
    case DLL_THREAD_ATTACH:
        tdata = ( thread_data * )RdosAllocateMem( __ThreadDataSize );
        if( tdata ) {
            memset( tdata, 0, __ThreadDataSize );
            tdata->__data_size = __ThreadDataSize;
            __RdosAddThread( tdata );
        }       
        break;
    case DLL_PROCESS_ATTACH:
        __InitRtns( INIT_PRIORITY_THREAD );
        tdata = ( thread_data * )RdosAllocateMem( __ThreadDataSize );
        memset( tdata, 0, __ThreadDataSize );
        tdata->__data_size = __ThreadDataSize;
        __InitThreadData( tdata );
        __RdosInit( 1, tdata, hdll );

        __InitRtns( 255 );
        __CommonInit();
        __sig_init_rtn();

        if( !__RdosThreadInit() ) return( -1 );
        __InitMultipleThread();

        rc = LibMain( hdll, reason, reserved );
        if( !rc ) {
            __FiniRtns( 0, 255 );
        }
        break;
    case DLL_THREAD_DETACH:
        __RdosRemoveThread();
        break;
    case DLL_PROCESS_DETACH:
        __FiniRtns( 0, FINI_PRIORITY_EXIT - 1 );
        __RdosRemoveThread();
        RdosFreeMem( __FirstThreadData );
        __FirstThreadData = NULL;
        break;
    }
    return( rc );
}
Exemplo n.º 2
0
void __F_NAME(__NTMain,__wNTMain)( void )
/***************************************/
{
#if defined(__SW_BR)
  #if defined(_M_IX86)
    REGISTRATION_RECORD rr;

    __NewExceptionFilter( &rr );
  #endif
    __process_fini = __FiniRtns;
    __InitRtns( 255 );
    __CommonInit();
    exit( __F_NAME(main( ___Argc, ___Argv ),wmain( ___wArgc, ___wArgv )) );
#else
    REGISTRATION_RECORD     rr;
    thread_data             *tdata;

    __InitRtns( INIT_PRIORITY_THREAD );
    tdata = __alloca( __ThreadDataSize );
    memset( tdata, 0, __ThreadDataSize );
    // tdata->__allocated = 0;
    tdata->__data_size = __ThreadDataSize;

    __InitThreadData( tdata );
    __NTMainInit( &rr, tdata );
    __F_NAME(__CMain,__wCMain)();
#endif
}
Exemplo n.º 3
0
void __cdecl _LinuxMain( int argc, char **argv, char **arge )
{
//    thread_data *tdata;

    // Initialise the heap. To do this we call sbrk() with
    // a value of 0, which will return the current top of the
    // process address space which is where we start the heap.
    _curbrk             = (unsigned)sbrk( 0 );

    // TODO: Need to find the end of the stack from the kernel! For now
    //       we make it big enough to cover the heap. This will work, but
    //       stack checking will not.
    _STACKLOW           = _curbrk;
    _argc               = argc;
    _argv               = argv;
    _Envptr             = (char *)arge;
    _LpPgmName          = argv[0];

    __InitRtns( INIT_PRIORITY_THREAD );
//    tdata = __alloca( __ThreadDataSize );
//    memset( tdata, 0, __ThreadDataSize );
//    tdata->__data_size = __ThreadDataSize;
    __InitRtns( 255 );

    /* allocate alternate stack for F77 */
    __ASTACKPTR = (char *)__alloca( __ASTACKSIZ ) + __ASTACKSIZ;

    _amblksiz = 8 * 1024;       /* set minimum memory block allocation  */
    exit( main( argc, argv, arge ) );
}
Exemplo n.º 4
0
void __F_NAME(__WinMain,__wWinMain)( void )
{
#ifdef __SW_BR
    {
#ifdef _M_IX86
        REGISTRATION_RECORD rr;
        __NewExceptionFilter( &rr );
#endif
        __process_fini = __FiniRtns;
        __InitRtns( 255 );
    }
#else
    {
        REGISTRATION_RECORD     rr;
        thread_data             *tdata;
        __InitRtns( INIT_PRIORITY_THREAD );
        tdata = __alloca( __ThreadDataSize );
        memset( tdata, 0, __ThreadDataSize );
        // tdata->__allocated = 0;
        tdata->__data_size = __ThreadDataSize;
        __InitThreadData( tdata );
        __NTMainInit( &rr, tdata );
        /* allocate alternate stack for F77 */
        __ASTACKPTR = (char *)alloca( __ASTACKSIZ ) + __ASTACKSIZ;
    }
#endif
    __CommonInit();
    exit( __F_NAME(WinMain,wWinMain)(
              GetModuleHandle( NULL ),
              0,
              __F_NAME(_LpCmdLine,_LpwCmdLine),
              SW_SHOWDEFAULT ) );
}
Exemplo n.º 5
0
void __RdosMain( void )
{
    int major, minor, release;

    __InitRtns( INIT_PRIORITY_THREAD );

#ifdef CMD_LINE
    _LpPgmName = (char *)RdosGetExeName();
#else
    _LpPgmName = "";
#endif    

    RdosGetVersion( &major, &minor, &release );
    _RWD_osmajor = major;
    _RWD_osminor = minor;

#ifdef CMD_LINE
    _LpCmdLine = (char *)RdosGetCmdLine();
    if( _LpCmdLine == 0 )
        _LpCmdLine = "";
    else {
       while( *_LpCmdLine != 0 && *_LpCmdLine != ' ' && *_LpCmdLine != 0x9 ) 
         _LpCmdLine++;
    }
#else
    _LpCmdLine = "";
#endif

    __InitRtns( 255 );
    __CMain();
}
Exemplo n.º 6
0
void __F_NAME(__NTMain,__wNTMain)( void )
/***************************************/
{

   init_heap();

    __process_fini = &__FiniRtns;
   __InitRtns( 255 );
   __CommonInit();
   __initPOSIXHandles();
   __appcwdlen = strrchr(_LpPgmName, '/') - _LpPgmName + 1;
   __appcwdlen = __appcwdlen > 512 ? 512 : __appcwdlen;
   __appcwd= (char*)malloc(__appcwdlen);
   strncpy(__appcwd, _LpPgmName, __appcwdlen);
   __appcwd[__appcwdlen] = 0;
   ___Argv[0] = _LpPgmName;
   if( *_LpCmdLine != 0)
   {
      ___Argc = 2;
      ___Argv[1] = _LpCmdLine;
   } else ___Argc = 1;

   #ifdef __WIDECHAR__
      exit( wmain( ___wArgc, ___wArgv ) );
   #else
      exit( main( ___Argc, ___Argv ) );
   #endif
}
Exemplo n.º 7
0
void __OS2MainInit( EXCEPTIONREGISTRATIONRECORD *xcpt, void *ptr,
                    unsigned hmod, char *env, char *cmd )
/*******************************************************/
{
    thread_data                 *tdata;
    char                        *args;
    char                        *cmd_path;

    tdata = ptr;
    for( args = cmd; *args != '\0'; ++args ); /* skip over program name */
    ++args;

    _RWD_Envptr = env;
    _LpCmdLine = args;
#ifdef _UNICODE
    _LpwCmdLine = lib_malloc( (strlen( _LpCmdLine ) + 1) * sizeof( wchar_t ) );
    _atouni( _LpwCmdLine, _LpCmdLine );
#endif
    for( cmd_path = cmd - 2; *cmd_path != '\0'; --cmd_path );
    ++cmd_path;
    _LpPgmName = cmd_path;
#ifdef _UNICODE
    _LpwPgmName = lib_malloc( (strlen( _LpPgmName ) + 1) * sizeof( wchar_t ) );
    _atouni( _LpwPgmName, _LpPgmName );
#endif

    __hmodule = hmod;
    __OS2Init( FALSE, tdata );
    /*
      initializers must be executed before signals initialized since
      __sig_init_rtn may get set by an initializer
    */
    __InitRtns( INIT_PRIORITY_LIBRARY );
    __XCPTHANDLER = xcpt;
    __sig_init_rtn();
#ifndef __SW_BM
    _STACKLOW = (unsigned)&_end;
#endif
    __InitRtns( 255 );
}
Exemplo n.º 8
0
unsigned __LibMain( int termination )
/***********************************/
{
    unsigned    rc;

    if( termination ) {
        rc = DllMain( termination, NULL );
        __CommonTerm();
        return( rc );
    }
    __InitRtns( 255 );  /* Run all initializers. */
    __CommonInit();
    return( DllMain( termination, NULL ) );
}
Exemplo n.º 9
0
/*****************************************************************************
//  Initialise runtime environemnt. Equivalent of old prelude
*****************************************************************************/
int     __init_environment( void *  reserved )
{
    int rc = -1;

    if(NULL == (NLMHandle = getnlmhandle()))
        return -1;

    if(NULL == (AllocRTag = AllocateResourceTag( NLMHandle, "OpenWatcom CLIB Memory", AllocSignature )))
        return -1;

    _saved_DS = __DS();

    /*
    //  Call initialisation routines where priority is <= 1 and set the
    //  initialisation finish level to 1
    */
    __InitRtns( INIT_PRIORITY_THREAD );
    InitFiniLevel = INIT_PRIORITY_THREAD;
    /*
    //  Initialise multiple thread support
    */
    if(__CreateFirstThreadData())
    {
        __InitMultipleThread();
        /*
        //  Call initiliation routines at priority 255 (all) and the set the
        //  initialisation finish level to 255
        */
        __InitRtns( 255 );
        InitFiniLevel = 255;
        /*
        //  Environment initialised.
        */
        rc = 0;
    }
    return( rc );
}
Exemplo n.º 10
0
/* Initialise the C runtime library from the passed in list of imports
 * and the defined OS type variable.
 */
int _CEXPORT InitLibC( LIBC_imports *imports, long os_type )
{
    int             i,max = sizeof( ___imports ) / sizeof( InitLibC_t );
    unsigned long   *p;

    /* Initialize all default imports to point to fatal error handler
     * for upwards compatibility.
     */
    for( i = 0, p = (unsigned long*)&___imports; i < max; i++ )
        *p++ = (unsigned long)fatalErrorHandler;

    /* Now copy all imported functions */
    memcpy( &___imports, imports, min(sizeof( ___imports ), imports->dwSize ) );
    ___drv_os_type = os_type;

    /* Run the clib initializers */
    __InitRtns( 255 );

    return 1;
}
Exemplo n.º 11
0
unsigned _LibMain( unsigned hmod, unsigned termination )
/******************************************************/
{
    static int  processes;
    unsigned    rc;

    if( termination != 0 ) {
        // If we're running with single DGROUP and tried to load
        // twice, do not run any termination code! Also reset the
        // process counter so that the already loaded DLL can
        // terminate properly
        if( processes > 1 ) {
            --processes;
            return( 0 );
        }
        rc = LibMain( hmod, termination );
        --processes;
#ifdef __SW_BR
        __FiniRtns( 0, 255 );
#else
        if( _LpwCmdLine ) {
            lib_free( _LpwCmdLine );
            _LpwCmdLine = NULL;
        }
        if( _LpwPgmName ) {
            lib_free( _LpwPgmName );
            _LpwPgmName = NULL;
        }
        __FiniRtns( FINI_PRIORITY_EXIT, 255 );
        // calls to free memory have to be done before semaphores closed
        __FreeInitThreadData( __FirstThreadData );
        __OS2Fini(); // must be done before following finalizers get called
        __FiniRtns( 0, FINI_PRIORITY_EXIT - 1 );
        __shutdown_stack_checking();
#endif
        return( rc );
    }
    ++processes;
    if( processes > 1 ) {
        if( __disallow_single_dgroup(hmod) ) {
            return( 0 );
        }
    }
    __hmodule = hmod;
#ifdef __SW_BR
    {
        static char     fname[_MAX_PATH];
        static wchar_t  wfname[_MAX_PATH];

        __Is_DLL = 1;
        __InitRtns( 255 );
        DosQueryModuleName( hmod, sizeof( fname ), fname );
        _LpDllName = fname;
        _LpwDllName = wfname;
        _atouni( _LpwDllName, _LpDllName );
    }
#else
    {
        PTIB        pptib;
        PPIB        pppib;
        unsigned    i;

        DosGetInfoBlocks( &pptib, &pppib );
        _RWD_Envptr = pppib->pib_pchenv;
        _LpCmdLine = pppib->pib_pchcmd;
        while( *_LpCmdLine ) {          // skip over program name
            _LpCmdLine++;
        }
        _LpCmdLine++;
        _LpwCmdLine = lib_malloc( (strlen( _LpCmdLine ) + 1) * sizeof( wchar_t ) );
        _atouni( _LpwCmdLine, _LpCmdLine );
        {
            // ugly stuff to deal with two copies of .exe name in the
            // environment space. apparently the OS fullpath name is
            // just before this one in the environment space
            char    *cmd_path;

            cmd_path = pppib->pib_pchcmd;
            for( cmd_path -= 2; *cmd_path != '\0'; --cmd_path );
            ++cmd_path;
            _LpPgmName = cmd_path;
            _LpwPgmName = lib_malloc( (strlen( _LpPgmName ) + 1) * sizeof( wchar_t ) );
            _atouni( _LpwPgmName, _LpPgmName );
        }
        __InitRtns( INIT_PRIORITY_THREAD );
        if( __InitThreadProcessing() == NULL )
            return( 0 );
        __OS2Init( TRUE, __AllocInitThreadData( NULL ) );
        for( i = 2; i <= __MaxThreads; i++ ) {
            if( !__OS2AddThread( i, NULL ) ) {
                return( 0 );
            }
        }
        __InitRtns( INIT_PRIORITY_EXIT - 1 );
        __InitMultipleThread();
        {
            static char     fname[_MAX_PATH];
            static wchar_t  wfname[_MAX_PATH];

            DosQueryModuleName( hmod, sizeof( fname ), fname );
            _LpDllName = fname;
            _LpwDllName = wfname;
            _atouni( _LpwDllName, _LpDllName );
        }
        __InitRtns( 255 );
    }
#endif
    __CommonInit();
#ifndef __SW_BR
    /* allocate alternate stack for F77 */
    __ASTACKPTR = (char *)_STACKLOW + __ASTACKSIZ;
#endif
    return( LibMain( hmod, termination ) );
}
Exemplo n.º 12
0
int _OS2Main( char far *stklow, char far * stktop,
               unsigned envseg, unsigned cmdoff )
/*************************************************/
{
    cmdoff = cmdoff;    /* supress warnings */
    envseg = envseg;
    stktop = stktop;

    /* set up global variables */
#if defined(__SW_BD)
    _STACKTOP = 0;
    _curbrk = _dynend = (unsigned)&end;
    stklow = NULL;
#else
    _STACKTOP = FP_OFF( stktop );
    _curbrk = _dynend = _STACKTOP;
#endif
    DosGetHugeShift( (PUSHORT)&_HShift );
    DosGetMachineMode( (PBYTE)&_osmode );
    {
    unsigned short      version;

    DosGetVersion( (PUSHORT)&version );
    _osmajor = version >> 8;
    _osminor = version & 0xff;
    }

#if defined(__SW_BD)
    _LpPgmName = "";
    _LpCmdLine = "";
#else
    /* copy progname and arguments to bottom of stack */
    {
    char                far *src;
    char                far *pgmp;

    src = MK_FP( envseg, cmdoff );
    _LpPgmName = stklow;
    /* back up from the ao: pointer to the eo: pointer (see OS/2 2.0 docs)*/
    for( pgmp = src - 1; *--pgmp != '\0'; );
    ++pgmp;
    while( *stklow++ = *pgmp++ );
    while( *src ) ++src;
    ++src;
    _LpCmdLine = stklow;
    while( *stklow++ = *src++ );
    }
#endif

#if defined(__SW_BM)
    {
        SEL             globalseg;
        SEL             localseg;

        DosGetInfoSeg( &globalseg, &localseg );
        _threadid = MK_FP( localseg, offsetof( LINFOSEG, tidCurrent ) );
        if( __InitThreadProcessing() == NULL )
            __fatal_runtime_error( "Not enough memory", 1 );
        #if defined(__SW_BD)
        {
            unsigned    i;
            unsigned    j;
            j = __MaxThreads;
            for( i = 1; i <= j; i++ ) {
                __SetupThreadProcessing( i );
            }
        }
        #else
            __SetupThreadProcessing( 1 );
        #endif
        _STACKLOW = (unsigned)stklow;
    }
#else
    _nothread = getpid();
    _threadid = &_nothread;
    _STACKLOW = (unsigned)stklow; /* set bottom of stack */
#endif
//  {   /* removed JBS 99/11/10 */
//      // make sure the iomode array is of the proper length
//      // this needs to be done before the InitRtns
//      extern  void    __grow_iomode(int);

//      if( _osmode == OS2_MODE ) {
//          __grow_iomode( 100 );
//      }
//  }
    __InitRtns( 255 );
#ifdef __SW_BD
    {
        int status;
        status = setjmp( JmpBuff );
        if( status == 0 ) return( _CMain() );
        return( RetCode );
    }
#else
    return( _CMain() );
#endif
}
Exemplo n.º 13
0
void _WCI86FAR __FInitRtns( unsigned limit ) {
    __InitRtns( limit );
}
Exemplo n.º 14
0
int APIENTRY _LibMain( HANDLE hdll, DWORD reason, LPVOID reserved )
{
    int rc;
    static int processes;

    switch( reason ) {
    case DLL_THREAD_ATTACH:
#ifndef __SW_BR
        if( !__NTAddThread( NULL ) ) {
            return( FALSE );
        }
#endif
        rc = LibMain( hdll, reason, reserved );
        break;
    case DLL_PROCESS_ATTACH:
        ++processes;
        if( processes > 1 ) {
            if( __disallow_single_dgroup( hdll ) ) {
                rc = FALSE;
                break;
            }
        }
#ifdef __SW_BR
        __Is_DLL = 1;
        __InitRtns( INIT_PRIORITY_EXIT - 1 );
#else
        // The following initializers are called: (in the CLIB run-time DLL):
        //      nothing is called
        __InitRtns( INIT_PRIORITY_THREAD );
        // allocate some thread data storage and initialize run-time variables
        {
            thread_data     *tdata = __AllocInitThreadData( NULL );

            if( !tdata || !__NTInit( TRUE, tdata, hdll ) ) {
                rc = FALSE;
                break;
            }
        }
        // set up TLSIndex thingee
        if( !__NTThreadInit() ) {   // safe to call multiple times
            rc = FALSE;
            break;
        }
        // The following initializers are called: (in the CLIB run-time DLL):
        //      __chk8087
        //      __verify_pentium_fdiv_bug
        //      __Init_Argv
        //      __imthread_fn (which calls _NTThreadInit and __InitMultipleThread)
        __InitRtns( INIT_PRIORITY_EXIT - 1 );
        // sets up semaphores and starts linked list of thread data storage
        __InitMultipleThread();     // now safe to call multiple times
#endif
        if( _pRawDllMain != NULL ) {
            if( !_pRawDllMain( hdll, reason, reserved ) ) {
                __FiniRtns( 0, FINI_PRIORITY_EXIT - 1 );
                rc = FALSE;
                break;
            }
        }
        // The following initializers are called: (in the CLIB run-time DLL):
        //      profilog_init
        //      __InitWinLinesSem
        //      dbgdata@do_it
        //      __setenvp
        //      __mbInitOnStartup
        //      __sig_init
        //      (??) in STK
        //      __InitFiles
        //      __clock_init
        __InitRtns( 255 );
#ifdef __SW_BR
        {
            static char    fn[_MAX_PATH];

            __lib_GetModuleFileNameA( hdll, fn, sizeof( fn ) );
            _LpDllName = fn;
        }
        {
            static wchar_t wfn[_MAX_PATH];
            __lib_GetModuleFileNameW( hdll, wfn, sizeof( wfn ) );
            _LpwDllName = wfn;
        }
#endif
        __CommonInit();
        __sig_init_rtn();
        rc = LibMain( hdll, reason, reserved );
        if( !rc ) {
            __FiniRtns( 0, 255 );
        }
        break;
    case DLL_THREAD_DETACH:
        rc = LibMain( hdll, reason, reserved );
#ifndef __SW_BR
        __NTRemoveThread( TRUE );
#endif
        break;
    case DLL_PROCESS_DETACH:
        rc = LibMain( hdll, reason, reserved );
        __FiniRtns( FINI_PRIORITY_EXIT, 255 );
        if( _pRawDllMain != NULL ) {
            _pRawDllMain( hdll, reason, reserved );
        }
#ifndef __SW_BR
        __NTFini(); // must be done before following finalizers get called
#endif
        __FiniRtns( 0, FINI_PRIORITY_EXIT - 1 );
#ifndef __SW_BR
        __NTRemoveThread( TRUE );
        __FreeInitThreadData( __FirstThreadData );
        __FirstThreadData = NULL;
#endif
        --processes;
    }
    return( rc );
}