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