devload.pp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2008 Free Pascal development team.
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. ********************************************************************** }
  10. //
  11. // Module Name:
  12. //
  13. // devload.h
  14. //
  15. // Abstract:
  16. //
  17. // Device loader structures and defines
  18. //
  19. //
  20. // Microsoft Windows Mobile 6.0 for PocketPC SDK.
  21. //
  22. {$IFNDEF FPC_DOTTEDUNITS}
  23. unit devload;
  24. {$ENDIF FPC_DOTTEDUNITS}
  25. {$CALLING cdecl}
  26. interface
  27. {$IFDEF FPC_DOTTEDUNITS}
  28. uses WinApi.Windows;
  29. {$ELSE FPC_DOTTEDUNITS}
  30. uses Windows;
  31. {$ENDIF FPC_DOTTEDUNITS}
  32. // @doc DRIVERS
  33. //
  34. // These keys are under HKEY_LOCAL_MACHINE
  35. //
  36. const
  37. DEVLOAD_DRIVERS_KEY = 'Drivers';
  38. DEVLOAD_BUILT_IN_KEY = 'Drivers\BuiltIn';
  39. DEVLOAD_PCMCIA_KEY = 'Drivers\PCMCIA';
  40. DEVLOAD_ACTIVE_KEY = 'Drivers\Active';
  41. DEVLOAD_DETECT_KEY = DEVLOAD_PCMCIA_KEY + '\Detect';
  42. //
  43. // These are the required and optional values under a device key.
  44. //
  45. const
  46. DEVLOAD_DLLNAME_VALNAME = 'Dll'; // DLL name (required)
  47. DEVLOAD_DLLNAME_VALTYPE = REG_SZ;
  48. DEVLOAD_ICLASS_VALNAME = 'IClass'; // Class(es) of device interface (semi-required)
  49. DEVLOAD_ICLASS_VALTYPE = REG_MULTI_SZ;
  50. DEVLOAD_LOADORDER_VALNAME = 'Order'; // LoadOrder (optional)
  51. DEVLOAD_LOADORDER_VALTYPE = REG_DWORD;
  52. DEVLOAD_ENTRYPOINT_VALNAME = 'Entry'; // Entrypoint name (deprecated)
  53. DEVLOAD_ENTRYPOINT_VALTYPE = REG_SZ;
  54. DEVLOAD_PREFIX_VALNAME = 'Prefix'; // Device prefix (optional)
  55. DEVLOAD_PREFIX_VALTYPE = REG_SZ;
  56. DEVLOAD_INDEX_VALNAME = 'Index'; // Device index (optional)
  57. DEVLOAD_INDEX_VALTYPE = REG_DWORD;
  58. DEVLOAD_CONTEXT_VALNAME = 'Context'; // Device context (optional)
  59. DEVLOAD_CONTEXT_VALTYPE = REG_DWORD;
  60. DEVLOAD_INITCODE_VALNAME = 'Ioctl'; // Device IO control code to indicate context (deprecated)
  61. DEVLOAD_INITCODE_VALTYPE = REG_DWORD;
  62. DEVLOAD_BUSINITCODE_VALNAME = 'BusIoctl'; // Bus IO control code to indicate context
  63. DEVLOAD_BUSINITCODE_VALTYPE = REG_DWORD;
  64. DEVLOAD_FLAGS_VALNAME = 'Flags'; // Flag to control loading/unloading (optional)
  65. DEVLOAD_FLAGS_VALTYPE = REG_DWORD;
  66. DEVLOAD_INTRPEND_VALNAME = 'NoIntrPend'; // Is the interrupt pending flag invalid (optional)
  67. DEVLOAD_INTRPEND_VALTYPE = REG_DWORD;
  68. DEVLOAD_REPARMS_VALNAME = 'RegenumParms'; // Regenum parms passed into Active\xx
  69. DEVLOAD_REPARMS_VALTYPE = REG_MULTI_SZ;
  70. DEVLOAD_MEMBASE_VALNAME = 'MemBase'; // Memory base (optional)
  71. DEVLOAD_MEMLEN_VALNAME = 'MemLen'; // Memory length (optional)
  72. DEVLOAD_IOBASE_VALNAME = 'IoBase'; // IO base (optional)
  73. DEVLOAD_IOLEN_VALNAME = 'IoLen'; // IO length (optional)
  74. DEVLOAD_SYSINTR_VALNAME = 'SysIntr'; // System interrupt number (optional)
  75. DEVLOAD_IRQ_VALNAME = 'Irq'; // Irq number (optional)
  76. DEVLOAD_IFCTYPE_VALNAME = 'InterfaceType'; // Bus interface type (i.e. PCIbus, ISA, etc) (optional)
  77. DEVLOAD_BUSNUMBER_VALNAME = 'BusNumber'; // Bus number (relevant for PCIbus) (optional)
  78. DEVLOAD_ISRDLL_VALNAME = 'IsrDll'; // DLL name of ISR (optional)
  79. DEVLOAD_ISRHANDLER_VALNAME = 'IsrHandler'; // ISR handler function name (optional)
  80. //
  81. // The presence of the value "Keep" will cause device.exe to skip the call to
  82. // FreeLibrary after calling the specified entrypoint. This only affects
  83. // builtin drivers that specify an entrypoint. (This usage is deprecated -
  84. // make appropriate use of the UNLOAD flag instead).
  85. //
  86. const
  87. DEVLOAD_KEEPLIB_VALNAME = 'Keep'; // (deprecated - see above)
  88. DEVLOAD_KEEPLIB_VALTYPE = REG_DWORD;
  89. //
  90. // Flag values.
  91. //
  92. const
  93. DEVFLAGS_NONE = $00000000; // No flags defined
  94. DEVFLAGS_UNLOAD = $00000001; // Unload driver after call to entry point returns
  95. DEVFLAGS_LOADLIBRARY = $00000002; // Use LoadLibrary instead of LoadDriver
  96. DEVFLAGS_NOLOAD = $00000004; // Don't load Dll
  97. DEVFLAGS_NAKEDENTRIES = $00000008; // Entry points don't have Prefix prepended
  98. DEVFLAGS_BOOTPHASE_1 = $00001000; // This driver only load at system phase 1
  99. DEVFLAGS_IRQ_EXCLUSIVE = $00000100; // This driver only can be load when it has exclusive access for IRQ.
  100. DEVFLAGS_TRUSTEDCALLERONLY = $00010000; // This driver only can be opened by trusted application.
  101. //
  102. // Structure passed in the input buffer of DeviceIoControl() for the
  103. // post initialization ioctl
  104. //
  105. type
  106. _POST_INIT_BUF = record
  107. p_hDevice:HANDLE; // device handle from RegisterDevice
  108. p_hDeviceKey:HKEY; // open registry handle to the driver's device key
  109. end;
  110. POST_INIT_BUF = _POST_INIT_BUF;
  111. PPOST_INIT_BUF = ^POST_INIT_BUF;
  112. //
  113. // For passing additional registry settings to ActivateDeviceEx()
  114. //
  115. type
  116. _REGINI = record
  117. lpszVal:LPCWSTR;
  118. pData:LPBYTE;
  119. dwLen:DWORD;
  120. dwType:DWORD;
  121. end;
  122. REGINI = _REGINI;
  123. LPCREGINI = ^_REGINI;
  124. //
  125. // These values reside under a device's active key
  126. //
  127. const
  128. DEVLOAD_CLIENTINFO_VALNAME = 'ClientInfo'; // ClientInfo DWORD from ActivateDriver
  129. DEVLOAD_CLIENTINFO_VALTYPE = REG_DWORD;
  130. DEVLOAD_HANDLE_VALNAME = 'Hnd'; // Device handle (from RegisterDevice)
  131. DEVLOAD_HANDLE_VALTYPE = REG_DWORD;
  132. DEVLOAD_DEVNAME_VALNAME = 'Name'; // Device name (i.e "COM1:")
  133. DEVLOAD_DEVNAME_VALTYPE = REG_SZ;
  134. DEVLOAD_DEVKEY_VALNAME = 'Key'; // Device key in \Drivers\(Built-In or PCMCIA)
  135. DEVLOAD_DEVKEY_VALTYPE = REG_SZ;
  136. DEVLOAD_PNPID_VALNAME = 'PnpId'; // Plug and Play Id (PCMCIA, optional)
  137. DEVLOAD_PNPID_VALTYPE = REG_SZ;
  138. DEVLOAD_SOCKET_VALNAME = 'Sckt'; // PCMCIA socket (optional)
  139. DEVLOAD_SOCKET_VALTYPE = REG_DWORD; // Actually a CARD_SOCKET_HANDLE
  140. DEVLOAD_INTERFACETYPE_VALNAME = 'InterfaceType'; // Bus Type
  141. DEVLOAD_INTERFACETYPE_VALTYPE = REG_DWORD;
  142. //
  143. // These values reside under a device's active key. They are provided by the device's bus
  144. // driver. All values are optional. The BusParent tells the Device Manager which device
  145. // driver loaded the new driver. The BusPrefix is used to specify DLL entry point decoration
  146. // for devices that do not expose a stream interface to applications (via the legacy or $device
  147. // namespaces). If a Prefix value is specified in the device's device key and a BusPrefix value
  148. // is specified, they must match. The BusName provides the Device Manager with the name that the
  149. // device driver will expose in the $bus namespace. This name must be unique and is completely
  150. // specified by the bus driver; it is not decorated with an instance index; if a duplicate name
  151. // is found, the driver will not load.
  152. //
  153. const
  154. DEVLOAD_BUSPARENT_VALNAME = 'BusParent'; // parent bus driver handle
  155. DEVLOAD_BUSPARENT_VALTYPE = REG_DWORD;
  156. DEVLOAD_BUSPREFIX_VALNAME = 'BusPrefix'; // DLL entry point decoration -- must match "Prefix" if present in device key
  157. DEVLOAD_BUSPREFIX_VALTYPE = REG_SZ;
  158. DEVLOAD_BUSNAME_VALNAME = 'BusName'; // device's name on the parent bus
  159. DEVLOAD_BUSNAME_VALTYPE = REG_SZ;
  160. //
  161. // TAPI Pnp support
  162. //
  163. const
  164. DEVLOAD_TSPDLL_VALNAME = 'Tsp'; // TAPI Service Provider DLL
  165. DEVLOAD_TSPDLL_VALTYPE = REG_SZ;
  166. DEVLOAD_TSPDEV_VALNAME = 'THnd'; // TAPI device index
  167. DEVLOAD_TSPDEV_VALTYPE = REG_DWORD;
  168. //
  169. // Prototype for the optional device driver entrypoint
  170. //
  171. type
  172. PFN_DEV_ENTRY = function(param1:LPTSTR):DWORD; cdecl; // Parameter is registry path of device's key
  173. const
  174. DEVKEY_LEN = 256; // Max length of registry key path name
  175. DEVNAME_LEN = 16; // Max length of device name
  176. DEVDLL_LEN = 64; // Max length of device driver DLL name
  177. DEVENTRY_LEN = 64; // Max length of device driver entrypoint name
  178. DEVPREFIX_LEN = 8; // Max length of device prefix
  179. //
  180. // Device APIs: EnumPnpIds, EnumDevices, GetDeviceKeys and OpenDeviceKey
  181. // (in coredll.dll)
  182. //
  183. function EnumPnpIds(PnpList:LPTSTR; lpBuflen:LPDWORD):DWORD; external KernelDLL name 'EnumPnpIds'; // index BE
  184. function EnumDevices(DevList:LPTSTR; lpBuflen:LPDWORD):DWORD; external KernelDLL name 'EnumDevices'; // index BF
  185. function GetDeviceKeys(DevName:LPCTSTR; ActiveKey:LPTSTR; lpActiveLen:LPDWORD;
  186. DriverKey:LPTSTR; lpDriverLen:LPDWORD):DWORD; external KernelDLL name 'GetDeviceKeys'; // index C0
  187. function OpenDeviceKey(ActiveKey:LPCTSTR):HKEY; external KernelDLL name 'OpenDeviceKey'; // index C1
  188. function GetDeviceHandleFromContext(pContext:LPCTSTR):HANDLE; external KernelDLL name 'GetDeviceHandleFromContext';
  189. const
  190. DevMgrDLL = 'devmgr.dll';
  191. //
  192. // Device Manager APIs located in devmgr.dll. These APIs are only available to drivers
  193. // loaded in the Device Manager's process context.
  194. //
  195. function DmAdvertiseInterface(hDevice:HANDLE; const devclass:LPGUID; name:LPCWSTR; fAdd:BOOL):DWORD; external DevMgrDLL name 'DmAdvertiseInterface';
  196. //
  197. // This interface GUID indicates that the device supports differentiating the $bus and $device
  198. // (and legacy) namespaces. Devices must advertise this GUID via IClass or calls to
  199. // DmAdvertiseInterface() before CreateFile() requests on their $bus names will succeed. The GUID
  200. // must be associated with their bus name, not their $device or legacy name.
  201. //
  202. const
  203. DMCLASS_PROTECTEDBUSNAMESPACE = '{6F40791D-300E-44E4-BC38-E0E63CA8375C}';
  204. //
  205. // Drivers that advertise DMCLASS_PROTECTEDBUSNAMESPACE will have this bit set in the dwAccess
  206. // parameter to their XXX_Open() entry point when a handle is opened using the $bus namespace.
  207. // This allows them to know which handles are allowed to carry out privileged operations. If they
  208. // advertise DMCLASS_PROTECTEDBUSNAMESPACE, they are required to block privileged operations on
  209. // handles opened in the $device or legacy namespaces.
  210. //
  211. const
  212. DEVACCESS_BUSNAMESPACE = FILE_WRITE_ATTRIBUTES;
  213. implementation
  214. end.