커널에 시스템콜을 추가하는 중입니다.

cjy1126의 이미지

교학사에서 출판한 "리눅스 매니아를 위한 커널 프로그래밍" 이란 책을 보면서 커널 프로그래밍을 따라하고 있습니다.

지금 4장 시스템 호출 구현을 하는데...

1. include/asm-i386/unistd.h 파일에 __NR_newsyscall 추가

   
#define __NR_newsyscall 259 

2. arch/i386/kernel/entry.S 에 sys_newsyscall 추가

.long SYMBOL_NAME(sys_newsyscall)

3. kernel/ 에 newfile.c 작성

#include <linux/unistd.h>
#include <linux/error.h>
#include <linux/kernel.h>
#include <linux/sched.h>

asmlinkage int sys_newsyscall()
{
   printk("Hello Linux, I'm in Kernel\n");
   return(0);
}

4. kernel/ 디렉토리의 Makefile에 newfile.o 추가

O_OBJS = sched.o dma.o fork.o ....
         ......................................................
         ..... newfile.o

5. 커널을 새로 컴파일한 후 그 커널로 부팅(uname -r 하면 2.4.20-8custom로 출력)

6. 새로만든 newsyscall을 이용한 테스트 프로그램(test_newsyscall.c) 작성

#include <linux/unistd.h>
_syscall0(int, newsyscall);

main()
{
   int i;
   i = newsyscall();
}

7. test_newsyscall.c 컴파일시 에러 발생

[root@hello-world kernel_programming]# gcc -o test_newsyscall test_newsyscall.c
test_newsyscall.c: In function `newsyscall':
test_newsyscall.c:2: `__NR_newsyscall' undeclared (first use in this function)
test_newsyscall.c:2: (Each undeclared identifier is reported only once
test_newsyscall.c:2: for each function it appears in.)

책을 몇번씩보면서 똑같이 다시해도 원인을 모르겠습니다.

저는 RedHat 9.0 을 사용하고, 커널 버전은 2.4.20-8c 입니다.

고수님들 답변 부탁드리고... 즐거운 크리스마스 되세요 :)

codebank의 이미지

에러의 원인은 헤더파일에 있습니다.
커널 컴파일시 참조하는 헤더파일은 /usr/src/linux/include에 있는 헤더파일입니다.
그리고 cjy1126님이 수정하신 헤더파일도 위에있는 헤더파일입니다.

그런데 실험을하기 위해서 포함시킨 헤더파일은 /usr/include에 있는 헤더파일을
참조하게 되어있습니다.
링크가 되어있지 않다면 당연히 헤더에 정의되어있지 않겠죠.
방법은 /usr/src/linux/include/asm/unistd.h 파일에 cjy1126님이 추가시킨
시스템콜을 정의해주면 될겁니다.
제가 알기로는 예전에는 /usr/include/linux, /usr/include/asm 디렉토리가
/usr/src/linux/include/linux, /usr/src/linux/include/asm-i386(기종에 따라서
틀리겠죠.)로 연결되어있었는데 어느순간부터 바뀐것 같네요.

------------------------------
좋은 하루 되세요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.