Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c8e0148753 | |||
| ef8056ccd7 | |||
| e1113ec277 |
4 changed files with 29 additions and 3 deletions
|
|
@ -81,7 +81,7 @@ struct proc {
|
|||
int proc_kill(struct proc *proc, int signal);
|
||||
void proc_mmap(struct proc *proc, paddr_t p, vaddr_t v, size_t len, u64 flags);
|
||||
ssize_t proc_load_file(const char *file, struct proc *proc);
|
||||
struct proc *proc_create(struct proc *parent);
|
||||
struct proc *proc_create(struct thread *parent);
|
||||
void proc_free(struct proc *proc);
|
||||
void switch_to(struct thread *from, struct thread *to);
|
||||
void proc_init();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <stdbool.h>
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t num);
|
||||
void *memcpy_user(struct proc *proc, void *dest, const void *src, size_t num);
|
||||
int memcmp(const void *aa, const void *bb, size_t num);
|
||||
int strcmp(const char *a, const char *b);
|
||||
int strncmp(const char *a, const char *b, size_t n);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <arch/page.h>
|
||||
#include <arch/proc.h>
|
||||
#include <kernel/proc.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <lib/string.h>
|
||||
|
|
@ -55,6 +56,7 @@ static int copy_parent(struct proc *new, struct proc *parent)
|
|||
|
||||
void *vm_alloc = proc_alloc(new, area->len);
|
||||
proc_mmap(new, TO_PHYS(vm_alloc), area->start, area->len, area->flags);
|
||||
memcpy_user(parent, (void *)area->start, vm_alloc, area->len);
|
||||
|
||||
node = rbt_successor(node);
|
||||
}
|
||||
|
|
@ -64,7 +66,7 @@ static int copy_parent(struct proc *new, struct proc *parent)
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct proc *proc_create(struct proc *parent)
|
||||
struct proc *proc_create(struct thread *parent)
|
||||
{
|
||||
struct proc *ret = slab_alloc(proc_slab);
|
||||
if (!ret)
|
||||
|
|
@ -104,7 +106,7 @@ struct proc *proc_create(struct proc *parent)
|
|||
ret->main_thread = r_mt;
|
||||
|
||||
if (parent) {
|
||||
int res = copy_parent(ret, parent);
|
||||
int res = copy_parent(ret, parent->proc);
|
||||
if (res)
|
||||
kerr("failed to copy parent memmap for new process: %s\n", strerror(-res));
|
||||
}
|
||||
|
|
@ -112,6 +114,12 @@ struct proc *proc_create(struct proc *parent)
|
|||
return ret;
|
||||
}
|
||||
|
||||
pid_t sys_fork()
|
||||
{
|
||||
struct thread *cur_thread = get_cur_thread();
|
||||
struct proc *ret = proc_create(cur_thread);
|
||||
}
|
||||
|
||||
void proc_free(struct proc *proc)
|
||||
{
|
||||
slab_free(proc_slab, proc);
|
||||
|
|
|
|||
17
lib/string.c
17
lib/string.c
|
|
@ -1,6 +1,8 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <kernel/types.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <kernel/proc.h>
|
||||
#include <arch/page.h>
|
||||
#include <lib/string.h>
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t num)
|
||||
|
|
@ -245,3 +247,18 @@ char *basename(const char *path)
|
|||
kfree(copy);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *memcpy_user(struct proc *proc, void *dest, const void *src, size_t num)
|
||||
{
|
||||
pgd_t *pgd = pgd_get();
|
||||
|
||||
if (pgd != proc->pgd)
|
||||
pgd_load(proc->pgd);
|
||||
|
||||
memcpy(dest, src, num);
|
||||
|
||||
if (pgd != proc->pgd)
|
||||
pgd_load(pgd);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue