Exemplo n.º 1
0
_WCRTLINK int dup2( int handle1, int handle2 )
{
    rdos_handle_type   *obj = 0;

    if( handle1 == handle2 )
        return( handle2 );

    if( handle2 < 0 )
        return( -1 );

    while( handle2 >= handle_count )
        GrowHandleArr( );
        
    RdosEnterSection( handle_section );

    if( handle1 >= 0 && handle1 < handle_count )
        if( handle_ptr[handle1] )
            obj = handle_ptr[handle1];

    if( obj )
        obj->ref_count++;
    
    RdosLeaveSection( handle_section );

    if( obj ) {
        if( ReplaceHandleEntry( handle2, obj ) )
            return( handle2 );
        else
            obj->ref_count--;
    }

    return( -1 );
}
Exemplo n.º 2
0
void AddWatch( struct TDebug *obj, int Sel, long Offset, int Size )
{
    struct TDebugWatch *neww;
    struct TDebugWatch *w;
    int found = FALSE;

    neww = (struct TDebugWatch *)malloc( sizeof( struct TDebugWatch ) );
    InitDebugWatch( neww, Sel, Offset, Size );    

    RdosEnterSection( obj->FSection );

    neww->Next = 0;

    w = obj->WatchList;
    if( w ) {
        while( w->Next ) {
            if( w->Sel == Sel && w->Offset == Offset )
                found = TRUE;
            w = w->Next;
        }

        if( !found )
            w->Next = neww;            
    }
    else
        obj->WatchList = neww;

    RdosLeaveSection( obj->FSection );
}
Exemplo n.º 3
0
void ClearWatch( struct TDebug *obj, int Sel, long Offset, int Size )
{
    struct TDebugWatch *w;
    struct TDebugWatch *delw;
    
    RdosEnterSection( obj->FSection );

    w = obj->WatchList;

    if( w ) {
        if( w->Offset == Offset && w->Sel == Sel ) {
            obj->WatchList = w->Next;
            free( w );
        }
        else
        {
            while( w->Next ) {
                delw = w->Next;
                
                if( delw->Offset == Offset && delw->Sel == Sel ) {
                    w->Next = delw->Next;
                    free( delw );
                }
                else
                    w = w->Next;                    
            }
        }
    }

    RdosLeaveSection( obj->FSection );
}
Exemplo n.º 4
0
static void HandleTerminateProcess( struct TDebug *obj, int exitcode )
{
    struct TDebugThread *t;
    struct TDebugModule *m;

    RdosEnterSection( obj->FSection );

    while( obj->ThreadList ) {
        t = obj->ThreadList->Next;
        FreeDebugThread( obj->ThreadList );
        free( obj->ThreadList );
        obj->ThreadList = t;
    }

    while( obj->ModuleList ) {
        m = obj->ModuleList->Next;
        FreeDebugModule( obj->ModuleList );
        free( obj->ModuleList );
        obj->ModuleList = m;
    }

    obj->CurrentThread = 0;
    obj->NewThread = 0;
    obj->FThreadChanged = TRUE;
    obj->FModuleChanged = TRUE;

    RdosLeaveSection( obj->FSection );
}
Exemplo n.º 5
0
int GetNextModule( struct TDebug *obj, int ModuleHandle )
{
    int Handle = 0xFFFF;
    struct TDebugModule *m;
    struct TDebugModule *rm = 0;

    RdosEnterSection( obj->FSection );

    m = obj->ModuleList;
    while (m)
    {
        if (m->FNew && m->Handle > ModuleHandle && m->Handle < Handle)
        {
            rm = m;
            Handle = m->Handle;
        }

        m = m->Next;            
    }

    RdosLeaveSection( obj->FSection );

    if (rm)
    {
        rm->FNew = FALSE;
        return Handle;
    }
    else
        return 0;
}
Exemplo n.º 6
0
void AddBreak( struct TDebug *obj, int Sel, long Offset, int Hw )
{
    struct TDebugBreak *newbr;
    struct TDebugBreak *b;
    int found = FALSE;

    newbr = (struct TDebugBreak *)malloc( sizeof( struct TDebugBreak ) );
    InitDebugBreak( newbr, Sel, Offset, Hw );    

    RdosEnterSection( obj->FSection );

    newbr->Next = 0;

    b = obj->BreakList;
    if( b ) {
        while( b->Next ) {
            if( b->Sel == Sel && b->Offset == Offset )
                found = TRUE;
            b = b->Next;
        }

        if( !found )
            b->Next = newbr;            
    }
    else
        obj->BreakList = newbr;

    RdosLeaveSection( obj->FSection );
}
Exemplo n.º 7
0
void ClearBreak( struct TDebug *obj, int Sel, long Offset )
{
    struct TDebugBreak *b;
    struct TDebugBreak *delbr;
    
    RdosEnterSection( obj->FSection );

    b = obj->BreakList;

    if( b ) {
        if( b->Offset == Offset && b->Sel == Sel ) {
            obj->BreakList = b->Next;
            free( b );
        }
        else
        {
            while( b->Next ) {
                delbr = b->Next;
                
                if( delbr->Offset == Offset && delbr->Sel == Sel ) {
                    b->Next = delbr->Next;
                    free( delbr );
                }
                else
                    b = b->Next;                    
            }
        }
    }

    RdosLeaveSection( obj->FSection );
}
Exemplo n.º 8
0
static void RemoveModule( struct TDebug *obj, int module )
{
    struct TDebugModule *p;
    struct TDebugModule *m;

    RdosEnterSection( obj->FSection );

    p = 0;
    m = obj->ModuleList;

    while( m ) {
        if( m->Handle == module ) {
            if( p )
                p->Next = m->Next;
            else
                obj->ModuleList = m->Next;
            break;            
        }
        else {
            p = m;
            m = m->Next;
        }
    }

    if( m )
        free( m );

    RdosLeaveSection( obj->FSection );
}
Exemplo n.º 9
0
void __SetIOMode_nogrow( int handle, unsigned value )
{
    RdosEnterSection( handle_section );

    if( handle >= 0 && handle < handle_count )
        if( handle_ptr[handle] )
            handle_ptr[handle]->mode = value;

    RdosLeaveSection( handle_section );
}
Exemplo n.º 10
0
struct TDebugModule *LockModule( struct TDebug *obj, int Handle )
{
    struct TDebugModule *m;

