Adding title to process structure and create default kernel process

This commit is contained in:
Ali Mashtizadeh 2015-01-22 10:08:09 -08:00
parent fa1b3c9ed2
commit 7aaf5cbc5f
3 changed files with 29 additions and 8 deletions

View File

@ -50,6 +50,7 @@ typedef struct Thread {
} Thread;
#define PROCESS_HANDLE_SLOTS 128
#define PROCESS_TITLE_LENGTH 128
typedef struct Process {
uint64_t pid;
@ -57,6 +58,7 @@ typedef struct Process {
uintptr_t ustackNext; // Next user stack
TAILQ_ENTRY(Process) processList;
uint64_t refCount;
char title[PROCESS_TITLE_LENGTH];
// Process
Process *parent;
TAILQ_ENTRY(Process) siblingList;
@ -76,7 +78,7 @@ typedef struct Process {
void Thread_Init();
// Process functions
Process *Process_Create();
Process *Process_Create(const char *title);
Process *Process_Lookup(uint64_t pid);
void Process_Retain(Process *proc);
void Process_Release(Process *proc);

View File

@ -91,7 +91,7 @@ Syscall_Spawn(uint64_t user_path)
return status;
}
proc = Process_Create();
proc = Process_Create(path);
thr = Thread_Create(proc);
Log(syscall, "SPAWN %lx\n", thr);

View File

@ -19,6 +19,7 @@ Spinlock threadLock;
uint64_t nextProcessID;
uint64_t nextThreadID;
Thread *curProc;
Process *kernelProcess;
// Scheduler Queues
Spinlock schedLock;
@ -51,8 +52,11 @@ Thread_Init()
Handle_GlobalInit();
// Kernel Process
kernelProcess = Process_Create("kernel");
// Create an thread object for current context
Process *proc = Process_Create();
Process *proc = Process_Create("init");
curProc = Thread_Create(proc);
curProc->schedState = SCHED_STATE_RUNNING;
}
@ -62,7 +66,7 @@ Thread_Init()
*/
Process *
Process_Create()
Process_Create(const char *title)
{
Process *proc = (Process *)Slab_Alloc(&processSlab);
@ -76,6 +80,12 @@ Process_Create()
proc->refCount = 1;
TAILQ_INIT(&proc->threadList);
if (title) {
strncpy((char *)&proc->title, title, PROCESS_TITLE_LENGTH);
} else {
proc->title[0] = '\0';
}
proc->space = PMap_NewAS();
if (proc->space == NULL) {
Slab_Free(&processSlab, proc);
@ -96,6 +106,7 @@ Process_Create()
static void
Process_Destroy(Process *proc)
{
Slab_Free(&processSlab, proc);
}
Process *
@ -182,7 +193,7 @@ Thread_Create(Process *proc)
Thread *
Thread_KThreadCreate(void (*f)(void *), void *arg)
{
Thread *thr = Thread_Create(NULL);
Thread *thr = Thread_Create(kernelProcess);
if (!thr)
return NULL;
@ -232,16 +243,23 @@ Thread_UThreadCreate(Thread *oldThr, uint64_t rip, uint64_t arg)
static void
Thread_Destroy(Thread *thr)
{
Process *proc = thr->proc;
// Free userspace stack
if (thr->proc) {
thr->proc->threads--;
TAILQ_REMOVE(&thr->proc->threadList, thr, threadList);
if (proc) {
proc->threads--;
TAILQ_REMOVE(&proc->threadList, thr, threadList);
}
// Free AS
PAlloc_Release((void *)thr->kstack);
Slab_Free(&threadSlab, thr);
// Release process handle
if (proc) {
//Process_Release(thr->proc);
}
}
Thread *
@ -424,6 +442,7 @@ ThreadKThreadEntry(TrapFrame *tf)
void
Process_Dump(Process *proc)
{
kprintf("title %s\n", proc->title);
kprintf("pid %llu\n", proc->pid);
kprintf("space %016llx\n", proc->space);
kprintf("threads %llu\n", proc->threads);