我最初尝试在这个问题的帮助下构建系统调用
我的发行版信息: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
在我的程序的当前版本中,这将允许我将其嵌入,因为系统调用确实有一个 main(即使这样说也很愚蠢,但只是为了让事情更明确)。
在我当前的程序中:
它接收来自用户的两个输入,并进行一些计算并以图形和一些数据的形式给出输出。
我最初的尝试是通过库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;
}
但是当我试图编译内核(注意:相同的内核版本)和旧的配置文件(如果需要我也会上传配置文件)。我收到以下错误:
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`
我检查了是否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
我检查了它是否在新的内核转储中可用,但它不可用。
复制unistd.h
到/usr/include/unistd.h
我要编译的新内核转储是否安全?
或者还有其他方法吗?
这是一个更新:编辑
我不得不将它从更改#include<unistd.h>
为#include<asm/unistd.h>
但我仍然收到错误
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]
真的不知道是什么问题。