|
@@ -12,9 +12,9 @@ int fakeopen(const char *path, int flags, int mod, struct s_sandboxenv *env)
|
|
|
{
|
|
{
|
|
|
int fd;
|
|
int fd;
|
|
|
#ifdef __x86_64__
|
|
#ifdef __x86_64__
|
|
|
- env->syscall_no.syscall_no = env->registers.orig_rax = (unsigned long long) __NR_open;
|
|
|
|
|
|
|
+ env->syscall_no.syscall_no = env->registers.orig_rax = (REGISTER_TYPE) __NR_open;
|
|
|
env->syscall_no.syscall_return = fd = open(path, flags, mod);
|
|
env->syscall_no.syscall_return = fd = open(path, flags, mod);
|
|
|
- env->syscall_args[0] = env->registers.rdi = (unsigned long long) path;
|
|
|
|
|
|
|
+ env->syscall_args[0] = env->registers.rdi = (REGISTER_TYPE) path;
|
|
|
env->syscall_args[1] = env->registers.rsi = flags;
|
|
env->syscall_args[1] = env->registers.rsi = flags;
|
|
|
env->syscall_args[2] = env->registers.rdx = mod;
|
|
env->syscall_args[2] = env->registers.rdx = mod;
|
|
|
#else
|
|
#else
|
|
@@ -27,7 +27,7 @@ int fakeopen(const char *path, int flags, int mod, struct s_sandboxenv *env)
|
|
|
int fakeclose(int fd, struct s_sandboxenv *env)
|
|
int fakeclose(int fd, struct s_sandboxenv *env)
|
|
|
{
|
|
{
|
|
|
#ifdef __x86_64__
|
|
#ifdef __x86_64__
|
|
|
- env->syscall_no.syscall_no = env->registers.orig_rax = (unsigned long long) __NR_close;
|
|
|
|
|
|
|
+ env->syscall_no.syscall_no = env->registers.orig_rax = (REGISTER_TYPE) __NR_close;
|
|
|
env->syscall_args[0] = env->registers.rdi = fd;
|
|
env->syscall_args[0] = env->registers.rdi = fd;
|
|
|
#else
|
|
#else
|
|
|
# error "non-x86 unsupported"
|
|
# error "non-x86 unsupported"
|
|
@@ -36,6 +36,22 @@ int fakeclose(int fd, struct s_sandboxenv *env)
|
|
|
return fd;
|
|
return fd;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+int fakewrite(int fd, char *buf, int len, struct s_sandboxenv *env)
|
|
|
|
|
+{
|
|
|
|
|
+#ifdef __x86_64__
|
|
|
|
|
+ env->syscall_no.syscall_no = env->registers.orig_rax = (REGISTER_TYPE) __NR_write;
|
|
|
|
|
+ env->syscall_args[0] = env->registers.rdi = fd;
|
|
|
|
|
+ env->syscall_args[1] = env->registers.rsi = (REGISTER_TYPE) buf;
|
|
|
|
|
+ env->syscall_args[2] = env->registers.rdx = len;
|
|
|
|
|
+#else
|
|
|
|
|
+# error "non-x86 unsupported"
|
|
|
|
|
+#endif
|
|
|
|
|
+ ovr_write(env);
|
|
|
|
|
+ if (env->registers.orig_rax == __NR_write)
|
|
|
|
|
+ env->registers.rax = write(fd, buf, len);
|
|
|
|
|
+ return env->registers.rax;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
|
|
|
int test_open(struct s_sandboxenv *env, int *final_fd)
|
|
int test_open(struct s_sandboxenv *env, int *final_fd)
|
|
|
{
|
|
{
|
|
@@ -71,8 +87,10 @@ int test_open(struct s_sandboxenv *env, int *final_fd)
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int test_write(struct s_sandboxenv *env)
|
|
|
|
|
|
|
+int test_write(struct s_sandboxenv *env, int fd)
|
|
|
{
|
|
{
|
|
|
|
|
+ _assertEqual(fakewrite(fd, "test", 5, env), 5);
|
|
|
|
|
+#warning TODO
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -86,7 +104,7 @@ int main()
|
|
|
tests_init_env(&env, ¶ms);
|
|
tests_init_env(&env, ¶ms);
|
|
|
|
|
|
|
|
success &= !test_open(&env, &fd);
|
|
success &= !test_open(&env, &fd);
|
|
|
- success &= !test_write(&env);
|
|
|
|
|
|
|
+ success &= !test_write(&env, fd);
|
|
|
|
|
|
|
|
fakeclose(fd, &env);
|
|
fakeclose(fd, &env);
|
|
|
tests_release_env(&env, ¶ms);
|
|
tests_release_env(&env, ¶ms);
|