__fetchint64

上级 a9b40e7e
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "kmtrace.hh" #include "kmtrace.hh"
extern "C" int __fetchstr(char* dst, const char* usrc, unsigned size); extern "C" int __fetchstr(char* dst, const char* usrc, unsigned size);
extern "C" int __fetchint64(uptr addr, u64* ip);
int int
fetchstr(char* dst, const char* usrc, unsigned size) fetchstr(char* dst, const char* usrc, unsigned size)
...@@ -20,22 +21,12 @@ fetchstr(char* dst, const char* usrc, unsigned size) ...@@ -20,22 +21,12 @@ fetchstr(char* dst, const char* usrc, unsigned size)
return __fetchstr(dst, usrc, size); return __fetchstr(dst, usrc, size);
} }
// User code makes a system call with INT T_SYSCALL.
// System call number in %eax.
// Arguments on the stack, from the user call to the C
// library system call function. The saved user %esp points
// to a saved program counter, and then the first argument.
// Fetch the int at addr from process p.
int int
fetchint64(uptr addr, u64 *ip) fetchint64(uptr addr, u64 *ip)
{ {
if(pagefault(myproc()->vmap, addr, 0) < 0) if(mycpu()->ncli != 0)
return -1; panic("fetchstr: cli'd");
if(pagefault(myproc()->vmap, addr+sizeof(*ip)-1, 0) < 0) return __fetchint64(addr, ip);
return -1;
*ip = *(u64*)(addr);
return 0;
} }
// Fetch the nul-terminated string at addr from process p. // Fetch the nul-terminated string at addr from process p.
......
...@@ -2,6 +2,20 @@ ...@@ -2,6 +2,20 @@
#include "asmdefines.h" #include "asmdefines.h"
.code64 .code64
.globl __fetchint64
.align 8
// rdi user src
// rsi kernel dst
// We aren't allowed to touch rbx,rsp,rbp,r12-r15
__fetchint64:
mov %gs:0x8, %r11
movl $1, PROC_UACCESS(%r11)
mov (%rdi), %r10
mov %r10, (%rsi)
mov $0, %rax
jmp __fetch_end
.code64
.globl __fetchstr .globl __fetchstr
.align 8 .align 8
// rdi kernel dst // rdi kernel dst
...@@ -20,13 +34,13 @@ __fetchstr: ...@@ -20,13 +34,13 @@ __fetchstr:
movb %r10b, (%rdi) movb %r10b, (%rdi)
// Check for NULL // Check for NULL
cmp $0, %r10b cmp $0, %r10b
je done je 2f
inc %rdi inc %rdi
inc %rsi inc %rsi
loop 1b loop 1b
// Error // Error
movq $-1, %rax movq $-1, %rax
done: 2: // Done
jmp __fetch_end jmp __fetch_end
.code64 .code64
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论