|
From: Nicholas N. <nj...@ca...> - 2004-10-18 17:00:35
|
CVS commit by nethercote:
Arch-abstraction:
- factor out the setting of syscall results, which can be more complicated
than just putting a value in the result register (eg. PPC has to fiddle with
multiple registers).
M +51 -49 vg_syscalls.c 1.147
M +1 -1 x86-linux/core_platform.h 1.6
--- valgrind/coregrind/vg_syscalls.c #1.146:1.147
@@ -1020,4 +1020,6 @@ static Bool fd_allowed(Int fd, const Cha
#define arg6 PLATFORM_SYSCALL_ARG6(tst->arch)
+#define set_result(val) PLATFORM_SET_SYSCALL_RESULT(tst->arch, (val))
+
PRE(exit_group)
{
@@ -1141,5 +1143,5 @@ PRE(set_thread_area)
/* "do" the syscall ourselves; the kernel never sees it */
- res = VG_(sys_set_thread_area)( tid, (void *)arg1 );
+ set_result( VG_(sys_set_thread_area)( tid, (void *)arg1 ) );
}
@@ -1152,5 +1154,5 @@ PRE(get_thread_area)
/* "do" the syscall ourselves; the kernel never sees it */
- res = VG_(sys_get_thread_area)( tid, (void *)arg1 );
+ set_result( VG_(sys_get_thread_area)( tid, (void *)arg1 ) );
if (!VG_(is_kerror)(res)) {
@@ -1455,5 +1457,5 @@ PRE(mremap)
arg1, arg2, arg3, arg4, arg5);
- res = mremap_segment((Addr)arg1, arg2, (Addr)arg5, arg3, arg4, tid);
+ set_result( mremap_segment((Addr)arg1, arg2, (Addr)arg5, arg3, arg4, tid) );
}
@@ -1762,5 +1764,5 @@ PRE(execve)
if (ret < 0) {
- res = ret;
+ set_result( ret );
return;
}
@@ -1769,5 +1771,5 @@ PRE(execve)
*/
if ((st.st_mode & 0100111) == 0100000) {
- res = -VKI_EACCES;
+ set_result( -VKI_EACCES );
return;
}
@@ -1838,5 +1840,5 @@ PRE(execve)
VG_(setrlimit)(VKI_RLIMIT_DATA, &VG_(client_rlimit_data));
- res = VG_(do_syscall)(__NR_execve, arg1, arg2, arg3);
+ set_result( VG_(do_syscall)(__NR_execve, arg1, arg2, arg3) );
/* If we got here, then the execve failed. We've already made too much of a mess
@@ -1882,5 +1884,5 @@ PRE(brk)
MAYBE_PRINTF("brk ( %p ) --> ",arg1);
- res = do_brk(arg1);
+ set_result( do_brk(arg1) );
MAYBE_PRINTF("0x%x\n", res);
@@ -1934,5 +1936,5 @@ PRE(close)
/* Detect and negate attempts by the client to close Valgrind's log fd */
if (!fd_allowed(arg1, "close", tid, False))
- res = -VKI_EBADF;
+ set_result( -VKI_EBADF );
}
@@ -1953,5 +1955,5 @@ POST(dup)
if (!fd_allowed(res, "dup", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if(VG_(clo_track_fds))
@@ -1965,5 +1967,5 @@ PRE(dup2)
MAYBE_PRINTF("dup2 ( %d, %d ) ...\n", arg1,arg2);
if (!fd_allowed(arg2, "dup2", tid, True))
- res = -VKI_EBADF;
+ set_result( -VKI_EBADF );
}
@@ -1990,5 +1992,5 @@ POST(fcntl)
if (!fd_allowed(res, "fcntl(DUPFD)", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
@@ -2031,5 +2033,5 @@ POST(fcntl64)
if (!fd_allowed(res, "fcntl64(DUPFD)", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
@@ -2103,5 +2105,5 @@ PRE(clone)
{
before_fork(tid, tst);
- res = VG_(do_syscall)(SYSNO, arg1, arg2, arg3, arg4, arg5);
+ set_result( VG_(do_syscall)(SYSNO, arg1, arg2, arg3, arg4, arg5) );
after_fork(tid, tst);
} else {
@@ -2618,10 +2620,10 @@ PRE(ipc)
arg5 = VG_(find_map_space)(0, segmentSize, True);
else if (!valid_client_addr(arg5, segmentSize, tid, "shmat"))
- res = -VKI_EINVAL;
+ set_result( -VKI_EINVAL );
break;
}
case 22: /* IPCOP_shmdt */
if (!valid_client_addr(arg5, 1, tid, "shmdt"))
- res = -VKI_EINVAL;
+ set_result( -VKI_EINVAL );
break;
case 23: /* IPCOP_shmget */
@@ -4056,5 +4058,5 @@ PRE(kill)
MAYBE_PRINTF("kill ( %d, %d )\n", arg1,arg2);
if (arg2 == VKI_SIGVGINT || arg2 == VKI_SIGVGKILL)
- res = -VKI_EINVAL;
+ set_result( -VKI_EINVAL );
}
@@ -4162,9 +4164,9 @@ PRE(mmap2)
if (arg4 & VKI_MAP_FIXED) {
if (!valid_client_addr(arg1, arg2, tid, "mmap2"))
- res = -VKI_ENOMEM;
+ set_result( -VKI_ENOMEM );
} else {
arg1 = VG_(find_map_space)(arg1, arg2, True);
if (arg1 == 0)
- res = -VKI_ENOMEM;
+ set_result( -VKI_ENOMEM );
else
arg4 |= VKI_MAP_FIXED;
@@ -4195,10 +4197,10 @@ PRE(mmap)
if (!valid_client_addr(a1, a2, tid, "mmap")) {
MAYBE_PRINTF("mmap failing: %p-%p\n", a1, a1+a2);
- res = -VKI_ENOMEM;
+ set_result( -VKI_ENOMEM );
}
} else {
a1 = VG_(find_map_space)(a1, a2, True);
if (a1 == 0)
- res = -VKI_ENOMEM;
+ set_result( -VKI_ENOMEM );
else
a4 |= VKI_MAP_FIXED;
@@ -4222,5 +4224,5 @@ PRE(mprotect)
if (!valid_client_addr(arg1, arg2, tid, "mprotect"))
- res = -VKI_ENOMEM;
+ set_result( -VKI_ENOMEM );
}
@@ -4246,5 +4248,5 @@ PRE(munmap)
if (!valid_client_addr(arg1, arg2, tid, "munmap"))
- res = -VKI_EINVAL;
+ set_result( -VKI_EINVAL );
}
@@ -4328,5 +4330,5 @@ POST(open)
if (!fd_allowed(res, "open", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
@@ -4342,5 +4344,5 @@ PRE(read)
if (!fd_allowed(arg1, "read", tid, False))
- res = -VKI_EBADF;
+ set_result( -VKI_EBADF );
else
SYSCALL_TRACK( pre_mem_write, tid, "read(buf)", arg2, arg3 );
@@ -4357,5 +4359,5 @@ PRE(write)
MAYBE_PRINTF("write ( %d, %p, %d )\n", arg1, arg2, arg3);
if (!fd_allowed(arg1, "write", tid, False))
- res = -VKI_EBADF;
+ set_result( -VKI_EBADF );
else
SYSCALL_TRACK( pre_mem_read, tid, "write(buf)", arg2, arg3 );
@@ -4373,5 +4375,5 @@ POST(creat)
if (!fd_allowed(res, "creat", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
@@ -4397,5 +4399,5 @@ POST(pipe)
VG_(close)(p[0]);
VG_(close)(p[1]);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
VG_TRACK( post_mem_write, arg1, 2*sizeof(int) );
@@ -4449,5 +4451,5 @@ POST(epoll_create)
if (!fd_allowed(res, "open", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
@@ -4505,5 +4507,5 @@ PRE(readv)
MAYBE_PRINTF("readv ( %d, %p, %d )\n",arg1,arg2,arg3);
if (!fd_allowed(arg1, "readv", tid, False)) {
- res = -VKI_EBADF;
+ set_result( -VKI_EBADF );
} else {
SYSCALL_TRACK( pre_mem_read, tid, "readv(vector)",
@@ -4712,9 +4714,9 @@ PRE(setrlimit)
if (((vki_rlimit *)arg2)->rlim_cur > VG_(fd_hard_limit) ||
((vki_rlimit *)arg2)->rlim_max != VG_(fd_hard_limit)) {
- res = -VKI_EPERM;
+ set_result( -VKI_EPERM );
}
else {
VG_(fd_soft_limit) = ((vki_rlimit *)arg2)->rlim_cur;
- res = 0;
+ set_result( 0 );
}
}
@@ -4722,9 +4724,9 @@ PRE(setrlimit)
if (((vki_rlimit *)arg2)->rlim_cur > ((vki_rlimit *)arg2)->rlim_max ||
((vki_rlimit *)arg2)->rlim_max > ((vki_rlimit *)arg2)->rlim_max) {
- res = -VKI_EPERM;
+ set_result( -VKI_EPERM );
}
else {
VG_(client_rlimit_data) = *(vki_rlimit *)arg2;
- res = 0;
+ set_result( 0 );
}
}
@@ -4732,10 +4734,10 @@ PRE(setrlimit)
if (((vki_rlimit *)arg2)->rlim_cur > ((vki_rlimit *)arg2)->rlim_max ||
((vki_rlimit *)arg2)->rlim_max > ((vki_rlimit *)arg2)->rlim_max) {
- res = -VKI_EPERM;
+ set_result( -VKI_EPERM );
}
else {
VG_(threads)[tid].stack_size = ((vki_rlimit *)arg2)->rlim_cur;
VG_(client_rlimit_stack) = *(vki_rlimit *)arg2;
- res = 0;
+ set_result( 0 );
}
}
@@ -4964,5 +4966,5 @@ PRE(socketcall)
default:
VG_(message)(Vg_DebugMsg,"Warning: unhandled socketcall 0x%x",arg1);
- res = -VKI_EINVAL;
+ set_result( -VKI_EINVAL );
break;
}
@@ -4984,5 +4986,5 @@ POST(socketcall)
VG_(close)(fd1);
VG_(close)(fd2);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
VG_TRACK( post_mem_write, ((UInt*)arg2)[3], 2*sizeof(int) );
@@ -4998,5 +5000,5 @@ POST(socketcall)
if (!fd_allowed(res, "socket", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
@@ -5018,5 +5020,5 @@ POST(socketcall)
if (!fd_allowed(res, "accept", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
Addr addr_p = ((UInt*)arg2)[1];
@@ -5333,5 +5335,5 @@ PRE(writev)
MAYBE_PRINTF("writev ( %d, %p, %d )\n",arg1,arg2,arg3);
if (!fd_allowed(arg1, "writev", tid, False)) {
- res = -VKI_EBADF;
+ set_result( -VKI_EBADF );
} else {
SYSCALL_TRACK( pre_mem_read, tid, "writev(vector)",
@@ -5409,5 +5411,5 @@ POST(futex)
if (!fd_allowed(res, "futex", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
@@ -5610,5 +5612,5 @@ PRE(io_setup)
VG_(pad_address_space)();
- res = VG_(do_syscall)(SYSNO, arg1, arg2);
+ set_result( VG_(do_syscall)(SYSNO, arg1, arg2) );
VG_(unpad_address_space)();
@@ -5636,5 +5638,5 @@ PRE(io_destroy)
MAYBE_PRINTF("io_destroy ( %ul )\n",arg1);
- res = VG_(do_syscall)(SYSNO, arg1);
+ set_result( VG_(do_syscall)(SYSNO, arg1) );
if (res == 0 && s != NULL && VG_(seg_contains)(s, arg1, size)) {
@@ -5748,5 +5750,5 @@ POST(mq_open)
if (!fd_allowed(res, "mq_open", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
@@ -5770,5 +5772,5 @@ PRE(mq_timedsend)
arg1,arg2,arg3,arg4,arg5);
if (!fd_allowed(arg1, "mq_timedsend", tid, False)) {
- res = -VKI_EBADF;
+ set_result( -VKI_EBADF );
} else {
SYSCALL_TRACK( pre_mem_read, tid, "mq_timedsend(msg_ptr)", arg2, arg3 );
@@ -5787,5 +5789,5 @@ PRE(mq_timedreceive)
arg1,arg2,arg3,arg4,arg5);
if (!fd_allowed(arg1, "mq_timedreceive", tid, False)) {
- res = -VKI_EBADF;
+ set_result( -VKI_EBADF );
} else {
SYSCALL_TRACK( pre_mem_write, tid, "mq_timedreceive(msg_ptr)", arg2, arg3 );
@@ -5811,5 +5813,5 @@ PRE(mq_notify)
MAYBE_PRINTF("mq_notify( %d, %p )\n", arg1,arg2 );
if (!fd_allowed(arg1, "mq_notify", tid, False))
- res = -VKI_EBADF;
+ set_result( -VKI_EBADF );
else if (arg2 != 0)
SYSCALL_TRACK( pre_mem_read, tid, "mq_notify", arg2,
@@ -5823,5 +5825,5 @@ PRE(mq_getsetattr)
MAYBE_PRINTF("mq_getsetattr( %d, %p, %p )\n", arg1,arg2,arg3 );
if (!fd_allowed(arg1, "mq_getsetattr", tid, False)) {
- res = -VKI_EBADF;
+ set_result( -VKI_EBADF );
} else {
if (arg2 != 0) {
@@ -5958,5 +5960,5 @@ static void bad_before(ThreadId tid, Thr
(Vg_DebugMsg,"Read the file README_MISSING_SYSCALL_OR_IOCTL.");
- res = -VKI_ENOSYS;
+ set_result( -VKI_ENOSYS );
}
--- valgrind/coregrind/x86-linux/core_platform.h #1.5:1.6
@@ -50,5 +50,5 @@
#define PLATFORM_SYSCALL_ARG6(regs) ((regs).m_ebp)
-#define PLATFORM_PRE_SYSCALL_RESULT(regs, val) ((regs).m_eax = (val))
+#define PLATFORM_SET_SYSCALL_RESULT(regs, val) ((regs).m_eax = (val))
// Interesting register numbers
|