提交 567366af 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

Merge branch 'scale-amd64' of git+ssh://pdos.csail.mit.edu/home/am0/6.828/xv6 into scale-amd64

Conflicts: kernel/exec.cc kernel/sysfile.cc
#if CILKENABLE
template<typename A1>
static void
cilk_call(void (*fn)(A1), A1 a1)
{
cilk_push((void(*)(uptr, uptr))fn, (uptr)a1, (uptr)0);
}
template<typename A1, typename A2>
static void
cilk_call(void (*fn)(A1, A2), A1 a1, A2 a2)
{
cilk_push((void(*)(uptr, uptr))fn, (uptr)a1, (uptr)a2);
}
#else // !CILKENABLE
template<typename A1>
static void
cilk_call(void (*fn)(A1), A1 a1)
{
fn(a1);
}
template<typename A1, typename A2>
static void
cilk_call(void (*fn)(A1, A2), A1 a1, A2 a2)
{
fn(a1, a2);
}
#endif
......@@ -13,7 +13,7 @@
#include "elf.hh"
#include "cpu.hh"
#include "wq.hh"
#include "cilk.hh"
#include "sperf.hh"
#include "kmtrace.hh"
#define BRK (USERTOP >> 1)
......@@ -152,6 +152,7 @@ exec_cleanup(vmap *oldvmap, uwq *olduwq)
int
exec(const char *path, char **argv, void *ascopev)
{
ANON_REGION(__func__, &perfgroup);
struct inode *ip = nullptr;
struct vmap *vmp = nullptr;
uwq* newuwq = nullptr;
......
......@@ -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.
......
......@@ -423,10 +423,11 @@ long
sys_exec(const char *upath, u64 uargv)
{
ANON_REGION(__func__, &perfgroup);
static const int len = 32;
char *argv[MAXARG];
char path[DIRSIZ+1];
long r = -1;
int i;
u64 uarg;
if (fetchstr(path, upath, sizeof(path)) < 0)
return -1;
......@@ -435,19 +436,24 @@ sys_exec(const char *upath, u64 uargv)
memset(argv, 0, sizeof(argv));
for(i=0;; i++){
u64 uarg;
if(i >= NELEM(argv))
return -1;
goto clean;
if(fetchint64(uargv+8*i, &uarg) < 0)
return -1;
if(uarg == 0){
argv[i] = 0;
goto clean;
if(uarg == 0)
break;
}
argv[i] = (char*) uarg;
if(argcheckstr(argv[i]) < 0)
return -1;
argv[i] = (char*) kmalloc(len, "execbuf");
if (argv[i]==nullptr || fetchstr(argv[i], (char*)uarg, len)<0)
goto clean;
}
return exec(path, argv, &ascope);
argv[i] = 0;
r = exec(path, argv, &ascope);
clean:
for (i=i-i; i >= 0; i--)
kmfree(argv[i], len);
return r;
}
long
......
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论