My initial attempts to build a system call with the help of this question
我最初尝试在这个问题的帮助下建立一个系统调用
My distro information: Linux linux-epq2.site 3.7.10-1.16-default #1 SMP Fri May 31 20:21:23 UTC 2013 (97c14ba) x86_64 x86_64 x86_64 GNU/Linux
我的发行信息:Linux linux-epq2.site 3.7.10-1.16-default#1 SMP Fri May 31 20:21:23 UTC 2013(97c14ba)x86_64 x86_64 x86_64 GNU / Linux
In the current version of my program, that will allow me to embed this as a system call does have a main (stupidity to even say that, but just to make things more explicit).
在我的程序的当前版本中,这将允许我嵌入这个作为系统调用确实有一个主要(愚蠢甚至说,但只是为了使事情更明确)。
In my current program:
在我目前的计划中:
It takes in two inputs from the user, and does some calculations and gives the output as the graph and some data.
它接收来自用户的两个输入,并进行一些计算并将输出作为图形和一些数据。
My initial attempt was to call that program via execlp
available in unistd
library like this:
我最初的尝试是通过execlp在unistd库中调用该程序,如下所示:
#include<linux/linkage.h>
#include<linux/kernel.h>
#include<unistd.h>
asmlinkage long graph(const char* granularity, char* application)
{
pid_t child;
child = fork();
if (!child) {
execlp("./system-call", granularity, application, NULL);
}
sleep(0.2);
return 0;
}
But when I am trying to compile the kernel (note: same kernel version) and the old config file (if necessary i'll also upload the config file). I get the following error:
但是当我试图编译内核(注意:相同的内核版本)和旧的配置文件时(如果需要我还会上传配置文件)。我收到以下错误:
linux-3.7.10 % make
make[1]: Nothing to be done for `all'.
make[1]: Nothing to be done for `relocs'.
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
make[3]: `arch/x86/realmode/rm/realmode.bin' is up to date.
CHK kernel/config_data.h
CC test/graph.o
test/graph.c:10:19: fatal error: unistd.h: No such file or directory
compilation terminated.
make[1]: *** [test/graph.o] Error 1
make: *** [test] Error 2
make 4.50s user 1.27s system 75% cpu 7.626 total`
I checked if glibc
was installed or no, i see that all the kernel header files ARE available.
我检查了是否安装了glibc或者没有,我看到所有内核头文件都可用。
zypper search glibc
Loading repository data...
Reading installed packages...
S | Name | Summary | Type
--+--------------------------+-------------------------------------------------------+--------
i | glibc | Standard Shared Libraries (from the GNU C Library) | package
i | glibc-32bit | Standard Shared Libraries (from the GNU C Library) | package
i | glibc-devel | Include Files and Libraries Mandatory for Development | package
i | glibc-devel-32bit | Include Files and Libraries Mandatory for Development | package
i | glibc-devel-static | C library static libraries for -static linking | package
i | glibc-devel-static-32bit | C library static libraries for -static linking | package
i | glibc-extra | Extra binaries from GNU C Library | package
i | glibc-info | Info Files for the GNU C Library | package
i | glibc-locale | Locale Data for Localized Programs | package
i | glibc-locale-32bit | Locale Data for Localized Programs | package
i | glibc-utils | Development utilities from GNU C library | package
i | linux-glibc-devel | Linux headers for userspace development | package
I checked to see if it is availble in the new kernel dump, and it is not available.
我检查了它是否在新的内核转储中可用,并且它不可用。
IS IT safe to copy unistd.h
from /usr/include/unistd.h
to the new kernel dump which I want to compile?
将unistd.h从/usr/include/unistd.h复制到我想编译的新内核转储是否安全?
OR is there another way around it?
还有另外一种方法吗?
Here is an update: EDIT
这是一个更新:编辑
I had to change it from #include<unistd.h>
to #include<asm/unistd.h>
But I still get the error
我不得不将它从#include
error: implicit declaration of function ‘fork’ [-Werror=implicit-function-declaration]
error: implicit declaration of function ‘execlp’ [-Werror=implicit-function-declaration]
warning: incompatible implicit declaration of built-in function ‘execlp’ [enabled by default]
Really not sure what the problem is.
真的不确定是什么问题。
1 个解决方案
#1
1
On fork()/exec() errors: You can not call library code from kernel mode. Think about what you are trying to do, fork spawns a new user process as a clone of the current process, and exec replaces that process with a new one. Fork and exec are themselves system calls (although the functions you normally call is a libc wrapper around the call itself), so trying to create a system call by calling a system call is bit backward.
on fork()/ exec()错误:您无法从内核模式调用库代码。考虑一下你要做什么,fork产生一个新的用户进程作为当前进程的克隆,exec用一个新进程替换该进程。 fork和exec本身就是系统调用(虽然你通常调用的函数是围绕调用本身的libc包装器),因此尝试通过调用系统调用来创建系统调用是有点落后的。
On implementing graph(): You can not run userspace programs (like your 'graph' program) from kernel mode, at least not easily. You would need to compile the graph program's code into the kernel somewhere (a module would be nice here, but that's harder then just plonking your .c files into the source tree and compiling them in).
在实现graph()时:您无法从内核模式运行用户空间程序(如“图形”程序),至少不容易。你需要将图形程序的代码编译到某个地方的内核中(这里的模块会很好,但是这样做比将你的.c文件压缩到源代码树并编译它们更难)。
It may be possible to call fork and exec directly from kernel mode, but this is not what you want to be doing to create your graph() system call.
可以直接从内核模式调用fork和exec,但这不是你想要创建graph()系统调用的。
#1
1
On fork()/exec() errors: You can not call library code from kernel mode. Think about what you are trying to do, fork spawns a new user process as a clone of the current process, and exec replaces that process with a new one. Fork and exec are themselves system calls (although the functions you normally call is a libc wrapper around the call itself), so trying to create a system call by calling a system call is bit backward.
on fork()/ exec()错误:您无法从内核模式调用库代码。考虑一下你要做什么,fork产生一个新的用户进程作为当前进程的克隆,exec用一个新进程替换该进程。 fork和exec本身就是系统调用(虽然你通常调用的函数是围绕调用本身的libc包装器),因此尝试通过调用系统调用来创建系统调用是有点落后的。
On implementing graph(): You can not run userspace programs (like your 'graph' program) from kernel mode, at least not easily. You would need to compile the graph program's code into the kernel somewhere (a module would be nice here, but that's harder then just plonking your .c files into the source tree and compiling them in).
在实现graph()时:您无法从内核模式运行用户空间程序(如“图形”程序),至少不容易。你需要将图形程序的代码编译到某个地方的内核中(这里的模块会很好,但是这样做比将你的.c文件压缩到源代码树并编译它们更难)。
It may be possible to call fork and exec directly from kernel mode, but this is not what you want to be doing to create your graph() system call.
可以直接从内核模式调用fork和exec,但这不是你想要创建graph()系统调用的。