,이 코드가 :이 코드는 작동하지 않으며 시스템의 작동을 중지리눅스 시스템 호출 (이상한 오프셋) 나는 커널 모듈에서 시스템 콜을 호출하기 위해 노력하고있어
set_fs(get_ds()); // lets our module do the system-calls
// Save everything before systemcalling
asm (" push %rax ");
asm (" push %rdi ");
asm (" push %rcx ");
asm (" push %rsi ");
asm (" push %rdx ");
asm (" push %r10 ");
asm (" push %r8 ");
asm (" push %r9 ");
asm (" push %r11 ");
asm (" push %r12 ");
asm (" push %r15 ");
asm (" push %rbp ");
asm (" push %rbx ");
// Invoke the long sys_mknod(const char __user *filename, int mode, unsigned dev);
asm volatile (" movq $133, %rax "); // system call number
asm volatile (" lea path(%rip), %rdi "); // path is char path[] = ".."
asm volatile (" movq mode, %rsi "); // mode is S_IFCHR | ...
asm volatile (" movq dev, %rdx "); // dev is 70 >> 8
asm volatile (" syscall ");
// POP EVERYTHING
asm (" pop %rbx ");
asm (" pop %rbp ");
asm (" pop %r15 ");
asm (" pop %r12 ");
asm (" pop %r11 ");
asm (" pop %r9 ");
asm (" pop %r8 ");
asm (" pop %r10 ");
asm (" pop %rdx ");
asm (" pop %rsi ");
asm (" pop %rcx ");
asm (" pop %rdi ");
asm (" pop %rax ");
set_fs(savedFS); // restore the former address-limit value
을 down (커널 모듈).
재배치 정보를 사용해, 코드의 조각의 덤프는 다음과 같습니다 R_X86_64_PC32의 경로를 0x4 :
내가 궁금하네요2c: 50 push %rax
2d: 57 push %rdi
2e: 51 push %rcx
2f: 56 push %rsi
30: 52 push %rdx
31: 41 52 push %r10
33: 41 50 push %r8
35: 41 51 push %r9
37: 41 53 push %r11
39: 41 54 push %r12
3b: 41 57 push %r15
3d: 55 push %rbp
3e: 53 push %rbx
3f: 48 c7 c0 85 00 00 00 mov $0x85,%rax
46: 48 8d 3d 00 00 00 00 lea 0x0(%rip),%rdi # 4d <init_module+0x4d>
49: R_X86_64_PC32 path-0x4
4d: 48 83 c7 04 add $0x4,%rdi
51: 48 8b 34 25 00 00 00 mov 0x0,%rsi
58: 00
55: R_X86_64_32S mode
59: 48 8b 14 25 00 00 00 mov 0x0,%rdx
60: 00
5d: R_X86_64_32S dev
61: 0f 05 syscall
63: 5b pop %rbx
64: 5d pop %rbp
65: 41 5f pop %r15
67: 41 5c pop %r12
69: 41 5b pop %r11
6b: 41 59 pop %r9
6d: 41 58 pop %r8
6f: 41 5a pop %r10
71: 5a pop %rdx
72: 5e pop %rsi
73: 59 pop %rcx
74: 5f pop %rdi
75: 58 pop %rax
.. 왜 49 오프셋 -0x4이있다?
의미 : 모드 및 dev는 문제없이 자동으로 해결되어야하지만 경로는 어떻게됩니까? 왜 -0x4 오프셋입니까?
나는레아 0x0을 (% 립), %의 RDI에 "그것을 보상"을 시도 //이 어떻게 든 -0x4가 추가 $ 0x4를, %의 RDI ....
오프셋 추가 그러나 코드는 여전히 추락했습니다.
어디서 잘못 되었나요?
커널 내부에서 시스템 호출을 호출 할 수 없습니다. 커널은 응용 프로그램에 시스템 호출을 제공합니다. 너 정말로하고 싶은게 뭐야? 커널 토지에서 일하는 것을 피할 수 없습니까? –
그래서 set_fs (get_ds()); 시스템 호출을 호출 할 수있는 세그먼트 제한이 증가해야합니다. 시험을위한 연습 (http://cs.usfca.edu/~cruse/cs635/)이므로 amd64로 수행하는 방법을 알아야합니다. – paulAl
'syscall' 호출 규칙에서'rcx return address for syscall/sysret, C arg3'을 실행하십시오. –