この質問の助けを借りてシステムコールを構築する私の最初の試み
私のディストリビューション情報: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
私のプログラムの現在のバージョンでは、システムコールがメインを持っているので、これを埋め込むことができます(それを言うのは愚かですが、物事をより明確にするためです)。
私の現在のプログラムでは:
ユーザーから 2 つの入力を受け取り、いくつかの計算を行い、出力をグラフとデータとして提供します。
execlp
私の最初の試みは、次のように available in unistd
libraryを介してそのプログラムを呼び出すことでした:
#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]
何が問題なのか本当にわかりません。