-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Absent alignment requirements for the CONTEXT struct #1044
Comments
Agree, there's a higher level packing/architecture bug here in metadata, transferring to that repo. Related: |
Any update on this? Just ran into this issue. |
@kennykerr, it doesn't fixed yet as I know, but you could use a wrapper with the alignment requirement. Something like this:
That's all I could advise for now. |
This issue has been reported again: #1412 |
Reported again: #1477 We've even had projects stop using windows-rs in part because this issue is not fixed: EmbarkStudios/crash-handling#62 |
@mikebattista Just an update: I've been looking into this and haven't found an easy fix yet. (I already tried adding support for per-architecture |
@tannergooding is
|
I added
Is this on your radar to support? In the absence of this, I guess we'll need to manually decorate structs with this macro at a per-architecture level. |
dotnet/ClangSharp#409 looks related. |
Note that packing and alignment are related but different. In MSVC, |
What do you expect on the metadata here for Just |
This can't be represented using It would need to be a distinct/separate attribute which is only respected by the languages that support specifying custom alignment/packing. |
Could maybe set |
I'm pretty sure we can't reuse pack. Just capture the alignment as a separate attribute and then have some build validation that ensures it's not mixed in with packing. |
At a minimum, can you read the Good examples are the
|
Here's a good background on alignment and packing. https://doc.rust-lang.org/reference/type-layout.html |
Those are all tagged with DECLSPEC_ALIGN which ClangSharp doesn't scrape. |
In .NET, alignment impacts allocation addresses while packing impacts field offsets. Alignment is a superset of packing and so It's also not that ClangSharp doesn't scrape the attribute, it's that it ignores overalignment today because .NET can't respect it. ClangSharp likely should surface a warning by default on such structs, specifying that it found an overaligned struct and specify what alignment it will be treated with instead. It should also emit some There is a separate issue in the above, however, that types such as While I can trivially update ClangSharp to emit something like |
The |
Yes we already handle multiple passes per architecture and then merging the results back. The problem is there's no record of DECLSPEC_ALIGN in the scraped output so that context is lost. If a NativeAlignment attribute were scraped, it should be persisted during our merge process. |
I'm posting here as well for visibility, as I've seen a wrong presumption on several different issues so far. Packing always matters, even if the struct only has a single field. The following godbolt example gives a more concrete visualization of this. That is the following code: #include <Windows.h>
#include <pshpack4.h>
struct MINIDUMP_INCLUDE_MODULE_CALLBACK1 {
ULONG64 BaseOfImage;
};
#include <poppack.h>
struct MINIDUMP_INCLUDE_MODULE_CALLBACK2 {
ULONG64 BaseOfImage;
};
struct Test1 {
BYTE x;
MINIDUMP_INCLUDE_MODULE_CALLBACK1 y;
};
struct Test2 {
BYTE x;
MINIDUMP_INCLUDE_MODULE_CALLBACK2 y;
};
unsigned M1() { return offsetof(Test1, y); }
unsigned M2() { return offsetof(Test2, y); } Gives you: unsigned int M1(void) PROC ; M1
mov eax, 4
ret 0
unsigned int M1(void) ENDP ; M1
unsigned int M2(void) PROC ; M2
mov eax, 8
ret 0
unsigned int M2(void) ENDP ; M2 |
As long as the metadata can capture both pack/align as described by MSVC I'll figure out how to make it work with Rust, I just can't make any headway until the metadata is actually complete and accurate. |
Hello. Are there any updates or this? I would like to add, thanks or all the amazing contributions. Respect. |
So, is there light at the end of the tunnel? |
I've been pretty heads down on other work related to .NET 9 and haven't had a chance to update ClangSharp. Contributions to dotnet/clangsharp are more than welcome to enable this scenario and should overall be fairly straightforward to do. |
Which crate is this about?
windows, windows-sys
Crate version
No response
Summary
According to the definition in the Windows.h, the CONTEXT struct must be aligned by 16 bytes, but it is not neither in windows_rs, nor in windows_sys (it's just a #[repr(C)] here).
It causes an ERROR_NOACCESS errors in the GetThreadContext()/SetThreadContext() functions.
Toolchain version/configuration
No response
Reproducible example
No response
Crate manifest
No response
Expected behavior
No response
Actual behavior
No response
Additional comments
No response
The text was updated successfully, but these errors were encountered: