From a1a7403b23e9c4c4491fa30c0270fa4d127efe05 Mon Sep 17 00:00:00 2001 From: Jan Beck Date: Tue, 28 May 2019 13:15:51 +0000 Subject: [PATCH 1/5] Fix bug when calling xsavec instruction There is an existing patch for the xsave instruction, but I came across an executable that fails with an xsavec instruction. This fixes that. --- tracers/pin/qirapin.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tracers/pin/qirapin.cpp b/tracers/pin/qirapin.cpp index 2d8e8f6b..0373055d 100644 --- a/tracers/pin/qirapin.cpp +++ b/tracers/pin/qirapin.cpp @@ -193,9 +193,9 @@ static inline void mmap_close(MMAPFILE fd) { close(fd); } static void *mmap_map(MMAPFILE fd, size_t size, size_t offset = 0) { - USIZE thesize=0; - OS_FileSizeFD(fd,&thesize); - if(static_cast(thesize) < offset+size) + struct stat st; + fstat(fd, &st); + if(static_cast(st.st_size) < offset+size) ftruncate(fd, offset+size); void *ret = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset); @@ -442,7 +442,7 @@ public: #ifndef TARGET_WINDOWS void fork_before(THREADID tid) { PIN_GetLock(&lock, 0); - // sync(); // commented out to be compatible with later PIN versions. Seems to work... + sync(); // TODO: Close all files, reopen later // I think this is only required for the current tid's data structure. } @@ -651,6 +651,12 @@ VOID Instruction(INS ins, VOID *v) { return; } + if(INS_Mnemonic(ins) == "XSAVEC") { + // Avoids "Cannot use IARG_MEMORYWRITE_SIZE on non-standard memory access of instruction at 0xfoo: xsavec ptr [rsp]" + // TODO: Bitch at the PIN folks. + return; + } + for(UINT32 i = 0; i < memOps; i++) { if(!filtered && INS_MemoryOperandIsRead(ins, i)) { INS_InsertPredicatedCall( From 0935c42da395f63e1e9d7850d7ec431b69beee3b Mon Sep 17 00:00:00 2001 From: Jan Beck Date: Tue, 28 May 2019 13:20:12 +0000 Subject: [PATCH 2/5] Add patch for xsavec instruction --- tracers/pin/qirapin.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tracers/pin/qirapin.cpp b/tracers/pin/qirapin.cpp index 0373055d..2eeb40c9 100644 --- a/tracers/pin/qirapin.cpp +++ b/tracers/pin/qirapin.cpp @@ -193,9 +193,11 @@ static inline void mmap_close(MMAPFILE fd) { close(fd); } static void *mmap_map(MMAPFILE fd, size_t size, size_t offset = 0) { - struct stat st; - fstat(fd, &st); - if(static_cast(st.st_size) < offset+size) + //struct stat st; + //fstat(fd, &st); + USIZE thesize=0; + OS_FileSizeFD(fd,&thesize); + if(static_cast(thesize) < offset+size) ftruncate(fd, offset+size); void *ret = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset); @@ -442,7 +444,7 @@ public: #ifndef TARGET_WINDOWS void fork_before(THREADID tid) { PIN_GetLock(&lock, 0); - sync(); + //sync(); // TODO: Close all files, reopen later // I think this is only required for the current tid's data structure. } @@ -650,7 +652,6 @@ VOID Instruction(INS ins, VOID *v) { // TODO: Bitch at the PIN folks. return; } - if(INS_Mnemonic(ins) == "XSAVEC") { // Avoids "Cannot use IARG_MEMORYWRITE_SIZE on non-standard memory access of instruction at 0xfoo: xsavec ptr [rsp]" // TODO: Bitch at the PIN folks. @@ -975,4 +976,3 @@ int main(int argc, char *argv[]) { process_state.init(PIN_GetPid()); PIN_StartProgram(); // Note that this unwinds the stack! } - From acc9fc52a192545576bc4900804ec30d9bb9a9bc Mon Sep 17 00:00:00 2001 From: Jan Beck Date: Tue, 28 May 2019 13:28:31 +0000 Subject: [PATCH 3/5] Update qirapin.cpp --- tracers/pin/qirapin.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tracers/pin/qirapin.cpp b/tracers/pin/qirapin.cpp index 2eeb40c9..da235b25 100644 --- a/tracers/pin/qirapin.cpp +++ b/tracers/pin/qirapin.cpp @@ -193,8 +193,6 @@ static inline void mmap_close(MMAPFILE fd) { close(fd); } static void *mmap_map(MMAPFILE fd, size_t size, size_t offset = 0) { - //struct stat st; - //fstat(fd, &st); USIZE thesize=0; OS_FileSizeFD(fd,&thesize); if(static_cast(thesize) < offset+size) @@ -444,7 +442,7 @@ public: #ifndef TARGET_WINDOWS void fork_before(THREADID tid) { PIN_GetLock(&lock, 0); - //sync(); + //sync(); // commented out to be compatible with later PIN versions. Seems to work... // TODO: Close all files, reopen later // I think this is only required for the current tid's data structure. } From d5e9fe58672ee0ad6443ffe34755deab20c29403 Mon Sep 17 00:00:00 2001 From: Jan Beck Date: Tue, 28 May 2019 13:29:29 +0000 Subject: [PATCH 4/5] Update qirapin.cpp --- tracers/pin/qirapin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracers/pin/qirapin.cpp b/tracers/pin/qirapin.cpp index da235b25..08f2d9c2 100644 --- a/tracers/pin/qirapin.cpp +++ b/tracers/pin/qirapin.cpp @@ -442,7 +442,7 @@ public: #ifndef TARGET_WINDOWS void fork_before(THREADID tid) { PIN_GetLock(&lock, 0); - //sync(); // commented out to be compatible with later PIN versions. Seems to work... + //sync();// commented out to be compatible with later PIN versions. Seems to work... // TODO: Close all files, reopen later // I think this is only required for the current tid's data structure. } From a5fadec67cfc75876d51c7048e8883acc222a715 Mon Sep 17 00:00:00 2001 From: Jan Beck Date: Tue, 28 May 2019 13:32:58 +0000 Subject: [PATCH 5/5] Update qirapin.cpp --- tracers/pin/qirapin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracers/pin/qirapin.cpp b/tracers/pin/qirapin.cpp index 08f2d9c2..a1aa3d40 100644 --- a/tracers/pin/qirapin.cpp +++ b/tracers/pin/qirapin.cpp @@ -442,7 +442,7 @@ public: #ifndef TARGET_WINDOWS void fork_before(THREADID tid) { PIN_GetLock(&lock, 0); - //sync();// commented out to be compatible with later PIN versions. Seems to work... + // sync(); // commented out to be compatible with later PIN versions. Seems to work... // TODO: Close all files, reopen later // I think this is only required for the current tid's data structure. }