Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/kernel/kernel/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void schedule(uint32_t ticks);

// process gestion
int process_create(void *func, int copy_page, int nargs, uint32_t *args);
int process_create_user(void *func, int nargs, uint32_t *args);
int process_fork(registers_t *regs);
int process_wakeup(uint32_t pid, int handover);
int process_sleep(uint32_t pid, uint32_t ms);
Expand Down
2 changes: 1 addition & 1 deletion include/kernel/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// build settings

#define KERNEL_VERSION "1.3.2"
#define KERNEL_VERSION "1.3.3"
#define KERNEL_EDITING "generic"

#define PROCESS_MAX 200 // max process count
Expand Down
4 changes: 2 additions & 2 deletions include/zlibs/profan/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int syscall_sc_get(void);
int syscall_sys_power(int);
int syscall_elf_exec(uint32_t, char **, char **);

int syscall_process_create(void *, int, int, uint32_t *);
int syscall_process_create(void *, int, uint32_t *);
int syscall_process_fork(void);
int syscall_process_sleep(uint32_t, uint32_t);
int syscall_process_wakeup(uint32_t, int);
Expand Down Expand Up @@ -141,7 +141,7 @@ extern int profan_syscall(uint32_t id, ...);
#define syscall_sys_power(a) ((int) profan_syscall(22, a))
#define syscall_elf_exec(a, b, c) ((int) profan_syscall(23, a, b, c))

#define syscall_process_create(a, b, c, d) ((int) profan_syscall(24, a, b, c, d))
#define syscall_process_create(a, c, d) ((int) profan_syscall(24, a, c, d))
#define syscall_process_fork() ((int) profan_syscall(25))
#define syscall_process_sleep(a, b) ((int) profan_syscall(26, a, b))
#define syscall_process_wakeup(a, b) ((int) profan_syscall(27, a, b))
Expand Down
2 changes: 1 addition & 1 deletion kernel/kpart/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
elf_exec, // 23

// process.h + runtime.h
process_create, // 24
process_create_user, // 24

Check failure on line 67 in kernel/kpart/syscall.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Either add a parameter list or the "&" operator to this use of "process_create_user".

See more on https://sonarcloud.io/project/issues?id=elydre_profanOS&issues=AZy9ufvMSc9WqdI6lWdn&open=AZy9ufvMSc9WqdI6lWdn&pullRequest=89
process_fork, // 25
process_sleep, // 26
process_wakeup, // 27
Expand Down
51 changes: 29 additions & 22 deletions kernel/system/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@
}


int process_create(void *func, int copy_page, int nargs, uint32_t *args) {
process_t *process_create_func(void *func, int copy_page, int nargs, uint32_t *args, int in_kernel) {
int place = i_get_free_place(g_pid_incrament + 1);

if (place == ERROR_CODE) {
sys_warning("[create] Too many processes");
return ERROR_CODE;
return NULL;
}

g_pid_incrament++;
Expand All @@ -295,7 +295,7 @@
new_proc->pid = g_pid_incrament;
new_proc->ppid = g_proc_current->pid;

new_proc->in_kernel = (uint32_t) func < 0x200000;
new_proc->in_kernel = in_kernel;
new_proc->state = PROC_STATE_SLP;

void *phys_stack;
Expand All @@ -311,7 +311,7 @@
i_new_process(new_proc, func, g_proc_current->regs.eflags, (uint32_t *) new_proc->scuba_dir);

if (func == NULL) {
return g_pid_incrament;
return new_proc;
}

// push arguments to the new process
Expand All @@ -327,33 +327,40 @@

new_proc->regs.esp = PROC_ESP_ADDR + PROC_ESP_SIZE - (nargs + 1) * sizeof(uint32_t);

return g_pid_incrament;
return new_proc;
}

int process_create(void *func, int copy_page, int nargs, uint32_t *args) {
// the function is used by the kernel only
process_t *proc = process_create_func(func, copy_page, nargs, args, 1);

Check warning on line 335 in kernel/system/process.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this variable a pointer-to-const. The current type of "proc" is "process_t *".

See more on https://sonarcloud.io/project/issues?id=elydre_profanOS&issues=AZy9ufxlSc9WqdI6lWdo&open=AZy9ufxlSc9WqdI6lWdo&pullRequest=89
return proc ? (int) proc->pid : ERROR_CODE;
}

int process_create_user(void *func, int nargs, uint32_t *args) {
// the function is used by the user processes only
process_t *proc = process_create_func(func, 1, nargs, args, 0);

Check warning on line 341 in kernel/system/process.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this variable a pointer-to-const. The current type of "proc" is "process_t *".

See more on https://sonarcloud.io/project/issues?id=elydre_profanOS&issues=AZy9ufxlSc9WqdI6lWdp&open=AZy9ufxlSc9WqdI6lWdp&pullRequest=89
return proc ? (int) proc->pid : ERROR_CODE;
}

int process_fork(registers_t *regs) {
int new_pid = process_create(NULL, 1, 0, NULL);
process_t *proc = process_create_func(NULL, 1, 0, NULL, 0); // fork can be call only trough a syscall

if (new_pid == ERROR_CODE) {
if (proc == NULL) {
return ERROR_CODE;
}

process_t *new_proc = &g_plist[i_pid_to_place(new_pid)];

new_proc->in_kernel = 0; // cannot call this without a syscall

new_proc->regs.eax = regs->eax;
new_proc->regs.ebx = regs->ebx;
new_proc->regs.ecx = regs->ecx;
new_proc->regs.edx = regs->edx;
new_proc->regs.esi = regs->esi;
new_proc->regs.edi = regs->edi;
new_proc->regs.eip = regs->eip;
new_proc->regs.esp = regs->esp + 20; // popa (interrupt.asm: isr_common_stub)
new_proc->regs.ebp = regs->ebp;
new_proc->regs.eflags = regs->eflags;
proc->regs.eax = regs->eax;
proc->regs.ebx = regs->ebx;
proc->regs.ecx = regs->ecx;
proc->regs.edx = regs->edx;
proc->regs.esi = regs->esi;
proc->regs.edi = regs->edi;
proc->regs.eip = regs->eip;
proc->regs.esp = regs->esp + 20; // popa (interrupt.asm: isr_common_stub)
proc->regs.ebp = regs->ebp;
proc->regs.eflags = regs->eflags;

return new_pid;
return proc->pid;
}


Expand Down