在 include/unistd.h
中 添加 iam
,whoami
系统调用宏定义的编号,
#define __NR_sgetmask 68
#define __NR_ssetmask 69
#define __NR_setreuid 70
#define __NR_setregid 71
#define __NR_iam 72
#define __NR_whoami 73
kernel/system_call.s
# offsets within sigaction
sa_handler = 0
sa_mask = 4
sa_flags = 8
sa_restorer = 12nr_system_calls = 74
为新增的系统调用 添加 系统调用名 并维护 系统调用表,
include/linux/sys.h
extern int sys_setregid();
extern int sys_iam();
extern int sys_whoami();fn_ptr sys_call_table[] = { sys_setup, sys_exit, sys_fork, sys_read,
sys_write, sys_open, sys_close, sys_waitpid, sys_creat, sys_link,
sys_unlink, sys_execve, sys_chdir, sys_time, sys_mknod, sys_chmod,
sys_chown, sys_break, sys_stat, sys_lseek, sys_getpid, sys_mount,
sys_umount, sys_setuid, sys_getuid, sys_stime, sys_ptrace, sys_alarm,
sys_fstat, sys_pause, sys_utime, sys_stty, sys_gtty, sys_access,
sys_nice, sys_ftime, sys_sync, sys_kill, sys_rename, sys_mkdir,
sys_rmdir, sys_dup, sys_pipe, sys_times, sys_prof, sys_brk, sys_setgid,
sys_getgid, sys_signal, sys_geteuid, sys_getegid, sys_acct, sys_phys,
sys_lock, sys_ioctl, sys_fcntl, sys_mpx, sys_setpgid, sys_ulimit,
sys_uname, sys_umask, sys_chroot, sys_ustat, sys_dup2, sys_getppid,
sys_getpgrp, sys_setsid, sys_sigaction, sys_sgetmask, sys_ssetmask,
sys_setreuid,sys_setregid, sys_iam, sys_whoami };
为新增的系统调用编写代码实现, 在 linux-0.11/kernel
目录下, 创建一个who.c
的文件;
make
修改 Makefile 文件,
参见这里makefile 文件修改
重新 make
到/home/shiyanlou/os/oslab/linux-0.11
的路径下,
重新执行 make clean && make BootImage
,
以上两个文件需要放到启动后的linux-0.11操作系统上运行,才能验证新增的系统调用是否有效,
这里我们采用挂载方式实现宿主机与虚拟机操作系统的文件共享,
:~/Hit_os-main/hit-oslab-linux-20110823/oslab$ sudo ./mount-hdc
挂载之后, 则虚拟机的操作系统的文件系统 可以显示:
~/Hit_os-main/hit-oslab-linux-20110823/oslab/hdc$ pwd
/home/shiyanlou/Hit_os-main/hit-oslab-linux-20110823/oslab/hdc
shiyanlou@Lenovo-Legion:~/Hit_os-main/hit-oslab-linux-20110823/oslab/hdc$ ls
bin dev etc image Image mnt shoelace tmp usr var
拷贝文件
cp /home/shiyanlou/Hit_os-main/hit-oslab-linux-20110823/lab3_system_call/iam.c /home/shiyanlou/Hit_os-main/hit-oslab-linux-20110823/lab3_system_call/whoami.c hdc/usr/root
~/Hit_os-main/hit-oslab-linux-20110823/oslab/hdc/usr/root$ ls
gcclib140 hello.c iam.c linux0.tgz README shoelace.tar.Z
hello hello.o linux-0.00 mtools.howto shoe whoami.c
注意,需要关闭该终端, 才能启动 bochs
启动 bochs
虚拟机, 在该虚拟环境下, 编译并运行这两个测试程序;
上一篇:快速排序详解-java实现