我正在关注this article添加系统调用。遵循所有步骤没有任何问题。是的,那里缺少一步, make menuconfig
但是,当我运行以下代码时,我收到错误:
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
#define __NR_hello_world 312
long hello_world_syscall(void) {
return syscall(__NR_hello_world);
}
int main(int argc, char*argv[])
{
long int a = hello_world_syscall();
printf("System call returned %ld\n", a);
return 0;
}
错误
System call returned -1
我注意到在arch / x86 / include / asm / unistd_32.h
中#define __NR_process_vm_readv 347
#define __NR_process_vm_writev 348
#define __NR_hello_world 349 /*added by me, but I see 349 is also given below*/
#ifdef __KERNEL__
#define NR_syscalls 349
#define __ARCH_WANT_IPC_PARSE_VERSION
#define __ARCH_WANT_OLD_READDIR
#define __ARCH_WANT_OLD_STAT
#define __ARCH_WANT_STAT64
是不是错了?
同样在arch / x86 / include / asm / unistd_64.h
中__SYSCALL(__NR_process_vm_readv, sys_process_vm_readv)
#define __NR_process_vm_writev 311
__SYSCALL(__NR_process_vm_writev, sys_process_vm_writev)
/*added by me*/
#define __NR_hello_world 312
__SYSCALL(__NR_hello_world, sys_hello_world)
#ifndef __NO_STUBS
#define __ARCH_WANT_OLD_READDIR
#define __ARCH_WANT_OLD_STAT
#define __ARCH_WANT_SYS_ALARM
#define __ARCH_WANT_SYS_GETHOSTNAME
#define __ARCH_WANT_SYS_PAUSE
#define __ARCH_WANT_SYS_SGETMASK
#define __ARCH_WANT_SYS_SIGNAL
我也在endif
之前编辑了文件:include / linux / syscalls.h unsigned long liovcnt,
const struct iovec __user *rvec,
unsigned long riovcnt,
unsigned long flags);
asmlinkage long sys_process_vm_writev(pid_t pid,
const struct iovec __user *lvec,
unsigned long liovcnt,
const struct iovec __user *rvec,
unsigned long riovcnt,
unsigned long flags);
asmlinkage long sys_hello_world(void); /*added by me*/
#endif
以上两个文件都在我下载的源代码中,然后进行编译和安装。
我也做过dmesg,但是我无处可见系统调用。
知道这里有什么问题吗?
OS。是Ubuntu 12.04,内核是:
Linux ubuntu 3.8.0-29-generic #42~precise1-Ubuntu SMP Wed Aug 14 16:19:23 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
答案 0 :(得分:0)
你应该添加行
在 拱/ 86 /包含/ ASM / unistd_32.h
在内核表中添加条目 #sudo gedit arch / x86 / syscalls / syscall_64.tbl
在64位表条目的末尾写下。
350 common hello sys_hello