Exemplo n.º 1
0
_WCRTLINK void _WCHUGE * halloc( unsigned long n, unsigned size )
{
    unsigned long len;
    USHORT      error, tseg;
    SEL         seg;
    USHORT      number_segments, remaining_bytes;
    USHORT      increment;

    len = n * size;
    if( len == 0 ) return( (void _WCHUGE *)0 );
    if( n > 65536 && ! only_one_bit( size ) ) return( (void _WCHUGE *)0 );
    error = DosGetHugeShift( &increment );
    if( error ) {
        __set_errno_dos( error );
        return( ( void _WCHUGE *)0 );
    }
    number_segments = len >> 16;
    remaining_bytes = len & 0xffff;
    error = DosAllocHuge( number_segments, remaining_bytes, &seg, 0, 0 );
    if( error ) {
        __set_errno_dos( error );
        return( (void _WCHUGE *)0 );  /* allocation failed */
    }
    tseg = seg;
    increment = 1 << increment;
    while( number_segments-- ) {
        _os2zero64k( 0, 0x8000, tseg, 0 );
        tseg += increment;
    }
    if( remaining_bytes != 0 ) {                        /* 30-apr-91 */
        _os2zero_rest( 0, remaining_bytes, tseg, 0 );
    }
    return( (void _WCHUGE *)((unsigned long )seg << 16) );
}
Exemplo n.º 2
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
}