    RdosEnterSection( obj->FSection );

    m = obj->ModuleList;
    while (m && m->Handle != Handle)
        m = m->Next;            

    return m;
}
Exemplo n.º 11
0
struct TDebugThread *LockThread( struct TDebug *obj, int ThreadID )
{
    struct TDebugThread *t;

    RdosEnterSection( obj->FSection );

    t = obj->ThreadList;
    while( t && t->ThreadID != ThreadID )
        t = t->Next;            

    return t;
}
Exemplo n.º 12
0
static void RemoveThread( struct TDebug *obj, int thread )
{
    struct TDebugThread *p;
    struct TDebugThread *t;

    RdosEnterSection( obj->FSection );

    p = 0;
    t = obj->ThreadList;

    while( t ) {
        if( t->ThreadID == thread ) {
            if( p )
                p->Next = t->Next;
            else
                obj->ThreadList = t->Next;
            break;            
        }
        else {
            p = t;
            t = t->Next;
        }
    }

    if( t ) {
        if( t == obj->CurrentThread ) {
            obj->CurrentThread = 0;
            RdosLeaveSection( obj->FSection );

            RdosWaitMilli( 25 );

            RdosEnterSection( obj->FSection );
        }
        free( t );
    }

    RdosLeaveSection( obj->FSection );
}
Exemplo n.º 13
0
unsigned __GetIOMode( int handle )
{
    unsigned mode = 0;
    
    RdosEnterSection( handle_section );

    if( handle >= 0 && handle < handle_count )
        if( handle_ptr[handle] )
            mode = handle_ptr[handle]->mode;

    RdosLeaveSection( handle_section );

    return( mode );
}
Exemplo n.º 14
0
void SetCurrentThread( struct TDebug *obj, int ThreadID )
{
    struct TDebugThread *t;

    RdosEnterSection( obj->FSection );

    t = obj->ThreadList;
    while( t && t->ThreadID != ThreadID )
        t = t->Next;

    if( t )
        obj->CurrentThread = t;

    RdosLeaveSection( obj->FSection );
}
Exemplo n.º 15
0
signed __SetIOMode( int handle, unsigned value )
{
    signed ret = -1;

    RdosEnterSection( handle_section );

    if( handle >= 0 && handle < handle_count )
        if( handle_ptr[handle] ) {
            handle_ptr[handle]->mode = value;
            ret = handle;
        }

    RdosLeaveSection( handle_section );

    return( ret );
}
Exemplo n.º 16
0
static void HandleException( struct TDebug *obj, struct TExceptionEvent *event, int thread )
{
    struct TDebugThread *Thread;

    RdosEnterSection( obj->FSection );

    Thread = obj->ThreadList;

    while( Thread && Thread->ThreadID != thread )
        Thread = Thread->Next;

    if( Thread )
        SetException( Thread, event );

    RdosLeaveSection( obj->FSection );
}
Exemplo n.º 17
0
static rdos_handle_type *FreeHandleEntry( int handle )
{
    rdos_handle_type *obj = 0;
    
    RdosEnterSection( handle_section );

    if( handle >= 0 && handle < handle_count ) {
        if( handle_ptr[handle] ) {
            obj = handle_ptr[handle];
            handle_ptr[handle] = 0;
        }
    }

    RdosLeaveSection( handle_section );

    return( obj );
}
Exemplo n.º 18
0
int HasModule( struct TDebug *obj, const char *Name )
{
    struct TDebugModule *m;
    int found = FALSE;

    RdosEnterSection( obj->FSection );

    m = obj->ModuleList;
    while (m && !found)
    {
        if ( !strcmp( Name, m->ModuleName ) )
            found = TRUE;
        m = m->Next;    
    }        
    RdosLeaveSection( obj->FSection );

    return found;
}
Exemplo n.º 19
0
char * __CreateInheritString( void ) 
{
    char               *str;
    char               *ptr;
    int                 handle;
    int                 remain;
    int                 count;
    rdos_handle_type   *obj;

    count = 0;

    str = lib_malloc( MAX_INHERIT_SPACE );

    remain = MAX_INHERIT_SPACE - 2 - sizeof( FILE_INHERIT );
    ptr = str;
    strcpy( ptr, FILE_INHERIT );
    ptr += strlen( FILE_INHERIT );
    *ptr = 0xd;
    ptr++;

    RdosEnterSection( handle_section );

    for( handle = 0; handle < handle_count; handle++ ) {
        obj = handle_ptr[handle];
        if( obj ) {
            if( obj->file_name ) {
                count++;
                ptr = AddInherit( ptr, handle, obj, &remain );                 
            }
        }
    }
    
    RdosLeaveSection( handle_section );

    if( count ) {    
        *ptr = 0;
        ptr++;
        *ptr = 0;
        return( str );
    } else {
        lib_free( str );
        return( 0 );
    }
}
Exemplo n.º 20
0
static int AllocHandleEntry( rdos_handle_type *obj )
{
    int i;

    RdosEnterSection( handle_section );

    for( i = 0; i < handle_count; i++)
        if( handle_ptr[i] == 0 )
            break;

    if( i == handle_count )
        GrowHandleArr();

    handle_ptr[i] = obj;

    RdosLeaveSection( handle_section );

    return( i );
}
Exemplo n.º 21
0
static struct TDebugModule *FindModule( struct TDebug *obj, int Cs )
{
    struct TDebugModule *m;

