Programming 版 (精华区)
发信人: zpw (zhao), 信区: Programming
标 题: Exporting Functions from VxDs to WDM Drivers
发信站: 紫 丁 香 (Wed Jul 29 21:02:40 1998), 转信
Exporting Functions from VxDs to WDM Drivers
VxDs and Win32 Driver Model drivers coexist on Windows 98. These two kinds of
drivers employ different methods of dynamic linkage, i.e. the means by which
the drivers link to external functions in other drivers. VxDs rely on a
software interrupt ( INT 0x20 ), which is followed in the instruction stream
by a constant that identifies the target service. WDM drivers rely on a
load-time method based on the same constructs in the PE executable that are
used by applications to link to DLLs.
Sometimes you want a WDM driver to call a function that is implemented in a
VxD. If the VxD exports the function through its VxD Service Table, then it is
possible to call the service by inserting an INT 0x20 sequence in the WDM
driver. However, this code won't work on Windows NT 5.0, because the INT 0x20
dynamic linkage mechanism does not exist on that platform.
A better solution is to export the function from the VxD in a way that enables
the system to locate it using the normal load-time linkage mechanism for WDM
drivers. That way, imported functions can be resolved in the same way on all
WDM platforms.
Windows 95 and Windows 98 provide the service PELDR_AddExportTable for this
purpose. It allows a VxD to export a set of functions to PE modules by
specifying a set of function names, addresses, and ordinals. Here is the
VtoolsD prototype for the service:
LRESULT PELDR_AddExportTable(
PHPEEXPORTTABLE phExportTable,
PSTR pszModuleName,
ULONG cExportedFunctions,
ULONG cExportedNames,
ULONG ulOrdinalBase,
PVOID *pExportNameList,
PUSHORT pExportOrdinals,
PVOID *pExportAddrs,
PHLIST phList
);
And the parameters are as follows:
phExportTable is the address of the variable that receives the handle of the
export table on output.
pszModuleName points to the null terminated name of the module to be associated
with the export table. This must match the name that the WDM
driver uses to identify functions that it imports.
cExportedFunctions is the number of functions to be exported.
cExportedNames is the number of exported functions for which names are provided.
ulOrdinalBase is the base ordinal for the set of functions.
pExportNameList is the address of an array of pointers to null terminated
functions names.
pExportOrdinals is the address of an array of ordinals. These values are
zero-based array indices into the array pointed to by
pExportAddrs. The length of this array is equal to
cExportedFunctions. If the ith element of this array is zero,
then the ith element of the array pointed to by pExportAddrs
is the address of the function whose ordinal is given by
parameter ulOrdinalBase.
pExportAddrs is the address of the array of addresses of the exported functions.
phList is the address of a handle for a list of import tables. The service adds
the new export table to the list. A driver that controls loading of PE
modules can use this list to restrict the set of export tables used to
resolve imports. Other drivers simply pass NULL, which causes the
service to add the new export table to the global list of export table.
Note that the VxD must be loaded prior to the WDM driver in order for this to
work, and the tables holding the names, addresses, and ordinals must remain
intact.
To remove an export table, use the service PELDR_RemoveExportTable.
Creating export tables is not something that most VxDs have to do. However,
it could be helpful in enabling your WDM driver to interoperate on multiple
WDM platforms
--
※ 来源:.紫 丁 香 bbs.hit.edu.cn.[FROM: yaoyu.hit.edu.cn]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:4.675毫秒