List* List_AddTail(List* pHead, List* pNode) { List* pListNode = pHead; Assert(pNode); pNode->m_pNext = Null; if(pHead == Null) { pNode->m_pPre = Null; pHead = pNode; goto END; } //Get the tail node while(pListNode->m_pNext) { pListNode = pListNode->m_pNext; Assert(pListNode != pNode); } pListNode->m_pNext = pNode; pNode->m_pPre = pListNode; END: PF(DL_LISTEX, ("List_AddTail(), count=%d\n", List_Count(pHead))); return pHead; }
void Utilities_ListToArray(List* SrcList, CpArray* DestArray) { int i = 0; for(i = 0; i < DestArray->Count; i++) free(DestArray->Items[i]); free(DestArray->Items); DestArray->Count = List_Count(SrcList); DestArray->Items = (char**)malloc(sizeof(char*) * DestArray->Count); for(i = 0; i < DestArray->Count; i++) DestArray->Items[i] = (char*)List_AtIndex(SrcList, i); };
static CONNINST *FindClient(IMO2SPROXY_INST *hProxy, HWND hWnd) { int i, nCount; CONNINST *pConn; for (i=0, nCount=List_Count(hProxy->hClients); i<nCount; i++) { if ((pConn=(CONNINST*)List_ElementAt (hProxy->hClients, i))->hWnd == hWnd) return pConn; } return NULL; }
AVATARENTRY *AvatarList_Find(TYP_LIST *hList, char *pszUser) { int i, nCount; AVATARENTRY *pEntry; for (i=0, nCount=List_Count(hList); i<nCount; i++) { pEntry = List_ElementAt (hList, i); if (strcmp(pEntry->pszUser, pszUser) == 0) return pEntry; } return NULL; }
static void CleanConnections (TYP_LIST *hList) { unsigned int i; CONNINST *hInst; for (i=0; i<List_Count(hList); i++) { hInst = List_ElementAt (hList, i); if (hInst->hThread == 0) { free (List_RemoveElementAt(hList, i)); i--; } } }
static void CleanConnections (TYP_LIST *hList) { unsigned int i; CONNINST *pInst; for (i=0; i<List_Count(hList); i++) { pInst = List_ElementAt (hList, i); if (!IsWindow (pInst->hWnd)) { if (pInst->hInst) FreeConnection(pInst); free (List_RemoveElementAt(hList, i)); i--; } } }
int main() { List *a; int v; List_Foreach_Variable; a = List_CreateNew(4); if(0==a) { printf("Create New list failed!\n"); return 0; } v=0; List_PushBack(a,(void*)&v); v=1; List_PushBack(a,(void*)&v); v=2; List_PushBack(a,(void*)&v); v=3; List_PushBack(a,(void*)&v); v=4; List_PushBack(a,(void*)&v); v=5; List_PushBack(a,(void*)&v); List_PushBack(a,(void*)&v); int val; List_Foreach(a) { val = *(int*)List_Foreach_Value; if(2==val) { List_Foreach_RmCurNode; continue; } printf("%d----------\n",val); } val = 2; printf("size of list %d\n",List_Count(a)); printf("value size of list %d\n",List_ValueCount(a,(void*)&val)); printf("index of \'%d\' is %d\n",val,List_Indexof(a,&val)); List_Clear(a); return 0; }
BOOL AvatarList_Remove(TYP_LIST *hList, AVATARENTRY *pEntry) { AVATARENTRY *pListEntry; int i, nCount; for (i=0, nCount=List_Count(hList); i<nCount; i++) { pListEntry = List_ElementAt (hList, i); if (pListEntry == pEntry) break; } if (i<nCount) { AvatarList_FreeEntry (pEntry); List_RemoveElementAt(hList, i); free (pEntry); return TRUE; } return FALSE; }
void MsgList_CollectGarbage(void) { unsigned int i; TYP_MSGLENTRY *pEntry; time_t t; if (!m_hMsgList) return; time(&t); t-=MSGLIST_TIMEOUT; for (i=0; i<List_Count(m_hMsgList); i++) { pEntry = List_ElementAt (m_hMsgList, i); if (pEntry->t < t) { LOG (("MsgList_CollectGarbage throwing out msg %d", pEntry->uMsgNum)); HeapFree (GetProcessHeap(), 0, List_RemoveElementAt (m_hMsgList, i)); i--; } } }
//Remove a node form list //Return: head node List* List_Remove(List* pNode) { List* pHead = pNode; Assert(pNode); //Head of list if(pNode->m_pPre == Null) { pHead = pNode->m_pNext; if(pHead) { pHead->m_pPre = Null; } goto END; } else { pNode->m_pPre->m_pNext = pNode->m_pNext; if(pNode->m_pNext) { pNode->m_pNext->m_pPre = pNode->m_pPre; } } while(pHead->m_pPre) { pHead = pHead->m_pPre; } END: pNode->m_pPre = Null; pNode->m_pNext = Null; PF(DL_LISTEX, ("List_Remove(), count=%d\n", List_Count(pHead))); return pHead; }
int List_bubble_sort(List *list, List_compare cmp) { int sorted = 1; if (List_Count(list) <= 1) { return 0; } do { sorted = 1; // Remember we have a custom function to iterate // over list items! LIST_FOREACH(list, first, next, cur) { if (cur->next) { if(cmp(cur->value, cur->next->value) > 0) { ListNode_swap(cur, cur->next); sorted = 0; } } } } while(!sorted); return 0; }
bool Scheduler::DoSchedule(int tick, uint32_t registers) { //DebugPrintf("\nScheduler"); int entryPoint = 0; unsigned int procStack = 0; /* switch to process address space */ if (systemOn == true) { Process* curProcess = ProcessManager::GetInstance()->g_pCurProcess; if (curProcess) { Thread* pCurThread = (Thread*)List_GetData(curProcess->pThreadQueue, "", 0); pCurThread->curESP = (*(uint32_t*)(registers - 8)); pCurThread->curFlags = (*(uint32_t*)(registers - 12)); pCurThread->curCS = (*(uint32_t*)(registers - 16)); pCurThread->curEip = (*(uint32_t*)(registers - 20)); /*pCurThread->curgs = (*(uint16_t*)(registers - 24)); pCurThread->curfs = (*(uint16_t*)(registers - 28)); pCurThread->curEs = (*(uint16_t*)(registers - 32)); pCurThread->curds = (*(uint16_t*)(registers - 36));*/ pCurThread->frame.eax = (*(uint32_t*)(registers - 24)); pCurThread->frame.ecx = (*(uint32_t*)(registers - 28)); pCurThread->frame.edx = (*(uint32_t*)(registers - 32)); pCurThread->frame.ebx = (*(uint32_t*)(registers - 36)); pCurThread->frame.esp = (*(uint32_t*)(registers - 40)); pCurThread->frame.ebp = (*(uint32_t*)(registers - 44)); pCurThread->frame.esi = (*(uint32_t*)(registers - 48)); pCurThread->frame.edi = (*(uint32_t*)(registers - 52)); LISTNODE *pProcessList = ProcessManager::GetInstance()->pProcessQueue; int processCount = List_Count(pProcessList); for (int index = 0; index < processCount; index++) { Process* pProcess = (Process*)List_GetData(pProcessList, "", index); if (curProcess == pProcess) continue; pProcess->dwTickCount++; if (pProcess->dwTickCount > 10) { pProcess->dwTickCount = 0; if (pProcess->dwProcessType == PROCESS_USER) { console.Print("Scheduler1 : %d\n", processCount); ProcessManager::GetInstance()->g_pCurProcess = pProcess; Thread* pThread = (Thread*)List_GetData(pProcess->pThreadQueue, "", 0); entryPoint = pThread->curEip; procStack = pThread->curESP; uint32_t eflags = pThread->curFlags; console.Print("eip : %x\n", pThread->curEip); console.Print("CS : %x\n", pThread->curCS); console.Print("flags : %x\n", pThread->curFlags); console.Print("esp : %x\n", pThread->curESP); //entryPoint = pThread->frame.eip; //procStack = pThread->frame.esp; uint32_t regEax = pThread->frame.eax; uint32_t regEcx = pThread->frame.ecx; uint32_t regEdx = pThread->frame.edx; uint32_t regEbx = pThread->frame.ebx; uint32_t regEsp = pThread->frame.esp; uint32_t regEbp = pThread->frame.ebp; uint32_t regEsi = pThread->frame.esi; uint32_t regEdi = pThread->frame.edi; uint16_t regGs = pThread->curgs; uint16_t regFs = pThread->curfs; uint16_t regEs = pThread->curEs; uint16_t regDs = pThread->curds; pmmngr_load_PDBR((physical_addr)pProcess->pPageDirectory); OutPortByte(0x20, 0x20); __asm { mov ax, 0x23; user mode data selector is 0x20 (GDT entry 3).Also sets RPL to 3 mov ds, ax mov es, ax mov fs, ax mov gs, ax ; create stack frame ; push 0x23; SS, notice it uses same selector as above push[procStack]; stack push[eflags]; EFLAGS push 0x1b; CS, user mode code selector is 0x18.With RPL 3 this is 0x1b push[entryPoint]; EIP mov eax, regEax mov ecx, regEcx mov edx, regEdx mov ebx, regEbx mov esp, regEsp mov ebp, regEbp mov esi, regEsi mov edi, regEdi iretd } } else { /*if (aa == 0) { aa = 1; DebugPrintf("\nasdasas : %x", registers); for (int i = 0; i < 20; i++) DebugPrintf("\nasdasas : %x", (*(uint32_t*)(registers - i * 4))); while (1); }*/ console.Print("Scheduler2\n"); ProcessManager::GetInstance()->g_pCurProcess = pProcess; Thread* pThread = (Thread*)List_GetData(pProcess->pThreadQueue, "", 0); entryPoint = pThread->frame.eip; procStack = pThread->frame.esp; //procStack = 0; pmmngr_load_PDBR((physical_addr)pProcess->pPageDirectory); OutPortByte(0x20, 0x20); __asm { mov ax, 0x10; mov ds, ax mov es, ax mov fs, ax mov gs, ax ; ; create stack frame ; push 0x10; SS, notice it uses same selector as above push[procStack]; stack push 0x200; EFLAGS push 0x08; push[entryPoint]; EIP iretd } } }