@@ -235,17 +235,24 @@ void Machine::setup_linux_system_calls()
235235 dst = address;
236236 }
237237 // Readv into the area
238+ const uint64_t read_length = regs.rsi ; // Don't align the read length
238239 std::array<Machine::WrBuffer, 256 > buffers;
239240 const size_t cnt =
240- cpu.machine ().writable_buffers_from_range (buffers.size (), buffers.data (), dst, length );
241+ cpu.machine ().writable_buffers_from_range (buffers.size (), buffers.data (), dst, read_length );
241242 // Seek to the given offset in the file and read the contents into guest memory
242243 if (preadv64 (real_fd, (const iovec *)&buffers[0 ], cnt, voff) < 0 ) {
243244 regs.rax = ~0LL ; /* MAP_FAILED */
244245 } else {
245246 regs.rax = dst;
246247 }
248+ // Zero the remaining area
249+ const size_t zero_length = length - read_length;
250+ if (zero_length > 0 )
251+ {
252+ cpu.machine ().memzero (dst + read_length, zero_length);
253+ }
247254 PRINTMMAP (" mmap(0x%lX, %lu, prot=%llX, flags=%llX) = 0x%llX\n " ,
248- address, length , regs.rdx , regs.r10 , regs.rax );
255+ address, read_length , regs.rdx , regs.r10 , regs.rax );
249256 cpu.set_registers (regs);
250257 return ;
251258 }
@@ -1072,14 +1079,18 @@ void Machine::setup_linux_system_calls()
10721079 struct rlimit64 lim{};
10731080 lim.rlim_cur = cpu.machine ().stack_address () - (4UL << 20 );
10741081 lim.rlim_max = cpu.machine ().stack_address ();
1082+ SYSPRINT (" prlimit64: current stack limit 0x%llX max 0x%llX\n " ,
1083+ lim.rlim_cur , lim.rlim_max );
10751084 cpu.machine ().copy_to_guest (oldptr, &lim, sizeof (lim));
10761085 }
10771086 else if (newptr != 0x0 )
10781087 {
1079- // struct rlimit64 lim {};
1080- // cpu.machine().copy_from_guest(&lim, newptr, sizeof(lim));
1081- // printf("prlimit64: new stack limit 0x%llX max 0x%llX\n",
1082- // lim.rlim_cur, lim.rlim_max);
1088+ #ifdef VERBOSE_SYSCALLS
1089+ struct rlimit64 lim {};
1090+ cpu.machine ().copy_from_guest (&lim, newptr, sizeof (lim));
1091+ SYSPRINT (" prlimit64: new stack limit 0x%llX max 0x%llX\n " ,
1092+ lim.rlim_cur , lim.rlim_max );
1093+ #endif
10831094 }
10841095 regs.rax = 0 ;
10851096 break ;
0 commit comments