Linux2.6.28.1 增加 system call - Linux

Table of Contents

剛剛試著要增加一個system call
一開始先進到 /usr/src/linux-2.6.28.1/usr/include/asm/unistd_32.h
在裡面最後一筆增加一個system call number
#define __NR_helloworld 333

然後再來到 /usr/src/linux-2.6.28.1/arch/x86/kernel/syscall_table_32.S
在最後面增加 .long sys_helloworld

接著到 /usr/include/asm/unistd_32.h
也在最後面增加一筆 #define __NR_helloworld 333

然後到/usr/src/linux-2.6.28.1/arch/x86/kernel/
新增一個helloworld.c檔
裡面程式碼是這樣
#include <linux/linkage.h>
#include <linux/kernel.h>
asmlinkage int sys_helloworld() {
printk("******hello world!******");
return 0;
}
然後在Makefile 增加obj-y += helloworld.o

接著就到/usr/src/linux-2.6.28.1裡進行編譯
執行make install

然後也成功編譯沒有產生error
就產生一個test.c來跑
程式如下
#define __KERNEL__
#include <sys/syscall.h>
#include <linux/unistd.h>
#include <errno.h>

#undef __KERNEL__

//_syscall0(int,helloworld);/*因為版本關係不能用這行的樣子..*/

int helloworld()/*所以先定義*/
{
return syscall(__NR_helloworld);
};


int main(void)
{
helloworld();
}

然後也成功編譯過
gcc test.c -o test.o
執行./test.o
然後再輸入
dmesg
結果跑了很多很多東西出來
但就是沒有******hello world!******

到底是哪裡出現問題ˊˋ
因為中間沒有編譯錯誤我不知道該如何下手找起ˊˋ
因為應該只是個小小的system call程式阿ˊˋ
請教一下各位是哪裡出錯了呢?
先謝謝各位摟:)

--

All Comments

Doris avatarDoris2009-04-06
加上errno以後出現Function not implemented.
Puput avatarPuput2009-04-10
應該是沒有把syscall的大小增加....只是找不到在哪個檔
裡面真冏...
Ingrid avatarIngrid2009-04-14
請問第一步的unistd_32.h是在哪裡找到的? usr下沒有include
Lily avatarLily2009-04-19
我的底下有耶 版本一樣媽?
Daniel avatarDaniel2009-04-19
沒有耶,2.6.28我應該是沒看錯..., 但是官方的LXR上也沒有
Rosalind avatarRosalind2009-04-23
ˊˋ
Enid avatarEnid2009-04-27
dmesg | tail