void _declspec(naked) CPlayerPed__ProcessInput_Hook() { _asm { mov m_pPed, ecx pushad } //CLogFile::Printf("CPlayerPed__ProcessInput Pre"); ContextSwitch(m_pPed, false); _asm { popad call COffsets::FUNC_CPlayerPed__ProcessInput pushad } ContextSwitch(m_pPed, true); //CLogFile::Printf("CPlayerPed__ProcessInput Post"); _asm { popad retn } }
void _declspec(naked) CPlane_ProcessInput_Hook() { _asm { mov m_pKeySyncIVVehicle, ecx pushad } ContextSwitch(m_pKeySyncIVVehicle->m_pDriver, false); _asm { popad call COffsets::FUNC_CPlane__ProcessInput pushad } ContextSwitch(m_pKeySyncIVVehicle->m_pDriver, true); _asm { popad retn } }
void _declspec(naked) CPlayerPed__ProcessInput_Hook() { _asm { mov g_pPed, ecx pushad } ContextSwitch(g_pPed, false); _asm { popad call COffsets::FUNC_CPlayerPed__ProcessInput pushad } ContextSwitch(g_pPed, true); _asm { popad ret } }
// // Schedule a new thread to run // static FORCEINLINE VOID Schedule () { PUTHREAD NextThread; NextThread = ExtractNextReadyThread(); ContextSwitch(RunningThread, NextThread); }
void _declspec(naked) CPlayerPed__ProcessInput_Hook() { _asm mov g_pPed, ecx; _asm pushad; ContextSwitch(g_pPed, false); _asm popad; _asm call COffsets::FUNC_CPlayerPed__ProcessInput; _asm pushad; ContextSwitch(g_pPed, true); _asm popad; _asm ret; }
void _declspec(naked) CPlane_ProcessInput_Hook() { _asm mov g_pKeySyncIVVehicle, ecx; _asm pushad; ContextSwitch(g_pKeySyncIVVehicle->m_pDriver, false); _asm popad; _asm call COffsets::FUNC_CPlane__ProcessInput; _asm pushad; ContextSwitch(g_pKeySyncIVVehicle->m_pDriver, true); _asm popad; _asm ret; }
NORETURN void CreateSession(struct NaClApp *nap) { uintptr_t stack_ptr; assert(nap != NULL); /* set up user stack */ stack_ptr = nap->mem_start + ((uintptr_t)1U << nap->addr_bits); stack_ptr -= STACK_USER_DATA_SIZE; memset((void*)stack_ptr, 0, STACK_USER_DATA_SIZE); ((uint32_t*)stack_ptr)[4] = 1; ((uint32_t*)stack_ptr)[5] = 0xfffffff0; /* * construct "nacl_user" and "nacl_sys" globals * note: nacl_sys->prog_ctr meaningless but should not be 0 */ ThreadContextCtor(nacl_user, nap, nap->initial_entry_pt, stack_ptr); ThreadContextCtor(nacl_sys, nap, 1, GetStackPtr()); /* pass control to the user side */ ZLOGS(LOG_DEBUG, "SESSION %d STARTED", nap->manifest->node); ContextSwitch(nacl_user); ZLOGFAIL(1, EFAULT, "the unreachable has been reached"); }
extern int KernelFork(void) { TracePrintf(256, "Fork\n"); struct PCBNode cur_active = *active_process; struct PCBNode* newproc = malloc(sizeof(struct PCBNode)); if(newproc == NULL) return ERROR; newproc = (struct PCBNode *)malloc(sizeof(struct PCBNode)); newproc -> PID = nextPID(); //will need to change this thing later newproc -> pageTable = malloc(PAGE_TABLE_LEN * sizeof(struct pte)); newproc -> status = READY; newproc -> blockedReason = 0; newproc -> numTicksRemainForDelay = 0; newproc -> parent = NULL; newproc -> child = NULL; newproc -> prevSibling = NULL; newproc -> nextSibling = NULL; TracePrintf(100, "Fork enter context switch\n"); ContextSwitch(forkSwitchFunc, &(cur_active.ctxp), &cur_active, newproc); TracePrintf(100, "Fork left context switch\n"); if(cur_active.PID == active_process->PID){ //return from parent return newproc->PID; }else{ //this is returning from child, which means we should maintain the child queue return 0; } return 0; }
// // Schedule a new thread to run // static FORCEINLINE VOID Schedule() { PUTHREAD NextThread; //switchCount++; NextThread = ExtractNextReadyThread(); RunningThread->State = READY; NextThread->State = RUNNING; ContextSwitch(RunningThread, NextThread); }
// Selects the next task and performs a context switch void Scheduler::resched() { Task *oldTask ; Task *newTask ; // remove highest priority task from readyList if (!readyList.isEmpty()) { newTask = (Task *)readyList.removeFront() ; } else { this->relinquish(); //newTask = (Task *)readyList[LOWEST_PRIORITY].removeFront() ; } // If calling task is still the highest priority just return if (newTask == activeTask) { activeTask->makeTaskActive() ; return ; } oldTask = activeTask ; activeTask = newTask ; activeTask->makeTaskActive() ; // a context switch is necessary - clear interrupts while we do this // interrupts are reenabled when the new task is swapped in cli() ; /*** sei() ; Printf("about to context switch\n") ; if (oldTask != NULL) Printf("from root ptr=%x, SP=%x \n", oldTask->rootFn, oldTask->pStack) ; Printf("to root ptr=%x, SP=%x \n", newTask->rootFn, newTask->pStack) ; cli() ; ***/ // swap the new task in // if it is the first run, then use processor state from current task // otherwise get processor state from the stack of its previous swap out // if the oldTask is NULL then this is the first time we've ever done // a task switch, and we don't try to save the context (IOW, the stack // state of main() is abandoned on the first task switch) int firstRun = activeTask->firstRun ; activeTask->firstRun = FALSE ; if (oldTask != NULL) { ContextSwitch(&oldTask->pStack, activeTask->pStack, firstRun) ; } else { FirstSwitch(activeTask->pStack) ; } }
extern void trapClock(ExceptionStackFrame *exceptionStackFrame) { TracePrintf(512, "trapClock: vector(%d), code(%d), addr(%d), psr(%d), pc(%d), sp(%d), regs(%s)\n", exceptionStackFrame->vector, exceptionStackFrame->code, exceptionStackFrame->addr, exceptionStackFrame->psr, exceptionStackFrame->pc, exceptionStackFrame->sp, exceptionStackFrame->regs); if(active_process->PID == 0) { clockCount = 1; // //TracePrintf(510, "Waiting for the next trap clock to do context switch\n"); ContextSwitch(generalSwitchFunc, &(active_process->ctxp), active_process,init); TracePrintf(510, "Trap_clock: switch from idle to init\n"); } else { clockCount = 0; ContextSwitch(generalSwitchFunc, &(active_process->ctxp), active_process, idle); TracePrintf(510, "Trap_clock: switch from init to idle\n"); } }
void mrtk_sched() { Uint16 cpuid = 0, hghrdytask = 0, runtask = 0; /* we disable all interrupts */ mrtk_begincriticalsection(); cpuid = mrtk_GetCpuId(); hghrdytask = mrtk_GetTaskWithNearestDeadline(cpuid, READY_TASKS_QUEUE); runtask = RunningTasks[cpuid]; if( hghrdytask != runtask ) { /* we remove the highest priority task in ready queue */ mrtk_RemoveFirstElementInQueue(cpuid, READY_TASKS_QUEUE); /* we get the stack pointer of each tack*/ TaskToExecuteSP = (Uint32*)&(TaskTcbTable[hghrdytask].StartStkptr); TaskToSleepSP = (Uint32*)&(TaskTcbTable[runtask].StartStkptr); /* we re-insert the task in ready queue, if it is an unsollicited preemption */ if (TaskTcbTable[runtask].TaskId <= NB_USERS_TASK_MAX && TaskTcbTable[runtask].State == EXECUTING ) { TaskTcbTable[runtask].State = READY; mrtk_InsertInQueue(cpuid, TaskTcbTable[runtask].TaskId, TaskTcbTable[runtask].AbsoluteDeadline , READY_TASKS_QUEUE); } /* we set the highest ready task state to executing, before performing the context switch */ if (TaskTcbTable[hghrdytask].TaskId <= NB_USERS_TASK_MAX && TaskTcbTable[hghrdytask].State == READY ) { TaskTcbTable[hghrdytask].State = EXECUTING; } /* we set the new running task in this processor */ RunningTasks[cpuid] = hghrdytask; ContextSwitch(); } else {/* no scheduling is needed!*/ } mrtk_endcriticalsection(); }
void idle() { for (;;) { ContextSwitch(); } }