From 2a7d3ae768f9e5b29acd5cb743c3fb13640a391c Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Thu, 2 Jan 2020 14:27:24 +0100 Subject: [PATCH] sys_statx: don't complain if both |filename| and |buf| are NULL. So as to work around the Rust library's dubious use of statx. --- coregrind/m_syswrap/syswrap-linux.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 87c513a21..96c309e28 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -3692,10 +3692,19 @@ PRE(sys_statx) PRINT("sys_statx ( %ld, %#" FMT_REGWORD "x(%s), %ld, %ld, %#" FMT_REGWORD "x )", (Word)ARG1,ARG2,(char*)(Addr)ARG2,(Word)ARG3,(Word)ARG4,ARG5); PRE_REG_READ5(long, "statx", - int, dirfd, char *, file_name, int, flags, + int, dirfd, char *, filename, int, flags, unsigned int, mask, struct statx *, buf); - PRE_MEM_RASCIIZ( "statx(file_name)", ARG2 ); - PRE_MEM_WRITE( "statx(buf)", ARG5, sizeof(struct vki_statx) ); + // Work around Rust's dubious use of statx, as described here: + // https://github.com/rust-lang/rust/blob/ + // ccd238309f9dce92a05a23c2959e2819668c69a4/ + // src/libstd/sys/unix/fs.rs#L128-L142 + // in which it passes NULL for both filename and buf, and then looks at the + // return value, so as to determine whether or not this syscall is supported. + Bool both_filename_and_buf_are_null = ARG2 == 0 && ARG5 == 0; + if (!both_filename_and_buf_are_null) { + PRE_MEM_RASCIIZ( "statx(filename)", ARG2 ); + PRE_MEM_WRITE( "statx(buf)", ARG5, sizeof(struct vki_statx) ); + } } POST(sys_statx) { -- 2.11.4.GIT