microsoft / Detours

Detours is a software package for monitoring and instrumenting API calls on Windows. It is distributed in source code form.
MIT License
5.18k stars 1.01k forks source link

Allow compilation with MinGW to succeed #108

Closed virtuald closed 3 years ago

virtuald commented 4 years ago

What the title says. MinGW doesn't support __try and __except, so it's just defined out here as it doesn't seem there's a better way to handle it.

Note: Includes #107

msftclas commented 4 years ago

CLA assistant check
All CLA requirements met.

bgianfo commented 4 years ago

Without SEH support, it's not safe to execute the code that is currently guarded by try / except. You'll crash at runtime, you should be able to easily verify this by running any of the tests, they will most likely crash instantly.

I'm not sure it makes sense to even support detours being built and run in this configuration.

bgianfo commented 4 years ago

Also, since #107 is merged, it doesn't make much sense to include those changes here.

virtuald commented 4 years ago

I am actively using this code and detours works fine under MinGW with this patch applied. I haven't tried the tests, but we're able to hook arbitrary functions/instructions without further modifications.

I'm sure that if the API is used to access some invalid piece of memory that a crash would occur instead of an error code as intended. But since MinGW doesn't support SEH, I guess I would tell someone "don't do that", or "don't use MinGW + Detours for production code".

Thaodan commented 3 years ago

How did you compile it with mingw, by hand or using different makefiles?

virtuald commented 3 years ago

Using different makefiles. I used cmake, very simple.

bgianfo commented 3 years ago

Merging this as it appears harmless and enables this corner case scenario. Thanks @virtuald sorry for the delay!