Author: tkreuzer
Date: Fri Jul 24 06:24:36 2009
New Revision: 42169
URL:
http://svn.reactos.org/svn/reactos?rev=42169&view=rev
Log:
Implement delayimp lib
This library will allow to delay import from dlls, if used together with the corresponding
delayimport lib for that dll. An initial patch for dlltool can be found in bug #4730.
Based on Matt Pietrek's "Under the Hood" article:
http://www.microsoft.com/msj/1298/hood/hood1298.aspx and msdn documentation.
Added:
trunk/reactos/lib/sdk/delayimp/ (with props)
trunk/reactos/lib/sdk/delayimp/delayimp.c (with props)
trunk/reactos/lib/sdk/delayimp/delayimp.h (with props)
trunk/reactos/lib/sdk/delayimp/delayimp.rbuild (with props)
Modified:
trunk/reactos/lib/sdk/sdk.rbuild
Propchange: trunk/reactos/lib/sdk/delayimp/
------------------------------------------------------------------------------
--- bugtraq:logregex (added)
+++ bugtraq:logregex Fri Jul 24 06:24:36 2009
@@ -1,0 +1,2 @@
+([Ii]ssue|[Bb]ug)s? #?(\d+)(,? ?#?(\d+))*(,? ?(and |or )?#?(\d+))?
+(\d+)
Propchange: trunk/reactos/lib/sdk/delayimp/
------------------------------------------------------------------------------
bugtraq:message = See issue #%BUGID% for more details.
Propchange: trunk/reactos/lib/sdk/delayimp/
------------------------------------------------------------------------------
bugtraq:url =
http://www.reactos.org/bugzilla/show_bug.cgi?id=%BUGID%
Propchange: trunk/reactos/lib/sdk/delayimp/
------------------------------------------------------------------------------
tsvn:logminsize = 10
Added: trunk/reactos/lib/sdk/delayimp/delayimp.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/delayimp/delayimp.…
==============================================================================
--- trunk/reactos/lib/sdk/delayimp/delayimp.c (added)
+++ trunk/reactos/lib/sdk/delayimp/delayimp.c [iso-8859-1] Fri Jul 24 06:24:36 2009
@@ -1,0 +1,106 @@
+#include <windows.h>
+#include "delayimp.h"
+
+inline
+unsigned
+IndexFromPImgThunkData(PCImgThunkData pData, PCImgThunkData pBase)
+{
+ return pData - pBase;
+}
+
+extern const IMAGE_DOS_HEADER _image_base__;
+
+inline PVOID
+PFromRva(RVA rva)
+{
+ return (PVOID)(((ULONG_PTR)(rva)) + ((ULONG_PTR)&_image_base__));
+}
+
+/**** load helper ****/
+
+FARPROC WINAPI
+__delayLoadHelper2(PCImgDelayDescr pidd, PImgThunkData pIATEntry)
+{
+ DelayLoadInfo dli;
+ int index;
+ PImgThunkData pIAT;
+ PImgThunkData pINT;
+ HMODULE *phMod;
+ FARPROC pProc;
+
+ pIAT = PFromRva(pidd->rvaIAT);
+ pINT = PFromRva(pidd->rvaINT);
+ phMod = PFromRva(pidd->rvaHmod);
+ index = IndexFromPImgThunkData(pIATEntry, pIAT);
+
+ dli.cb = sizeof(dli);
+ dli.pidd = pidd;
+ dli.ppfn = (FARPROC*)pIATEntry->u1.Function;
+ dli.szDll = PFromRva(pidd->rvaDLLName);
+ dli.dlp.fImportByName = !(pINT[index].u1.Ordinal & IMAGE_ORDINAL_FLAG);
+ if (dli.dlp.fImportByName)
+ {
+ /* u1.AdressOfData points to a IMAGE_IMPORT_BY_NAME struct */
+ PIMAGE_IMPORT_BY_NAME piibn = PFromRva((RVA)pINT[index].u1.AddressOfData);
+ dli.dlp.szProcName = (LPCSTR)&piibn->Name;
+ }
+ else
+ {
+ dli.dlp.dwOrdinal = pINT[index].u1.Ordinal & ~IMAGE_ORDINAL_FLAG;
+ }
+ dli.hmodCur = *phMod;
+ dli.pfnCur = (FARPROC)pIAT[index].u1.Function;
+ dli.dwLastError = GetLastError();
+ pProc = __pfnDliNotifyHook2(dliStartProcessing, &dli);
+ if (pProc)
+ {
+ pIAT[index].u1.Function = (DWORD)pProc;
+ return pProc;
+ }
+
+ if (dli.hmodCur == NULL)
+ {
+ dli.hmodCur = LoadLibraryA(dli.szDll);
+ if (!dli.hmodCur)
+ {
+ dli.dwLastError = GetLastError();
+ __pfnDliFailureHook2(dliFailLoadLib, &dli);
+// if (ret)
+// {
+// }
+ // FIXME: raise exception;
+ return NULL;
+ }
+ *phMod = dli.hmodCur;
+ }
+
+ /* dli.dlp.szProcName might also contain the ordinal */
+ pProc = GetProcAddress(dli.hmodCur, dli.dlp.szProcName);
+ if (!pProc)
+ {
+ dli.dwLastError = GetLastError();
+ __pfnDliFailureHook2(dliFailGetProc, &dli);
+ // FIXME: handle return value & raise exception
+ return NULL;
+ }
+ pIAT[index].u1.Function = (DWORD)pProc;
+
+ return pProc;
+}
+
+/*** The default hooks ***/
+
+FARPROC WINAPI
+DefaultDliNotifyHook2(unsigned dliNotify, PDelayLoadInfo pdli)
+{
+ return NULL;
+}
+
+FARPROC WINAPI
+DefaultDliFailureHook2(unsigned dliNotify, PDelayLoadInfo pdli)
+{
+ return NULL;
+}
+
+PfnDliHook __pfnDliNotifyHook2 = DefaultDliNotifyHook2;
+PfnDliHook __pfnDliFailureHook2 = DefaultDliFailureHook2;
Propchange: trunk/reactos/lib/sdk/delayimp/delayimp.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/lib/sdk/delayimp/delayimp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/delayimp/delayimp.…
==============================================================================
--- trunk/reactos/lib/sdk/delayimp/delayimp.h (added)
+++ trunk/reactos/lib/sdk/delayimp/delayimp.h [iso-8859-1] Fri Jul 24 06:24:36 2009
@@ -1,0 +1,65 @@
+#ifndef _DELAYIMP_H_
+#define _DELAYIMP_H_
+
+typedef void *RVA;
+
+typedef IMAGE_THUNK_DATA *PImgThunkData;
+typedef const IMAGE_THUNK_DATA *PCImgThunkData;
+
+enum
+{
+ dlattrRva
+};
+
+/* Notification codes */
+enum
+{
+ dliStartProcessing,
+ dliNotePreLoadLibrary,
+ dliNotePreGetProcAddress,
+ dliFailLoadLib,
+ dliFailGetProc,
+ dliNoteEndProcessing,
+};
+
+typedef struct ImgDelayDescr
+{
+ DWORD grAttrs;
+ RVA rvaDLLName;
+ RVA rvaHmod;
+ RVA rvaIAT;
+ RVA rvaINT;
+ RVA rvaBoundIAT;
+ RVA rvaUnloadIAT;
+ DWORD dwTimeStamp;
+} ImgDelayDescr, *PImgDelayDescr;
+typedef const ImgDelayDescr *PCImgDelayDescr;
+
+typedef struct DelayLoadProc
+{
+ BOOL fImportByName;
+ union
+ {
+ LPCSTR szProcName;
+ DWORD dwOrdinal;
+ };
+} DelayLoadProc;
+
+typedef struct DelayLoadInfo
+{
+ DWORD cb;
+ PCImgDelayDescr pidd;
+ FARPROC *ppfn;
+ LPCSTR szDll;
+ DelayLoadProc dlp;
+ HMODULE hmodCur;
+ FARPROC pfnCur;
+ DWORD dwLastError;
+} DelayLoadInfo, *PDelayLoadInfo;
+
+typedef FARPROC (WINAPI *PfnDliHook)(unsigned, PDelayLoadInfo);
+
+extern PfnDliHook __pfnDliNotifyHook2;
+extern PfnDliHook __pfnDliFailureHook2;
+
+#endif /* not _DELAYIMP_H_ */
Propchange: trunk/reactos/lib/sdk/delayimp/delayimp.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/lib/sdk/delayimp/delayimp.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/delayimp/delayimp.…
==============================================================================
--- trunk/reactos/lib/sdk/delayimp/delayimp.rbuild (added)
+++ trunk/reactos/lib/sdk/delayimp/delayimp.rbuild [iso-8859-1] Fri Jul 24 06:24:36 2009
@@ -1,0 +1,7 @@
+<?xml version="1.0"?>
+<!DOCTYPE group SYSTEM "../../../tools/rbuild/project.dtd">
+<group>
+ <module name="delayimp" type="staticlibrary"
unicode="yes">
+ <file>delayimp.c</file>
+ </module>
+</group>
Propchange: trunk/reactos/lib/sdk/delayimp/delayimp.rbuild
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/lib/sdk/sdk.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/sdk.rbuild?rev=421…
==============================================================================
--- trunk/reactos/lib/sdk/sdk.rbuild [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/sdk.rbuild [iso-8859-1] Fri Jul 24 06:24:36 2009
@@ -4,6 +4,9 @@
<directory name="crt">
<xi:include href="crt/crt.rbuild" />
<xi:include href="crt/libcntpr.rbuild" />
+ </directory>
+ <directory name="delayimp">
+ <xi:include href="delayimp/delayimp.rbuild" />
</directory>
<directory name="dxguid">
<xi:include href="dxguid/dxguid.rbuild" />