__fetchint64

上级 a9b40e7e
......@@ -11,6 +11,7 @@
#include "kmtrace.hh"
extern "C" int __fetchstr(char* dst, const char* usrc, unsigned size);
extern "C" int __fetchint64(uptr addr, u64* ip);
int
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);
}
// 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
fetchint64(uptr addr, u64 *ip)
{
if(pagefault(myproc()->vmap, addr, 0) < 0)
return -1;
if(pagefault(myproc()->vmap, addr+sizeof(*ip)-1, 0) < 0)
return -1;
*ip = *(u64*)(addr);
return 0;
if(mycpu()->ncli != 0)
panic("fetchstr: cli'd");
return __fetchint64(addr, ip);
}
// Fetch the nul-terminated string at addr from process p.
......
......@@ -2,6 +2,20 @@
#include "asmdefines.h"
.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
.align 8
// rdi kernel dst
......@@ -20,13 +34,13 @@ __fetchstr:
movb %r10b, (%rdi)
// Check for NULL
cmp $0, %r10b
je done
je 2f
inc %rdi
inc %rsi
loop 1b
// Error
movq $-1, %rax
done:
2: // Done
jmp __fetch_end
.code64
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论