system call 관련 소스 분석
본 자료는 2페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
해당 자료는 2페이지 까지만 미리보기를 제공합니다.
2페이지 이후부터 다운로드 후 확인할 수 있습니다.

목차

1. Wrapper Routine
 example
 macro들
 test program
 wrapper routine
 sample.s
2. System call handler
 macro들
 system call handler 수행과정

본문내용

1. Wrapper Routines
 example : write() system call  _syscall3()을 이용.
argument가 3개이므로..
 wapper routine에 필요한 macro들(/include/asm-i386/unistd.h)
#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
type name(type1 arg1,type2 arg2,type3 arg3) \
{ \
long __res; \
__asm__ volatile (“int $0x80” \
: “=a” (__res) \
: “0” (__NR_##name),”b” ((long)(arg1)),”c” ((long)(arg2)), \
“d” ((long)(arg3))); \
__syscall_return(type,__res); \
}
#define __syscall_return(type, res) \
do { \
if ((unsigned long)(res) >= (unsigned long)(-125)) { \
errno = -(res); \
res = -1; \
} \
return (type) (res); \
} while (0)
#define __NR_write 4
 test program : sample.c
compile할 때 결과가 assembly code로 나오게
(gcc –S sample.c)
#include
int main(){
_syscall3(int, write , int, fd, const char*, buf, int, count)
}
 wrapper routine :
_syscall3(int, write, int, fd, const char*, buf, unsigned int, count)
int write(int fd, const char *buf, unsigned int count)
{
long __res;
asm(“int $0x80”
: “=a” (__res) // __res가 eax가 되고, 4가 된다.
: “0” (__NR_write), “b” ((long)fd),
“c” ((long)buf), “d” ((long)count);
if((unsigned long)__res >= (unsigned long)-125) {
errno = -__res;
__res = -1;
}
return (int) __res;
}
assem code로 변환.
현재 user mode stack에 함수 리턴주소와 인자값이 들어가 있다.
write :
pushl %ebx ; ebx를 보호하기 위해 stack에 저장
movl 8(%esp), %ebx ; stack의 8번지의 첫번째 인자를 ebx에 저장
movl 12(%esp), %ecx ; stack의 12번지의 두번째 인자를 ecx에 저장
movl 16(%esp), %edx ; stack의 16번지의 세번째 인자를 edx에 저장
movl $4, %eax ; eax에 __NR_writ(4)를 저장
int $0x80 ; system call을 invoke
cmpl $-126, %eax ; eax(4)와 –125를 비교(error인지 check)
jbe .L1 ; 작으면 즉, error가 없으면 return으로 jump
negl %eax ; 크거나 같으면 eax의 값을 complement
movl %eax, errno ; eax를 errno에 저장
movl $-1, %eax ; eax에 –1을 저장
L1.: popl %ebx ; stack에 있는 ebx값을 다시 가져온다.
ret ; return to calling program
return시 정상이면 4가 return되고, error이면 –1이 return된다.

키워드

  • 가격1,000
  • 페이지수7페이지
  • 등록일2008.03.27
  • 저작시기2008.1
  • 파일형식워드(doc)
  • 자료번호#457934
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니