new: 内核态fork

This commit is contained in:
fslongjin
2022-08-01 11:34:06 +08:00
parent 311a6181b5
commit 2fd21e0395
6 changed files with 135 additions and 27 deletions

View File

@ -3,7 +3,7 @@ CFLAGS += -I .
kernel_common_subdirs:=libELF math
all: glib.o printk.o cpu.o bitree.o kfifo.o wait_queue.o mutex.o wait.o
all: glib.o printk.o cpu.o bitree.o kfifo.o wait_queue.o mutex.o wait.o unistd.o
@list='$(kernel_common_subdirs)'; for subdir in $$list; do \
echo "make all in $$subdir";\
cd $$subdir;\
@ -33,4 +33,7 @@ mutex.o: mutex.c
gcc $(CFLAGS) -c mutex.c -o mutex.o
wait.o: sys/wait.c
gcc $(CFLAGS) -c sys/wait.c -o sys/wait.o
gcc $(CFLAGS) -c sys/wait.c -o sys/wait.o
unistd.o: unistd.c
gcc $(CFLAGS) -c unistd.c -o unistd.o

21
kernel/common/unistd.c Normal file
View File

@ -0,0 +1,21 @@
#include <common/unistd.h>
/**
* @brief fork当前进程
*
* @return pid_t
*/
pid_t fork(void)
{
return (pid_t)enter_syscall_int(SYS_FORK, 0, 0, 0, 0, 0, 0, 0, 0);
}
/**
* @brief vfork当前进程
*
* @return pid_t
*/
pid_t vfork(void)
{
return (pid_t)enter_syscall_int(SYS_VFORK, 0, 0, 0, 0, 0, 0, 0, 0);
}

View File

@ -12,3 +12,17 @@
#include <syscall/syscall.h>
#include <syscall/syscall_num.h>
/**
* @brief fork当前进程
*
* @return pid_t
*/
pid_t fork(void);
/**
* @brief vfork当前进程
*
* @return pid_t
*/
pid_t vfork(void);