시스템콜 작성완료후 시스템 콜 호출 오류 에 대한 질문 입니다.

justgn의 이미지

gcc test.c
test.c:6: error: expected declaration specifiers or ‘...’ before ''
test.c:6: warning: data definition has no type or storage class

시스템 콜 호출 할때 위와 같은 에러가 뜨네요...도데체 무슨 에러인지 알 수가 없어서 이렇게 질문 합니다.

현재 시스템은 Fedora core 5 kernel version 2.6.15에서
kernel version 2.6.19로 한후에 에러가 나는데

구글링해도 잘 안나오네요 ...

좋은 답변 기대 하겠습니다.

freemckang의 이미지

드래그 앤 드롭??

句日新, 日新 日新 又日新.

句日新, 日新 日新 又日新.

goro14의 이미지

아마도 _syscallX 메크로가 안먹는것 같습니다...

syscall(시스템콜넘버);

ex) syscall(318);

이런식으로는 호출이 되는데 _syscallX(); 메크로를 사용하면 에러가 나네요...

solvalow의 이미지

_syscall0 을 사용하고 컴파일하면 syntax error before "newsyscall"
이렇게 에러메시지가 나옵니다. unistd.h 경로를 직접 설정하는 등의 방법을써도 안 되네요..
syscall(317) 이런식으로 호출하면 되는데 말이죠..
커널은 2.6.17 배포판은 우분투를 사용하고 있습니다.

bejoy4him의 이미지

레뎃 리눅스 9에서 동작중인 코드를 우분투 Edgy 상에서 컴파일이 되지 않는데
위와 비슷한 문제 같습니다.
Kernel 2.6으로 옮겨가면서 시스템 콜 관련하여 바뀐부분 때문일까요?

답변 부탁드립니다.

테스트 코드는 아래와 같습니다.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <linux/unistd.h>
 
_syscall0(pid_t,gettid);
 
int main(void)
{
        printf("Start Main!! %d\n",gettid());
        return 0;
}

컴파일시 에러는 다음과 같습니다.
taewon@taewon:~/testCode$ gcc -g -W -Wall -o2 test1.c -o test
test1.c:8: error: syntax error before "gettid"
test1.c:8: warning: type defaults to `int' in declaration of `_syscall0'
test1.c:8: warning: data definition has no type or storage class
test1.c: In function `main':
test1.c:12: warning: implicit declaration of function `gettid'

sayhappy의 이미지

error: expected declaration specifiers or ‘...’ before

라고 에러가 나는데..

naddolki의 이미지

error: expected declaration specifiers or ‘...’ before ''
warning: data definition has no type or storage class

보다 확실한 방법이 있겠지만 .. 어쨌든 현재까지 제가 찾아낸 방법은 아래와 같습니다 .
참고할 가치는 스스로의 판단에 맡기며, "확실한 방법" 을 아시는 분께서는 리플 좀 부탁드립니다 .

//-------------------------------------------------------------------------
* 유저 레벨에서
응용프로그램 : main(){open(); } -> 라이브러리 : open(){int 0x80;/*어셈*/}

* 커널 레벨에서
sys_open(){/*...*/};
//-------------------------------------------------------------------------

커널 소스를 편집해 시스템콜 관련 사항을 추가하고, 컴파일 후 해당 커널로 부팅하셨다면 ..
앞서 만든 시스템콜을 사용하는 어플리케이션을 작성이 가능합니다 .

유저 레벨의 어플리케이션은 시스템콜을 사용하기 위해 ..
커널 레벨에 진입하는 인터럽트(0x80)를 건 후, 사용코자 하는 시스템콜의 번호
앞서 커널 소스에 등록했던 '시스템콜 번호')로 시스템콜을 호출합니다 .

이 작업들(어플리케이션 함수를 통해 시스템콜에 접근하는) 아키텍쳐 종속적이기 때문에 ..
어셈블리어로 작성해야 합니다 .

open()의 경우 커널 레벨에 진입하기 위해 위의 두 작업을 어떤 식으로 구현했지는 모르겠으나 ..
보통은 어셈블리로 코딩하는 번거로움을 덜어주기 위해 미리 만들어 놓은 ..
매크로 함수를 이용합니다 .

/usr/include/asm/unistd.h 에 정의되어 있는 _syscall0(type,name) ~ _syscall6(type,name,type1,arg1, ...) 이 그것입니다 .

이 매크로는 말씀드린 두가지 작업을 수행하는 어셈블리 코드로 치환해줍니다 .

헌데, /usr/include/asm/unistd.h 에 앞서 말씀드린 매크로가 빠져 있는 경우가 더러 있더군요 ..
따라서, 해당 시스템콜 타입의 _syscallx(type,name, ...) 매크로를 앞서 작업했던 커널 소스의
"(kernel-src-root)/include/asm/unistd.h" 에서 복사해 붙여 넣어주시면 ..

정상적으로 처리됩니다 .
(커널 소스의 .../include/asm/unistd.h 에 있는 _syscallx() 는 같은 파일 내에 정의된 매크로
__syscall_return(type, res) 를 호출하기 때문에, 해당 매크로도 추가해 줘야합니다)

unistd.h 가 만들어질 때, 이를 빠뜨리는 실수가 있었다 보기는 힘들기 때문에 ..
glibc 버전에 따라 .. 구현 방식에 차이가 좀 있지 않나 싶기도 한데 ...
어디까지나 제 추측일 뿐고요, 정확한 답은 저 또한 아직 찾고 있는 중이기 때문에 ..
먼저 알게 되신 분께서는 리플 좀 남겨주셨으면 좋겠네요 .
감사합니다 .

설연희 입니다 ^ ㅡ^ㅋ

naddolki의 이미지


// _syscall1(long, helloworld, int, i);

long helloworld(int i)
{
return syscall(__NR_helloworld, i);
};

설연희 입니다 ^ ㅡ^ㅋ

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.