Under what conditions do I need to configure SEH unind info for the x86-64 build function?

The 64-bit version of Windows ABI defines a generic exception handling mechanism that I believe is used in conjunction with C ++ exceptions and structured exceptions that are available even in other languages ​​such as C.

If I write an x86-64 build procedure that needs to be compiled into nasm and linked to a C or C ++ library, what kind of placements do I need to do on Windows in terms of generating information for unwinding, etc.?

I do not plan to throw any exceptions directly in the assembly code, although, I believe, it is possible that the code may receive an access violation if the user buffer is invalid, etc.

I would like to write the minimum possible for this to work, especially since it seems that nasm has poor support for generating U-turn information, and using MASM not an option for this cross-platform project. I need to use (hence save and restore) non-volatile registers.

+5
source share
2 answers

Typically, Windows x64 requires all the features to provide unwinding information. The only exception is for sheet functions that do not change rsp and do not change any non-volatile registers.

+8
source

Judging by the context of your question, what you really want to know is the practical consequences of not providing shutdown information for your build functions without a sheet in x64 Windows. Since C ++ exceptions are implemented based on SEH exceptions, when I talk about the exceptions below, I mean as β€œnative” (violation of access rights, what is raised using RaiseException , etc.), So are the exceptions C ++. Here is the list above:

  • Exceptions will not be able to go through your function.

It is important to note that this issue is not to throw an exception, or in violation of access rights directly in your function. Let them say that your assembly code calls a C ++ function that throws an exception. Even if the calling object of your assembly has a matching catch , it will never be able to catch an exception, since unwinding will stop in your function without decompressing the data.

  • When passing through the stack, stop moves stop at a function without unwinding data (or go astray, the point is that you will receive an invalid call stack)

In principle, everything that goes onto the stack is screwed up if your function is present in the call stack (debuggers when displaying the call stack, profilers, etc.).

This interferes with everything that relies on UEF. For example, custom fault handlers. Or something potentially more relevant: std::terminate will not return in this case if your program throws a C ++ exception that is unhandled (since it is dictated by the C ++ standard). The MSVC runtime uses the UEF to implement this, so this will not work either.


Are you developing a third-party library? If in this case the importance of the above points will depend on the use of your customers.

+2
source

Source: https://habr.com/ru/post/1270238/


All Articles