标签:内核 highlight segment 实验环境 访问 file err 内容 博客
extern int sys_iaml extern int sys_whoami
添加sys_call_table表项:
sys_iam,sys_whoami
typedef int (fn_ptr*)();
sys_call_table是中断服务程序调用系统调用要查的表。表项是函数指针,长度为4字节。中断服务程序执行call来调用系统调用:
call _sys_call_table(,%eax,4) //a(,%eax,4)=a+4*eax , 每个表项4字节所以第i个系统调用的偏移是i*4
2.linux-0.11/kernel下的system_call.s,将nr_system_calls修改为74(添加了两个系统调用)
2)添加一行
who.s who.o: who.c ../include/linux/kernel.h ../include/unistd.h //图错了!!!! //图中who.o后面少了个冒号!!!!
4.系统调用编号使用的宏定义,例如在unistd.g中 :
#define NR_CLOSE 6 //close是sys_call_table第7个
添加系统调用需要修改unistd.h文件,不能直接在机器中修改而是在虚拟机文件系统中修改
Tip: 1.命令模式下/__NR ---->命令模式下 /+要查找的字符可以快速定位,n是下一个,N是上一个 2.‘ __NR ‘的_是shift加-,这里有两个‘_‘
然后添加:
#define __NR_iam 72 #define __NR_whoami 73
然后在linux-0.11/kernel下添加who.c,包含两个 系统调用
#define __LIBRARY__ #include <unistd.h> #include <errno.h>
#include <asm/segment.h> char temp[64]={0}; int sys_iam(const char* name) { int i=0; while(get_fs_byte(name+i)!=‘\0‘) i++; if(i>23){ return -EINVAL; } printk("%d\n",i); i=0; while((temp[i]=get_fs_byte(name+i))!=‘\0‘){ i++; } return i; }
int sys_whoami(char* name,unsigned int size) { int i=0; while (temp[i]!=‘\0‘) i++; if (size<i) return -1; i=0; while(temp[i]!=‘\0‘){ put_fs_byte(temp[i],(name+i)); i++; } return i; }
2)iam.c
gcc iam.c -o iam gcc whoami.c -o whoami
标签:内核 highlight segment 实验环境 访问 file err 内容 博客
原文地址:https://www.cnblogs.com/coderlynn/p/9127632.html