示例#1
0
static DWORD PspThreadCutterThread(PVOID StartContext)
{
	HANDLE ProcessHandle, ThreadHandle;
	PTHREAD_CONTROL_BLOCK *pt_prev_thread, *pt_cur_thread;

	while(1) {
		/* check thread cutting list */
		if(!PspPopCuttingItem(&m_ThreadCuttingList, &ThreadHandle)) {
			HalTaskSwitch();
			continue;
		}

ENTER_CRITICAL_SECTION();
		ProcessHandle = PsGetThreadPtr(ThreadHandle)->parent_process_handle;

		/* if requsted thread's parent process handle is same with system process handle, then do nothing!! protect system thread */
		if(ProcessHandle == PsGetThreadPtr(PsGetCurrentThread())->parent_process_handle) {
			goto $exit;
		}

		/* invalid thread */
		if(PsGetProcessPtr(ProcessHandle)->thread_count == 0) {
			goto $exit;
		} 
		/* check whether there is only one thread exist in the parent process */
		else if(PsGetProcessPtr(ProcessHandle)->thread_count == 1) {
			PsGetProcessPtr(ProcessHandle)->pt_head_thread = NULL;
		}
		/* more than 2 threads exist */
		else {
			pt_prev_thread = pt_cur_thread = &(PsGetProcessPtr(ProcessHandle)->pt_head_thread);
			while(*pt_cur_thread != PsGetThreadPtr(ThreadHandle)) {
				/* there is no requested thread in the parent process */
				if((*pt_cur_thread)->pt_next_thread == NULL) {
					goto $exit;
				}
				pt_prev_thread = pt_cur_thread;
				pt_cur_thread = &((*pt_cur_thread)->pt_next_thread);
			}
			/* change next thread pointer */
			(*pt_prev_thread)->pt_next_thread = (*pt_cur_thread)->pt_next_thread;
		}
		PsGetProcessPtr(ProcessHandle)->thread_count--;

		/* except user mode program's stack */
		if(PsGetThreadPtr(ThreadHandle)->pt_stack_base_address >= (int *)0x00200000)
			MmFreeNonCachedMemory((PVOID)(PsGetThreadPtr(ThreadHandle)->pt_stack_base_address)); /* dealloc stack */
		MmFreeNonCachedMemory((PVOID)(PsGetThreadPtr(ThreadHandle))); /* dealloc thread */

$exit:
EXIT_CRITICAL_SECTION();
	}

	return 0;
}
示例#2
0
static DWORD PspProcessCutterThread(PVOID StartContext)
{
	HANDLE ProcessHandle;
	PPROCESS_CONTROL_BLOCK *pt_prev_process, *pt_cur_process;
	PTHREAD_CONTROL_BLOCK  *pt_cur_thread;

	while(1) {
		/* check process cutting list */
		if(!PspPopCuttingItem(&m_ProcessCuttingList, &ProcessHandle)) {
			HalTaskSwitch();
			continue;
		}

ENTER_CRITICAL_SECTION();
		/* if requsted process handle is same with system process handle, then do nothing!! protect system process */
		if(ProcessHandle == PsGetThreadPtr(PsGetCurrentThread())->parent_process_handle) {
			goto $exit;
		}

		/* find requested process position in the process list */
		pt_prev_process = pt_cur_process = &(m_ProcMgrBlk.pt_head_process);
		while(*pt_cur_process != PsGetProcessPtr(ProcessHandle)) {
			/* there is no requested process in the list */
			if((*pt_cur_process)->pt_next_process == NULL) {
				goto $exit;
			}
			pt_prev_process = pt_cur_process;
			pt_cur_process = &((*pt_cur_process)->pt_next_process);
		}

		/* change next process pointer */
		(*pt_prev_process)->pt_next_process = (*pt_cur_process)->pt_next_process;
		m_ProcMgrBlk.process_count--;

		/* dealloc all threads belonged to the requested process */
		pt_cur_thread = &(PsGetProcessPtr(ProcessHandle)->pt_head_thread);
		while(*pt_cur_thread != NULL) {
			MmFreeNonCachedMemory((PVOID)((*pt_cur_thread)->pt_stack_base_address));
			MmFreeNonCachedMemory((PVOID)(*pt_cur_thread));
			pt_cur_thread = &((*pt_cur_thread)->pt_next_thread);
		}

		/* dealloc the requested process memory */
		MmFreeNonCachedMemory((PVOID)ProcessHandle);

$exit:
EXIT_CRITICAL_SECTION();
	}

	return 0;
}
示例#3
0
文件: process.c 项目: alohays/mylysos
//종료된 쓰레드의 삭제
static DWORD PspThreadCutterThread(PVOID StartContext)
{
	HANDLE ProcessHandle, ThreadHandle;
	PTHREAD_CONTROL_BLOCK *pt_prev_thread, *pt_cur_thread;

	while(1) {
		if(!PspPopCuttingItem(&m_ThreadCuttingList, &ThreadHandle)) {
			HalTaskSwitch();
			continue;
		}
ENTER_CRITICAL_SECTION();
		ProcessHandle = PsGetThreadPtr(ThreadHandle)->parent_process_handle;

		if(ProcessHandle == PsGetThreadPtr(PsGetCurrentThread())->parent_process_handle) {
			goto $exit;
		}

		if(PsGetProcessPtr(ProcessHandle)->thread_count == 0) {
			goto $exit;
		}

		else if(PsGetProcessPtr(ProcessHandle)->thread_count == 1) {
			PsGetProcessPtr(ProcessHandle)->pt_head_thread = NULL;
		}

		else {
			pt_prev_thread = pt_cur_thread = &(PsGetProcessPtr(ProcessHandle)->pt_head_thread);
			while(*pt_cur_thread != PsGetThreadPtr(ThreadHandle)) {
				if((*pt_cur_thread)->pt_next_thread == NULL) {
					goto $exit;
				}
				pt_prev_thread = pt_cur_thread;
				pt_cur_thread = &((*pt_cur_thread)->pt_next_thread);
			}
			(*pt_prev_thread)->pt_next_thread = (*pt_cur_thread)->pt_next_thread;
		}
		PsGetProcessPtr(ProcessHandle)->thread_count--;

		if(PsGetThreadPtr(ThreadHandle)->pt_stack_base_address >= (int *)0x00200000)
			MmFreeNonCachedMemory((PVOID)(PsGetThreadPtr(ThreadHandle)->pt_stack_base_address));

		MmFreeNonCachedMemory((PVOID)(PsGetThreadPtr(ThreadHandle)));

$exit:
EXIT_CRITICAL_SECTION();
	}
}
示例#4
0
文件: process.c 项目: alohays/mylysos
//종료된 프로세스의 삭제
static DWORD PspProcessCutterThread(PVOID StartContext)
{
	HANDLE ProcessHandle;
	PPROCESS_CONTROL_BLOCK	*pt_prev_process, *pt_cur_process;
	PTHREAD_CONTROL_BLOCK	*pt_cur_thread;

	while(1) {
		if(!PspPopCuttingItem(&m_ProcessCuttingList, &ProcessHandle)) {
			HalTaskSwitch();
			continue;
		}
ENTER_CRITICAL_SECTION();
		if(ProcessHandle == PsGetThreadPtr(PsGetCurrentThread())->parent_process_handle) {
			goto $exit;
		}

		pt_prev_process = pt_cur_process = &(m_ProcMgrBlk.pt_head_process);
		while(*pt_cur_process != PsGetProcessPtr(ProcessHandle)) {
			if((*pt_cur_process)->pt_next_process == NULL) {
				goto $exit;
			}
			pt_prev_process = pt_cur_process;
			pt_cur_process = &((*pt_cur_process)->pt_next_process);
		}

		(*pt_prev_process)->pt_next_process = (*pt_cur_process)->pt_next_process;
		m_ProcMgrBlk.process_count--;

		pt_cur_thread = &(PsGetProcessPtr(ProcessHandle)->pt_head_thread);
		while(*pt_cur_thread != NULL) {
			MmFreeNonCachedMemory((PVOID)((*pt_cur_thread)->pt_stack_base_address));
			MmFreeNonCachedMemory((PVOID)(*pt_cur_thread));
			pt_cur_thread = &((*pt_cur_thread)->pt_next_thread);
		}

		MmFreeNonCachedMemory((PVOID)ProcessHandle);

$exit:
EXIT_CRITICAL_SECTION();
	}

	return 0;
}