剛剛試著要增加一個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程式阿ˊˋ
請教一下各位是哪裡出錯了呢?
先謝謝各位摟:)
--
一開始先進到 /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