|
1 | 1 | #include <alloca.h> |
2 | 2 | #include <assert.h> |
3 | 3 | #include <errno.h> |
| 4 | +#include <stdio.h> |
4 | 5 | #include <stdlib.h> |
5 | 6 | #include <sys/syscall.h> |
6 | 7 |
|
@@ -181,6 +182,42 @@ static SysCallReg _shim_emulated_syscall_event(const ShimEvent* syscall_event) { |
181 | 182 | rv.as_i64 = shim_native_syscall( |
182 | 183 | syscall_event->event_data.syscall.syscall_args.number, regs[0].as_u64, |
183 | 184 | 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 | + |
184 | 221 | return rv; |
185 | 222 | } |
186 | 223 | case SHD_SHIM_EVENT_SYSCALL: { |
|
0 commit comments