Exemple #1
0
void ReaderEnd(Reader* reader) {
    if (reader->thread != NULL) {
        if (reader->queue != NULL) {
            EnqueueExitItem(reader->queue);
        }

        if (reader->selector != NULL) {
            SelectorWakeUp(reader->selector);
        }

        ThreadJoin(reader->thread);
    }

    FreeSelector(&reader->selector);

    if (reader->name != NULL) {
        aio4c_free(reader->name);
    }

    if (reader->pipe != NULL) {
        aio4c_free(reader->pipe);
    }

    aio4c_free(reader);
}
Exemple #2
0
/*
 * FinishDebugging - undo all the stuff done by InitDebugging
 */
void FinishDebugging( void )
{

    InterruptUnRegister( NULL );
    if( faultInstance != NULL ) {
        FreeProcInstance( faultInstance );
    }
    NotifyUnRegister( NULL );
    if( notifyInstance != NULL ) {
        FreeProcInstance( notifyInstance );
    }
    if( WDebug386 ) {
        ResetDebugInterrupts32();
        DebuggerIsExecuting( -1 );
        Out((OUT_INIT,"Debug interrupts reset"));
        FreeLibrary( wint32 );
    }
    KillWDebug386();
//    FreeProcInstance( SubClassProcInstance );
    FiniDebugHook();
    WasInt32 = FALSE;
    if( CSAlias != NULL ) {
        FreeSelector( CSAlias );
    }
    CSAlias = 0;
    DisableHookEvents();
    HookRtn = NULL;

} /* FinishDebugging */
Exemple #3
0
void
IT_GLOBALFREE (ENV *envp,LONGPROC f)
{
	DWORD retcode;
	WORD wSel;
	HGLOBAL hGlobal;

	wSel = GETWORD(SP+4) | 1;

	if (wSel == 1)
	{
		envp->reg.sp += HANDLE_86 + RET_86;
		envp->reg.ax = GETWORD(SP+4);
		envp->reg.dx = 0;
		return;
	}

	hGlobal = GetSelectorHandle(wSel);
				
	ZapSegRegs(envp,wSel);

        /* for HUGE objects */
	while ((GetSelectorHandle((UINT)(wSel-8))==hGlobal)) 
	    wSel -= 8;

	while (GetSelectorHandle(wSel) == hGlobal) {
	    FreeSelector(wSel);
	    wSel += 8;
	}
	retcode = (f)(hGlobal);
	envp->reg.sp += HANDLE_86 + RET_86;
	envp->reg.ax = LOWORD(retcode);
	envp->reg.dx = HIWORD(retcode);
}
Exemple #4
0
static void PatchSegmentEntryPoints(HMODULE hModule, PATCHFN sds,
                                    WORD segnum, WORD wSelector)
{
    WORD segment = AllocCStoDSAlias(wSelector);
    LPTABLE lpTable = (LPTABLE) MAKELONG(0, hModule);
    LPETABLE lpETable = (LPETABLE) MAKELONG(lpTable->table, hModule);
    
    PatchEntryPoints(hModule, lpETable, &segment, segnum - 1, sds);
    FreeSelector(segment);    
}
Exemple #5
0
BOOL FAR PASCAL __loadds FreeRing0Callgate( WORD callgate )
{
    CALLGATE_DESCRIPTOR far *callgate_desc;
    unsigned short ldt_alias;

    if ( (ldt_alias = GetLDTAlias()) == 0 )
        return FALSE;

    //
    // Create a pointer to the call gate descriptor
    //
    callgate_desc = MAKELP( ldt_alias, callgate & 0xFFF8 );

    //
    // First, free the ring 0 alias selector stored in the LDT
    // call gate descriptor, then free the call gate selector.
    //
    FreeSelector( callgate_desc->selector );
    FreeSelector( callgate );
}
Exemple #6
0
WORD WINAPI PrkPatchDLLEntryPoints(HINSTANCE hInst, PATCHFN sds, 
                                   LPWORD wDataSize, 
                                   BOOL FAR *_dll_patched)
{
    HMODULE hModule = GetModuleHandle((LPSTR) MAKELONG(hInst, 0));
    LPTABLE lpTable = (LPTABLE) MAKELONG(0, hModule);
    LPETABLE lpETable = (LPETABLE) MAKELONG(lpTable->table, hModule);
    LPSEGMENT lpSegment = (LPSEGMENT) MAKELONG(lpTable->segtable, hModule);
    WORD wCount = 0;
    WORD wDataSeg;
    LPWORD segments;
    SEGINFO seginfo;
    
    wDataSeg = lpSegment[lpTable->dgroup_num - 1].handle + 1;
    GetCodeInfo((FARPROC) MAKELONG(lpTable->dgroup_num, hModule), &seginfo);
    *wDataSize = seginfo.cbAlloc;

    if (*_dll_patched)
        return wDataSeg;

    __setds();

    segments = (LPWORD) malloc(lpTable->numseg * sizeof(WORD));
        
    while (wCount < lpTable->numseg) {
        if (!(lpSegment[wCount].flags & 0x1))
        {
            WORD wSel = lpSegment[wCount].handle + 1;
            LPSTR code = (LPSTR) MAKELONG(0, wSel);
                
            /* touch the code segment (could be LOADONCALL) */
            memchr(code, '\x1e', 8);
            segments[wCount] = AllocCStoDSAlias(wSel);
        }
        else
            segments[wCount] = 0;

        wCount++;
    }
        
    PatchEntryPoints(hModule, lpETable, segments, 0xffff, sds);
        
    wCount = 0;
    while (wCount < lpTable->numseg) {
        if (segments[wCount])
            FreeSelector(segments[wCount]);
        wCount++;
    }

    free(segments);
    *_dll_patched = TRUE;
    
    return wDataSeg;
}
Exemple #7
0
void
_86_FreeSelector (ENV *envp,LONGPROC f)
{
	WORD wSel;

	wSel = GETWORD(SP+4);
	ZapSegRegs(envp,wSel);
	FreeSelector(wSel);
	envp->reg.ax = 0;
	envp->reg.dx = 0;
	envp->reg.sp += WORD_86 + RET_86;
}
Exemple #8
0
void
IT_FREERESOURCE (ENV *envp,LONGPROC f)
{
	WORD wSel;
	HGLOBAL hGlobal;

	wSel = GETWORD(SP+4) | 1;
	hGlobal = GetSelectorHandle(wSel);
	GlobalUnlock(hGlobal);

				
	ZapSegRegs(envp,wSel);
	FreeSelector(wSel);
#ifdef LATER
	envp->reg.ax = GlobalFree(hGlobal);
#else
	envp->reg.ax = 0;
#endif
	envp->reg.dx = 0;
	envp->reg.sp += HANDLE_86 + RET_86;
}
Exemple #9
0
WORD FAR PASCAL __loadds GetRing0Callgate( DWORD func_address,
											unsigned cParams )
{
    CALLGATE_DESCRIPTOR far *callgate_desc;
    CODE_SEG_DESCRIPTOR far *ring0_desc;
    unsigned short ldt_alias;
    unsigned short ring_0_alias;
    unsigned short callgate_selector;

    if ( (ldt_alias = GetLDTAlias()) == 0 )
        return 0;

    //
    // Grab a selector from Windows to use as the CS at ring 0
    //
    if ( !(ring_0_alias = AllocSelector(0)) )
        return 0;

    //
	// Set up the fields in the descriptor to be a ring 0, flat model seg
    //
    ring0_desc = MAKELP( ldt_alias, ring_0_alias & 0xFFF8 );
	ring0_desc->limit_0_15 = 0xFFFF;
	ring0_desc->base_0_15 = 0;
	ring0_desc->base_16_23 = 0;
	ring0_desc->readable = 1;
	ring0_desc->conforming = 0;
	ring0_desc->code_data = 1;
	ring0_desc->app_system = 1;
    ring0_desc->dpl = 0;
    ring0_desc->present = 1;
	ring0_desc->limit_16_19 = 0xF;
	ring0_desc->always_0 = 0;
	ring0_desc->seg_16_32 = 1;
	ring0_desc->granularity = 1;
	ring0_desc->base_24_31 = 0;
	
    //
    // Allocate the selector that'll be used for the call gate
    //
    if ( (callgate_selector= AllocSelector(0)) == 0 )
    {
        FreeSelector( ring_0_alias );
        return 0;
    }

    //
    // Create a pointer to the call gate descriptor
    //
    callgate_desc = MAKELP( ldt_alias, callgate_selector & 0xFFF8 );

    //
    // Fill in the fields of the call gate descriptor with the
    // appropriate values for a 16 bit callgate.
    //
    callgate_desc->offset_0_15 = LOWORD( func_address );
    callgate_desc->selector = ring_0_alias;
    callgate_desc->param_count = cParams;
    callgate_desc->some_bits = 0;
    callgate_desc->type = 0xC;          // 386 call gate
    callgate_desc->app_system = 0;      // A system descriptor
    callgate_desc->dpl = 3;             // Ring 3 code can call
    callgate_desc->present = 1;
    callgate_desc->offset_16_31 = HIWORD(func_address);

    return callgate_selector;
}
Exemple #10
0
Reader* NewReader(char* pipeName, aio4c_size_t bufferSize) {
    Reader* reader = NULL;
    ErrorCode code = AIO4C_ERROR_CODE_INITIALIZER;

    if ((reader = aio4c_malloc(sizeof(Reader))) == NULL) {
#ifndef AIO4C_WIN32
        code.error = errno;
#else /* AIO4C_WIN32 */
        code.source = AIO4C_ERRNO_SOURCE_SYS;
#endif /* AIO4C_WIN32 */
        code.size = sizeof(Reader);
        code.type = "Reader";
        Raise(AIO4C_LOG_LEVEL_ERROR, AIO4C_ALLOC_ERROR_TYPE, AIO4C_ALLOC_ERROR, &code);
        return NULL;
    }

    reader->selector   = NULL;
    reader->queue      = NULL;
    reader->worker     = NULL;
    reader->bufferSize = bufferSize;
    reader->load       = 0;

    if (pipeName != NULL) {
        reader->pipe       = pipeName;
        reader->name       = aio4c_malloc(strlen(pipeName) + 1 + 7);
        if (reader->name != NULL) {
            snprintf(reader->name, strlen(pipeName) + 1 + 7, "%s-reader", pipeName);
        }
    } else {
        reader->pipe = NULL;
        reader->name = NULL;
    }

    reader->thread = NewThread(
            reader->name,
           _ReaderInit,
           _ReaderRun,
           _ReaderExit,
           (ThreadData)reader);

    if (reader->thread == NULL) {
        FreeSelector(&reader->selector);
        if (reader->pipe != NULL) {
            aio4c_free(reader->pipe);
        }
        if (reader->name != NULL) {
            aio4c_free(reader->name);
        }
        aio4c_free(reader);
        return NULL;
    }

    if (!ThreadStart(reader->thread)) {
        FreeSelector(&reader->selector);
        if (reader->pipe != NULL) {
            aio4c_free(reader->pipe);
        }
        if (reader->name != NULL) {
            aio4c_free(reader->name);
        }
        aio4c_free(reader);
        return NULL;
    }

    return reader;
}