#include "fd.h"
#include "sched.h"
+/* FIXME: Remove struct stack_frame from process.c */
+struct stack_frame {
+ u32_t cr3;
+ u32_t ds;
+ u32_t edi;
+ u32_t esi;
+ u32_t ebp;
+ u32_t esp;
+ u32_t ebx;
+ u32_t edx;
+ u32_t ecx;
+ u32_t eax;
+ u32_t intn;
+ u32_t error;
+ u32_t eip;
+ u32_t cs;
+ u32_t eflags;
+ u32_t prevesp;
+ u32_t ss;
+} __attribute__((packed));
+
enum procstate {
PROC_STATE_INIT = 0,
PROC_STATE_READY,
struct task *p_tasks;
u32_t p_privl;
pid_t p_id;
+ pid_t p_pid;
struct {
struct cxmsg *msg;
return(ret_val);
}
+void* task_get_eip3(void);
+
int process_create(process_t **dst, pid_t pid, u32_t ppl, void *entry)
{
int ret_val;
process_t *proc;
+ pid_t ppid;
ret_val = -ENOMEM;
proc = NULL;
+ ppid = 1;
/* was a specific pid requested? */
if(pid != PID_ANY) {
}
}
+ if(entry == PROC_ENTRY_FORK ||
+ entry == PROC_ENTRY_VFORK) {
+ task_t *ctask;
+
+ /* inherit the ppl from the current task, in the case of fork and vfork */
+ ctask = task_get_current();
+ ppl = ctask->t_privl;
+ ppid = ctask->t_pid;
+ }
+
proc = kmalloc(sizeof(*proc));
if(proc) {
}
proc->p_privl = ppl;
+ proc->p_pid = ppid;
if(pid == PID_ANY) {
/* no specific pid requested */
proc->p_id = pid;
}
+ if(entry == PROC_ENTRY_FORK ||
+ entry == PROC_ENTRY_VFORK) {
+ struct stack_frame *stack0;
+ task_t *ctask;
+
+ ctask = task_get_current();
+
+ /*
+ * In the case of fork() and vfork() we have to get the address that the
+ * interrupt is supposed to return to. The stack that the address was pushed
+ * onto is located at ctask->t_kstack.
+ */
+
+ stack0 = ((struct stack_frame*)(ctask->t_kstack + CONFIG_KERNEL_STACK_SIZE)) - 1;
+
+ entry = (void*)stack0->eip;
+ dbg_printf("entry = 0x%08x\n", (u32_t)entry);
+
+ for(;;);
+ }
+
task_prepare(proc->p_tasks, (u32_t)pdbr, (u32_t)entry,
(u32_t)kstack + CONFIG_KERNEL_STACK_SIZE,
(u32_t)ustack + CONFIG_USER_STACK_SIZE, ppl);
return(ret_val);
}
+
+int process_fork(int v)
+{
+ process_t *proc;
+ int ret_val;
+
+ proc = process_get_current();
+ ret_val = -EFAULT;
+
+ if(proc) {
+ process_t *nproc;
+
+ ret_val = process_create(&nproc, PID_ANY, proc->p_privl, PROC_ENTRY_FORK);
+ }
+
+ return(ret_val);
+}
#include <corax/types.h>
#include <corax/ipc.h>
+#define PROC_ENTRY_FORK ((void*)0)
+#define PROC_ENTRY_VFORK ((void*)1)
+
typedef struct process process_t;
int process_create(process_t**, pid_t, u32_t, void*);
void* process_get_tasks(process_t*);
pid_t process_get_id(process_t*);
int process_exit(process_t*, int);
+int process_fork(int);
#endif /* __PROCESS_H */