Skip to content

Commit 09f2155

Browse files
committed
Log the return value for native syscalls
1 parent e6f10cb commit 09f2155

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/lib/shim/shim_syscall.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <alloca.h>
22
#include <assert.h>
33
#include <errno.h>
4+
#include <stdio.h>
45
#include <stdlib.h>
56
#include <sys/syscall.h>
67

@@ -181,6 +182,42 @@ static SysCallReg _shim_emulated_syscall_event(const ShimEvent* syscall_event) {
181182
rv.as_i64 = shim_native_syscall(
182183
syscall_event->event_data.syscall.syscall_args.number, regs[0].as_u64,
183184
regs[1].as_u64, regs[2].as_u64, regs[3].as_u64, regs[4].as_u64, regs[5].as_u64);
185+
186+
int straceFd = shimshmem_getProcessStraceFd(shim_processSharedMem());
187+
188+
// shadow would have alrady logged the syscall and arguments but wouldn't have
189+
// logged the return value, so we can log it here
190+
if (straceFd >= 0) {
191+
// TODO: format the time
192+
uint64_t emulated_time_ms = shim_sys_get_simtime_nanos();
193+
pid_t tid = shimshmem_getThreadId(shim_threadSharedMem());
194+
195+
bool oldNativeSyscallFlag = shim_swapAllowNativeSyscalls(true);
196+
197+
char buf[100] = {0};
198+
int len = snprintf(buf, sizeof(buf), "%018ld [tid %d] ^^^ = %ld\n",
199+
emulated_time_ms, tid, rv.as_i64);
200+
len = MIN(len, sizeof(buf));
201+
202+
int written = 0;
203+
while (1) {
204+
int write_rv = write(straceFd, buf + written, len - written);
205+
if (write_rv < 0) {
206+
if (errno == -EINTR || errno == -EAGAIN) {
207+
continue;
208+
}
209+
warning("Unable to write to strace log");
210+
break;
211+
}
212+
written += write_rv;
213+
if (written == len) {
214+
break;
215+
}
216+
}
217+
218+
shim_swapAllowNativeSyscalls(oldNativeSyscallFlag);
219+
}
220+
184221
return rv;
185222
}
186223
case SHD_SHIM_EVENT_SYSCALL: {

0 commit comments

Comments
 (0)