Comments (11)
Patch-free workaround:
- call
HeapLock(GetProcessHeap())
beforeDetourTransactionBegin()
- call
HeapFree(GetProcessHeap())
afterDetourTransactionCommit()
/DetourTransactionAbort()
Edit: turns out this is suggested at https://devblogs.microsoft.com/oldnewthing/20170125-00/?p=95255
from detours.
To be clear, I'm only suggesting it as a work around for common cases. The thorough new allocator approach is more thorough, and likely better for merging.
Yep, if another thread has the lock and is busy or suspended, it can't acquire the lock until that's free. Whether this is OK for a workaround depends on your use case.
HeapLock/HeapUnlock should always be in matched pairs, so being unlocked by another thread "shouldn't" happen. This would be extremely misbehaved code, but there's admittedly lots of misbehaved code out there - and I'm surprised that HeapUnlock doesn't require that HeapUnlock is called from the same thread as HeapLock.
I'd much rather see a thorough fix like the custom heap/alloc merged into detours - but until that's done, where I am able to assume there's no long-running heap locks and no cross-thread heap unlock, I prefer to minimize the amount of code that I'm using that hasn't been reviewed/merged by the project maintainers.
from detours.
Yes, it's possible. I met it.
from detours.
I'm fairly reliably hitting this, and @adams85's patch mentioned above fixes it for me (apply with --ignore-whitespace
to get a readable diff) - however, in debug builds, there's another deadlock in debug builds, as DETOUR_TRACE calls printf
from detours.
please use PR #144 to fix your rest problems like DETOUR_TRACE you said.
I'm fairly reliably hitting this, and @adams85's patch mentioned above fixes it for me (apply with
--ignore-whitespace
to get a readable diff) - however, in debug builds, there's another deadlock in debug builds, as DETOUR_TRACE calls printf
from detours.
While that might be a more thorough fix, I'm not comfortable diverging that far from master, or familiar enough with Detours to review #144 even for my own use. The smaller patch - and sticking to release builds of Detours - is a better solution for me.
from detours.
@sonyps5201314 fwiw, while I don't work on Detours or at Microsoft, it's generally best to create pull requests that address a single bug/issue at a time, keeping them as small as possible - this makes them much easier to review, and usually leads to them getting merged by the project maintainers much faster.
from detours.
@fredemmott,Please read the latest reply in PR #144 to answer your doubts.
from detours.
@fredemmott Thanks for pointing out HeapLock
/HeapUnlock
. This is much simpler, so I've updated my fork to use this. I'll even submit this as a PR, let's see how the maintainers like it.
from detours.
As it turned out, the HeapLock
approach isn't viable because of a nasty race condition (for more details, see #232 (comment) and #144 (comment)). It seems that the only fail-safe way to tackle this bug is HeapCreate
and custom allocation as mentioned above.
from detours.
I started a PR which enables you to use Detours in a way that avoids deadlocks. See the PR description for details at #261. This doesn't solve the issue for any existing Detours user. You have to change your code that uses Detours in the way explained in the PR description.
from detours.
Related Issues (20)
- Using Detours if either the .exe or the .dll is within a directory with unicode characters? HOT 12
- Hook on return
- This repo is missing important files HOT 6
- NMAKE failing at the end. HOT 4
- NMAKE failed HOT 1
- Windows 11 ARM64 Processor x86, x64 COM API Hook Crash.
- `detour_skip_jmp` for x64 doesn't support `rex.w` prefix
- Wiki is missing sample tracessl
- `detour_skip_jmp` for arm64 doesn't support unconditional branch HOT 1
- `detour_sign_extend` is implemented incorrectly
- Noting the Optimizations greatly influence the result
- return value of 'main()'
- Calling DetourCreateProcessWithDllsW crashes .NET applications compiled for Any-CPU
- Hook unexported functions HOT 5
- Hooking inline function HOT 1
- Incorrect Behaviour: Arm64 CopyLdrLiteral for non-SIMD inlines Pointer Read
- Incorrect Behaviour: Arm64 CopyLdrLiteral rewrites Prefetch as Memory Read, which can Trash a Potentially Used Register
- <BUG>crash on jmp addr? HOT 1
- contains invalid OMF record, type 0x21 (possibly COFF) HOT 3
- Unable to hook winsock2 recv() HOT 1
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 detours.