    RdosEnterSection( obj->FSection );

    m = obj->ModuleList;

    while (m) {
        if ( m->CodeSel == Cs )
            break;

        m = m->Next;
    }

    RdosLeaveSection( obj->FSection );

    return m;
}
Exemplo n.º 22
0
_WCRTLINK int dup( int handle )
{
    rdos_handle_type   *obj = 0;

    RdosEnterSection( handle_section );

    if( handle >= 0 && handle < handle_count )
        if( handle_ptr[handle] )
            obj = handle_ptr[handle];

    if( obj )
        obj->ref_count++;
    
    RdosLeaveSection( handle_section );

    if( obj )
        return( AllocHandleEntry( obj ) );
    else
        return( -1 );
}
Exemplo n.º 23
0
static void InsertModule( struct TDebug *obj, struct TDebugModule *mod )
{
    struct TDebugModule *m;

    RdosEnterSection( obj->FSection );

    mod->Next = 0;

    m = obj->ModuleList;
    if( m ) {
        while( m->Next )
            m = m->Next;

        m->Next = mod;            
    }
    else
        obj->ModuleList = mod;

    RdosLeaveSection( obj->FSection );
}
Exemplo n.º 24
0
int IsWatch( struct TDebug *obj, int Sel, long Offset )
{
    struct TDebugWatch *w;
    int ok = FALSE;
    
    RdosEnterSection( obj->FSection );

    w = obj->WatchList;

    while (w && !ok)
    {
        if (w->Sel == Sel && w->Offset == Offset)
            ok = TRUE;
        else
            w = w->Next;
    }

    RdosLeaveSection( obj->FSection );

    return ok;
}
Exemplo n.º 25
0
int IsBreak( struct TDebug *obj, int Sel, long Offset )
{
    struct TDebugBreak *b;
    int ok = FALSE;
    
    RdosEnterSection( obj->FSection );

    b = obj->BreakList;

    while (b && !ok)
    {
        if (b->Sel == Sel && b->Offset == Offset)
            ok = TRUE;
        else
            b = b->Next;
    }

    RdosLeaveSection( obj->FSection );

    return ok;
}
Exemplo n.º 26
0
static int ReplaceHandleEntry( int handle, rdos_handle_type *new_obj )
{
    int                 ok = 0;
    rdos_handle_type   *obj = 0;
    
    RdosEnterSection( handle_section );

    if( handle >= 0 && handle < handle_count ) {
        if( handle_ptr[handle] )
            obj = handle_ptr[handle];
            
        handle_ptr[handle] = new_obj;
        ok = 1;
    }

    RdosLeaveSection( handle_section );

    if( obj )
        FreeHandleObj( obj );

    return ( ok );
}
Exemplo n.º 27
0
static char GetHandle( int handle, int *rdos_handle, unsigned *mode )
{
    char type;

    RdosEnterSection( handle_section );

    type = 0;
    *rdos_handle = 0;
    *mode = 0;
    
    if( handle >= 0 && handle < handle_count ) {
        if( handle_ptr[handle] ) {
            *rdos_handle = handle_ptr[handle]->rdos_handle;
            *mode = handle_ptr[handle]->mode;
            type = handle_ptr[handle]->type;
        }
    }
    
    RdosLeaveSection( handle_section );

    return( type );
}
Exemplo n.º 28
0
int GetNextThread( struct TDebug *obj, int ThreadID )
{
    int ID = 0xFFFF;
    struct TDebugThread *t;

    RdosEnterSection( obj->FSection );

    t = obj->ThreadList;
    while( t ) {
        if( t->ThreadID > ThreadID && t->ThreadID < ID )
            ID = t->ThreadID;

        t = t->Next;            
    }

    RdosLeaveSection( obj->FSection );

    if (ID != 0xFFFF)
        return ID;
    else
        return 0;
}
Exemplo n.º 29
0
static void InsertThread( struct TDebug *obj, struct TDebugThread *thread )
{
    struct TDebugThread *t;

    RdosEnterSection( obj->FSection );

    thread->Next = 0;

    t = obj->ThreadList;
    if( t ) {
        while( t->Next )
            t = t->Next;

        t->Next = thread;            
    }
    else
        obj->ThreadList = thread;

    if( !obj->CurrentThread )
        obj->CurrentThread = thread;

    RdosLeaveSection( obj->FSection );
}
Exemplo n.º 30
0
_WCRTLINK void __AccessSemaphore( semaphore_object *obj )
{
    TID tid;

    tid = GetCurrentThreadId();
#if defined( _NETWARE_CLIB )
    if( tid == 0 )
        return;
#endif
    if( obj->owner != tid ) {
#if defined( _M_I86 )
        DosSemRequest( &obj->semaphore, -1L );
#else
  #if !defined( __NETWARE__ )
        if( obj->initialized == 0 ) {
    #if defined( __RUNTIME_CHECKS__ ) && defined( _M_IX86 )
            if( obj == &InitSemaphore ) {
                __fatal_runtime_error( "Bad semaphore lock", 1 );
            }
    #endif
            __AccessSemaphore( &InitSemaphore );
            if( obj->initialized == 0 ) {
    #if defined( __NT__ )
                obj->semaphore = __NTGetCriticalSection();
    #elif defined( __QNX__ )
                __qsem_init( &obj->semaphore, 1, 1 );
    #elif defined( __LINUX__ )
                // TODO: Access semaphore under Linux!
    #elif defined( __RDOS__ )
                obj->semaphore = RdosCreateSection();
    #elif defined( __RDOSDEV__ )
                RdosInitKernelSection(&obj->semaphore);
    #else
                DosCreateMutexSem( NULL, &obj->semaphore, 0, FALSE );
    #endif
                obj->initialized = 1;
            }
            __ReleaseSemaphore( &InitSemaphore );
        }
  #endif
  #if defined( __NETWARE__ )
        while( obj->semaphore != 0 ) {
    #if defined (_NETWARE_CLIB)
            ThreadSwitch();
    #else
            NXThreadYield();
    #endif
        }

        obj->semaphore = 1;
        obj->initialized = 1;
  #elif defined( __NT__ )
        EnterCriticalSection( obj->semaphore );
  #elif defined( __QNX__ )
        __qsem_wait( &obj->semaphore );
  #elif defined( __LINUX__ )
        // TODO: Wait for semaphore under Linux!
  #elif defined( __RDOS__ )
        RdosEnterSection( obj->semaphore );
  #elif defined( __RDOSDEV__ )
        RdosEnterKernelSection( &obj->semaphore );
  #else
        DosRequestMutexSem( obj->semaphore, SEM_INDEFINITE_WAIT );
  #endif
#endif
        obj->owner = tid;
    }
    obj->count++;
}