proc: add memcpy_user to copy_parent
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
e1113ec277
commit
ef8056ccd7
2 changed files with 11 additions and 3 deletions
|
|
@ -81,7 +81,7 @@ struct proc {
|
||||||
int proc_kill(struct proc *proc, int signal);
|
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);
|
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);
|
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 proc_free(struct proc *proc);
|
||||||
void switch_to(struct thread *from, struct thread *to);
|
void switch_to(struct thread *from, struct thread *to);
|
||||||
void proc_init();
|
void proc_init();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
#include <arch/page.h>
|
#include <arch/page.h>
|
||||||
|
#include <arch/proc.h>
|
||||||
#include <kernel/proc.h>
|
#include <kernel/proc.h>
|
||||||
#include <kernel/slab.h>
|
#include <kernel/slab.h>
|
||||||
#include <lib/string.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);
|
void *vm_alloc = proc_alloc(new, area->len);
|
||||||
proc_mmap(new, TO_PHYS(vm_alloc), area->start, area->len, area->flags);
|
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);
|
node = rbt_successor(node);
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +66,7 @@ static int copy_parent(struct proc *new, struct proc *parent)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct proc *proc_create(struct proc *parent)
|
struct proc *proc_create(struct thread *parent)
|
||||||
{
|
{
|
||||||
struct proc *ret = slab_alloc(proc_slab);
|
struct proc *ret = slab_alloc(proc_slab);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
|
|
@ -104,7 +106,7 @@ struct proc *proc_create(struct proc *parent)
|
||||||
ret->main_thread = r_mt;
|
ret->main_thread = r_mt;
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
int res = copy_parent(ret, parent);
|
int res = copy_parent(ret, parent->proc);
|
||||||
if (res)
|
if (res)
|
||||||
kerr("failed to copy parent memmap for new process: %s\n", strerror(-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;
|
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)
|
void proc_free(struct proc *proc)
|
||||||
{
|
{
|
||||||
slab_free(proc_slab, proc);
|
slab_free(proc_slab, proc);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue