Comments (8)
Concretely:
diff --git a/src/win/hooks.c b/src/win/hooks.c
index eb1e66a..529612b 100644
--- a/src/win/hooks.c
+++ b/src/win/hooks.c
@@ -3,6 +3,8 @@
#endif
#include <winternl.h>
#include <limits.h>
+#include <processthreadsapi.h>
+
#undef ASSERT
#include "dbg.h"
@@ -213,7 +215,7 @@ static NTSTATUS NTAPI hNtQueryFullAttributesFile(POBJECT_ATTRIBUTES oa, PFILE_NE
static NTSTATUS NTAPI hNtResumeThread(HANDLE th, PULONG sc) {
NTSTATUS r;
D;
- if (!patchInstalled())
+ if (!patchInstalled(GetProcessIdOfThread(th)))
injectThread(th);
r = oNtResumeThread(th, sc);
return r;
diff --git a/src/win/patch.c b/src/win/patch.c
index 6fdc26d..7b63f0a 100644
--- a/src/win/patch.c
+++ b/src/win/patch.c
@@ -95,12 +95,12 @@ void patchInstall(void *orig, void *hook, void **preal, const char *nm) {
dbg("modules patched\n");
}
-int patchInstalled() {
+int patchInstalled(DWORD old) {
int ret;
ASSERT(s_hooked);
- ret = (int)(intptr_t)TlsGetValue(s_hooked);
- CHK(TlsSetValue(s_hooked, (void *)1));
- return ret;
+ ret = (DWORD)(intptr_t)TlsGetValue(s_hooked);
+ CHK(TlsSetValue(s_hooked, (void *)old));
+ return ret == old;
}
void patchInit() {
diff --git a/src/win/patch.h b/src/win/patch.h
index a9628ec..64ba3d0 100644
--- a/src/win/patch.h
+++ b/src/win/patch.h
@@ -1,5 +1,4 @@
void patchInit();
void patchTerm();
void patchInstall(void *orig, void *hook, void **preal, const char *nm);
-int patchInstalled();
-
+int patchInstalled(DWORD old);
from fsatrace.
Looks certainly better than what we have now, but I guess it isn't bulletproof either. A different thread could call ResumeThread() and we could end up with 2 patches installed.
I guess a 4 KB bit mask indexed by the lower bits of (pid/4) could be quite robust.
from fsatrace.
Here's what I thought could be a solution, but it didn't pass the tests.
Unfortunately I can't check with a windows box yet.
from fsatrace.
I'll try tomorrow on a real windows box. Why do the pid byte masking and not just have an actual array with the values seen?
from fsatrace.
OK, I think I found the bug. Please, check if the fix-23 branch works for you.
from fsatrace.
Yeah, it's kind of silly to worry about that table size considering the amount of memory I reserve for the logs :)
from fsatrace.
Oh, you mean doing a lookup in the array? Yes, that would probably be a better option. Feel free to change it.
from fsatrace.
It worked for me, thanks a lot. Given it's currently working I'd probably just leave it at that.
from fsatrace.
Related Issues (20)
- sh.exe test fails on Windows
- Doesn't trace execution on Windows HOT 4
- Make a release HOT 1
- Output file even on non-zero exit code HOT 1
- Can't trace Go code on Linux HOT 2
- Can't trace gcc on Mac HOT 2
- fsatrace isn't recording executable being run as a "read". HOT 6
- Clarify (or clean up) the Windows makefile HOT 1
- Can't spawn a 32bit process from a .bat file HOT 3
- Tracking reads from non-existing files HOT 6
- Corruption of PATH HOT 2
- failures on ubuntu 20.04 HOT 6
- Quantifying fsatrace's coverage HOT 2
- Consider ETW on Windows HOT 3
- Removing a symlink looks like removing its target HOT 8
- segfault in emiting op HOT 8
- Tracing mkdir syscalls
- Basic tracing does not appear to work on macOS Monterey Version 12.5.1 HOT 3
- Fails to compile on GitHub Mac runners (incompatible architecture) HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fsatrace.