#define arg5 PLATFORM_SYSCALL_ARG5(tst->arch)
#define arg6 PLATFORM_SYSCALL_ARG6(tst->arch)
+#define set_result(val) PLATFORM_SET_SYSCALL_RESULT(tst->arch, (val))
+
PRE(exit_group)
{
VG_(core_panic)("syscall exit_group() not caught by the scheduler?!");
sizeof(struct vki_modify_ldt_ldt_s) );
/* "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 ) );
}
PRE(get_thread_area)
sizeof(struct vki_modify_ldt_ldt_s) );
/* "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)) {
VG_TRACK( post_mem_write, arg1, sizeof(struct vki_modify_ldt_ldt_s) );
MAYBE_PRINTF("mremap ( %p, %d, %d, 0x%x, %p )\n",
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) );
}
PRE(nice)
Int ret = VG_(stat)((Char *)arg1, &st);
if (ret < 0) {
- res = ret;
+ set_result( ret );
return;
}
/* just look for regular file with any X bit set
XXX do proper permissions check?
*/
if ((st.st_mode & 0100111) == 0100000) {
- res = -VKI_EACCES;
+ set_result( -VKI_EACCES );
return;
}
}
/* restore the DATA rlimit for the child */
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
of ourselves to continue, so we have to abort. */
*/
MAYBE_PRINTF("brk ( %p ) --> ",arg1);
- res = do_brk(arg1);
+ set_result( do_brk(arg1) );
MAYBE_PRINTF("0x%x\n", res);
MAYBE_PRINTF("close ( %d )\n",arg1);
/* 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 );
}
POST(close)
MAYBE_PRINTF("%d\n", res);
if (!fd_allowed(res, "dup", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if(VG_(clo_track_fds))
record_fd_open(tid, res, VG_(resolve_filename)(res));
/* int dup2(int oldfd, int newfd); */
MAYBE_PRINTF("dup2 ( %d, %d ) ...\n", arg1,arg2);
if (!fd_allowed(arg2, "dup2", tid, True))
- res = -VKI_EBADF;
+ set_result( -VKI_EBADF );
}
POST(dup2)
if (arg2 == VKI_F_DUPFD) {
if (!fd_allowed(res, "fcntl(DUPFD)", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
record_fd_open(tid, res, VG_(resolve_filename)(res));
if (arg2 == VKI_F_DUPFD) {
if (!fd_allowed(res, "fcntl64(DUPFD)", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
record_fd_open(tid, res, VG_(resolve_filename)(res));
|| arg1 == (VKI_CLONE_PARENT_SETTID|VKI_SIGCHLD)))
{
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 {
VG_(unimplemented)
if (arg5 == 0)
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 */
break;
/* int kill(pid_t pid, int sig); */
MAYBE_PRINTF("kill ( %d, %d )\n", arg1,arg2);
if (arg2 == VKI_SIGVGINT || arg2 == VKI_SIGVGKILL)
- res = -VKI_EINVAL;
+ set_result( -VKI_EINVAL );
}
POST(kill)
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;
}
if (a4 & VKI_MAP_FIXED) {
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;
}
MAYBE_PRINTF("mprotect ( %p, %d, %d )\n", arg1,arg2,arg3);
if (!valid_client_addr(arg1, arg2, tid, "mprotect"))
- res = -VKI_ENOMEM;
+ set_result( -VKI_ENOMEM );
}
POST(mprotect)
MAYBE_PRINTF("munmap ( %p, %d )\n", arg1,arg2);
if (!valid_client_addr(arg1, arg2, tid, "munmap"))
- res = -VKI_EINVAL;
+ set_result( -VKI_EINVAL );
}
POST(munmap)
{
if (!fd_allowed(res, "open", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
record_fd_open(tid, res, VG_(arena_strdup)(VG_AR_CORE, (Char*)arg1));
MAYBE_PRINTF("read ( %d, %p, %d )\n", arg1, arg2, arg3);
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 );
}
/* size_t write(int fd, const void *buf, size_t count); */
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 );
}
{
if (!fd_allowed(res, "creat", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
record_fd_open(tid, res, VG_(arena_strdup)(VG_AR_CORE, (Char*)arg1));
!fd_allowed(p[1], "pipe", tid, True)) {
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) );
if (VG_(clo_track_fds)) {
{
if (!fd_allowed(res, "open", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
record_fd_open (tid, res, NULL);
struct iovec * vec;
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)",
arg2, arg3 * sizeof(struct iovec) );
if (arg1 == VKI_RLIMIT_NOFILE) {
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 );
}
}
else if (arg1 == VKI_RLIMIT_DATA) {
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 );
}
}
else if (arg1 == VKI_RLIMIT_STACK && tid == 1) {
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 );
}
}
}
default:
VG_(message)(Vg_DebugMsg,"Warning: unhandled socketcall 0x%x",arg1);
- res = -VKI_EINVAL;
+ set_result( -VKI_EINVAL );
break;
}
}
!fd_allowed(fd2, "socketcall.socketpair", tid, True)) {
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) );
if (VG_(clo_track_fds)) {
case SYS_SOCKET:
if (!fd_allowed(res, "socket", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
record_fd_open(tid, res, NULL);
/* int accept(int s, struct sockaddr *addr, int *addrlen); */
if (!fd_allowed(res, "accept", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
Addr addr_p = ((UInt*)arg2)[1];
Addr addrlen_p = ((UInt*)arg2)[2];
struct iovec * vec;
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)",
arg2, arg3 * sizeof(struct iovec) );
if (arg2 == VKI_FUTEX_FD) {
if (!fd_allowed(res, "futex", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
record_fd_open(tid, res, VG_(arena_strdup)(VG_AR_CORE, (Char*)arg1));
VG_(map_segment)(addr, size, VKI_PROT_READ|VKI_PROT_EXEC, SF_FIXED);
VG_(pad_address_space)();
- res = VG_(do_syscall)(SYSNO, arg1, arg2);
+ set_result( VG_(do_syscall)(SYSNO, arg1, arg2) );
VG_(unpad_address_space)();
if (res == 0) {
/* long io_destroy (aio_context_t ctx); */
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)) {
VG_TRACK( die_mem_munmap, arg1, size );
{
if (!fd_allowed(res, "mq_open", tid, True)) {
VG_(close)(res);
- res = -VKI_EMFILE;
+ set_result( -VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
record_fd_open(tid, res, VG_(arena_strdup)(VG_AR_CORE, (Char*)arg1));
MAYBE_PRINTF("mq_timedsend ( %d, %p, %d, %d, %p )\n",
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 );
if (arg5 != 0)
MAYBE_PRINTF("mq_timedreceive( %d, %p, %d, %p, %p )\n",
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 );
if (arg4 != 0)
/* int mq_notify(mqd_t mqdes, const struct sigevent *notification); */
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,
sizeof(struct sigevent) );
struct mq_attr *restrict omqstat); */
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) {
const struct vki_mq_attr *attr = (struct vki_mq_attr *)arg2;
VG_(message)
(Vg_DebugMsg,"Read the file README_MISSING_SYSCALL_OR_IOCTL.");
- res = -VKI_ENOSYS;
+ set_result( -VKI_ENOSYS );
}
static void bad_after(ThreadId tid, ThreadState *tst)