gpt4 book ai didi

c - ubuntu 12.04 无法成功添加系统调用

转载 作者:行者123 更新时间:2023-11-30 17:38:45 24 4
gpt4 key购买 nike

我正在关注this article添加系统调用。遵循所有步骤,没有任何问题。是的,其中缺少一个步骤,即 ma​​ke 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,但我没有看到我的系统调用被调用。

知道这里出了什么问题吗?

操作系统。是 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

最佳答案

您应该添加行

定义__NR_hello_world 350

在拱门/x86/include/asm/unistd_32.h

在内核表中添加条目 #sudo gedit arch/x86/syscalls/syscall_64.tbl

在 64 位表条目末尾写入以下内容。

350 常见的你好 sys_hello

关于c - ubuntu 12.04 无法成功添加系统调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22041910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com