mingw-w64 / mingw-w64.github.io

mingw-w64.net web page contents (The new web page)
Other
599 stars 1.34k forks source link

The MinGW headers are missing SAL annotations #41

Closed LordNoteworthy closed 2 months ago

LordNoteworthy commented 1 year ago

Hello,

If we compare the prototypes from the Windows SDK:

WINBASEAPI
HANDLE
WINAPI
CreateFileA(
    _In_ LPCSTR lpFileName,
    _In_ DWORD dwDesiredAccess,
    _In_ DWORD dwShareMode,
    _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
    _In_ DWORD dwCreationDisposition,
    _In_ DWORD dwFlagsAndAttributes,
    _In_opt_ HANDLE hTemplateFile
    );

Versus the minGW ones:

  WINBASEAPI HANDLE WINAPI CreateFileA (LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);

You can see SAL annotations missing. Is there any way to generate them with those annotations ?

Cheers.

Biswa96 commented 1 year ago

The SAL annotations are defined in mingw-w64-headers/include/sal.h as empty macros. Those are not required in mingw toolchain.

LordNoteworthy commented 1 year ago

Thanks a lot @Biswa96 for your answer.

Yes, I understand that they are not required for mingw toolchain, I was wondering if I can re-generate the headers so that they includes those SAL annotations or somehow modify the code.

Just to put some context, I am using the mingw headers just to parse the Windows APIs, and I happen to need those annotations. I am not really compiling anything, just parsing the header files.

As you know, those SAL annotations only works in MSVC and obviously don't make sense to have them in mingw headers. I am asking just to get some idea or feedback from developers who are familiar with the mingw codebase and recommend some hack I can do to have them.

Cheers.

Biswa96 commented 1 year ago

I am using the mingw headers just to parse the Windows APIs

That seems new to me. Would you like to explain the requirement? Maintainers may provide some information.

LordNoteworthy commented 1 year ago

I work on an Win32 API tracer. It hooks APIs so we can log them. To be able to that, I need the prototypes of all Windows APIs, something like this: https://github.com/saferwall/winsdk2json/blob/main/assets/apis.json

I am the author of that repo, I was able to obtain that data simply by using regex. However sometimes, the Windows APIs get quiet complex and it is very hard to extract the functions prototypes without having a proper C language parser.

So I started using https://github.com/zchee/cznic-ccgo which takes a C code as input and translate it to an AST.

I had issues with parsing the Windows SDK directly, because that library cannot deal with a lot of MS compiler specific features and its more tested against GCC toolchain. That's what brought me to this project.

Now I can extract all the prototypes that I need:

...
DWORD GetFileVersionInfoSizeExA (DWORD dwFlags,LPCSTR lpwstrFilename,LPDWORD lpdwHandle,)
DWORD GetFileVersionInfoSizeExW (DWORD dwFlags,LPCWSTR lpwstrFilename,LPDWORD lpdwHandle,)
WINBOOL GetFileVersionInfoA (LPCSTR lptstrFilename,DWORD dwHandle,DWORD dwLen,LPVOID lpData,)
WINBOOL GetFileVersionInfoW (LPCWSTR lptstrFilename,DWORD dwHandle,DWORD dwLen,LPVOID lpData,)
WINBOOL GetFileVersionInfoExA (DWORD dwFlags,LPCSTR lpwstrFilename,DWORD dwHandle,DWORD dwLen,LPVOID lpData,)
WINBOOL GetFileVersionInfoExW (DWORD dwFlags,LPCWSTR lpwstrFilename,DWORD dwHandle,DWORD dwLen,LPVOID lpData,)
DWORD VerLanguageNameA (DWORD wLang,LPSTR szLang,DWORD nSize,)
DWORD VerLanguageNameW (DWORD wLang,LPWSTR szLang,DWOR
...

The only thing I am missing is those SAL annotations.

I apologies because this issue is a bit out of topic, please feel free to close the issue.

Cheers.

Kreijstal commented 3 months ago

i guess you would have to use msvc headers instead.. no?

LordNoteworthy commented 2 months ago

That's the only way yeah, thanks @Kreijstal