Beispiel #1
0
int DoCloseInterruptHandler (int handle)
{
    struct ISRHandler *isr_handler;
    struct Process *current;
    int irq;
    
    current = GetCurrentProcess();

    if ((isr_handler = GetObject(current, handle, HANDLE_TYPE_ISR)) == NULL)
        return paramErr;

    DisablePreemption();    
    
    irq = isr_handler->irq;

    DisableInterrupts();

    LIST_REM_ENTRY (&isr_handler_list[irq], isr_handler, isr_handler_entry);
    irq_handler_cnt[irq] --;
    
    if (irq_handler_cnt[irq] == 0)
        MaskInterrupt(irq);
    
    EnableInterrupts();
        
    LIST_ADD_HEAD (&free_isr_handler_list, isr_handler, isr_handler_entry);
    free_isr_handler_cnt ++;
    
    FreeHandle (handle);

    return 0;
}
Beispiel #2
0
void HandleSystem::ReleasePrimHandle(unsigned int index)
{
	QHandle *pHandle = &m_Handles[index];
	HandleSet set = pHandle->set;

	if (pHandle->owner && (set != HandleSet_Identity))
	{
		UnlinkHandleFromOwner(pHandle, index);
	}

	/* Were we an identity ourself? */
	QHandle *pLocal;
	if (set == HandleSet_Identity)
	{
		/* Extra work to do.  We need to find everything connected to this identity and release it. */
		unsigned int ch_index;
#if defined _DEBUG
		unsigned int old_index = 0;
#endif
		while ((ch_index = pHandle->ch_next) != 0)
		{
			pLocal = &m_Handles[ch_index];
#if defined _DEBUG
			assert(old_index != ch_index);
			assert(pLocal->set == HandleSet_Used);
			old_index = ch_index;
#endif
			FreeHandle(pLocal, ch_index);
		}
	}

	pHandle->set = HandleSet_None;
	m_Types[pHandle->type].opened--;
	m_Handles[++m_FreeHandles].freeID = index;
}
Beispiel #3
0
static UCHAR EmsFree(USHORT Handle)
{
    PLIST_ENTRY Entry;
    PEMS_HANDLE HandleEntry = GetHandleRecord(Handle);

    if (!ValidateHandle(HandleEntry))
        return EMS_STATUS_INVALID_HANDLE;

    for (Entry = HandleEntry->PageList.Flink;
         Entry != &HandleEntry->PageList;
         Entry = Entry->Flink)
    {
        PEMS_PAGE PageEntry = (PEMS_PAGE)CONTAINING_RECORD(Entry, EMS_PAGE, Entry);
        ULONG PageNumber = ARRAY_INDEX(PageEntry, PageTable);

        /* Free the page */
        RtlClearBits(&AllocBitmap, PageNumber, 1);
    }

    InitializeListHead(&HandleEntry->PageList);

    if (Handle != EMS_SYSTEM_HANDLE)
        FreeHandle(HandleEntry);

    return EMS_STATUS_SUCCESS;
}
Beispiel #4
0
HandleError HandleSystem::FreeHandle(Handle_t handle, const HandleSecurity *pSecurity)
{
    unsigned int index;
    QHandle *pHandle;
    HandleError err;
    IdentityToken_t *ident = pSecurity ? pSecurity->pIdentity : NULL;

    if ((err=GetHandle(handle, ident, &pHandle, &index)) != HandleError_None)
    {
        return err;
    }

    if (!CheckAccess(pHandle, HandleAccess_Delete, pSecurity))
    {
        return HandleError_Access;
    }

    if (pHandle->is_destroying)
    {
        /* Someone tried to free this recursively.
         * We'll just ignore this safely.
         */
        return HandleError_None;
    }

    return FreeHandle(pHandle, index);
}
Beispiel #5
0
static cell AMX_NATIVE_CALL SQL_FreeHandle(AMX *amx, cell *params)
{
	if (!FreeHandle(params[1]))
	{
		MF_LogError(amx, AMX_ERR_NATIVE, "Invalid handle: %d", params[1]);
		return 0;
	}

	return 1;
}
Beispiel #6
0
//public QueryHandler(state, Handle:query, error[], errnum, data[], size)
void MysqlThread::Execute()
{
	cell data_addr;
	if (m_datalen)
	{
		data_addr = MF_PrepareCellArray(m_data, m_datalen);
	} else {
		static cell tmpdata[1] = {0};
		data_addr = MF_PrepareCellArray(tmpdata, 1);
	}
	int state = 0;
	if (!m_qrInfo.connect_success)
	{
		state = -2;
	} else if (!m_qrInfo.query_success) {
		state = -1;
	}
	float diff = gpGlobals->time - m_qrInfo.queue_time;
	cell c_diff = amx_ftoc(diff);
	unsigned int hndl = MakeHandle(&m_qrInfo.amxinfo, Handle_Query, NullFunc);
	if (state != 0)
	{
		MF_ExecuteForward(m_fwd, 
			(cell)state, 
			(cell)hndl, 
			m_qrInfo.amxinfo.error, 
			m_qrInfo.amxinfo.info.errorcode,
			data_addr,
			m_datalen,
			c_diff);
	} else {
		MF_ExecuteForward(m_fwd,
			(cell)0,
			(cell)hndl,
			"",
			(cell)0,
			data_addr,
			m_datalen,
			c_diff);
	}
		FreeHandle(hndl);
	if (m_qrInfo.amxinfo.pQuery)
	{
		m_qrInfo.amxinfo.pQuery->FreeHandle();
		m_qrInfo.amxinfo.pQuery = NULL;
	}
	delete [] m_qrInfo.amxinfo.opt_ptr;
	m_qrInfo.amxinfo.opt_ptr = NULL;
}
Beispiel #7
0
AtomicResult::~AtomicResult()
{
	if (!m_IsFree)
	{
		FreeHandle();
	}

	for (size_t i=0; i<=m_AllocSize; i++)
	{
		delete m_Table[i];
	}

	delete [] m_Table;

	m_Table = NULL;
	m_IsFree = true;
}
Beispiel #8
0
void AxisSweep3::RemoveHandle(unsigned short handle)
{
	Handle* pHandle = GetHandle(handle);

	RemoveOverlappingPairsContainingProxy(pHandle);


	// compute current limit of edge arrays
	int limit = m_numHandles * 2;
	int axis;

	for (axis = 0;axis<3;axis++)
	{
		Edge* pEdges = m_pEdges[axis];
		int maxEdge= pHandle->m_maxEdges[axis];
		pEdges[maxEdge].m_pos = 0xffff;
		int minEdge = pHandle->m_minEdges[axis];
		pEdges[minEdge].m_pos = 0xffff;
	}

	// remove the edges by sorting them up to the end of the list
	for ( axis = 0; axis < 3; axis++)
	{
		Edge* pEdges = m_pEdges[axis];
		int max = pHandle->m_maxEdges[axis];
		pEdges[max].m_pos = 0xffff;

		SortMaxUp(axis,max,false);
		
		int i = pHandle->m_minEdges[axis];
		pEdges[i].m_pos = 0xffff;

		SortMinUp(axis,i,false);

		pEdges[limit-1].m_handle = 0;
		pEdges[limit-1].m_pos = 0xffff;

	}

	// free the handle
	FreeHandle(handle);

	
}
Beispiel #9
0
HandleError HandleSystem::FreeHandle(Handle_t handle, const HandleSecurity *pSecurity)
{
	unsigned int index;
	QHandle *pHandle;
	HandleError err;
	IdentityToken_t *ident = pSecurity ? pSecurity->pIdentity : NULL;

	if ((err=GetHandle(handle, ident, &pHandle, &index)) != HandleError_None)
	{
		return err;
	}

	if (!CheckAccess(pHandle, HandleAccess_Delete, pSecurity))
	{
		return HandleError_Access;
	}

	return FreeHandle(pHandle, index);
}
Beispiel #10
0
/*!
******************************************************************************

 @Function	PVRSRVReleaseHandle

 @Description	Release a handle that is no longer needed

 @Input 	hHandle - handle from client
		eType - handle type

 @Return	Error code or PVRSRV_OK

******************************************************************************/
PVRSRV_ERROR PVRSRVReleaseHandle(PVRSRV_HANDLE_BASE *psBase,
				 IMG_HANDLE hHandle,
				 PVRSRV_HANDLE_TYPE eType)
{

	PVRSRV_ERROR eError;

	/* PVRSRV_HANDLE_TYPE_NONE is reserved for internal use */
	PVR_ASSERT(eType != PVRSRV_HANDLE_TYPE_NONE);
	PVR_ASSERT(gpsHandleFuncs);

	if (psBase == IMG_NULL)
	{
		PVR_DPF((PVR_DBG_ERROR, "PVRSRVReleaseHandle: Missing handle base"));
		eError = PVRSRV_ERROR_INVALID_PARAMS;
		goto exit_ReleaseHandle;
	}

	eError = FreeHandle(psBase, hHandle, eType, IMG_NULL);

exit_ReleaseHandle:
	return eError;
}
Beispiel #11
0
ODBCLib::CODBCHandle::~CODBCHandle() {
	FreeHandle();
}
Beispiel #12
0
static PVRSRV_ERROR FreeHandleWrapper(PVRSRV_HANDLE_BASE *psBase, IMG_HANDLE hHandle)
{
	return FreeHandle(psBase, hHandle, PVRSRV_HANDLE_TYPE_NONE, IMG_NULL);
}
Beispiel #13
0
/*!
******************************************************************************

 @Function	PVRSRVAllocSubHandle

 @Description	Allocate a subhandle

 @Input		phHandle - location for new subhandle
		pvData - pointer to resource to be associated with the subhandle
		eType - the type of resource
		hParent - parent handle

 @Output	phHandle - points to new subhandle

 @Return	Error code or PVRSRV_OK

******************************************************************************/
PVRSRV_ERROR PVRSRVAllocSubHandle(PVRSRV_HANDLE_BASE *psBase,
				  IMG_HANDLE *phHandle,
				  IMG_VOID *pvData,
				  PVRSRV_HANDLE_TYPE eType,
				  PVRSRV_HANDLE_ALLOC_FLAG eFlag,
				  IMG_HANDLE hParent)
{
	HANDLE_DATA *psPHandleData = IMG_NULL;
	HANDLE_DATA *psCHandleData = IMG_NULL;
	IMG_HANDLE hParentKey;
	IMG_HANDLE hHandle;
	PVRSRV_ERROR eError;

	*phHandle = IMG_NULL;

	/* PVRSRV_HANDLE_TYPE_NONE is reserved for internal use */
	PVR_ASSERT(eType != PVRSRV_HANDLE_TYPE_NONE);
	PVR_ASSERT(gpsHandleFuncs);

	if (psBase == IMG_NULL)
	{
		PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSubHandle: Missing handle base"));
		eError = PVRSRV_ERROR_INVALID_PARAMS;
		goto err;
	}

	hParentKey = TEST_FLAG(eFlag, PVRSRV_HANDLE_ALLOC_FLAG_PRIVATE) ? hParent : IMG_NULL;

	/* Lookup the parent handle */
	eError = GetHandleData(psBase, &psPHandleData, hParent, PVRSRV_HANDLE_TYPE_NONE);
	if (eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSubHandle: Failed to get parent handle structure"));
		goto err;
	}

	if (!TEST_FLAG(eFlag, PVRSRV_HANDLE_ALLOC_FLAG_MULTI))
	{
		/* See if there is already a handle for this data pointer */
		hHandle = FindHandle(psBase, pvData, eType, hParentKey);
		if (hHandle != IMG_NULL)
		{
			eError = GetHandleData(psBase, &psCHandleData, hHandle, eType);
			if (eError != PVRSRV_OK)
			{
				PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSubHandle: Lookup of existing handle failed"));
				goto err;
			}

			PVR_ASSERT(hParentKey != IMG_NULL && ParentHandle(psCHandleData) == hParent);

			/*
			 * If the client is willing to share a handle, the
			 * existing handle is marked as shareable, and the
			 * existing handle has the same parent, return the
			 * existing handle.
			 */
			if (TEST_FLAG(psCHandleData->eFlag & eFlag, PVRSRV_HANDLE_ALLOC_FLAG_SHARED) && 
			    ParentHandle(psCHandleData) == hParent)
			{
				psCHandleData->ui32Refs++;
				*phHandle = hHandle;
				eError = PVRSRV_OK;
				goto err;
			}
			eError = PVRSRV_ERROR_HANDLE_NOT_SHAREABLE;
			goto err;
		}
	}

	eError = AllocHandle(psBase, &hHandle, pvData, eType, eFlag, hParentKey);
	if (eError != PVRSRV_OK)
	{
		goto err;
	}

	eError = GetHandleData(psBase, &psCHandleData, hHandle, PVRSRV_HANDLE_TYPE_NONE);
	if (eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSubHandle: Failed to get parent handle structure"));

		/* If we were able to allocate the handle then there should be no reason why we 
		   can't also get it's handle structure. Otherwise something has gone badly wrong. */
		PVR_ASSERT(eError == PVRSRV_OK);

		goto err;
	}

	/*
	 * Get the parent handle structure again, in case the handle
	 * structure has moved (depending on the implementation
	 * of AllocHandle).
	 */
	eError = GetHandleData(psBase, &psPHandleData, hParent, PVRSRV_HANDLE_TYPE_NONE);
	if (eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSubHandle: Failed to get parent handle structure"));

		FreeHandle(psBase, hHandle, eType, IMG_NULL);
		goto err;
	}

	eError = AdoptChild(psBase, psPHandleData, psCHandleData);
	if (eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR, "PVRSRVAllocSubHandle: Parent handle failed to adopt subhandle"));

		FreeHandle(psBase, hHandle, eType, IMG_NULL);
		goto err;
	}

	*phHandle = hHandle;

	eError = PVRSRV_OK;

	err:
	return eError;
}
Beispiel #14
0
_Use_decl_annotations_
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR commandLine, int commandShow)
{
    UMSpinLock spinLock;
    UMCriticalSection cs;
    CRITICAL_SECTION cs2;
    LARGE_INTEGER freq, start, stop, osCS, myCS;

    HANDLE threads[64];

    UMSpinLockInitialize(&spinLock);
    UMCriticalSectionInitialize(&cs, _countof(threads));
    InitializeCriticalSection(&cs2);

    for (uint32_t i = 0; i < _countof(threads); ++i)
    {
        threads[i] = CreateThread(NULL, 0, ThreadProcSpinLock, &spinLock, 0, NULL);
        assert(threads[i] != NULL);
    }

    WaitForMultipleObjects(_countof(threads), threads, TRUE, INFINITE);
    uint32_t value = buffer[0];
    for (uint32_t i = 0; i < _countof(buffer); ++i)
    {
        if (buffer[i] != value)
        {
            OutputDebugString(L"\n\nERROR ERROR\n");
            assert(false);
        }
    }

    QueryPerformanceFrequency(&freq);
    QueryPerformanceCounter(&start);
    for (uint32_t i = 0; i < _countof(threads); ++i)
    {
        CloseHandle(threads[i]);
        threads[i] = CreateThread(NULL, 0, ThreadProcCS, &cs, 0, NULL);
        assert(threads[i] != NULL);
    }

    WaitForMultipleObjects(_countof(threads), threads, TRUE, INFINITE);
    QueryPerformanceCounter(&stop);
    myCS.QuadPart = stop.QuadPart - start.QuadPart;

    value = buffer[0];
    for (uint32_t i = 0; i < _countof(buffer); ++i)
    {
        if (buffer[i] != value)
        {
            OutputDebugString(L"\n\nERROR ERROR\n");
            assert(false);
        }
    }

    QueryPerformanceCounter(&start);
    for (uint32_t i = 0; i < _countof(threads); ++i)
    {
        CloseHandle(threads[i]);
        threads[i] = CreateThread(NULL, 0, ThreadProcOSCS, &cs2, 0, NULL);
        assert(threads[i] != NULL);
    }

    WaitForMultipleObjects(_countof(threads), threads, TRUE, INFINITE);
    QueryPerformanceCounter(&stop);
    osCS.QuadPart = stop.QuadPart - start.QuadPart;

    value = buffer[0];
    for (uint32_t i = 0; i < _countof(buffer); ++i)
    {
        if (buffer[i] != value)
        {
            OutputDebugString(L"\n\nERROR ERROR\n");
            assert(false);
        }
    }

    for (uint32_t i = 0; i < _countof(threads); ++i)
    {
        CloseHandle(threads[i]);
    }

    UMCriticalSectionDestroy(&cs);

    typedef struct
    {
        uint32_t X;
        float F;
    } Foo;

    Foo f;
    Foo* g;
    Handle h;
    char buffer[] = "Hello, World";
    wchar_t buffer2[100];
    char buffer3[100];

    GameObject go1;
    GameObject go2;
    AabbNode* root = NULL;

    go1.Signature = SIGNATURE;
    go2.Signature = SIGNATURE;

    AabbNodeStartup(GetGameObjectBounds);

    go1.Node = AabbNodeInsert(&root, go1.Mins, go1.Maxs, &go1);
    go2.Node = AabbNodeInsert(&root, go2.Mins, go2.Maxs, &go2);

//    AabbNodeRemove(&root, root);
    AabbNodeRemove(&root, go1.Node);
    AabbNodeRemove(&root, go2.Node);

    UNREFERENCED_PARAMETER(instance);
    UNREFERENCED_PARAMETER(prevInstance);
    UNREFERENCED_PARAMETER(commandLine);
    UNREFERENCED_PARAMETER(commandShow);

    f.X = 3;
    f.F = -234.8f;

    if (!HandleTableStartup())
    {
        return -1;
    }

    h = AllocHandle(&f, 1);
    if (h == InvalidHandle)
    {
        return -2;
    }

    g = (Foo*)GetObjectFromHandle(h);
    if (g == 0)
    {
        return -3;
    }

    FreeHandle(h);

    HandleTableShutdown();

    if (!ConvertCharToWChar(buffer, buffer2, 100))
    {
        return -3;
    }

    if (!ConvertWCharToChar(buffer2, buffer3, 100))
    {
        return -4;
    }

    return 0;
}
Beispiel #15
0
bool HandleSystem::RemoveType(HandleType_t type, IdentityToken_t *ident)
{
	if (type == 0 || type >= HANDLESYS_TYPEARRAY_SIZE)
	{
		return false;
	}

	QHandleType *pType = &m_Types[type];

	if (pType->typeSec.ident
		&& pType->typeSec.ident != ident)
	{
		return false;
	}

	if (pType->dispatch == NULL)
	{
		return false;
	}

	/* Remove children if we have to */
	if (!(type & HANDLESYS_SUBTYPE_MASK))
	{
		QHandleType *childType;
		for (unsigned int i=1; i<=HANDLESYS_MAX_SUBTYPES; i++)
		{
			childType = &m_Types[type + i];
			if (childType->dispatch)
			{
				RemoveType(type + i, childType->typeSec.ident);
			}
		}
		/* Link us into the free chain */
		m_Types[++m_FreeTypes].freeID = type;
	}

	/* Make sure nothing is using this type. */
	if (pType->opened)
	{
		QHandle *pHandle;
		for (unsigned int i=1; i<=m_HandleTail; i++)
		{
			pHandle = &m_Handles[i];
			if (!pHandle->set || pHandle->type != type)
			{
				continue;
			}

			FreeHandle(pHandle, i);

			if (pType->opened == 0)
			{
				break;
			}
		}
	}

	/* Invalidate the type now */
	pType->dispatch = NULL;

	/* Remove it from the type cache. */
	if (pType->name)
		m_TypeLookup.remove(pType->name->chars());

	return true;
}
Beispiel #16
0
	OdbcHandleBase<HandleType>::~OdbcHandleBase()
{
	FreeHandle(handle_type_, this_handle_, OdbcThrowFlags::None);
}