Ejemplo n.º 1
0
/*
	FUNCTION: PaintWindow(HWND)

	PURPOSE: Paints the area determined by the paint struct of the DC.

	PARAMETERS:
		hWnd	- Handle to the window

*/
void PaintWindow(HWND hWnd) {
	PAINTSTRUCT		ps;
	HDC				hDC;
	HMENU			hMenu;
	pPROGRAM_ITEM	pListItem;
	pPROGRAM_ITEM	pPrevItem;
	pPROGRAM_ITEM	pArray[MAX_OBJECTS]; // ugly hack since I can't reverse the stupid list
	int				i, iter = 0;

	hMenu = GetMenu(hWnd);
	hDC = BeginPaint(hWnd, &ps);

	(PSLIST_HEADER)pListItem = gpListHead;

	// Reverse the linked list
	while (pListItem) {

		// Add the pointers to our array
		if (QueryDepthSList(gpListHead) != 0 && iter != MAX_OBJECTS) {
			pArray[iter++] = pListItem;
		}

		//switch to next list item
		pPrevItem = pListItem;
		pListItem = (pPROGRAM_ITEM)pListItem->ItemEntry.Next;
	}

	if (selCount != 0) {
		// Remove the inserted objects
		for (; selCount != 0; --selCount) {
			InterlockedPopEntrySList(gpListHead);
		}
	}

	// Iterate backwards through our array of pointers
	if (QueryDepthSList(gpListHead) != 0) {
		// Make sure we don't iterate beyond the bounds of our array (ugly hack, yes)
		if (QueryDepthSList(gpListHead) > MAX_OBJECTS) {
			iter = MAX_OBJECTS;
		}
		for (i = iter - 1; i != 0; i--) {
			if (pArray[i]->fLine) {
				DrawLine(hWnd, pArray[i]->line, pArray[i]->colour, TRUE);
			}
			else { // Draw a rectangle
				DrawRect(hWnd, &(pArray[i]->rect), pArray[i]->colour, TRUE);
			}
		}
	}

	EndPaint(hWnd, &ps);
}
Ejemplo n.º 2
0
/**
 * called only from main thread
 */
static void freerdp_channels_process_sync(rdpChannels* channels, freerdp* instance)
{
	SYNC_DATA* item;
	rdpChannel* lrdp_channel;
	struct channel_data* lchannel_data;

	while (QueryDepthSList(channels->pSyncDataList) > 0)
	{
		item = (SYNC_DATA*) InterlockedPopEntrySList(channels->pSyncDataList);

		if (!item)
			break;

		lchannel_data = channels->channels_data + item->Index;

		lrdp_channel = freerdp_channels_find_channel_by_name(channels, instance->settings,
			lchannel_data->name, &item->Index);

		if (lrdp_channel != NULL)
			instance->SendChannelData(instance, lrdp_channel->ChannelId, item->Data, item->DataLength);

		if (lchannel_data->open_event_proc != 0)
		{
			lchannel_data->open_event_proc(lchannel_data->open_handle,
				CHANNEL_EVENT_WRITE_COMPLETE, item->UserData, sizeof(void*), sizeof(void*), 0);
		}

		_aligned_free(item);
	}
}
Ejemplo n.º 3
0
VOID
BtrFreeLookaside(
	__in BTR_LOOKASIDE_TYPE Type,
	__in PVOID Ptr
	)
{
	PBTR_LOOKASIDE Lookaside;
	PSLIST_ENTRY ListEntry;
	USHORT Depth;

	if (!Ptr) {
		return;
	}

	Lookaside = &BtrLookaside[Type];
	InterlockedIncrement(&Lookaside->TotalFrees);

	Depth = QueryDepthSList(&Lookaside->ListHead);
	ListEntry = (PSLIST_ENTRY)((PUCHAR)Ptr - MEMORY_ALLOCATION_ALIGNMENT);

	if (Depth < Lookaside->MaximumDepth) {
		InterlockedPushEntrySList(&Lookaside->ListHead, ListEntry);
	} else {
		InterlockedIncrement(&Lookaside->FreeMisses);
		BtrAlignedFree(ListEntry);
	}
}
Ejemplo n.º 4
0
VOID
NTAPI
DbgLogEvent(PSLIST_HEADER pslh, LOG_EVENT_TYPE nEventType, LPARAM lParam)
{
    PLOGENTRY pLogEntry;

    /* Log a maximum of 100 events */
    if (QueryDepthSList(pslh) >= 1000) return;

    /* Allocate a logentry */
    pLogEntry = EngAllocMem(0, sizeof(LOGENTRY), 'golG');
    if (!pLogEntry) return;

    /* Set type */
    pLogEntry->nEventType = nEventType;
    pLogEntry->ulUnique = InterlockedIncrement((LONG*)&gulLogUnique);
    pLogEntry->dwProcessId = HandleToUlong(PsGetCurrentProcessId());
    pLogEntry->dwThreadId = HandleToUlong(PsGetCurrentThreadId());
    pLogEntry->lParam = lParam;

    /* Capture a backtrace */
    DbgCaptureStackBackTace(pLogEntry->apvBackTrace, 20);

    switch (nEventType)
    {
        case EVENT_ALLOCATE:
        case EVENT_CREATE_HANDLE:
        case EVENT_REFERENCE:
        case EVENT_DEREFERENCE:
        case EVENT_LOCK:
        case EVENT_UNLOCK:
        case EVENT_DELETE:
        case EVENT_FREE:
        case EVENT_SET_OWNER:
        default:
            break;
    }

    /* Push it on the list */
    InterlockedPushEntrySList(pslh, &pLogEntry->sleLink);
}
Ejemplo n.º 5
0
	void Push( __out_opt SNI_Packet *pPacket)
	{
		if( QueryDepthSList(&m_SListHeader) < MAX_PACKET_CACHE_SIZE - 1 )
		{
			SLIST_ENTRY* pEntry = static_cast<SLIST_ENTRY*>(SNIPacketGetDescriptor(pPacket));
			InterlockedPushEntrySList(&m_SListHeader, pEntry);
		}
		else
		{
			// Strategy: Don't make an effort to clean up the "extra" entries, but don't push this one onto the stack
			// if it will go over. This guarantees an *approximate* maximum 
			// (bounded above by MAX_PACKET_CACHE_SIZE + ConcurrentThreadsAccessingTheStack)
			
			// It would cost a lot of performance to put a stronger guarantee on the maximal size, since
			// we would need to synchronize access to two variables (stack head, stack size), which we 
			// don't know how to do without using a true [....] primitive, rather than the two separate
			// Interlocked operations which are all that's required to maintain consistency of the list header and 
			// an *approximate* depth guarantee.
			SNIPacketDelete(pPacket);
		}
	}