Windows 8 introduced a new implementation of the delay loading mechanism,
this time implemented almost entirely in the OS.  The 'glue' to hook this
new implementation up to the linker is provided in the Windows SDK as
dloadhelper.lib, and a somewhat incomplete header called
delayloadhelper.h is also provided in the Windows SDK.

This new implementation is required to be used in store apps that wish to
delay load, in lieu of libdelayimp.a.

Around the Windows 8.1 "November" update, delay loading got some
additional security features, such as the ability to set a flag to have
the delay load IAT in a read-only section.  The Visual Studio
"delayimp.lib" implementation gained some VirtualProtect calls to switch
back and forth between read-only and read-write when it needs to overwrite
the import thunks.  Updating the delayimp.c implementation here might be a
worthwhile future project.

I have tested linking in libdloadhelper.a on Windows 10 21H2 x86 and on
Windows 11 ARM64, and confirmed that the OS APIs are being used rather
than the delayimp.c implementation.  I was surprised that libdelayimp.a is
empty in mingw-w64, and the delayimp objects are in libmingwex.a instead.
I was concerned this may cause some conflict when trying to subsititute
the new implementation, but this does not seem to be a problem.

I added delay-f.c to libdloadhelper.a because it uses the same failure
hook symbol as delayimp, but because delay-f is in libmingwex (rather than
in delayimp) this is probably not necessary.  Also, the typedefs used in
the failure callback have some different names in the new header, so
perhaps a new .c file containing the failure hook symbol with the
'correct' type should be added to libdloadhelper.a instead.

Microsoft's documentation for these APIs is rather lacking.  As part of
this, I opened a pull request with them to at least make them not be
false.  https://github.com/MicrosoftDocs/win32/pull/1187


Jeremy Drake (2):
  headers: add delayloadhandler.h
  crt: add libdloadhelper.a

 mingw-w64-crt/Makefile.am                    | 17 ++++++
 mingw-w64-crt/libsrc/dloadhelper.c           | 63 ++++++++++++++++++++
 mingw-w64-headers/include/delayloadhandler.h | 46 ++++++++++++++
 3 files changed, 126 insertions(+)
 create mode 100644 mingw-w64-crt/libsrc/dloadhelper.c
 create mode 100644 mingw-w64-headers/include/delayloadhandler.h

-- 
2.35.1.windows.2



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to