Changeset 4800 in vbox for trunk/src/VBox/HostDrivers/Support
- Timestamp:
- Sep 14, 2007 2:59:15 PM (17 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPDRV.h
r4755 r4800 198 198 199 199 /* dprintf */ 200 #if (defined(DEBUG) && !defined(NO_LOGGING)) || defined(RT_OS_FREEBSD)200 /* bird debugging - #if (defined(DEBUG) && !defined(NO_LOGGING)) || defined(RT_OS_FREEBSD) 201 201 # ifdef LOG_TO_COM 202 202 # include <VBox/log.h> 203 203 # define dprintf(a) RTLogComPrintf a 204 # else 204 # else */ 205 205 # define dprintf(a) OSDBGPRINT(a) 206 # endif206 /*# endif 207 207 #else 208 208 # define dprintf(a) do {} while (0) 209 #endif 209 #endif*/ 210 210 211 211 /* dprintf2 - extended logging. */ 212 #if defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD)212 #if 1//bird defined(RT_OS_DARWIN) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) 213 213 # define dprintf2 dprintf 214 214 #else … … 735 735 * Shared Functions * 736 736 *******************************************************************************/ 737 int VBOXCALL supdrvIOCtl(unsigned uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, 738 void *pvIn, unsigned cbIn, void *pvOut, unsigned cbOut, unsigned *pcbReturned); 737 int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr); 739 738 #ifdef VBOX_WITHOUT_IDT_PATCHING 740 int VBOXCALL supdrvIOCtlFast(u nsigneduIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession);739 int VBOXCALL supdrvIOCtlFast(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession); 741 740 #endif 742 741 int VBOXCALL supdrvInitDevExt(PSUPDRVDEVEXT pDevExt); 743 intVBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt);742 void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt); 744 743 int VBOXCALL supdrvCreateSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION *ppSession); 745 744 void VBOXCALL supdrvCloseSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession); -
trunk/src/VBox/HostDrivers/Support/SUPDRVIOC.h
r4755 r4800 16 16 */ 17 17 18 #ifndef __ SUPDRVIOC_h__19 #define __ SUPDRVIOC_h__18 #ifndef ___SUPDRVIOC_h___ 19 #define ___SUPDRVIOC_h___ 20 20 21 21 /* … … 39 39 40 40 #ifdef RT_OS_WINDOWS 41 # define SUP_CTL_CODE(Function) CTL_CODE(FILE_DEVICE_UNKNOWN, (Function) | SUP_IOCTL_FLAG, METHOD_BUFFERED, FILE_WRITE_ACCESS)42 # define SUP_CTL_CODE_FAST(Function) CTL_CODE(FILE_DEVICE_UNKNOWN, (Function) | SUP_IOCTL_FLAG, METHOD_NEITHER, FILE_WRITE_ACCESS)43 44 /** @todo get rid of this duplication of window header #defines! */45 41 # ifndef CTL_CODE 46 # define CTL_CODE(DeviceType, Function, Method, Access) \ 47 ( ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) ) 42 # include <Windows.h> 48 43 # endif 49 # ifndef METHOD_BUFFERED 50 # define METHOD_BUFFERED 0 51 # endif 52 # ifndef METHOD_NEITHER 53 # define METHOD_NEITHER 3 54 # endif 55 # ifndef FILE_WRITE_ACCESS 56 # define FILE_WRITE_ACCESS 0x0002 57 # endif 58 # ifndef FILE_DEVICE_UNKNOWN 59 # define FILE_DEVICE_UNKNOWN 0x00000022 60 # endif 44 /* Automatic buffering, size not encoded. */ 45 # define SUP_CTL_CODE_SIZE(Function, Size) CTL_CODE(FILE_DEVICE_UNKNOWN, (Function) | SUP_IOCTL_FLAG, METHOD_BUFFERED, FILE_WRITE_ACCESS) 46 # define SUP_CTL_CODE_BIG(Function) CTL_CODE(FILE_DEVICE_UNKNOWN, (Function) | SUP_IOCTL_FLAG, METHOD_BUFFERED, FILE_WRITE_ACCESS) 47 # define SUP_CTL_CODE_FAST(Function) CTL_CODE(FILE_DEVICE_UNKNOWN, (Function) | SUP_IOCTL_FLAG, METHOD_NEITHER, FILE_WRITE_ACCESS) 48 # define SUP_CTL_CODE_NO_SIZE(uIOCtl) (uIOCtl) 49 50 #elif defined(RT_OS_SOLARIS) 51 /* No automatic buffering, size limited to 255 bytes. */ 52 # include <sys/ioccom.h> 53 # define SUP_CTL_CODE_SIZE(Function, Size) _IOWRN('V', (Function) | SUP_IOCTL_FLAG, sizeof(SUPREQHDR)) 54 # define SUP_CTL_CODE_BIG(Function) _IO( 'V', (Function) | SUP_IOCTL_FLAG) 55 # define SUP_CTL_CODE_FAST(Function) _IO( 'V', (Function) | SUP_IOCTL_FLAG) 56 # define SUP_CTL_CODE_NO_SIZE(uIOCtl) (uIOCtl) 61 57 62 58 #elif defined(RT_OS_OS2) 63 # define SUP_CTL_CATEGORY 0xc0 64 # define SUP_CTL_CODE(Function) ((unsigned char)(Function)) 65 # define SUP_CTL_CATEGORY_FAST 0xc1 66 # define SUP_CTL_CODE_FAST(Function) ((unsigned char)(Function)) 59 /* No automatic buffering, size not encoded. */ 60 # define SUP_CTL_CATEGORY 0xc0 61 # define SUP_CTL_CODE_SIZE(Function, Size) ((unsigned char)(Function)) 62 # define SUP_CTL_CODE_BIG(Function) ((unsigned char)(Function)) 63 # define SUP_CTL_CATEGORY_FAST 0xc1 64 # define SUP_CTL_CODE_FAST(Function) ((unsigned char)(Function)) 65 # define SUP_CTL_CODE_NO_SIZE(uIOCtl) (uIOCtl) 67 66 68 67 #elif defined(RT_OS_LINUX) 69 # ifdef RT_ARCH_X86 /** @todo With the next major version change, drop this branch. */ 70 # define SUP_CTL_CODE(Function) \ 71 ( (3U << 30) | ((0x22) << 8) | ((Function) | SUP_IOCTL_FLAG) | (sizeof(SUPDRVIOCTLDATA) << 16) ) 72 # define SUP_CTL_CODE_FAST(Function) \ 73 ( (3U << 30) | ((0x22) << 8) | ((Function) | SUP_IOCTL_FLAG) | (0 << 16) ) 74 # else 75 # include <linux/ioctl.h> 76 # if 1 /* figure out when this changed. */ 77 # define SUP_CTL_CODE(Function) _IOWR('V', (Function) | SUP_IOCTL_FLAG, SUPDRVIOCTLDATA) 78 # define SUP_CTL_CODE_FAST(Function) _IO( 'V', (Function) | SUP_IOCTL_FLAG) 79 # else /* now: _IO_BAD and _IOWR_BAD */ 80 # define SUP_CTL_CODE(Function) _IOWR('V', (Function) | SUP_IOCTL_FLAG, sizeof(SUPDRVIOCTLDATA)) 81 # define SUP_CTL_CODE_FAST(Function) _IO( 'V', (Function) | SUP_IOCTL_FLAG) 82 # endif 83 # endif 68 /* No automatic buffering, size limited to 16KB. */ 69 # include <linux/ioctl.h> 70 # define SUP_CTL_CODE_SIZE(Function, Size) _IOC(_IOC_READ | _IOC_WRITE, 'V', (Function) | SUP_IOCTL_FLAG, (Size)) 71 # define SUP_CTL_CODE_BIG(Function) _IO('V', (Function) | SUP_IOCTL_FLAG) 72 # define SUP_CTL_CODE_FAST(Function) _IO('V', (Function) | SUP_IOCTL_FLAG) 73 # define SUP_CTL_CODE_NO_SIZE(uIOCtl) ((uIOCtl) & ~IOCSIZE_MASK) 84 74 85 75 #elif defined(RT_OS_L4) 86 # define SUP_CTL_CODE(Function) \ 87 ( (3U << 30) | ((0x22) << 8) | ((Function) | SUP_IOCTL_FLAG) | (sizeof(SUPDRVIOCTLDATA) << 16) ) 88 # define SUP_CTL_CODE_FAST(Function) \ 89 ( (3U << 30) | ((0x22) << 8) | ((Function) | SUP_IOCTL_FLAG) | (0 << 16) ) 90 91 #else /* BSD */ 76 /* Implemented in suplib, no worries. */ 77 # define SUP_CTL_CODE_SIZE(Function, Size) (Function) 78 # define SUP_CTL_CODE_BIG(Function) (Function) 79 # define SUP_CTL_CODE_FAST(Function) (Function) 80 # define SUP_CTL_CODE_NO_SIZE(uIOCtl) (uIOCtl) 81 82 #else /* BSD Like */ 83 /* Automatic buffering, size limited to 4KB on *BSD and 8KB on Darwin - commands the limit, 4KB. */ 92 84 # include <sys/ioccom.h> 93 # define SUP_CTL_CODE(Function) _IOWR('V', (Function) | SUP_IOCTL_FLAG, SUPDRVIOCTLDATA) 94 # define SUP_CTL_CODE_FAST(Function) _IO( 'V', (Function) | SUP_IOCTL_FLAG) 85 # define SUP_CTL_CODE_SIZE(Function, Size) _IOC(IOC_INOUT, 'V', (Function) | SUP_IOCTL_FLAG, (Size)) 86 # define SUP_CTL_CODE_BIG(Function) _IO('V', (Function) | SUP_IOCTL_FLAG) 87 # define SUP_CTL_CODE_FAST(Function) _IO('V', (Function) | SUP_IOCTL_FLAG) 88 # define SUP_CTL_CODE_NO_SIZE(uIOCtl) ( (uIOCtl) & ~_IOC(0,0,0,IOCPARM_MASK) ) 95 89 #endif 96 90 97 98 /** Negotiate cookie. */99 #define SUP_IOCTL_COOKIE SUP_CTL_CODE( 1)100 /** Query SUPR0 functions. */101 #define SUP_IOCTL_QUERY_FUNCS SUP_CTL_CODE( 2)102 /** Install IDT patch for calling processor. */103 #define SUP_IOCTL_IDT_INSTALL SUP_CTL_CODE( 3)104 /** Remove IDT patch for calling processor. */105 #define SUP_IOCTL_IDT_REMOVE SUP_CTL_CODE( 4)106 /** Pin down physical pages. */107 #define SUP_IOCTL_PINPAGES SUP_CTL_CODE( 5)108 /** Unpin physical pages. */109 #define SUP_IOCTL_UNPINPAGES SUP_CTL_CODE( 6)110 /** Allocate contious memory. */111 #define SUP_IOCTL_CONT_ALLOC SUP_CTL_CODE( 7)112 /** Free contious memory. */113 #define SUP_IOCTL_CONT_FREE SUP_CTL_CODE( 8)114 /** Open an image. */115 #define SUP_IOCTL_LDR_OPEN SUP_CTL_CODE( 9)116 /** Upload the image bits. */117 #define SUP_IOCTL_LDR_LOAD SUP_CTL_CODE(10)118 /** Free an image. */119 #define SUP_IOCTL_LDR_FREE SUP_CTL_CODE(11)120 /** Get address of a symbol within an image. */121 #define SUP_IOCTL_LDR_GET_SYMBOL SUP_CTL_CODE(12)122 /** Call the R0 VMM Entry point. */123 #define SUP_IOCTL_CALL_VMMR0 SUP_CTL_CODE(14)124 /** Get the host paging mode. */125 #define SUP_IOCTL_GET_PAGING_MODE SUP_CTL_CODE(15)126 /** Allocate memory below 4GB (physically). */127 #define SUP_IOCTL_LOW_ALLOC SUP_CTL_CODE(16)128 /** Free low memory. */129 #define SUP_IOCTL_LOW_FREE SUP_CTL_CODE(17)130 /** Map the GIP into user space. */131 #define SUP_IOCTL_GIP_MAP SUP_CTL_CODE(18)132 /** Unmap the GIP. */133 #define SUP_IOCTL_GIP_UNMAP SUP_CTL_CODE(19)134 /** Set the VM handle for doing fast call ioctl calls. */135 #define SUP_IOCTL_SET_VM_FOR_FAST SUP_CTL_CODE(20)136 /** Allocate memory and map into the user process. */137 #define SUP_IOCTL_PAGE_ALLOC SUP_CTL_CODE(21)138 /** Free memory allocated with SUP_IOCTL_PAGE_ALLOC. */139 #define SUP_IOCTL_PAGE_FREE SUP_CTL_CODE(22)140 141 91 /** Fast path IOCtl: VMMR0_DO_RAW_RUN */ 142 #define SUP_IOCTL_FAST_DO_RAW_RUN SUP_CTL_CODE_FAST(64)92 #define SUP_IOCTL_FAST_DO_RAW_RUN SUP_CTL_CODE_FAST(64) 143 93 /** Fast path IOCtl: VMMR0_DO_HWACC_RUN */ 144 #define SUP_IOCTL_FAST_DO_HWACC_RUN SUP_CTL_CODE_FAST(65)94 #define SUP_IOCTL_FAST_DO_HWACC_RUN SUP_CTL_CODE_FAST(65) 145 95 /** Just a NOP call for profiling the latency of a fast ioctl call to VMMR0. */ 146 #define SUP_IOCTL_FAST_DO_NOP SUP_CTL_CODE_FAST(66) 96 #define SUP_IOCTL_FAST_DO_NOP SUP_CTL_CODE_FAST(66) 97 147 98 148 99 … … 156 107 #endif 157 108 158 #ifndef RT_OS_WINDOWS 109 159 110 /** 160 * Structure used by OSes with less advanced ioctl interfaces, i.e. most 161 * Unix like OSes :-) 162 */ 163 typedef struct SUPDRVIOCTLDATA 164 { 165 void *pvIn; 166 unsigned long cbIn; 167 void *pvOut; 168 unsigned long cbOut; 169 #ifdef RT_OS_OS2 170 int rc; 171 #endif 172 } SUPDRVIOCTLDATA, *PSUPDRVIOCTLDATA; 173 #endif 174 175 176 /** SUPCOOKIE_IN magic word. */ 177 #define SUPCOOKIE_MAGIC "The Magic Word!" 178 /** Current interface version. 179 * The upper 16-bit is the major version, the the lower the minor version. 180 * When incompatible changes are made, the upper major number has to be changed. */ 181 #define SUPDRVIOC_VERSION 0x00050001 182 183 /** SUP_IOCTL_COOKIE Input. */ 184 typedef struct SUPCOOKIE_IN 185 { 186 /** Magic word. */ 187 char szMagic[16]; 188 /** The requested interface version number. */ 189 uint32_t u32ReqVersion; 190 /** The minimum interface version number. */ 191 uint32_t u32MinVersion; 192 } SUPCOOKIE_IN, *PSUPCOOKIE_IN; 193 194 /** SUP_IOCTL_COOKIE Output. */ 195 typedef struct SUPCOOKIE_OUT 111 * Common In/Out header. 112 */ 113 typedef struct SUPREQHDR 196 114 { 197 115 /** Cookie. */ … … 199 117 /** Session cookie. */ 200 118 uint32_t u32SessionCookie; 201 /** Interface version for this session. */ 202 uint32_t u32SessionVersion; 203 /** The actual interface version in the driver. */ 204 uint32_t u32DriverVersion; 205 /** Number of functions available for the SUP_IOCTL_QUERY_FUNCS request. */ 206 uint32_t cFunctions; 207 /** Session handle. */ 208 R0PTRTYPE(PSUPDRVSESSION) pSession; 209 } SUPCOOKIE_OUT, *PSUPCOOKIE_OUT; 210 211 212 213 /** SUP_IOCTL_QUERY_FUNCS Input. */ 214 typedef struct SUPQUERYFUNCS_IN 215 { 216 /** Cookie. */ 217 uint32_t u32Cookie; 218 /** Session cookie. */ 219 uint32_t u32SessionCookie; 220 } SUPQUERYFUNCS_IN, *PSUPQUERYFUNCS_IN; 221 222 /** Function. */ 119 /** The size of the input. */ 120 uint32_t cbIn; 121 /** The size of the output. */ 122 uint32_t cbOut; 123 /** Flags. See SUPREQHDR_FLAGS_* for details and values. */ 124 uint32_t fFlags; 125 /** The VBox status code of the operation, out direction only. */ 126 int32_t rc; 127 } SUPREQHDR; 128 /** Pointer to a IOC header. */ 129 typedef SUPREQHDR *PSUPREQHDR; 130 131 /** @name SUPREQHDR::fFlags values 132 * @{ */ 133 /** Masks out the magic value. */ 134 #define SUPREQHDR_FLAGS_MAGIC_MASK UINT32_C(0xff0000ff) 135 /** The generic mask. */ 136 #define SUPREQHDR_FLAGS_GEN_MASK UINT32_C(0x0000ff00) 137 /** The request specific mask. */ 138 #define SUPREQHDR_FLAGS_REQ_MASK UINT32_C(0x00ff0000) 139 140 /** There is extra input that needs copying on some platforms. */ 141 #define SUPREQHDR_FLAGS_EXTRA_IN UINT32_C(0x00000100) 142 /** There is extra output that needs copying on some platforms. */ 143 #define SUPREQHDR_FLAGS_EXTRA_OUT UINT32_C(0x00000200) 144 145 /** The magic value. */ 146 #define SUPREQHDR_FLAGS_MAGIC UINT32_C(0x42000042) 147 /** The default value. Use this when no special stuff is requested. */ 148 #define SUPREQHDR_FLAGS_DEFAULT SUPREQHDR_FLAGS_MAGIC 149 /** @} */ 150 151 152 /** @name SUP_IOCTL_COOKIE 153 * @{ 154 */ 155 /** Negotiate cookie. */ 156 #define SUP_IOCTL_COOKIE SUP_CTL_CODE_SIZE(1, SUP_IOCTL_COOKIE_SIZE) 157 /** The request size. */ 158 #define SUP_IOCTL_COOKIE_SIZE sizeof(SUPCOOKIE) 159 /** The SUPREQHDR::cbIn value. */ 160 #define SUP_IOCTL_COOKIE_SIZE_IN sizeof(SUPREQHDR) + RT_SIZEOFMEMB(SUPCOOKIE, u.In) 161 /** The SUPREQHDR::cbOut value. */ 162 #define SUP_IOCTL_COOKIE_SIZE_OUT sizeof(SUPREQHDR) + RT_SIZEOFMEMB(SUPCOOKIE, u.Out) 163 /** SUPCOOKIE_IN magic word. */ 164 #define SUPCOOKIE_MAGIC "The Magic Word!" 165 /** The initial cookie. */ 166 #define SUPCOOKIE_INITIAL_COOKIE 0x69726f74 /* 'tori' */ 167 168 /** Current interface version. 169 * The upper 16-bit is the major version, the the lower the minor version. 170 * When incompatible changes are made, the upper major number has to be changed. */ 171 #define SUPDRVIOC_VERSION 0x00060000 172 173 /** SUP_IOCTL_COOKIE. */ 174 typedef struct SUPCOOKIE 175 { 176 /** The header. 177 * u32Cookie must be set to SUPCOOKIE_INITIAL_COOKIE. 178 * u32SessionCookie should be set to some random value. */ 179 SUPREQHDR Hdr; 180 union 181 { 182 struct 183 { 184 /** Magic word. */ 185 char szMagic[16]; 186 /** The requested interface version number. */ 187 uint32_t u32ReqVersion; 188 /** The minimum interface version number. */ 189 uint32_t u32MinVersion; 190 } In; 191 struct 192 { 193 /** Cookie. */ 194 uint32_t u32Cookie; 195 /** Session cookie. */ 196 uint32_t u32SessionCookie; 197 /** Interface version for this session. */ 198 uint32_t u32SessionVersion; 199 /** The actual interface version in the driver. */ 200 uint32_t u32DriverVersion; 201 /** Number of functions available for the SUP_IOCTL_QUERY_FUNCS request. */ 202 uint32_t cFunctions; 203 /** Session handle. */ 204 R0PTRTYPE(PSUPDRVSESSION) pSession; 205 } Out; 206 } u; 207 } SUPCOOKIE, *PSUPCOOKIE; 208 /** @} */ 209 210 211 /** @name SUP_IOCTL_QUERY_FUNCS 212 * Query SUPR0 functions. 213 * @{ 214 */ 215 #define SUP_IOCTL_QUERY_FUNCS(cFuncs) SUP_CTL_CODE_SIZE(2, SUP_IOCTL_QUERY_FUNCS_SIZE(cFuncs)) 216 #define SUP_IOCTL_QUERY_FUNCS_SIZE(cFuncs) RT_OFFSETOF(SUPQUERYFUNCS, u.Out.aFunctions[(cFuncs)]) 217 #define SUP_IOCTL_QUERY_FUNCS_SIZE_IN sizeof(SUPREQHDR) 218 #define SUP_IOCTL_QUERY_FUNCS_SIZE_OUT(cFuncs) SUP_IOCTL_QUERY_FUNCS_SIZE(cFuncs) 219 220 /** A function. */ 223 221 typedef struct SUPFUNC 224 222 { … … 229 227 } SUPFUNC, *PSUPFUNC; 230 228 231 /** SUP_IOCTL_QUERY_FUNCS Output. */ 232 typedef struct SUPQUERYFUNCS_OUT 233 { 234 /** Number of functions returned. */ 235 uint32_t cFunctions; 236 /** Array of functions. */ 237 SUPFUNC aFunctions[1]; 238 } SUPQUERYFUNCS_OUT, *PSUPQUERYFUNCS_OUT; 239 240 241 242 /** SUP_IOCTL_IDT_INSTALL Input. */ 243 typedef struct SUPIDTINSTALL_IN 244 { 245 /** Cookie. */ 246 uint32_t u32Cookie; 247 /** Session cookie. */ 248 uint32_t u32SessionCookie; 249 } SUPIDTINSTALL_IN, *PSUPIDTINSTALL_IN; 250 251 /** SUP_IOCTL_IDT_INSTALL Output. */ 252 typedef struct SUPIDTINSTALL_OUT 253 { 254 /** Cookie. */ 255 uint8_t u8Idt; 256 } SUPIDTINSTALL_OUT, *PSUPIDTINSTALL_OUT; 257 258 259 260 /** SUP_IOCTL_IDT_REMOVE Input. */ 261 typedef struct SUPIDTREMOVE_IN 262 { 263 /** Cookie. */ 264 uint32_t u32Cookie; 265 /** Session cookie. */ 266 uint32_t u32SessionCookie; 267 } SUPIDTREMOVE_IN, *PSUPIDTREMOVE_IN; 268 269 270 271 /** SUP_IOCTL_PINPAGES Input. */ 272 typedef struct SUPPINPAGES_IN 273 { 274 /** Cookie. */ 275 uint32_t u32Cookie; 276 /** Session cookie. */ 277 uint32_t u32SessionCookie; 278 /** Start of page range. Must be PAGE aligned. */ 279 RTR3PTR pvR3; 280 /** Size of the range. Must be PAGE aligned. */ 281 uint32_t cPages; 282 } SUPPINPAGES_IN, *PSUPPINPAGES_IN; 283 284 /** SUP_IOCTL_PINPAGES Output. */ 285 typedef struct SUPPINPAGES_OUT 286 { 287 /** Array of pages. */ 288 SUPPAGE aPages[1]; 289 } SUPPINPAGES_OUT, *PSUPPINPAGES_OUT; 290 291 292 293 /** SUP_IOCTL_UNPINPAGES Input. */ 294 typedef struct SUPUNPINPAGES_IN 295 { 296 /** Cookie. */ 297 uint32_t u32Cookie; 298 /** Session cookie. */ 299 uint32_t u32SessionCookie; 300 /** Start of page range of a range previuosly pinned. */ 301 RTR3PTR pvR3; 302 } SUPUNPINPAGES_IN, *PSUPUNPINPAGES_IN; 303 304 305 306 /** SUP_IOCTL_CONT_ALLOC Input. */ 307 typedef struct SUPCONTALLOC_IN 308 { 309 /** Cookie. */ 310 uint32_t u32Cookie; 311 /** Session cookie. */ 312 uint32_t u32SessionCookie; 313 /** Number of bytes to allocate. */ 314 uint32_t cPages; 315 } SUPCONTALLOC_IN, *PSUPCONTALLOC_IN; 316 317 318 319 /** SUP_IOCTL_CONT_ALLOC Output. */ 320 typedef struct SUPCONTALLOC_OUT 321 { 322 /** The address of the ring-0 mapping of the allocated memory. */ 323 RTR0PTR pvR0; 324 /** The address of the ring-3 mapping of the allocated memory. */ 325 RTR3PTR pvR3; 326 /** The physical address of the allocation. */ 327 RTHCPHYS HCPhys; 328 } SUPCONTALLOC_OUT, *PSUPCONTALLOC_OUT; 329 330 331 332 /** SUP_IOCTL_CONT_FREE Input. */ 333 typedef struct SUPCONTFREE_IN 334 { 335 /** Cookie. */ 336 uint32_t u32Cookie; 337 /** Session cookie. */ 338 uint32_t u32SessionCookie; 339 /** The ring-3 address of the memory to free. */ 340 RTR3PTR pvR3; 341 } SUPCONTFREE_IN, *PSUPCONTFREE_IN; 342 343 344 345 /** SUP_IOCTL_LDR_OPEN Input. */ 346 typedef struct SUPLDROPEN_IN 347 { 348 /** Cookie. */ 349 uint32_t u32Cookie; 350 /** Session cookie. */ 351 uint32_t u32SessionCookie; 352 /** Size of the image we'll be loading. */ 353 uint32_t cbImage; 354 /** Image name. 355 * This is the NAME of the image, not the file name. It is used 356 * to share code with other processes. (Max len is 32 chars!) */ 357 char szName[32]; 358 } SUPLDROPEN_IN, *PSUPLDROPEN_IN; 359 360 /** SUP_IOCTL_LDR_OPEN Output. */ 361 typedef struct SUPLDROPEN_OUT 362 { 363 /** The base address of the image. */ 364 RTR0PTR pvImageBase; 365 /** Indicate whether or not the image requires loading. */ 366 bool fNeedsLoading; 367 } SUPLDROPEN_OUT, *PSUPLDROPEN_OUT; 368 369 229 typedef struct SUPQUERYFUNCS 230 { 231 /** The header. */ 232 SUPREQHDR Hdr; 233 union 234 { 235 struct 236 { 237 /** Number of functions returned. */ 238 uint32_t cFunctions; 239 /** Array of functions. */ 240 SUPFUNC aFunctions[1]; 241 } Out; 242 } u; 243 } SUPQUERYFUNCS, *PSUPQUERYFUNCS; 244 /** @} */ 245 246 247 /** @name SUP_IOCTL_IDT_INSTALL 248 * Install IDT patch for calling processor. 249 * @{ 250 */ 251 #define SUP_IOCTL_IDT_INSTALL SUP_CTL_CODE_SIZE(3, SUP_IOCTL_IDT_INSTALL_SIZE) 252 #define SUP_IOCTL_IDT_INSTALL_SIZE sizeof(SUPIDTINSTALL) 253 #define SUP_IOCTL_IDT_INSTALL_SIZE_IN sizeof(SUPREQHDR) 254 #define SUP_IOCTL_IDT_INSTALL_SIZE_OUT sizeof(SUPIDTINSTALL) 255 typedef struct SUPIDTINSTALL 256 { 257 /** The header. */ 258 SUPREQHDR Hdr; 259 union 260 { 261 struct 262 { 263 /** The IDT entry number. */ 264 uint8_t u8Idt; 265 } Out; 266 } u; 267 } SUPIDTINSTALL, *PSUPIDTINSTALL; 268 /** @} */ 269 270 271 /** @name SUP_IOCTL_IDT_REMOVE 272 * Remove IDT patch for calling processor. 273 * @{ 274 */ 275 #define SUP_IOCTL_IDT_REMOVE SUP_CTL_CODE_SIZE(4, SUP_IOCTL_IDT_REMOVE_SIZE) 276 #define SUP_IOCTL_IDT_REMOVE_SIZE sizeof(SUPIDTREMOVE) 277 #define SUP_IOCTL_IDT_REMOVE_SIZE_IN sizeof(SUPIDTREMOVE) 278 #define SUP_IOCTL_IDT_REMOVE_SIZE_OUT sizeof(SUPIDTREMOVE) 279 typedef struct SUPIDTREMOVE 280 { 281 /** The header. */ 282 SUPREQHDR Hdr; 283 } SUPIDTREMOVE, *PSUPIDTREMOVE; 284 /** @}*/ 285 286 287 /** @name SUP_IOCTL_LDR_OPEN 288 * Open an image. 289 * @{ 290 */ 291 #define SUP_IOCTL_LDR_OPEN SUP_CTL_CODE_SIZE(5, SUP_IOCTL_LDR_OPEN_SIZE) 292 #define SUP_IOCTL_LDR_OPEN_SIZE sizeof(SUPLDROPEN) 293 #define SUP_IOCTL_LDR_OPEN_SIZE_IN sizeof(SUPLDROPEN) 294 #define SUP_IOCTL_LDR_OPEN_SIZE_OUT (sizeof(SUPREQHDR) + RT_SIZEOFMEMB(SUPLDROPEN, u.Out)) 295 typedef struct SUPLDROPEN 296 { 297 /** The header. */ 298 SUPREQHDR Hdr; 299 union 300 { 301 struct 302 { 303 /** Size of the image we'll be loading. */ 304 uint32_t cbImage; 305 /** Image name. 306 * This is the NAME of the image, not the file name. It is used 307 * to share code with other processes. (Max len is 32 chars!) */ 308 char szName[32]; 309 } In; 310 struct 311 { 312 /** The base address of the image. */ 313 RTR0PTR pvImageBase; 314 /** Indicate whether or not the image requires loading. */ 315 bool fNeedsLoading; 316 } Out; 317 } u; 318 } SUPLDROPEN, *PSUPLDROPEN; 319 /** @} */ 320 321 322 /** @name SUP_IOCTL_LDR_LOAD 323 * Upload the image bits. 324 * @{ 325 */ 326 #define SUP_IOCTL_LDR_LOAD SUP_CTL_CODE_BIG(6) 327 #define SUP_IOCTL_LDR_LOAD_SIZE(cbImage) RT_OFFSETOF(SUPLDRLOAD, u.In.achImage[cbImage]) 328 #define SUP_IOCTL_LDR_LOAD_SIZE_IN(cbImage) RT_OFFSETOF(SUPLDRLOAD, u.In.achImage[cbImage]) 329 #define SUP_IOCTL_LDR_LOAD_SIZE_OUT sizeof(SUPREQHDR) 370 330 371 331 /** … … 399 359 } SUPLDRSYM, *PSUPLDRSYM; 400 360 401 /** SUP_IOCTL_LDR_LOAD Input. */ 402 typedef struct SUPLDRLOAD_IN 403 { 404 /** Cookie. */ 405 uint32_t u32Cookie; 406 /** Session cookie. */ 407 uint32_t u32SessionCookie; 408 /** The address of module initialization function. Similar to _DLL_InitTerm(hmod, 0). */ 409 PFNR0MODULEINIT pfnModuleInit; 410 /** The address of module termination function. Similar to _DLL_InitTerm(hmod, 1). */ 411 PFNR0MODULETERM pfnModuleTerm; 412 /** Special entry points. */ 413 union 414 { 415 struct 416 { 417 /** The module handle (i.e. address). */ 418 RTR0PTR pvVMMR0; 419 /** Address of VMMR0Entry function. */ 420 RTR0PTR pvVMMR0Entry; 421 } VMMR0; 422 } EP; 423 /** Address. */ 424 RTR0PTR pvImageBase; 425 /** Entry point type. */ 426 enum { EP_NOTHING, EP_VMMR0 } 427 eEPType; 428 /** The offset of the symbol table. */ 429 uint32_t offSymbols; 430 /** The number of entries in the symbol table. */ 431 uint32_t cSymbols; 432 /** The offset of the string table. */ 433 uint32_t offStrTab; 434 /** Size of the string table. */ 435 uint32_t cbStrTab; 436 /** Size of image (including string and symbol tables). */ 437 uint32_t cbImage; 438 /** The image data. */ 439 char achImage[1]; 440 } SUPLDRLOAD_IN, *PSUPLDRLOAD_IN; 441 442 443 444 /** SUP_IOCTL_LDR_FREE Input. */ 445 typedef struct SUPLDRFREE_IN 446 { 447 /** Cookie. */ 448 uint32_t u32Cookie; 449 /** Session cookie. */ 450 uint32_t u32SessionCookie; 451 /** Address. */ 452 RTR0PTR pvImageBase; 453 } SUPLDRFREE_IN, *PSUPLDRFREE_IN; 454 455 456 457 /** SUP_IOCTL_LDR_GET_SYMBOL Input. */ 458 typedef struct SUPLDRGETSYMBOL_IN 459 { 460 /** Cookie. */ 461 uint32_t u32Cookie; 462 /** Session cookie. */ 463 uint32_t u32SessionCookie; 464 /** Address. */ 465 RTR0PTR pvImageBase; 466 /** The symbol name (variable length). */ 467 char szSymbol[1]; 468 } SUPLDRGETSYMBOL_IN, *PSUPLDRGETSYMBOL_IN; 469 470 /** SUP_IOCTL_LDR_GET_SYMBOL Output. */ 471 typedef struct SUPLDRGETSYMBOL_OUT 472 { 473 /** The symbol address. */ 474 RTR0PTR pvSymbol; 475 } SUPLDRGETSYMBOL_OUT, *PSUPLDRGETSYMBOL_OUT; 476 477 478 479 /** SUP_IOCTL_CALL_VMMR0 Input. */ 480 typedef struct SUPCALLVMMR0_IN 481 { 482 /** Cookie. */ 483 uint32_t u32Cookie; 484 /** Session cookie. */ 485 uint32_t u32SessionCookie; 486 /** The VM handle. */ 487 PVMR0 pVMR0; 488 /** Which operation to execute. */ 489 uint32_t uOperation; 490 /** The size of the buffer pointed to by pvArg. */ 491 uint32_t cbArg; 492 /** Argument to that operation. */ 493 RTR3PTR pvArg; 494 } SUPCALLVMMR0_IN, *PSUPCALLVMMR0_IN; 495 496 /** SUP_IOCTL_CALL_VMMR0 Output. */ 497 typedef struct SUPCALLVMMR0_OUT 498 { 499 /** The VBox status code for the operation. */ 500 int32_t rc; 501 } SUPCALLVMMR0_OUT, *PSUPCALLVMMR0_OUT; 502 503 504 505 /** SUP_IOCTL_GET_PAGING_MODE Input. */ 506 typedef struct SUPGETPAGINGMODE_IN 507 { 508 /** Cookie. */ 509 uint32_t u32Cookie; 510 /** Session cookie. */ 511 uint32_t u32SessionCookie; 512 } SUPGETPAGINGMODE_IN, *PSUPGETPAGINGMODE_IN; 513 514 /** SUP_IOCTL_GET_PAGING_MODE Output. */ 515 typedef struct SUPGETPAGINGMODE_OUT 516 { 517 /** The paging mode. */ 518 SUPPAGINGMODE enmMode; 519 } SUPGETPAGINGMODE_OUT, *PSUPGETPAGINGMODE_OUT; 520 521 522 523 /** SUP_IOCTL_LOW_ALLOC Input. */ 524 typedef struct SUPLOWALLOC_IN 525 { 526 /** Cookie. */ 527 uint32_t u32Cookie; 528 /** Session cookie. */ 529 uint32_t u32SessionCookie; 530 /** Number of pages to allocate. */ 531 uint32_t cPages; 532 } SUPLOWALLOC_IN, *PSUPLOWALLOC_IN; 533 534 /** SUP_IOCTL_LOW_ALLOC Output. */ 535 typedef struct SUPLOWALLOC_OUT 536 { 537 /** The ring-3 address of the allocated memory. */ 538 RTR3PTR pvR3; 539 /** The ring-0 address of the allocated memory. */ 540 RTR0PTR pvR0; 541 /** Array of pages. */ 542 SUPPAGE aPages[1]; 543 } SUPLOWALLOC_OUT, *PSUPLOWALLOC_OUT; 544 545 546 547 /** SUP_IOCTL_LOW_FREE Input. */ 548 typedef struct SUPLOWFREE_IN 549 { 550 /** Cookie. */ 551 uint32_t u32Cookie; 552 /** Session cookie. */ 553 uint32_t u32SessionCookie; 554 /** The ring-3 address of the memory to free. */ 555 RTR3PTR pvR3; 556 } SUPLOWFREE_IN, *PSUPLOWFREE_IN; 557 558 559 560 /** SUP_IOCTL_GIP_MAP Input. */ 561 typedef struct SUPGIPMAP_IN 562 { 563 /** Cookie. */ 564 uint32_t u32Cookie; 565 /** Session cookie. */ 566 uint32_t u32SessionCookie; 567 } SUPGIPMAP_IN, *PSUPGIPMAP_IN; 568 569 /** SUP_IOCTL_GIP_MAP Output. */ 570 typedef struct SUPGIPMAP_OUT 571 { 572 /** Pointer to the read-only usermode GIP mapping for this session. */ 573 R3PTRTYPE(PSUPGLOBALINFOPAGE) pGipR3; 574 /** Pointer to the supervisor mode GIP mapping. */ 575 R0PTRTYPE(PSUPGLOBALINFOPAGE) pGipR0; 576 /** The physical address of the GIP. */ 577 RTHCPHYS HCPhysGip; 578 } SUPGIPMAP_OUT, *PSUPGIPMAP_OUT; 579 580 581 582 /** SUP_IOCTL_GIP_UNMAP Input. */ 583 typedef struct SUPGIPUNMAP_IN 584 { 585 /** Cookie. */ 586 uint32_t u32Cookie; 587 /** Session cookie. */ 588 uint32_t u32SessionCookie; 589 } SUPGIPUNMAP_IN, *PSUPGIPUNMAP_IN; 590 591 592 593 /** SUP_IOCTL_SET_VM_FOR_FAST Input. */ 594 typedef struct SUPSETVMFORFAST_IN 595 { 596 /** Cookie. */ 597 uint32_t u32Cookie; 598 /** Session cookie. */ 599 uint32_t u32SessionCookie; 600 /** The ring-0 VM handle (pointer). */ 601 PVMR0 pVMR0; 602 } SUPSETVMFORFAST_IN, *PSUPSETVMFORFAST_IN; 603 604 typedef struct SUPALLOCPAGE_IN 605 { 606 /** Cookie. */ 607 uint32_t u32Cookie; 608 /** Session cookie. */ 609 uint32_t u32SessionCookie; 610 /** Number of pages to allocate */ 611 uint32_t cPages; 612 } SUPALLOCPAGE_IN, *PSUPALLOCPAGE_IN; 613 614 typedef struct SUPALLOCPAGE_OUT 615 { 616 /** Cookie. */ 617 uint32_t u32Cookie; 618 /** Returned ring-3 address */ 619 R3PTRTYPE(void *) pvR3; 620 } SUPALLOCPAGE_OUT, *PSUPALLOCPAGE_OUT; 621 622 typedef struct SUPFREEPAGE_IN 623 { 624 /** Cookie. */ 625 uint32_t u32Cookie; 626 /** Session cookie. */ 627 uint32_t u32SessionCookie; 628 /** Address of memory range to free */ 629 R3PTRTYPE(void *) pvR3; 630 } SUPFREEPAGE_IN, *PSUPFREEPAGE_IN; 361 typedef struct SUPLDRLOAD 362 { 363 /** The header. */ 364 SUPREQHDR Hdr; 365 union 366 { 367 struct 368 { 369 /** The address of module initialization function. Similar to _DLL_InitTerm(hmod, 0). */ 370 PFNR0MODULEINIT pfnModuleInit; 371 /** The address of module termination function. Similar to _DLL_InitTerm(hmod, 1). */ 372 PFNR0MODULETERM pfnModuleTerm; 373 /** Special entry points. */ 374 union 375 { 376 struct 377 { 378 /** The module handle (i.e. address). */ 379 RTR0PTR pvVMMR0; 380 /** Address of VMMR0Entry function. */ 381 RTR0PTR pvVMMR0Entry; 382 } VMMR0; 383 } EP; 384 /** Address. */ 385 RTR0PTR pvImageBase; 386 /** Entry point type. */ 387 enum { EP_NOTHING, EP_VMMR0 } 388 eEPType; 389 /** The offset of the symbol table. */ 390 uint32_t offSymbols; 391 /** The number of entries in the symbol table. */ 392 uint32_t cSymbols; 393 /** The offset of the string table. */ 394 uint32_t offStrTab; 395 /** Size of the string table. */ 396 uint32_t cbStrTab; 397 /** Size of image (including string and symbol tables). */ 398 uint32_t cbImage; 399 /** The image data. */ 400 char achImage[1]; 401 } In; 402 } u; 403 } SUPLDRLOAD, *PSUPLDRLOAD; 404 /** @} */ 405 406 407 /** @name SUP_IOCTL_LDR_FREE 408 * Free an image. 409 * @{ 410 */ 411 #define SUP_IOCTL_LDR_FREE SUP_CTL_CODE_SIZE(7, SUP_IOCTL_LDR_FREE_SIZE) 412 #define SUP_IOCTL_LDR_FREE_SIZE sizeof(SUPLDRFREE) 413 #define SUP_IOCTL_LDR_FREE_SIZE_IN sizeof(SUPLDRFREE) 414 #define SUP_IOCTL_LDR_FREE_SIZE_OUT sizeof(SUPREQHDR) 415 typedef struct SUPLDRFREE 416 { 417 /** The header. */ 418 SUPREQHDR Hdr; 419 union 420 { 421 struct 422 { 423 /** Address. */ 424 RTR0PTR pvImageBase; 425 } In; 426 } u; 427 } SUPLDRFREE, *PSUPLDRFREE; 428 /** @} */ 429 430 431 /** @name SUP_IOCTL_LDR_GET_SYMBOL 432 * Get address of a symbol within an image. 433 * @{ 434 */ 435 #define SUP_IOCTL_LDR_GET_SYMBOL SUP_CTL_CODE_SIZE(8, SUP_IOCTL_LDR_GET_SYMBOL_SIZE) 436 #define SUP_IOCTL_LDR_GET_SYMBOL_SIZE sizeof(SUPLDRGETSYMBOL) 437 #define SUP_IOCTL_LDR_GET_SYMBOL_SIZE_IN sizeof(SUPLDRGETSYMBOL) 438 #define SUP_IOCTL_LDR_GET_SYMBOL_SIZE_OUT (sizeof(SUPREQHDR) + RT_SIZEOFMEMB(SUPLDRGETSYMBOL, u.Out)) 439 typedef struct SUPLDRGETSYMBOL 440 { 441 /** The header. */ 442 SUPREQHDR Hdr; 443 union 444 { 445 struct 446 { 447 /** Address. */ 448 RTR0PTR pvImageBase; 449 /** The symbol name. */ 450 char szSymbol[64]; 451 } In; 452 struct 453 { 454 /** The symbol address. */ 455 RTR0PTR pvSymbol; 456 } Out; 457 } u; 458 } SUPLDRGETSYMBOL, *PSUPLDRGETSYMBOL; 459 /** @} */ 460 461 462 /** @name SUP_IOCTL_CALL_VMMR0 463 * Call the R0 VMM Entry point. 464 * 465 * @todo Might have to convert this to a big request... 466 * @{ 467 */ 468 #define SUP_IOCTL_CALL_VMMR0(cbReq) SUP_CTL_CODE_SIZE(9, SUP_IOCTL_CALL_VMMR0_SIZE(cbReq)) 469 #define SUP_IOCTL_CALL_VMMR0_SIZE(cbReq) RT_OFFSETOF(SUPCALLVMMR0, abReqPkt[cbReq]) 470 #define SUP_IOCTL_CALL_VMMR0_SIZE_IN(cbReq) SUP_IOCTL_CALL_VMMR0_SIZE(cbReq) 471 #define SUP_IOCTL_CALL_VMMR0_SIZE_OUT(cbReq) SUP_IOCTL_CALL_VMMR0_SIZE(cbReq) 472 typedef struct SUPCALLVMMR0 473 { 474 /** The header. */ 475 SUPREQHDR Hdr; 476 union 477 { 478 struct 479 { 480 /** The VM handle. */ 481 PVMR0 pVMR0; 482 /** Which operation to execute. */ 483 uint32_t uOperation; 484 #if R0_ARCH_BITS == 64 485 /** Alignment. */ 486 uint32_t u32Reserved; 487 #endif 488 /** Argument to use when no request packet is supplied. */ 489 RTR0UINTPTR uArg; 490 } In; 491 } u; 492 /** The VMMR0Entry request packet. */ 493 uint8_t abReqPkt[1]; 494 } SUPCALLVMMR0, *PSUPCALLVMMR0; 495 /** @} */ 496 497 498 /** @name SUP_IOCTL_LOW_ALLOC 499 * Allocate memory below 4GB (physically). 500 * @{ 501 */ 502 #define SUP_IOCTL_LOW_ALLOC SUP_CTL_CODE_BIG(10) 503 #define SUP_IOCTL_LOW_ALLOC_SIZE(cPages) RT_OFFSETOF(SUPLOWALLOC, u.Out.aPages[cPages]) 504 #define SUP_IOCTL_LOW_ALLOC_SIZE_IN (sizeof(SUPREQHDR) + RT_SIZEOFMEMB(SUPLOWALLOC, u.In)) 505 #define SUP_IOCTL_LOW_ALLOC_SIZE_OUT(cPages) SUP_IOCTL_LOW_ALLOC_SIZE(cPages) 506 typedef struct SUPLOWALLOC 507 { 508 /** The header. */ 509 SUPREQHDR Hdr; 510 union 511 { 512 struct 513 { 514 /** Number of pages to allocate. */ 515 uint32_t cPages; 516 } In; 517 struct 518 { 519 /** The ring-3 address of the allocated memory. */ 520 RTR3PTR pvR3; 521 /** The ring-0 address of the allocated memory. */ 522 RTR0PTR pvR0; 523 /** Array of pages. */ 524 RTHCPHYS aPages[1]; 525 } Out; 526 } u; 527 } SUPLOWALLOC, *PSUPLOWALLOC; 528 /** @} */ 529 530 531 /** @name SUP_IOCTL_LOW_FREE 532 * Free low memory. 533 * @{ 534 */ 535 #define SUP_IOCTL_LOW_FREE SUP_CTL_CODE_SIZE(11, SUP_IOCTL_LOW_FREE_SIZE) 536 #define SUP_IOCTL_LOW_FREE_SIZE sizeof(SUPLOWFREE) 537 #define SUP_IOCTL_LOW_FREE_SIZE_IN sizeof(SUPLOWFREE) 538 #define SUP_IOCTL_LOW_FREE_SIZE_OUT sizeof(SUPREQHDR) 539 typedef struct SUPLOWFREE 540 { 541 /** The header. */ 542 SUPREQHDR Hdr; 543 union 544 { 545 struct 546 { 547 /** The ring-3 address of the memory to free. */ 548 RTR3PTR pvR3; 549 } In; 550 } u; 551 } SUPLOWFREE, *PSUPLOWFREE; 552 /** @} */ 553 554 555 /** @name SUP_IOCTL_PAGE_ALLOC 556 * Allocate memory and map into the user process. 557 * The memory is of course locked. 558 * @{ 559 */ 560 #define SUP_IOCTL_PAGE_ALLOC SUP_CTL_CODE_BIG(12) 561 #define SUP_IOCTL_PAGE_ALLOC_SIZE(cPages) RT_OFFSETOF(SUPPAGEALLOC, u.Out.aPages[cPages]) 562 #define SUP_IOCTL_PAGE_ALLOC_SIZE_IN (sizeof(SUPREQHDR) + RT_SIZEOFMEMB(SUPPAGEALLOC, u.In)) 563 #define SUP_IOCTL_PAGE_ALLOC_SIZE_OUT(cPages) SUP_IOCTL_PAGE_ALLOC_SIZE(cPages) 564 typedef struct SUPPAGEALLOC 565 { 566 /** The header. */ 567 SUPREQHDR Hdr; 568 union 569 { 570 struct 571 { 572 /** Number of pages to allocate */ 573 uint32_t cPages; 574 } In; 575 struct 576 { 577 /** Returned ring-3 address. */ 578 RTR3PTR pvR3; 579 /** The physical addresses of the allocated pages. */ 580 RTHCPHYS aPages[1]; 581 } Out; 582 } u; 583 } SUPPAGEALLOC, *PSUPPAGEALLOC; 584 /** @} */ 585 586 587 /** @name SUP_IOCTL_PAGE_FREE 588 * Free memory allocated with SUP_IOCTL_PAGE_ALLOC. 589 * @{ 590 */ 591 #define SUP_IOCTL_PAGE_FREE SUP_CTL_CODE_SIZE(13, SUP_IOCTL_PAGE_FREE_SIZE_IN) 592 #define SUP_IOCTL_PAGE_FREE_SIZE sizeof(SUPPAGEFREE) 593 #define SUP_IOCTL_PAGE_FREE_SIZE_IN sizeof(SUPPAGEFREE) 594 #define SUP_IOCTL_PAGE_FREE_SIZE_OUT sizeof(SUPREQHDR) 595 typedef struct SUPPAGEFREE 596 { 597 /** The header. */ 598 SUPREQHDR Hdr; 599 union 600 { 601 struct 602 { 603 /** Address of memory range to free. */ 604 RTR3PTR pvR3; 605 } In; 606 } u; 607 } SUPPAGEFREE, *PSUPPAGEFREE; 608 /** @} */ 609 610 611 /** @name SUP_IOCTL_PAGE_LOCK 612 * Pin down physical pages. 613 * @{ 614 */ 615 #define SUP_IOCTL_PAGE_LOCK SUP_CTL_CODE_BIG(14) 616 #define SUP_IOCTL_PAGE_LOCK_SIZE(cPages) (RT_MAX((size_t)SUP_IOCTL_PAGE_LOCK_SIZE_IN, (size_t)SUP_IOCTL_PAGE_LOCK_SIZE_OUT(cPages))) 617 #define SUP_IOCTL_PAGE_LOCK_SIZE_IN (sizeof(SUPREQHDR) + RT_SIZEOFMEMB(SUPPAGELOCK, u.In)) 618 #define SUP_IOCTL_PAGE_LOCK_SIZE_OUT(cPages) RT_OFFSETOF(SUPPAGELOCK, u.Out.aPages[cPages]) 619 typedef struct SUPPAGELOCK 620 { 621 /** The header. */ 622 SUPREQHDR Hdr; 623 union 624 { 625 struct 626 { 627 /** Start of page range. Must be PAGE aligned. */ 628 RTR3PTR pvR3; 629 /** The range size given as a page count. */ 630 uint32_t cPages; 631 } In; 632 633 struct 634 { 635 /** Array of pages. */ 636 RTHCPHYS aPages[1]; 637 } Out; 638 } u; 639 } SUPPAGELOCK, *PSUPPAGELOCK; 640 /** @} */ 641 642 643 /** @name SUP_IOCTL_PAGE_UNLOCK 644 * Unpin physical pages. 645 * @{ */ 646 #define SUP_IOCTL_PAGE_UNLOCK SUP_CTL_CODE_SIZE(15, SUP_IOCTL_PAGE_UNLOCK_SIZE) 647 #define SUP_IOCTL_PAGE_UNLOCK_SIZE sizeof(SUPPAGEUNLOCK) 648 #define SUP_IOCTL_PAGE_UNLOCK_SIZE_IN sizeof(SUPPAGEUNLOCK) 649 #define SUP_IOCTL_PAGE_UNLOCK_SIZE_OUT sizeof(SUPREQHDR) 650 typedef struct SUPPAGEUNLOCK 651 { 652 /** The header. */ 653 SUPREQHDR Hdr; 654 union 655 { 656 struct 657 { 658 /** Start of page range of a range previuosly pinned. */ 659 RTR3PTR pvR3; 660 } In; 661 } u; 662 } SUPPAGEUNLOCK, *PSUPPAGEUNLOCK; 663 /** @} */ 664 665 666 /** @name SUP_IOCTL_CONT_ALLOC 667 * Allocate contious memory. 668 * @{ 669 */ 670 #define SUP_IOCTL_CONT_ALLOC SUP_CTL_CODE_SIZE(16, SUP_IOCTL_CONT_ALLOC_SIZE) 671 #define SUP_IOCTL_CONT_ALLOC_SIZE sizeof(SUPCONTALLOC) 672 #define SUP_IOCTL_CONT_ALLOC_SIZE_IN (sizeof(SUPREQHDR) + RT_SIZEOFMEMB(SUPCONTALLOC, u.In)) 673 #define SUP_IOCTL_CONT_ALLOC_SIZE_OUT sizeof(SUPCONTALLOC) 674 typedef struct SUPCONTALLOC 675 { 676 /** The header. */ 677 SUPREQHDR Hdr; 678 union 679 { 680 struct 681 { 682 /** The allocation size given as a page count. */ 683 uint32_t cPages; 684 } In; 685 686 struct 687 { 688 /** The address of the ring-0 mapping of the allocated memory. */ 689 RTR0PTR pvR0; 690 /** The address of the ring-3 mapping of the allocated memory. */ 691 RTR3PTR pvR3; 692 /** The physical address of the allocation. */ 693 RTHCPHYS HCPhys; 694 } Out; 695 } u; 696 } SUPCONTALLOC, *PSUPCONTALLOC; 697 /** @} */ 698 699 700 /** @name SUP_IOCTL_CONT_FREE Input. 701 * @{ 702 */ 703 /** Free contious memory. */ 704 #define SUP_IOCTL_CONT_FREE SUP_CTL_CODE_SIZE(17, SUP_IOCTL_CONT_FREE_SIZE) 705 #define SUP_IOCTL_CONT_FREE_SIZE sizeof(SUPCONTFREE) 706 #define SUP_IOCTL_CONT_FREE_SIZE_IN sizeof(SUPCONTFREE) 707 #define SUP_IOCTL_CONT_FREE_SIZE_OUT sizeof(SUPREQHDR) 708 typedef struct SUPCONTFREE 709 { 710 /** The header. */ 711 SUPREQHDR Hdr; 712 union 713 { 714 struct 715 { 716 /** The ring-3 address of the memory to free. */ 717 RTR3PTR pvR3; 718 } In; 719 } u; 720 } SUPCONTFREE, *PSUPCONTFREE; 721 /** @} */ 722 723 724 /** @name SUP_IOCTL_GET_PAGING_MODE 725 * Get the host paging mode. 726 * @{ 727 */ 728 #define SUP_IOCTL_GET_PAGING_MODE SUP_CTL_CODE_SIZE(18, SUP_IOCTL_GET_PAGING_MODE_SIZE) 729 #define SUP_IOCTL_GET_PAGING_MODE_SIZE sizeof(SUPGETPAGINGMODE) 730 #define SUP_IOCTL_GET_PAGING_MODE_SIZE_IN sizeof(SUPREQHDR) 731 #define SUP_IOCTL_GET_PAGING_MODE_SIZE_OUT sizeof(SUPGETPAGINGMODE) 732 typedef struct SUPGETPAGINGMODE 733 { 734 /** The header. */ 735 SUPREQHDR Hdr; 736 union 737 { 738 struct 739 { 740 /** The paging mode. */ 741 SUPPAGINGMODE enmMode; 742 } Out; 743 } u; 744 } SUPGETPAGINGMODE, *PSUPGETPAGINGMODE; 745 /** @} */ 746 747 748 /** @name SUP_IOCTL_SET_VM_FOR_FAST 749 * Set the VM handle for doing fast call ioctl calls. 750 * @{ 751 */ 752 #define SUP_IOCTL_SET_VM_FOR_FAST SUP_CTL_CODE_SIZE(19, SUP_IOCTL_SET_VM_FOR_FAST_SIZE) 753 #define SUP_IOCTL_SET_VM_FOR_FAST_SIZE sizeof(SUPSETVMFORFAST) 754 #define SUP_IOCTL_SET_VM_FOR_FAST_SIZE_IN sizeof(SUPSETVMFORFAST) 755 #define SUP_IOCTL_SET_VM_FOR_FAST_SIZE_OUT sizeof(SUPREQHDR) 756 typedef struct SUPSETVMFORFAST 757 { 758 /** The header. */ 759 SUPREQHDR Hdr; 760 union 761 { 762 struct 763 { 764 /** The ring-0 VM handle (pointer). */ 765 PVMR0 pVMR0; 766 } In; 767 } u; 768 } SUPSETVMFORFAST, *PSUPSETVMFORFAST; 769 /** @} */ 770 771 772 /** @name SUP_IOCTL_GIP_MAP 773 * Map the GIP into user space. 774 * @{ 775 */ 776 #define SUP_IOCTL_GIP_MAP SUP_CTL_CODE_SIZE(20, SUP_IOCTL_GIP_MAP_SIZE) 777 #define SUP_IOCTL_GIP_MAP_SIZE sizeof(SUPGIPMAP) 778 #define SUP_IOCTL_GIP_MAP_SIZE_IN sizeof(SUPREQHDR) 779 #define SUP_IOCTL_GIP_MAP_SIZE_OUT sizeof(SUPGIPMAP) 780 typedef struct SUPGIPMAP 781 { 782 /** The header. */ 783 SUPREQHDR Hdr; 784 union 785 { 786 struct 787 { 788 /** The physical address of the GIP. */ 789 RTHCPHYS HCPhysGip; 790 /** Pointer to the read-only usermode GIP mapping for this session. */ 791 R3PTRTYPE(PSUPGLOBALINFOPAGE) pGipR3; 792 /** Pointer to the supervisor mode GIP mapping. */ 793 R0PTRTYPE(PSUPGLOBALINFOPAGE) pGipR0; 794 } Out; 795 } u; 796 } SUPGIPMAP, *PSUPGIPMAP; 797 /** @} */ 798 799 800 /** @name SUP_IOCTL_GIP_UNMAP 801 * Unmap the GIP. 802 * @{ 803 */ 804 #define SUP_IOCTL_GIP_UNMAP SUP_CTL_CODE_SIZE(21, SUP_IOCTL_GIP_UNMAP_SIZE) 805 #define SUP_IOCTL_GIP_UNMAP_SIZE sizeof(SUPGIPUNMAP) 806 #define SUP_IOCTL_GIP_UNMAP_SIZE_IN sizeof(SUPGIPUNMAP) 807 #define SUP_IOCTL_GIP_UNMAP_SIZE_OUT sizeof(SUPGIPUNMAP) 808 typedef struct SUPGIPUNMAP 809 { 810 /** The header. */ 811 SUPREQHDR Hdr; 812 } SUPGIPUNMAP, *PSUPGIPUNMAP; 813 /** @} */ 814 631 815 632 816 #pragma pack() /* paranoia */ -
trunk/src/VBox/HostDrivers/Support/SUPDRVShared.c
r4792 r4800 64 64 #define GIP_UPDATEHZ_RECALC_FREQ 0x800 65 65 66 /** 67 * Validates a session pointer. 68 * 69 * @returns true/false accordingly. 70 * @param pSession The session. 71 */ 72 #define SUP_IS_SESSION_VALID(pSession) \ 73 ( VALID_PTR(pSession) \ 74 && pSession->u32Cookie == BIRD_INV) 75 66 76 67 77 /******************************************************************************* … … 87 97 #ifdef USE_NEW_OS_INTERFACE_FOR_MM 88 98 { "SUPR0PageAlloc", (void *)SUPR0PageAlloc }, 89 { "SUPR0PageGetPhys", (void *)SUPR0PageGetPhys },90 99 { "SUPR0PageFree", (void *)SUPR0PageFree }, 91 100 #endif … … 147 156 * Internal Functions * 148 157 *******************************************************************************/ 149 __BEGIN_DECLS150 158 static int supdrvMemAdd(PSUPDRVMEMREF pMem, PSUPDRVSESSION pSession); 151 159 static int supdrvMemRelease(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, SUPDRVMEMREFTYPE eType); 152 160 #ifndef VBOX_WITHOUT_IDT_PATCHING 153 static int supdrvIOCtl_IdtInstall(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPIDTINSTALL _IN pIn, PSUPIDTINSTALL_OUT pOut);161 static int supdrvIOCtl_IdtInstall(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPIDTINSTALL pReq); 154 162 static PSUPDRVPATCH supdrvIdtPatchOne(PSUPDRVDEVEXT pDevExt, PSUPDRVPATCH pPatch); 155 163 static int supdrvIOCtl_IdtRemoveAll(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession); … … 157 165 static void supdrvIdtWrite(volatile void *pvIdtEntry, const SUPDRVIDTE *pNewIDTEntry); 158 166 #endif /* !VBOX_WITHOUT_IDT_PATCHING */ 159 static int supdrvIOCtl_LdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDROPEN _IN pIn, PSUPLDROPEN_OUT pOut);160 static int supdrvIOCtl_LdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRLOAD _IN pIn);161 static int supdrvIOCtl_LdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRFREE _IN pIn);162 static int supdrvIOCtl_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRGETSYMBOL _IN pIn, PSUPLDRGETSYMBOL_OUT pOut);167 static int supdrvIOCtl_LdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDROPEN pReq); 168 static int supdrvIOCtl_LdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRLOAD pReq); 169 static int supdrvIOCtl_LdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRFREE pReq); 170 static int supdrvIOCtl_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRGETSYMBOL pReq); 163 171 static int supdrvLdrSetR0EP(PSUPDRVDEVEXT pDevExt, void *pvVMMR0, void *pvVMMR0Entry); 164 172 static void supdrvLdrUnsetR0EP(PSUPDRVDEVEXT pDevExt); 165 173 static void supdrvLdrAddUsage(PSUPDRVSESSION pSession, PSUPDRVLDRIMAGE pImage); 166 174 static void supdrvLdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage); 167 static int supdrvIOCtl_GetPagingMode(PSUPGETPAGINGMODE_OUT pOut);175 static SUPPAGINGMODE supdrvIOCtl_GetPagingMode(void); 168 176 static SUPGIPMODE supdrvGipDeterminTscMode(void); 177 #ifdef RT_OS_WINDOWS 178 static int supdrvPageGetPhys(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages); 179 static bool supdrvPageWasLockedByPageAlloc(PSUPDRVSESSION pSession, RTR3PTR pvR3); 180 #endif 169 181 #ifdef USE_NEW_OS_INTERFACE_FOR_GIP 170 182 static int supdrvGipCreate(PSUPDRVDEVEXT pDevExt); 171 static intsupdrvGipDestroy(PSUPDRVDEVEXT pDevExt);183 static void supdrvGipDestroy(PSUPDRVDEVEXT pDevExt); 172 184 static DECLCALLBACK(void) supdrvGipTimer(PRTTIMER pTimer, void *pvUser); 173 185 #endif 174 186 175 __END_DECLS176 177 187 178 188 /** 179 189 * Initializes the device extentsion structure. 180 190 * 181 * @returns 0 on success. 182 * @returns SUPDRV_ERR_ on failure. 191 * @returns IPRT status code. 183 192 * @param pDevExt The device extension to initialize. 184 193 */ … … 203 212 if (RT_SUCCESS(rc)) 204 213 { 205 pDevExt->u32Cookie = BIRD; 206 return 0;214 pDevExt->u32Cookie = BIRD; /** @todo make this random? */ 215 return VINF_SUCCESS; 207 216 } 208 217 #else 209 218 pDevExt->u32Cookie = BIRD; 210 return 0;219 return VINF_SUCCESS; 211 220 #endif 212 221 } … … 220 229 } 221 230 231 222 232 /** 223 233 * Delete the device extension (e.g. cleanup members). 224 234 * 225 * @returns 0.226 235 * @param pDevExt The device extension to delete. 227 236 */ 228 intVBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt)237 void VBOXCALL supdrvDeleteDevExt(PSUPDRVDEVEXT pDevExt) 229 238 { 230 239 #ifndef VBOX_WITHOUT_IDT_PATCHING … … 247 256 * Free lists. 248 257 */ 249 250 258 #ifndef VBOX_WITHOUT_IDT_PATCHING 251 259 /* patches */ … … 288 296 supdrvGipDestroy(pDevExt); 289 297 #endif 290 291 return 0;292 298 } 293 299 … … 296 302 * Create session. 297 303 * 298 * @returns 0 on success. 299 * @returns SUPDRV_ERR_ on failure. 304 * @returns IPRT status code. 300 305 * @param pDevExt Device extension. 301 306 * @param ppSession Where to store the pointer to the session data. … … 306 311 * Allocate memory for the session data. 307 312 */ 308 int rc = SUPDRV_ERR_NO_MEMORY;313 int rc = VERR_NO_MEMORY; 309 314 PSUPDRVSESSION pSession = *ppSession = (PSUPDRVSESSION)RTMemAllocZ(sizeof(*pSession)); 310 315 if (pSession) … … 325 330 326 331 dprintf(("Created session %p initial cookie=%#x\n", pSession, pSession->u32Cookie)); 327 return 0;332 return VINF_SUCCESS; 328 333 } 329 334 … … 461 466 * Check and unlock all entries in the bundle. 462 467 */ 463 for (i = 0; i < sizeof(pBundle->aMem) / sizeof(pBundle->aMem[0]); i++)468 for (i = 0; i < RT_ELEMENTS(pBundle->aMem); i++) 464 469 { 465 470 #ifdef USE_NEW_OS_INTERFACE_FOR_MM … … 467 472 { 468 473 int rc; 469 dprintf2(("eType=%d pvR0=%p pvR3=%p cb=% d\n", pBundle->aMem[i].eType,470 RTR0MemObjAddress(pBundle->aMem[i].MapObj), RTR0MemObjAddressR3(pBundle->aMem[i].MapObjR3),RTR0MemObjSize(pBundle->aMem[i].MemObj)));474 dprintf2(("eType=%d pvR0=%p pvR3=%p cb=%ld\n", pBundle->aMem[i].eType, RTR0MemObjAddress(pBundle->aMem[i].MemObj), 475 (void *)RTR0MemObjAddressR3(pBundle->aMem[i].MapObjR3), (long)RTR0MemObjSize(pBundle->aMem[i].MemObj))); 471 476 if (pBundle->aMem[i].MapObjR3 != NIL_RTR0MEMOBJ) 472 477 { … … 571 576 * Fast path I/O Control worker. 572 577 * 573 * @returns 0 on success. 574 * @returns One of the SUPDRV_ERR_* on failure. 578 * @returns VBox status code that should be passed down to ring-3 unchanged. 575 579 * @param uIOCtl Function number. 576 580 * @param pDevExt Device extention. 577 581 * @param pSession Session data. 578 582 */ 579 int VBOXCALL supdrvIOCtlFast(unsigneduIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession)583 int VBOXCALL supdrvIOCtlFast(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession) 580 584 { 581 585 /* … … 619 623 * 620 624 * @returns 0 on success. 621 * @returns One of the SUPDRV_ERR_* on failure. 625 * @returns VERR_INVALID_PARAMETER if the request is invalid. 626 * 622 627 * @param uIOCtl Function number. 623 628 * @param pDevExt Device extention. 624 629 * @param pSession Session data. 625 * @param pvIn Input data. 626 * @param cbIn Size of input data. 627 * @param pvOut Output data. 628 * IMPORTANT! This buffer may be shared with the input 629 * data, thus no writing before done reading 630 * input data!!! 631 * @param cbOut Size of output data. 632 * @param pcbReturned Size of the returned data. 633 */ 634 int VBOXCALL supdrvIOCtl(unsigned int uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, 635 void *pvIn, unsigned cbIn, void *pvOut, unsigned cbOut, unsigned *pcbReturned) 636 { 637 *pcbReturned = 0; 638 switch (uIOCtl) 639 { 640 case SUP_IOCTL_COOKIE: 641 { 642 PSUPCOOKIE_IN pIn = (PSUPCOOKIE_IN)pvIn; 643 PSUPCOOKIE_OUT pOut = (PSUPCOOKIE_OUT)pvOut; 644 630 * @param pReqHdr The request header. 631 */ 632 int VBOXCALL supdrvIOCtl(uintptr_t uIOCtl, PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPREQHDR pReqHdr) 633 { 634 /* 635 * Validate the request. 636 */ 637 /* this first check could probably be omitted as its also done by the OS specific code... */ 638 if (RT_UNLIKELY( (pReqHdr->fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC 639 || pReqHdr->cbIn < sizeof(*pReqHdr) 640 || pReqHdr->cbOut < sizeof(*pReqHdr))) 641 { 642 OSDBGPRINT(("vboxdrv: Bad ioctl request header; cbIn=%#lx cbOut=%#lx fFlags=%#lx\n", 643 (long)pReqHdr->cbIn, (long)pReqHdr->cbOut, (long)pReqHdr->fFlags)); 644 return VERR_INVALID_PARAMETER; 645 } 646 if (RT_UNLIKELY(uIOCtl == SUP_IOCTL_COOKIE)) 647 { 648 if (pReqHdr->u32Cookie != SUPCOOKIE_INITIAL_COOKIE) 649 { 650 OSDBGPRINT(("SUP_IOCTL_COOKIE: bad cookie %#lx\n", (long)pReqHdr->u32Cookie)); 651 return VERR_INVALID_PARAMETER; 652 } 653 } 654 else if (RT_UNLIKELY( pReqHdr->u32Cookie != pDevExt->u32Cookie 655 || pReqHdr->u32SessionCookie != pSession->u32Cookie)) 656 { 657 OSDBGPRINT(("vboxdrv: bad cookie %#lx / %#lx.\n", (long)pReqHdr->u32Cookie, (long)pReqHdr->u32SessionCookie)); 658 return VERR_INVALID_PARAMETER; 659 } 660 661 /* 662 * Validation macros 663 */ 664 #define REQ_CHECK_SIZES_EX(Name, cbInExpect, cbOutExpect) \ 665 do { \ 666 if (RT_UNLIKELY(pReqHdr->cbIn != (cbInExpect) || pReqHdr->cbOut != (cbOutExpect))) \ 667 { \ 668 OSDBGPRINT(( #Name ": Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", \ 669 (long)pReq->Hdr.cbIn, (long)(cbInExpect), (long)pReq->Hdr.cbOut, (long)(cbOutExpect))); \ 670 return pReq->Hdr.rc = VERR_INVALID_PARAMETER; \ 671 } \ 672 } while (0) 673 674 #define REQ_CHECK_SIZES(Name) REQ_CHECK_SIZES_EX(Name, Name ## _SIZE_IN, Name ## _SIZE_OUT) 675 676 #define REQ_CHECK_SIZE_IN(Name, cbInExpect) \ 677 do { \ 678 if (RT_UNLIKELY(pReqHdr->cbIn != (cbInExpect))) \ 679 { \ 680 OSDBGPRINT(( #Name ": Invalid input/output sizes. cbIn=%ld expected %ld.\n", \ 681 (long)pReq->Hdr.cbIn, (long)(cbInExpect))); \ 682 return pReq->Hdr.rc = VERR_INVALID_PARAMETER; \ 683 } \ 684 } while (0) 685 686 #define REQ_CHECK_SIZE_OUT(Name, cbOutExpect) \ 687 do { \ 688 if (RT_UNLIKELY(pReqHdr->cbOut != (cbOutExpect))) \ 689 { \ 690 OSDBGPRINT(( #Name ": Invalid input/output sizes. cbOut=%ld expected %ld.\n", \ 691 (long)pReq->Hdr.cbOut, (long)(cbOutExpect))); \ 692 return pReq->Hdr.rc = VERR_INVALID_PARAMETER; \ 693 } \ 694 } while (0) 695 696 #define REQ_CHECK_EXPR(Name, expr) \ 697 do { \ 698 if (RT_UNLIKELY(!(expr))) \ 699 { \ 700 OSDBGPRINT(( #Name ": %s\n", #expr)); \ 701 return pReq->Hdr.rc = VERR_INVALID_PARAMETER; \ 702 } \ 703 } while (0) 704 705 #define REQ_CHECK_EXPR_FMT(expr, fmt) \ 706 do { \ 707 if (RT_UNLIKELY(!(expr))) \ 708 { \ 709 OSDBGPRINT( fmt ); \ 710 return pReq->Hdr.rc = VERR_INVALID_PARAMETER; \ 711 } \ 712 } while (0) 713 714 715 /* 716 * The switch. 717 */ 718 switch (SUP_CTL_CODE_NO_SIZE(uIOCtl)) 719 { 720 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_COOKIE): 721 { 722 PSUPCOOKIE pReq = (PSUPCOOKIE)pReqHdr; 723 REQ_CHECK_SIZES(SUP_IOCTL_COOKIE); 724 if (strncmp(pReq->u.In.szMagic, SUPCOOKIE_MAGIC, sizeof(pReq->u.In.szMagic))) 725 { 726 OSDBGPRINT(("SUP_IOCTL_COOKIE: invalid magic %.16s\n", pReq->u.In.szMagic)); 727 pReq->Hdr.rc = VERR_INVALID_MAGIC; 728 return 0; 729 } 730 731 #if 0 645 732 /* 646 * Validate. 733 * Call out to the OS specific code and let it do permission checks on the 734 * client process. 647 735 */ 648 if ( cbIn != sizeof(*pIn) 649 || cbOut != sizeof(*pOut)) 736 if (!supdrvOSValidateClientProcess(pDevExt, pSession)) 650 737 { 651 OSDBGPRINT(("SUP_IOCTL_COOKIE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 652 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut))); 653 return SUPDRV_ERR_INVALID_PARAM; 738 pReq->u.Out.u32Cookie = 0xffffffff; 739 pReq->u.Out.u32SessionCookie = 0xffffffff; 740 pReq->u.Out.u32SessionVersion = 0xffffffff; 741 pReq->u.Out.u32DriverVersion = SUPDRVIOC_VERSION; 742 pReq->u.Out.pSession = NULL; 743 pReq->u.Out.cFunctions = 0; 744 pReq->Hdr.rc = VERR_PERMISSION_DENIED; 745 return 0; 654 746 } 655 if (strncmp(pIn->szMagic, SUPCOOKIE_MAGIC, sizeof(pIn->szMagic))) 656 { 657 OSDBGPRINT(("SUP_IOCTL_COOKIE: invalid magic %.16s\n", pIn->szMagic)); 658 return SUPDRV_ERR_INVALID_MAGIC; 659 } 747 #endif 660 748 661 749 /* … … 663 751 * The current logic is very simple, match the major interface version. 664 752 */ 665 if ( p In->u32MinVersion > SUPDRVIOC_VERSION666 || (p In->u32MinVersion & 0xffff0000) != (SUPDRVIOC_VERSION & 0xffff0000))753 if ( pReq->u.In.u32MinVersion > SUPDRVIOC_VERSION 754 || (pReq->u.In.u32MinVersion & 0xffff0000) != (SUPDRVIOC_VERSION & 0xffff0000)) 667 755 { 668 756 OSDBGPRINT(("SUP_IOCTL_COOKIE: Version mismatch. Requested: %#x Min: %#x Current: %#x\n", 669 p In->u32ReqVersion, pIn->u32MinVersion, SUPDRVIOC_VERSION));670 p Out->u32Cookie = 0xffffffff;671 p Out->u32SessionCookie = 0xffffffff;672 p Out->u32SessionVersion = 0xffffffff;673 p Out->u32DriverVersion = SUPDRVIOC_VERSION;674 p Out->pSession = NULL;675 p Out->cFunctions = 0;676 *pcbReturned = sizeof(*pOut);677 return SUPDRV_ERR_VERSION_MISMATCH;757 pReq->u.In.u32ReqVersion, pReq->u.In.u32MinVersion, SUPDRVIOC_VERSION)); 758 pReq->u.Out.u32Cookie = 0xffffffff; 759 pReq->u.Out.u32SessionCookie = 0xffffffff; 760 pReq->u.Out.u32SessionVersion = 0xffffffff; 761 pReq->u.Out.u32DriverVersion = SUPDRVIOC_VERSION; 762 pReq->u.Out.pSession = NULL; 763 pReq->u.Out.cFunctions = 0; 764 pReq->Hdr.rc = VERR_VERSION_MISMATCH; 765 return 0; 678 766 } 679 767 … … 683 771 * u32SessionVersion <= u32ReqVersion! 684 772 */ 685 /** @todo A more secure cookie negotiation?*/686 p Out->u32Cookie = pDevExt->u32Cookie;687 p Out->u32SessionCookie = pSession->u32Cookie;688 p Out->u32SessionVersion = SUPDRVIOC_VERSION;689 p Out->u32DriverVersion = SUPDRVIOC_VERSION;690 p Out->pSession = pSession;691 p Out->cFunctions = sizeof(g_aFunctions) / sizeof(g_aFunctions[0]);692 *pcbReturned = sizeof(*pOut);773 /** @todo Somehow validate the client and negotiate a secure cookie... */ 774 pReq->u.Out.u32Cookie = pDevExt->u32Cookie; 775 pReq->u.Out.u32SessionCookie = pSession->u32Cookie; 776 pReq->u.Out.u32SessionVersion = SUPDRVIOC_VERSION; 777 pReq->u.Out.u32DriverVersion = SUPDRVIOC_VERSION; 778 pReq->u.Out.pSession = pSession; 779 pReq->u.Out.cFunctions = sizeof(g_aFunctions) / sizeof(g_aFunctions[0]); 780 pReq->Hdr.rc = VINF_SUCCESS; 693 781 return 0; 694 782 } 695 783 696 697 case SUP_IOCTL_QUERY_FUNCS: 698 { 699 unsigned cFunctions; 700 PSUPQUERYFUNCS_IN pIn = (PSUPQUERYFUNCS_IN)pvIn; 701 PSUPQUERYFUNCS_OUT pOut = (PSUPQUERYFUNCS_OUT)pvOut; 702 703 /* 704 * Validate. 705 */ 706 if ( cbIn != sizeof(*pIn) 707 || cbOut < sizeof(*pOut)) 784 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_QUERY_FUNCS(0)): 785 { 786 /* validate */ 787 PSUPQUERYFUNCS pReq = (PSUPQUERYFUNCS)pReqHdr; 788 REQ_CHECK_SIZES_EX(SUP_IOCTL_QUERY_FUNCS, SUP_IOCTL_QUERY_FUNCS_SIZE_IN, SUP_IOCTL_QUERY_FUNCS_SIZE_OUT(RT_ELEMENTS(g_aFunctions))); 789 790 /* execute */ 791 pReq->u.Out.cFunctions = RT_ELEMENTS(g_aFunctions); 792 memcpy(&pReq->u.Out.aFunctions[0], g_aFunctions, sizeof(g_aFunctions)); 793 pReq->Hdr.rc = VINF_SUCCESS; 794 return 0; 795 } 796 797 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_IDT_INSTALL): 798 { 799 /* validate */ 800 PSUPIDTINSTALL pReq = (PSUPIDTINSTALL)pReqHdr; 801 REQ_CHECK_SIZES(SUP_IOCTL_IDT_INSTALL); 802 803 /* execute */ 804 #ifndef VBOX_WITHOUT_IDT_PATCHING 805 pReq->Hdr.rc = supdrvIOCtl_IdtInstall(pDevExt, pSession, pReq); 806 #else 807 pReq->u.Out.u8Idt = 3; 808 pReq->Hdr.rc = VERR_NOT_SUPPORTED; 809 #endif 810 return 0; 811 } 812 813 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_IDT_REMOVE): 814 { 815 /* validate */ 816 PSUPIDTREMOVE pReq = (PSUPIDTREMOVE)pReqHdr; 817 REQ_CHECK_SIZES(SUP_IOCTL_IDT_REMOVE); 818 819 /* execute */ 820 #ifndef VBOX_WITHOUT_IDT_PATCHING 821 pReq->Hdr.rc = supdrvIOCtl_IdtRemoveAll(pDevExt, pSession); 822 #else 823 pReq->Hdr.rc = VERR_NOT_SUPPORTED; 824 #endif 825 return 0; 826 } 827 828 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_PAGE_LOCK): 829 { 830 /* validate */ 831 PSUPPAGELOCK pReq = (PSUPPAGELOCK)pReqHdr; 832 REQ_CHECK_SIZE_IN(SUP_IOCTL_PAGE_LOCK, SUP_IOCTL_PAGE_LOCK_SIZE_IN); 833 REQ_CHECK_SIZE_OUT(SUP_IOCTL_PAGE_LOCK, SUP_IOCTL_PAGE_LOCK_SIZE_OUT(pReq->u.In.cPages)); 834 REQ_CHECK_EXPR(SUP_IOCTL_PAGE_LOCK, pReq->u.In.cPages > 0); 835 REQ_CHECK_EXPR(SUP_IOCTL_PAGE_LOCK, pReq->u.In.pvR3 >= PAGE_SIZE); 836 837 /* execute */ 838 pReq->Hdr.rc = SUPR0LockMem(pSession, pReq->u.In.pvR3, pReq->u.In.cPages, &pReq->u.Out.aPages[0]); 839 if (RT_FAILURE(pReq->Hdr.rc)) 840 pReq->Hdr.cbOut = sizeof(pReq->Hdr); 841 return 0; 842 } 843 844 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_PAGE_UNLOCK): 845 { 846 /* validate */ 847 PSUPPAGEUNLOCK pReq = (PSUPPAGEUNLOCK)pReqHdr; 848 REQ_CHECK_SIZES(SUP_IOCTL_PAGE_UNLOCK); 849 850 /* execute */ 851 pReq->Hdr.rc = SUPR0UnlockMem(pSession, pReq->u.In.pvR3); 852 return 0; 853 } 854 855 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_CONT_ALLOC): 856 { 857 /* validate */ 858 PSUPCONTALLOC pReq = (PSUPCONTALLOC)pReqHdr; 859 REQ_CHECK_SIZES(SUP_IOCTL_CONT_ALLOC); 860 861 /* execute */ 862 pReq->Hdr.rc = SUPR0ContAlloc(pSession, pReq->u.In.cPages, &pReq->u.Out.pvR0, &pReq->u.Out.pvR3, &pReq->u.Out.HCPhys); 863 if (RT_FAILURE(pReq->Hdr.rc)) 864 pReq->Hdr.cbOut = sizeof(pReq->Hdr); 865 return 0; 866 } 867 868 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_CONT_FREE): 869 { 870 /* validate */ 871 PSUPCONTFREE pReq = (PSUPCONTFREE)pReqHdr; 872 REQ_CHECK_SIZES(SUP_IOCTL_CONT_FREE); 873 874 /* execute */ 875 pReq->Hdr.rc = SUPR0ContFree(pSession, (RTHCUINTPTR)pReq->u.In.pvR3); 876 return 0; 877 } 878 879 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_LDR_OPEN): 880 { 881 /* validate */ 882 PSUPLDROPEN pReq = (PSUPLDROPEN)pReqHdr; 883 REQ_CHECK_SIZES(SUP_IOCTL_LDR_OPEN); 884 REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImage > 0); 885 REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.cbImage < _1M*16); 886 REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, pReq->u.In.szName[0]); 887 REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, memchr(pReq->u.In.szName, '\0', sizeof(pReq->u.In.szName))); 888 REQ_CHECK_EXPR(SUP_IOCTL_LDR_OPEN, !strpbrk(pReq->u.In.szName, ";:()[]{}/\\|&*%#@!~`\"'")); 889 890 /* execute */ 891 pReq->Hdr.rc = supdrvIOCtl_LdrOpen(pDevExt, pSession, pReq); 892 return 0; 893 } 894 895 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_LDR_LOAD): 896 { 897 /* validate */ 898 PSUPLDRLOAD pReq = (PSUPLDRLOAD)pReqHdr; 899 REQ_CHECK_EXPR(Name, pReq->Hdr.cbIn >= sizeof(*pReq)); 900 REQ_CHECK_SIZES_EX(SUP_IOCTL_LDR_LOAD, SUP_IOCTL_LDR_LOAD_SIZE_IN(pReq->u.In.cbImage), SUP_IOCTL_LDR_LOAD_SIZE_OUT); 901 REQ_CHECK_EXPR(SUP_IOCTL_LDR_LOAD, pReq->u.In.cSymbols <= 16384); 902 REQ_CHECK_EXPR_FMT( !pReq->u.In.cSymbols 903 || ( pReq->u.In.offSymbols < pReq->u.In.cbImage 904 && pReq->u.In.offSymbols + pReq->u.In.cSymbols * sizeof(SUPLDRSYM) <= pReq->u.In.cbImage), 905 ("SUP_IOCTL_LDR_LOAD: offSymbols=%#lx cSymbols=%#lx cbImage=%#lx\n", (long)pReq->u.In.offSymbols, 906 (long)pReq->u.In.cSymbols, (long)pReq->u.In.cbImage)); 907 REQ_CHECK_EXPR_FMT( !pReq->u.In.cbStrTab 908 || ( pReq->u.In.offStrTab < pReq->u.In.cbImage 909 && pReq->u.In.offStrTab + pReq->u.In.cbStrTab <= pReq->u.In.cbImage 910 && pReq->u.In.cbStrTab <= pReq->u.In.cbImage), 911 ("SUP_IOCTL_LDR_LOAD: offStrTab=%#lx cbStrTab=%#lx cbImage=%#lx\n", (long)pReq->u.In.offStrTab, 912 (long)pReq->u.In.cbStrTab, (long)pReq->u.In.cbImage)); 913 914 if (pReq->u.In.cSymbols) 708 915 { 709 dprintf(("SUP_IOCTL_QUERY_FUNCS: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 710 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut))); 711 return SUPDRV_ERR_INVALID_PARAM; 712 } 713 if ( pIn->u32Cookie != pDevExt->u32Cookie 714 || pIn->u32SessionCookie != pSession->u32Cookie ) 715 { 716 dprintf(("SUP_IOCTL_QUERY_FUNCS: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 717 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 718 return SUPDRV_ERR_INVALID_MAGIC; 719 } 720 721 /* 722 * Copy the functions. 723 */ 724 cFunctions = (cbOut - RT_OFFSETOF(SUPQUERYFUNCS_OUT, aFunctions)) / sizeof(pOut->aFunctions[0]); 725 cFunctions = RT_MIN(cFunctions, ELEMENTS(g_aFunctions)); 726 AssertMsg(cFunctions == ELEMENTS(g_aFunctions), 727 ("Why aren't R3 querying all the functions!?! cFunctions=%d while there are %d available\n", 728 cFunctions, ELEMENTS(g_aFunctions))); 729 pOut->cFunctions = cFunctions; 730 memcpy(&pOut->aFunctions[0], g_aFunctions, sizeof(pOut->aFunctions[0]) * cFunctions); 731 *pcbReturned = RT_OFFSETOF(SUPQUERYFUNCS_OUT, aFunctions[cFunctions]); 732 return 0; 733 } 734 735 736 case SUP_IOCTL_IDT_INSTALL: 737 { 738 PSUPIDTINSTALL_IN pIn = (PSUPIDTINSTALL_IN)pvIn; 739 PSUPIDTINSTALL_OUT pOut = (PSUPIDTINSTALL_OUT)pvOut; 740 741 /* 742 * Validate. 743 */ 744 if ( cbIn != sizeof(*pIn) 745 || cbOut != sizeof(*pOut)) 746 { 747 dprintf(("SUP_IOCTL_INSTALL: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 748 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut))); 749 return SUPDRV_ERR_INVALID_PARAM; 750 } 751 if ( pIn->u32Cookie != pDevExt->u32Cookie 752 || pIn->u32SessionCookie != pSession->u32Cookie ) 753 { 754 dprintf(("SUP_IOCTL_INSTALL: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 755 pIn->u32Cookie, pDevExt->u32Cookie, 756 pIn->u32SessionCookie, pSession->u32Cookie)); 757 return SUPDRV_ERR_INVALID_MAGIC; 758 } 759 760 *pcbReturned = sizeof(*pOut); 761 #ifndef VBOX_WITHOUT_IDT_PATCHING 762 return supdrvIOCtl_IdtInstall(pDevExt, pSession, pIn, pOut); 763 #else 764 pOut->u8Idt = 3; 765 return 0; 766 #endif 767 } 768 769 770 case SUP_IOCTL_IDT_REMOVE: 771 { 772 PSUPIDTREMOVE_IN pIn = (PSUPIDTREMOVE_IN)pvIn; 773 774 /* 775 * Validate. 776 */ 777 if ( cbIn != sizeof(*pIn) 778 || cbOut != 0) 779 { 780 dprintf(("SUP_IOCTL_REMOVE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 781 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0)); 782 return SUPDRV_ERR_INVALID_PARAM; 783 } 784 if ( pIn->u32Cookie != pDevExt->u32Cookie 785 || pIn->u32SessionCookie != pSession->u32Cookie ) 786 { 787 dprintf(("SUP_IOCTL_REMOVE: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 788 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 789 return SUPDRV_ERR_INVALID_MAGIC; 790 } 791 792 #ifndef VBOX_WITHOUT_IDT_PATCHING 793 return supdrvIOCtl_IdtRemoveAll(pDevExt, pSession); 794 #else 795 return 0; 796 #endif 797 } 798 799 800 case SUP_IOCTL_PINPAGES: 801 { 802 int rc; 803 PSUPPINPAGES_IN pIn = (PSUPPINPAGES_IN)pvIn; 804 PSUPPINPAGES_OUT pOut = (PSUPPINPAGES_OUT)pvOut; 805 806 /* 807 * Validate. 808 */ 809 if ( cbIn != sizeof(*pIn) 810 || cbOut < sizeof(*pOut)) 811 { 812 dprintf(("SUP_IOCTL_PINPAGES: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 813 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut))); 814 return SUPDRV_ERR_INVALID_PARAM; 815 } 816 if ( pIn->u32Cookie != pDevExt->u32Cookie 817 || pIn->u32SessionCookie != pSession->u32Cookie ) 818 { 819 dprintf(("SUP_IOCTL_PINPAGES: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 820 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 821 return SUPDRV_ERR_INVALID_MAGIC; 822 } 823 if (pIn->cPages <= 0 || !pIn->pvR3) 824 { 825 dprintf(("SUP_IOCTL_PINPAGES: Illegal request %p %d\n", (void *)pIn->pvR3, pIn->cPages)); 826 return SUPDRV_ERR_INVALID_PARAM; 827 } 828 if ((unsigned)RT_OFFSETOF(SUPPINPAGES_OUT, aPages[pIn->cPages]) > cbOut) 829 { 830 dprintf(("SUP_IOCTL_PINPAGES: Output buffer is too small! %d required %d passed in.\n", 831 RT_OFFSETOF(SUPPINPAGES_OUT, aPages[pIn->cPages]), cbOut)); 832 return SUPDRV_ERR_INVALID_PARAM; 833 } 834 835 /* 836 * Execute. 837 */ 838 *pcbReturned = RT_OFFSETOF(SUPPINPAGES_OUT, aPages[pIn->cPages]); 839 rc = SUPR0LockMem(pSession, pIn->pvR3, pIn->cPages, &pOut->aPages[0]); 840 if (rc) 841 *pcbReturned = 0; 842 return rc; 843 } 844 845 846 case SUP_IOCTL_UNPINPAGES: 847 { 848 PSUPUNPINPAGES_IN pIn = (PSUPUNPINPAGES_IN)pvIn; 849 850 /* 851 * Validate. 852 */ 853 if ( cbIn != sizeof(*pIn) 854 || cbOut != 0) 855 { 856 dprintf(("SUP_IOCTL_UNPINPAGES: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 857 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0)); 858 return SUPDRV_ERR_INVALID_PARAM; 859 } 860 if ( pIn->u32Cookie != pDevExt->u32Cookie 861 || pIn->u32SessionCookie != pSession->u32Cookie) 862 { 863 dprintf(("SUP_IOCTL_UNPINPAGES: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 864 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 865 return SUPDRV_ERR_INVALID_MAGIC; 866 } 867 868 /* 869 * Execute. 870 */ 871 return SUPR0UnlockMem(pSession, pIn->pvR3); 872 } 873 874 case SUP_IOCTL_CONT_ALLOC: 875 { 876 int rc; 877 PSUPCONTALLOC_IN pIn = (PSUPCONTALLOC_IN)pvIn; 878 PSUPCONTALLOC_OUT pOut = (PSUPCONTALLOC_OUT)pvOut; 879 880 /* 881 * Validate. 882 */ 883 if ( cbIn != sizeof(*pIn) 884 || cbOut < sizeof(*pOut)) 885 { 886 dprintf(("SUP_IOCTL_CONT_ALLOC: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 887 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut))); 888 return SUPDRV_ERR_INVALID_PARAM; 889 } 890 if ( pIn->u32Cookie != pDevExt->u32Cookie 891 || pIn->u32SessionCookie != pSession->u32Cookie ) 892 { 893 dprintf(("SUP_IOCTL_CONT_ALLOC: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 894 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 895 return SUPDRV_ERR_INVALID_MAGIC; 896 } 897 898 /* 899 * Execute. 900 */ 901 rc = SUPR0ContAlloc(pSession, pIn->cPages, &pOut->pvR0, &pOut->pvR3, &pOut->HCPhys); 902 if (!rc) 903 *pcbReturned = sizeof(*pOut); 904 return rc; 905 } 906 907 908 case SUP_IOCTL_CONT_FREE: 909 { 910 PSUPCONTFREE_IN pIn = (PSUPCONTFREE_IN)pvIn; 911 912 /* 913 * Validate. 914 */ 915 if ( cbIn != sizeof(*pIn) 916 || cbOut != 0) 917 { 918 dprintf(("SUP_IOCTL_CONT_FREE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 919 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0)); 920 return SUPDRV_ERR_INVALID_PARAM; 921 } 922 if ( pIn->u32Cookie != pDevExt->u32Cookie 923 || pIn->u32SessionCookie != pSession->u32Cookie) 924 { 925 dprintf(("SUP_IOCTL_CONT_FREE: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 926 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 927 return SUPDRV_ERR_INVALID_MAGIC; 928 } 929 930 /* 931 * Execute. 932 */ 933 return SUPR0ContFree(pSession, (RTHCUINTPTR)pIn->pvR3); 934 } 935 936 937 case SUP_IOCTL_LDR_OPEN: 938 { 939 PSUPLDROPEN_IN pIn = (PSUPLDROPEN_IN)pvIn; 940 PSUPLDROPEN_OUT pOut = (PSUPLDROPEN_OUT)pvOut; 941 942 /* 943 * Validate. 944 */ 945 if ( cbIn != sizeof(*pIn) 946 || cbOut != sizeof(*pOut)) 947 { 948 dprintf(("SUP_IOCTL_LDR_OPEN: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 949 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut))); 950 return SUPDRV_ERR_INVALID_PARAM; 951 } 952 if ( pIn->u32Cookie != pDevExt->u32Cookie 953 || pIn->u32SessionCookie != pSession->u32Cookie) 954 { 955 dprintf(("SUP_IOCTL_LDR_OPEN: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 956 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 957 return SUPDRV_ERR_INVALID_MAGIC; 958 } 959 if ( pIn->cbImage <= 0 960 || pIn->cbImage >= 16*1024*1024 /*16MB*/) 961 { 962 dprintf(("SUP_IOCTL_LDR_OPEN: Invalid size %d. (max is 16MB)\n", pIn->cbImage)); 963 return SUPDRV_ERR_INVALID_PARAM; 964 } 965 if (!memchr(pIn->szName, '\0', sizeof(pIn->szName))) 966 { 967 dprintf(("SUP_IOCTL_LDR_OPEN: The image name isn't terminated!\n")); 968 return SUPDRV_ERR_INVALID_PARAM; 969 } 970 if (!pIn->szName[0]) 971 { 972 dprintf(("SUP_IOCTL_LDR_OPEN: The image name is too short\n")); 973 return SUPDRV_ERR_INVALID_PARAM; 974 } 975 if (strpbrk(pIn->szName, ";:()[]{}/\\|&*%#@!~`\"'")) 976 { 977 dprintf(("SUP_IOCTL_LDR_OPEN: The name is invalid '%s'\n", pIn->szName)); 978 return SUPDRV_ERR_INVALID_PARAM; 979 } 980 981 *pcbReturned = sizeof(*pOut); 982 return supdrvIOCtl_LdrOpen(pDevExt, pSession, pIn, pOut); 983 } 984 985 986 case SUP_IOCTL_LDR_LOAD: 987 { 988 PSUPLDRLOAD_IN pIn = (PSUPLDRLOAD_IN)pvIn; 989 990 /* 991 * Validate. 992 */ 993 if ( cbIn <= sizeof(*pIn) 994 || cbOut != 0) 995 { 996 dprintf(("SUP_IOCTL_LDR_LOAD: Invalid input/output sizes. cbIn=%ld expected greater than %ld. cbOut=%ld expected %ld.\n", 997 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0)); 998 return SUPDRV_ERR_INVALID_PARAM; 999 } 1000 if ( pIn->u32Cookie != pDevExt->u32Cookie 1001 || pIn->u32SessionCookie != pSession->u32Cookie) 1002 { 1003 dprintf(("SUP_IOCTL_LDR_LOAD: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 1004 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 1005 return SUPDRV_ERR_INVALID_MAGIC; 1006 } 1007 if ((unsigned)RT_OFFSETOF(SUPLDRLOAD_IN, achImage[pIn->cbImage]) > cbIn) 1008 { 1009 dprintf(("SUP_IOCTL_LDR_LOAD: Invalid size %d. InputBufferLength=%d\n", 1010 pIn->cbImage, cbIn)); 1011 return SUPDRV_ERR_INVALID_PARAM; 1012 } 1013 if (pIn->cSymbols > 16384) 1014 { 1015 dprintf(("SUP_IOCTL_LDR_LOAD: Too many symbols. cSymbols=%u max=16384\n", pIn->cSymbols)); 1016 return SUPDRV_ERR_INVALID_PARAM; 1017 } 1018 if ( pIn->cSymbols 1019 && ( pIn->offSymbols >= pIn->cbImage 1020 || pIn->offSymbols + pIn->cSymbols * sizeof(SUPLDRSYM) > pIn->cbImage) 1021 ) 1022 { 1023 dprintf(("SUP_IOCTL_LDR_LOAD: symbol table is outside the image bits! offSymbols=%u cSymbols=%d cbImage=%d\n", 1024 pIn->offSymbols, pIn->cSymbols, pIn->cbImage)); 1025 return SUPDRV_ERR_INVALID_PARAM; 1026 } 1027 if ( pIn->cbStrTab 1028 && ( pIn->offStrTab >= pIn->cbImage 1029 || pIn->offStrTab + pIn->cbStrTab > pIn->cbImage 1030 || pIn->offStrTab + pIn->cbStrTab < pIn->offStrTab) 1031 ) 1032 { 1033 dprintf(("SUP_IOCTL_LDR_LOAD: string table is outside the image bits! offStrTab=%u cbStrTab=%d cbImage=%d\n", 1034 pIn->offStrTab, pIn->cbStrTab, pIn->cbImage)); 1035 return SUPDRV_ERR_INVALID_PARAM; 1036 } 1037 1038 if (pIn->cSymbols) 1039 { 1040 uint32_t i; 1041 PSUPLDRSYM paSyms = (PSUPLDRSYM)&pIn->achImage[pIn->offSymbols]; 1042 for (i = 0; i < pIn->cSymbols; i++) 916 uint32_t i; 917 PSUPLDRSYM paSyms = (PSUPLDRSYM)&pReq->u.In.achImage[pReq->u.In.offSymbols]; 918 for (i = 0; i < pReq->u.In.cSymbols; i++) 1043 919 { 1044 if (paSyms[i].offSymbol >= pIn->cbImage) 1045 { 1046 dprintf(("SUP_IOCTL_LDR_LOAD: symbol i=%d has an invalid symbol offset: %#x (max=%#x)\n", 1047 i, paSyms[i].offSymbol, pIn->cbImage)); 1048 return SUPDRV_ERR_INVALID_PARAM; 1049 } 1050 if (paSyms[i].offName >= pIn->cbStrTab) 1051 { 1052 dprintf(("SUP_IOCTL_LDR_LOAD: symbol i=%d has an invalid name offset: %#x (max=%#x)\n", 1053 i, paSyms[i].offName, pIn->cbStrTab)); 1054 return SUPDRV_ERR_INVALID_PARAM; 1055 } 1056 if (!memchr(&pIn->achImage[pIn->offStrTab + paSyms[i].offName], '\0', pIn->cbStrTab - paSyms[i].offName)) 1057 { 1058 dprintf(("SUP_IOCTL_LDR_LOAD: symbol i=%d has an unterminated name! offName=%#x (max=%#x)\n", 1059 i, paSyms[i].offName, pIn->cbStrTab)); 1060 return SUPDRV_ERR_INVALID_PARAM; 1061 } 920 REQ_CHECK_EXPR_FMT(paSyms[i].offSymbol < pReq->u.In.cbImage, 921 ("SUP_IOCTL_LDR_LOAD: sym #%ld: symb off %#lx (max=%#lx)\n", (long)i, (long)paSyms[i].offSymbol, (long)pReq->u.In.cbImage)); 922 REQ_CHECK_EXPR_FMT(paSyms[i].offName < pReq->u.In.cbStrTab, 923 ("SUP_IOCTL_LDR_LOAD: sym #%ld: name off %#lx (max=%#lx)\n", (long)i, (long)paSyms[i].offName, (long)pReq->u.In.cbImage)); 924 REQ_CHECK_EXPR_FMT(memchr(&pReq->u.In.achImage[pReq->u.In.offStrTab + paSyms[i].offName], '\0', pReq->u.In.cbStrTab - paSyms[i].offName), 925 ("SUP_IOCTL_LDR_LOAD: sym #%ld: unterminated name! (%#lx / %#lx)\n", (long)i, (long)paSyms[i].offName, (long)pReq->u.In.cbImage)); 1062 926 } 1063 927 } 1064 928 1065 return supdrvIOCtl_LdrLoad(pDevExt, pSession, pIn); 1066 } 1067 1068 1069 case SUP_IOCTL_LDR_FREE: 1070 { 1071 PSUPLDRFREE_IN pIn = (PSUPLDRFREE_IN)pvIn; 1072 1073 /* 1074 * Validate. 1075 */ 1076 if ( cbIn != sizeof(*pIn) 1077 || cbOut != 0) 929 /* execute */ 930 pReq->Hdr.rc = supdrvIOCtl_LdrLoad(pDevExt, pSession, pReq); 931 return 0; 932 } 933 934 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_LDR_FREE): 935 { 936 /* validate */ 937 PSUPLDRFREE pReq = (PSUPLDRFREE)pReqHdr; 938 REQ_CHECK_SIZES(SUP_IOCTL_LDR_FREE); 939 940 /* execute */ 941 pReq->Hdr.rc = supdrvIOCtl_LdrFree(pDevExt, pSession, pReq); 942 return 0; 943 } 944 945 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_LDR_GET_SYMBOL): 946 { 947 /* validate */ 948 PSUPLDRGETSYMBOL pReq = (PSUPLDRGETSYMBOL)pReqHdr; 949 REQ_CHECK_SIZES(SUP_IOCTL_LDR_GET_SYMBOL); 950 REQ_CHECK_EXPR(SUP_IOCTL_LDR_GET_SYMBOL, memchr(pReq->u.In.szSymbol, '\0', sizeof(pReq->u.In.szSymbol))); 951 952 /* execute */ 953 pReq->Hdr.rc = supdrvIOCtl_LdrGetSymbol(pDevExt, pSession, pReq); 954 return 0; 955 } 956 957 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_CALL_VMMR0(0)): 958 { 959 /* validate */ 960 PSUPCALLVMMR0 pReq = (PSUPCALLVMMR0)pReqHdr; 961 if (pReq->Hdr.cbIn == SUP_IOCTL_CALL_VMMR0(0)) 1078 962 { 1079 dprintf(("SUP_IOCTL_LDR_FREE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 1080 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0)); 1081 return SUPDRV_ERR_INVALID_PARAM; 963 REQ_CHECK_SIZES_EX(SUP_IOCTL_CALL_VMMR0, SUP_IOCTL_CALL_VMMR0_SIZE_IN(0), SUP_IOCTL_CALL_VMMR0_SIZE_OUT(0)); 964 965 /* execute */ 966 if (RT_LIKELY(pDevExt->pfnVMMR0Entry)) 967 pReq->Hdr.rc = pDevExt->pfnVMMR0Entry(pReq->u.In.pVMR0, pReq->u.In.uOperation, (void *)pReq->u.In.uArg); 968 else 969 pReq->Hdr.rc = VERR_WRONG_ORDER; 1082 970 } 1083 if ( pIn->u32Cookie != pDevExt->u32Cookie 1084 || pIn->u32SessionCookie != pSession->u32Cookie) 971 else 1085 972 { 1086 dprintf(("SUP_IOCTL_LDR_FREE: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 1087 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 1088 return SUPDRV_ERR_INVALID_MAGIC; 973 PSUPVMMR0REQHDR pVMMReq = (PSUPVMMR0REQHDR)&pReq->abReqPkt[0]; 974 REQ_CHECK_EXPR(SUP_IOCTL_CALL_VMMR0, pReq->Hdr.cbIn >= SUP_IOCTL_CALL_VMMR0_SIZE(sizeof(SUPVMMR0REQHDR))); 975 REQ_CHECK_EXPR(SUP_IOCTL_CALL_VMMR0, pVMMReq->u32Magic == SUPVMMR0REQHDR_MAGIC); 976 REQ_CHECK_SIZES_EX(SUP_IOCTL_CALL_VMMR0, SUP_IOCTL_CALL_VMMR0_SIZE_IN(pVMMReq->cbReq), SUP_IOCTL_CALL_VMMR0_SIZE_OUT(pVMMReq->cbReq)); 977 978 /* execute */ 979 if (RT_LIKELY(pDevExt->pfnVMMR0Entry)) 980 pReq->Hdr.rc = pDevExt->pfnVMMR0Entry(pReq->u.In.pVMR0, pReq->u.In.uOperation, pVMMReq); 981 else 982 pReq->Hdr.rc = VERR_WRONG_ORDER; 1089 983 } 1090 1091 return supdrvIOCtl_LdrFree(pDevExt, pSession, pIn);1092 }1093 1094 1095 case SUP_IOCTL_LDR_GET_SYMBOL:1096 {1097 PSUPLDRGETSYMBOL_IN pIn = (PSUPLDRGETSYMBOL_IN)pvIn;1098 PSUPLDRGETSYMBOL_OUT pOut = (PSUPLDRGETSYMBOL_OUT)pvOut;1099 char *pszEnd;1100 1101 /*1102 * Validate.1103 */1104 if ( cbIn < (unsigned)RT_OFFSETOF(SUPLDRGETSYMBOL_IN, szSymbol[2])1105 || cbOut != sizeof(*pOut))1106 {1107 dprintf(("SUP_IOCTL_LDR_GET_SYMBOL: Invalid input/output sizes. cbIn=%d expected >=%d. cbOut=%d expected at%d.\n",1108 cbIn, RT_OFFSETOF(SUPLDRGETSYMBOL_IN, szSymbol[2]), cbOut, 0));1109 return SUPDRV_ERR_INVALID_PARAM;1110 }1111 if ( pIn->u32Cookie != pDevExt->u32Cookie1112 || pIn->u32SessionCookie != pSession->u32Cookie)1113 {1114 dprintf(("SUP_IOCTL_LDR_GET_SYMBOL: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n",1115 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie));1116 return SUPDRV_ERR_INVALID_MAGIC;1117 }1118 pszEnd = memchr(pIn->szSymbol, '\0', cbIn - RT_OFFSETOF(SUPLDRGETSYMBOL_IN, szSymbol));1119 if (!pszEnd)1120 {1121 dprintf(("SUP_IOCTL_LDR_GET_SYMBOL: The symbol name isn't terminated!\n"));1122 return SUPDRV_ERR_INVALID_PARAM;1123 }1124 if (pszEnd - &pIn->szSymbol[0] >= 1024)1125 {1126 dprintf(("SUP_IOCTL_LDR_GET_SYMBOL: The symbol name too long (%ld chars, max is %d)!\n",1127 (long)(pszEnd - &pIn->szSymbol[0]), 1024));1128 return SUPDRV_ERR_INVALID_PARAM;1129 }1130 1131 pOut->pvSymbol = NULL;1132 *pcbReturned = sizeof(*pOut);1133 return supdrvIOCtl_LdrGetSymbol(pDevExt, pSession, pIn, pOut);1134 }1135 1136 1137 /** @todo this interface needs re-doing, we're accessing Ring-3 buffers directly here! */1138 case SUP_IOCTL_CALL_VMMR0:1139 {1140 PSUPCALLVMMR0_IN pIn = (PSUPCALLVMMR0_IN)pvIn;1141 PSUPCALLVMMR0_OUT pOut = (PSUPCALLVMMR0_OUT)pvOut;1142 RTCCUINTREG uFlags;1143 1144 /*1145 * Validate.1146 */1147 if ( cbIn != sizeof(*pIn)1148 || cbOut != sizeof(*pOut))1149 {1150 dprintf(("SUP_IOCTL_CALL_VMMR0: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n",1151 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut)));1152 return SUPDRV_ERR_INVALID_PARAM;1153 }1154 if ( pIn->u32Cookie != pDevExt->u32Cookie1155 || pIn->u32SessionCookie != pSession->u32Cookie )1156 {1157 dprintf(("SUP_IOCTL_CALL_VMMR0: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n",1158 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie));1159 return SUPDRV_ERR_INVALID_MAGIC;1160 }1161 1162 /*1163 * Do we have an entrypoint?1164 */1165 if (!pDevExt->pfnVMMR0Entry)1166 return SUPDRV_ERR_GENERAL_FAILURE;1167 1168 /*1169 * Execute.1170 */1171 uFlags = ASMGetFlags();1172 ASMIntDisable();1173 pOut->rc = pDevExt->pfnVMMR0Entry(pIn->pVMR0, pIn->uOperation, (void *)pIn->pvArg); /** @todo address the pvArg problem! */1174 ASMSetFlags(uFlags);1175 *pcbReturned = sizeof(*pOut);1176 984 return 0; 1177 985 } 1178 986 1179 1180 case SUP_IOCTL_GET_PAGING_MODE: 1181 { 1182 int rc; 1183 PSUPGETPAGINGMODE_IN pIn = (PSUPGETPAGINGMODE_IN)pvIn; 1184 PSUPGETPAGINGMODE_OUT pOut = (PSUPGETPAGINGMODE_OUT)pvOut; 1185 1186 /* 1187 * Validate. 1188 */ 1189 if ( cbIn != sizeof(*pIn) 1190 || cbOut != sizeof(*pOut)) 1191 { 1192 dprintf(("SUP_IOCTL_GET_PAGING_MODE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 1193 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut))); 1194 return SUPDRV_ERR_INVALID_PARAM; 1195 } 1196 if ( pIn->u32Cookie != pDevExt->u32Cookie 1197 || pIn->u32SessionCookie != pSession->u32Cookie ) 1198 { 1199 dprintf(("SUP_IOCTL_GET_PAGING_MODE: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 1200 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 1201 return SUPDRV_ERR_INVALID_MAGIC; 1202 } 1203 1204 /* 1205 * Execute. 1206 */ 1207 *pcbReturned = sizeof(*pOut); 1208 rc = supdrvIOCtl_GetPagingMode(pOut); 1209 if (rc) 1210 *pcbReturned = 0; 1211 return rc; 1212 } 1213 1214 1215 case SUP_IOCTL_LOW_ALLOC: 1216 { 1217 int rc; 1218 PSUPLOWALLOC_IN pIn = (PSUPLOWALLOC_IN)pvIn; 1219 PSUPLOWALLOC_OUT pOut = (PSUPLOWALLOC_OUT)pvOut; 1220 1221 /* 1222 * Validate. 1223 */ 1224 if ( cbIn != sizeof(*pIn) 1225 || cbOut < sizeof(*pOut)) 1226 { 1227 dprintf(("SUP_IOCTL_LOW_ALLOC: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 1228 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut))); 1229 return SUPDRV_ERR_INVALID_PARAM; 1230 } 1231 if ( pIn->u32Cookie != pDevExt->u32Cookie 1232 || pIn->u32SessionCookie != pSession->u32Cookie ) 1233 { 1234 dprintf(("SUP_IOCTL_LOW_ALLOC: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 1235 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 1236 return SUPDRV_ERR_INVALID_MAGIC; 1237 } 1238 if ((unsigned)RT_OFFSETOF(SUPLOWALLOC_OUT, aPages[pIn->cPages]) > cbOut) 1239 { 1240 dprintf(("SUP_IOCTL_LOW_ALLOC: Output buffer is too small! %d required %d passed in.\n", 1241 RT_OFFSETOF(SUPLOWALLOC_OUT, aPages[pIn->cPages]), cbOut)); 1242 return SUPDRV_ERR_INVALID_PARAM; 1243 } 1244 1245 /* 1246 * Execute. 1247 */ 1248 *pcbReturned = RT_OFFSETOF(SUPLOWALLOC_OUT, aPages[pIn->cPages]); 1249 rc = SUPR0LowAlloc(pSession, pIn->cPages, &pOut->pvR0, &pOut->pvR3, &pOut->aPages[0]); 1250 if (rc) 1251 *pcbReturned = 0; 1252 return rc; 1253 } 1254 1255 1256 case SUP_IOCTL_LOW_FREE: 1257 { 1258 PSUPLOWFREE_IN pIn = (PSUPLOWFREE_IN)pvIn; 1259 1260 /* 1261 * Validate. 1262 */ 1263 if ( cbIn != sizeof(*pIn) 1264 || cbOut != 0) 1265 { 1266 dprintf(("SUP_IOCTL_LOW_FREE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 1267 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0)); 1268 return SUPDRV_ERR_INVALID_PARAM; 1269 } 1270 if ( pIn->u32Cookie != pDevExt->u32Cookie 1271 || pIn->u32SessionCookie != pSession->u32Cookie) 1272 { 1273 dprintf(("SUP_IOCTL_LOW_FREE: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 1274 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 1275 return SUPDRV_ERR_INVALID_MAGIC; 1276 } 1277 1278 /* 1279 * Execute. 1280 */ 1281 return SUPR0LowFree(pSession, (RTHCUINTPTR)pIn->pvR3); 1282 } 1283 1284 1285 case SUP_IOCTL_GIP_MAP: 1286 { 1287 int rc; 1288 PSUPGIPMAP_IN pIn = (PSUPGIPMAP_IN)pvIn; 1289 PSUPGIPMAP_OUT pOut = (PSUPGIPMAP_OUT)pvOut; 1290 1291 /* 1292 * Validate. 1293 */ 1294 if ( cbIn != sizeof(*pIn) 1295 || cbOut != sizeof(*pOut)) 1296 { 1297 dprintf(("SUP_IOCTL_GIP_MAP: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 1298 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0)); 1299 return SUPDRV_ERR_INVALID_PARAM; 1300 } 1301 if ( pIn->u32Cookie != pDevExt->u32Cookie 1302 || pIn->u32SessionCookie != pSession->u32Cookie) 1303 { 1304 dprintf(("SUP_IOCTL_GIP_MAP: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 1305 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 1306 return SUPDRV_ERR_INVALID_MAGIC; 1307 } 1308 1309 /* 1310 * Execute. 1311 */ 1312 rc = SUPR0GipMap(pSession, &pOut->pGipR3, &pOut->HCPhysGip); 1313 if (!rc) 1314 { 1315 pOut->pGipR0 = pDevExt->pGip; 1316 *pcbReturned = sizeof(*pOut); 1317 } 1318 return rc; 1319 } 1320 1321 1322 case SUP_IOCTL_GIP_UNMAP: 1323 { 1324 PSUPGIPUNMAP_IN pIn = (PSUPGIPUNMAP_IN)pvIn; 1325 1326 /* 1327 * Validate. 1328 */ 1329 if ( cbIn != sizeof(*pIn) 1330 || cbOut != 0) 1331 { 1332 dprintf(("SUP_IOCTL_GIP_UNMAP: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 1333 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0)); 1334 return SUPDRV_ERR_INVALID_PARAM; 1335 } 1336 if ( pIn->u32Cookie != pDevExt->u32Cookie 1337 || pIn->u32SessionCookie != pSession->u32Cookie) 1338 { 1339 dprintf(("SUP_IOCTL_GIP_UNMAP: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 1340 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 1341 return SUPDRV_ERR_INVALID_MAGIC; 1342 } 1343 1344 /* 1345 * Execute. 1346 */ 1347 return SUPR0GipUnmap(pSession); 1348 } 1349 1350 1351 case SUP_IOCTL_SET_VM_FOR_FAST: 1352 { 1353 PSUPSETVMFORFAST_IN pIn = (PSUPSETVMFORFAST_IN)pvIn; 1354 1355 /* 1356 * Validate. 1357 */ 1358 if ( cbIn != sizeof(*pIn) 1359 || cbOut != 0) 1360 { 1361 dprintf(("SUP_IOCTL_SET_VM_FOR_FAST: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 1362 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0)); 1363 return SUPDRV_ERR_INVALID_PARAM; 1364 } 1365 if ( pIn->u32Cookie != pDevExt->u32Cookie 1366 || pIn->u32SessionCookie != pSession->u32Cookie) 1367 { 1368 dprintf(("SUP_IOCTL_SET_VM_FOR_FAST: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 1369 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 1370 return SUPDRV_ERR_INVALID_MAGIC; 1371 } 1372 if ( pIn->pVMR0 != NULL 1373 && ( !VALID_PTR(pIn->pVMR0) 1374 || ((uintptr_t)pIn->pVMR0 & (PAGE_SIZE - 1)) 1375 ) 1376 ) 1377 { 1378 dprintf(("SUP_IOCTL_SET_VM_FOR_FAST: pVMR0=%p! Must be a valid, page aligned, pointer.\n", pIn->pVMR0)); 1379 return SUPDRV_ERR_INVALID_POINTER; 1380 } 1381 1382 /* 1383 * Execute. 1384 */ 987 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_GET_PAGING_MODE): 988 { 989 /* validate */ 990 PSUPGETPAGINGMODE pReq = (PSUPGETPAGINGMODE)pReqHdr; 991 REQ_CHECK_SIZES(SUP_IOCTL_GET_PAGING_MODE); 992 993 /* execute */ 994 pReq->Hdr.rc = VINF_SUCCESS; 995 pReq->u.Out.enmMode = supdrvIOCtl_GetPagingMode(); 996 return 0; 997 } 998 999 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_LOW_ALLOC): 1000 { 1001 /* validate */ 1002 PSUPLOWALLOC pReq = (PSUPLOWALLOC)pReqHdr; 1003 REQ_CHECK_EXPR(SUP_IOCTL_LOW_ALLOC, pReq->Hdr.cbIn <= SUP_IOCTL_LOW_ALLOC_SIZE_IN); 1004 REQ_CHECK_SIZES_EX(SUP_IOCTL_LOW_ALLOC, SUP_IOCTL_LOW_ALLOC_SIZE_IN, SUP_IOCTL_LOW_ALLOC_SIZE_OUT(pReq->u.In.cPages)); 1005 1006 /* execute */ 1007 pReq->Hdr.rc = SUPR0LowAlloc(pSession, pReq->u.In.cPages, &pReq->u.Out.pvR0, &pReq->u.Out.pvR3, &pReq->u.Out.aPages[0]); 1008 if (RT_FAILURE(pReq->Hdr.rc)) 1009 pReq->Hdr.cbOut = sizeof(pReq->Hdr); 1010 return 0; 1011 } 1012 1013 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_LOW_FREE): 1014 { 1015 /* validate */ 1016 PSUPLOWFREE pReq = (PSUPLOWFREE)pReqHdr; 1017 REQ_CHECK_SIZES(SUP_IOCTL_LOW_FREE); 1018 1019 /* execute */ 1020 pReq->Hdr.rc = SUPR0LowFree(pSession, (RTHCUINTPTR)pReq->u.In.pvR3); 1021 return 0; 1022 } 1023 1024 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_GIP_MAP): 1025 { 1026 /* validate */ 1027 PSUPGIPMAP pReq = (PSUPGIPMAP)pReqHdr; 1028 REQ_CHECK_SIZES(SUP_IOCTL_GIP_MAP); 1029 1030 /* execute */ 1031 pReq->Hdr.rc = SUPR0GipMap(pSession, &pReq->u.Out.pGipR3, &pReq->u.Out.HCPhysGip); 1032 if (RT_SUCCESS(pReq->Hdr.rc)) 1033 pReq->u.Out.pGipR0 = pDevExt->pGip; 1034 return 0; 1035 } 1036 1037 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_GIP_UNMAP): 1038 { 1039 /* validate */ 1040 PSUPGIPUNMAP pReq = (PSUPGIPUNMAP)pReqHdr; 1041 REQ_CHECK_SIZES(SUP_IOCTL_GIP_UNMAP); 1042 1043 /* execute */ 1044 pReq->Hdr.rc = SUPR0GipUnmap(pSession); 1045 return 0; 1046 } 1047 1048 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_SET_VM_FOR_FAST): 1049 { 1050 /* validate */ 1051 PSUPSETVMFORFAST pReq = (PSUPSETVMFORFAST)pReqHdr; 1052 REQ_CHECK_SIZES(SUP_IOCTL_SET_VM_FOR_FAST); 1053 REQ_CHECK_EXPR_FMT( !pReq->u.In.pVMR0 1054 || ( VALID_PTR(pReq->u.In.pVMR0) 1055 && !((uintptr_t)pReq->u.In.pVMR0 & (PAGE_SIZE - 1))), 1056 ("SUP_IOCTL_SET_VM_FOR_FAST: pVMR0=%p!\n", pReq->u.In.pVMR0)); 1057 /* execute */ 1385 1058 #ifndef VBOX_WITHOUT_IDT_PATCHING 1386 1059 OSDBGPRINT(("SUP_IOCTL_SET_VM_FOR_FAST: !VBOX_WITHOUT_IDT_PATCHING\n")); 1387 return SUPDRV_ERR_GENERAL_FAILURE;1060 pReq->Hdr.rc = VERR_NOT_SUPPORTED; 1388 1061 #else 1389 pSession->pVM = pIn->pVMR0; 1062 pSession->pVM = pReq->u.In.pVMR0; 1063 pReq->Hdr.rc = VINF_SUCCESS; 1064 #endif 1390 1065 return 0; 1391 #endif1392 1066 } 1393 1067 1394 1068 #ifdef USE_NEW_OS_INTERFACE_FOR_MM 1395 case SUP_IOCTL_PAGE_ALLOC: 1396 { 1397 int rc; 1398 PSUPALLOCPAGE_IN pIn = (PSUPALLOCPAGE_IN)pvIn; 1399 PSUPALLOCPAGE_OUT pOut = (PSUPALLOCPAGE_OUT)pvOut; 1400 1401 /* 1402 * Validate. 1403 */ 1404 if ( cbIn != sizeof(*pIn) 1405 || cbOut < sizeof(*pOut)) 1406 { 1407 dprintf(("SUP_IOCTL_PAGE_ALLOC: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 1408 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)sizeof(*pOut))); 1409 return SUPDRV_ERR_INVALID_PARAM; 1410 } 1411 if ( pIn->u32Cookie != pDevExt->u32Cookie 1412 || pIn->u32SessionCookie != pSession->u32Cookie 1413 || pOut->u32Cookie != pDevExt->u32Cookie) 1414 { 1415 dprintf(("SUP_IOCTL_PAGE_ALLOC: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 1416 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 1417 return SUPDRV_ERR_INVALID_MAGIC; 1418 } 1419 /* 1420 * Execute. 1421 */ 1422 *pcbReturned = sizeof(*pOut); 1423 rc = SUPR0PageAlloc(pSession, pIn->cPages, &pOut->pvR3); 1424 if (rc) 1425 *pcbReturned = 0; 1426 return rc; 1427 } 1428 1429 case SUP_IOCTL_PAGE_FREE: 1430 { 1431 PSUPFREEPAGE_IN pIn = (PSUPFREEPAGE_IN)pvIn; 1432 1433 /* 1434 * Validate. 1435 */ 1436 if ( cbIn != sizeof(*pIn) 1437 || cbOut != 0) 1438 { 1439 dprintf(("SUP_IOCTL_PAGE_FREE: Invalid input/output sizes. cbIn=%ld expected %ld. cbOut=%ld expected %ld.\n", 1440 (long)cbIn, (long)sizeof(*pIn), (long)cbOut, (long)0)); 1441 return SUPDRV_ERR_INVALID_PARAM; 1442 } 1443 if ( pIn->u32Cookie != pDevExt->u32Cookie 1444 || pIn->u32SessionCookie != pSession->u32Cookie) 1445 { 1446 dprintf(("SUP_IOCTL_PAGE_FREE: Cookie mismatch {%#x,%#x} != {%#x,%#x}!\n", 1447 pIn->u32Cookie, pDevExt->u32Cookie, pIn->u32SessionCookie, pSession->u32Cookie)); 1448 return SUPDRV_ERR_INVALID_MAGIC; 1449 } 1450 /* 1451 * Execute. 1452 */ 1453 return SUPR0PageFree(pSession, (RTHCUINTPTR)pIn->pvR3); 1069 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_PAGE_ALLOC): 1070 { 1071 /* validate */ 1072 PSUPPAGEALLOC pReq = (PSUPPAGEALLOC)pReqHdr; 1073 REQ_CHECK_EXPR(SUP_IOCTL_PAGE_ALLOC, pReq->Hdr.cbIn <= SUP_IOCTL_PAGE_ALLOC_SIZE_IN); 1074 REQ_CHECK_SIZES_EX(SUP_IOCTL_PAGE_ALLOC, SUP_IOCTL_PAGE_ALLOC_SIZE_IN, SUP_IOCTL_PAGE_ALLOC_SIZE_OUT(pReq->u.In.cPages)); 1075 1076 /* execute */ 1077 pReq->Hdr.rc = SUPR0PageAlloc(pSession, pReq->u.In.cPages, &pReq->u.Out.pvR3, &pReq->u.Out.aPages[0]); 1078 if (RT_FAILURE(pReq->Hdr.rc)) 1079 pReq->Hdr.cbOut = sizeof(pReq->Hdr); 1080 return 0; 1081 } 1082 1083 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_PAGE_FREE): 1084 { 1085 /* validate */ 1086 PSUPPAGEFREE pReq = (PSUPPAGEFREE)pReqHdr; 1087 REQ_CHECK_SIZES(SUP_IOCTL_PAGE_FREE); 1088 1089 /* execute */ 1090 pReq->Hdr.rc = SUPR0PageFree(pSession, pReq->u.In.pvR3); 1091 return 0; 1454 1092 } 1455 1093 #endif /* USE_NEW_OS_INTERFACE_FOR_MM */ 1456 1094 1457 1095 default: 1458 dprintf(("Unknown IOCTL %# x\n",uIOCtl));1096 dprintf(("Unknown IOCTL %#lx\n", (long)uIOCtl)); 1459 1097 break; 1460 1098 } … … 1484 1122 * Validate the input. 1485 1123 */ 1486 if (!pSession) 1487 { 1488 AssertMsgFailed(("Invalid pSession=%p\n", pSession)); 1489 return NULL; 1490 } 1491 if ( enmType <= SUPDRVOBJTYPE_INVALID 1492 || enmType >= SUPDRVOBJTYPE_END) 1493 { 1494 AssertMsgFailed(("Invalid enmType=%d\n", enmType)); 1495 return NULL; 1496 } 1497 if (!pfnDestructor) 1498 { 1499 AssertMsgFailed(("Invalid pfnDestructor=%d\n", pfnDestructor)); 1500 return NULL; 1501 } 1124 AssertReturn(SUP_IS_SESSION_VALID(pSession), NULL); 1125 AssertReturn(enmType > SUPDRVOBJTYPE_INVALID && enmType < SUPDRVOBJTYPE_END, NULL); 1126 AssertPtrReturn(pfnDestructor, NULL); 1502 1127 1503 1128 /* … … 1565 1190 * with the specified session. 1566 1191 * 1567 * @returns 0 on success. 1568 * @returns SUPDRV_ERR_* on failure. 1192 * @returns IPRT status code. 1569 1193 * @param pvObj The identifier returned by SUPR0ObjRegister(). 1570 1194 * @param pSession The session which is referencing the object. … … 1581 1205 * Validate the input. 1582 1206 */ 1583 if (!pSession) 1584 { 1585 AssertMsgFailed(("Invalid pSession=%p\n", pSession)); 1586 return SUPDRV_ERR_INVALID_PARAM; 1587 } 1588 if (!pObj || pObj->u32Magic != SUPDRVOBJ_MAGIC) 1589 { 1590 AssertMsgFailed(("Invalid pvObj=%p magic=%#x (exepcted %#x)\n", 1591 pvObj, pObj ? pObj->u32Magic : 0, SUPDRVOBJ_MAGIC)); 1592 return SUPDRV_ERR_INVALID_PARAM; 1593 } 1207 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 1208 AssertMsgReturn(VALID_PTR(pObj) && pObj->u32Magic == SUPDRVOBJ_MAGIC, 1209 ("Invalid pvObj=%p magic=%#x (exepcted %#x)\n", pvObj, pObj ? pObj->u32Magic : 0, SUPDRVOBJ_MAGIC), 1210 VERR_INVALID_PARAMETER); 1594 1211 1595 1212 /* … … 1606 1223 pUsagePre = (PSUPDRVUSAGE)RTMemAlloc(sizeof(*pUsagePre)); 1607 1224 if (!pUsagePre) 1608 return SUPDRV_ERR_NO_MEMORY;1225 return VERR_NO_MEMORY; 1609 1226 RTSpinlockAcquire(pDevExt->Spinlock, &SpinlockTmp); 1610 1227 } … … 1649 1266 RTSpinlockRelease(pDevExt->Spinlock, &SpinlockTmp); 1650 1267 1651 return 0;1268 return VINF_SUCCESS; 1652 1269 } 1653 1270 … … 1658 1275 * The object is uniquely identified by pfnDestructor+pvUser1+pvUser2. 1659 1276 * 1660 * @returns 0 on success. 1661 * @returns SUPDRV_ERR_* on failure. 1277 * @returns IPRT status code. 1662 1278 * @param pvObj The identifier returned by SUPR0ObjRegister(). 1663 1279 * @param pSession The session which is referencing the object. … … 1675 1291 * Validate the input. 1676 1292 */ 1677 if (!pSession) 1678 { 1679 AssertMsgFailed(("Invalid pSession=%p\n", pSession)); 1680 return SUPDRV_ERR_INVALID_PARAM; 1681 } 1682 if (!pObj || pObj->u32Magic != SUPDRVOBJ_MAGIC) 1683 { 1684 AssertMsgFailed(("Invalid pvObj=%p magic=%#x (exepcted %#x)\n", 1685 pvObj, pObj ? pObj->u32Magic : 0, SUPDRVOBJ_MAGIC)); 1686 return SUPDRV_ERR_INVALID_PARAM; 1687 } 1293 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 1294 AssertMsgReturn(VALID_PTR(pObj) && pObj->u32Magic == SUPDRVOBJ_MAGIC, 1295 ("Invalid pvObj=%p magic=%#x (exepcted %#x)\n", pvObj, pObj ? pObj->u32Magic : 0, SUPDRVOBJ_MAGIC), 1296 VERR_INVALID_PARAMETER); 1688 1297 1689 1298 /* … … 1758 1367 1759 1368 AssertMsg(pUsage, ("pvObj=%p\n", pvObj)); 1760 return pUsage ? 0 : SUPDRV_ERR_INVALID_PARAM;1369 return pUsage ? VINF_SUCCESS : VERR_INVALID_PARAMETER; 1761 1370 } 1762 1371 … … 1764 1373 * Verifies that the current process can access the specified object. 1765 1374 * 1766 * @returns 0 if access is granted. 1767 * @returns SUPDRV_ERR_PERMISSION_DENIED if denied access. 1768 * @returns SUPDRV_ERR_INVALID_PARAM if invalid parameter. 1375 * @returns The following IPRT status code: 1376 * @retval VINF_SUCCESS if access was granted. 1377 * @retval VERR_PERMISSION_DENIED if denied access. 1378 * @retval VERR_INVALID_PARAMETER if invalid parameter. 1769 1379 * 1770 1380 * @param pvObj The identifier returned by SUPR0ObjRegister(). … … 1778 1388 { 1779 1389 PSUPDRVOBJ pObj = (PSUPDRVOBJ)pvObj; 1780 int rc = SUPDRV_ERR_GENERAL_FAILURE;1390 int rc; 1781 1391 1782 1392 /* 1783 1393 * Validate the input. 1784 1394 */ 1785 if (!pSession) 1786 { 1787 AssertMsgFailed(("Invalid pSession=%p\n", pSession)); 1788 return SUPDRV_ERR_INVALID_PARAM; 1789 } 1790 if (!pObj || pObj->u32Magic != SUPDRVOBJ_MAGIC) 1791 { 1792 AssertMsgFailed(("Invalid pvObj=%p magic=%#x (exepcted %#x)\n", 1793 pvObj, pObj ? pObj->u32Magic : 0, SUPDRVOBJ_MAGIC)); 1794 return SUPDRV_ERR_INVALID_PARAM; 1795 } 1395 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 1396 AssertMsgReturn(VALID_PTR(pObj) && pObj->u32Magic == SUPDRVOBJ_MAGIC, 1397 ("Invalid pvObj=%p magic=%#x (exepcted %#x)\n", pvObj, pObj ? pObj->u32Magic : 0, SUPDRVOBJ_MAGIC), 1398 VERR_INVALID_PARAMETER); 1796 1399 1797 1400 /* 1798 1401 * Check access. (returns true if a decision has been made.) 1799 1402 */ 1403 rc = VERR_INTERNAL_ERROR; 1800 1404 if (supdrvOSObjCanAccess(pObj, pSession, pszObjName, &rc)) 1801 1405 return rc; … … 1806 1410 */ 1807 1411 if (pObj->CreatorUid == pSession->Uid) 1808 return 0;1809 return SUPDRV_ERR_PERMISSION_DENIED;1412 return VINF_SUCCESS; 1413 return VERR_PERMISSION_DENIED; 1810 1414 } 1811 1415 … … 1814 1418 * Lock pages. 1815 1419 * 1420 * @returns IPRT status code. 1816 1421 * @param pSession Session to which the locked memory should be associated. 1817 1422 * @param pvR3 Start of the memory range to lock. … … 1820 1425 * This must be page aligned. 1821 1426 */ 1822 SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, P SUPPAGEpaPages)1427 SUPR0DECL(int) SUPR0LockMem(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages) 1823 1428 { 1824 1429 int rc; 1825 1430 SUPDRVMEMREF Mem = {0}; 1826 1431 const size_t cb = (size_t)cPages << PAGE_SHIFT; 1827 dprintf(("SUPR0LockMem: pSession=%p pvR3=%p cPages=%d paPages=%p\n", 1828 pSession, (void *)pvR3, cPages, paPages)); 1432 dprintf(("SUPR0LockMem: pSession=%p pvR3=%p cPages=%d paPages=%p\n", pSession, (void *)pvR3, cPages, paPages)); 1829 1433 1830 1434 /* 1831 1435 * Verify input. 1832 1436 */ 1833 if (RT_ALIGN_R3PT(pvR3, PAGE_SIZE, RTR3PTR) != pvR3 || !pvR3) 1437 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 1438 AssertPtrReturn(paPages, VERR_INVALID_PARAMETER); 1439 if ( RT_ALIGN_R3PT(pvR3, PAGE_SIZE, RTR3PTR) != pvR3 1440 || !pvR3) 1834 1441 { 1835 1442 dprintf(("pvR3 (%p) must be page aligned and not NULL!\n", (void *)pvR3)); 1836 return SUPDRV_ERR_INVALID_PARAM; 1837 } 1838 if (!paPages) 1839 { 1840 dprintf(("paPages is NULL!\n")); 1841 return SUPDRV_ERR_INVALID_PARAM; 1443 return VERR_INVALID_PARAMETER; 1842 1444 } 1843 1445 1844 1446 #ifdef USE_NEW_OS_INTERFACE_FOR_MM 1447 # ifdef RT_OS_WINDOWS /* A temporary hack for windows, will be removed once all ring-3 code has been cleaned up. */ 1845 1448 /* First check if we allocated it using SUPPageAlloc; if so then we don't need to lock it again */ 1846 rc = SUPR0PageGetPhys(pSession, pvR3, cPages, paPages);1449 rc = supdrvPageGetPhys(pSession, pvR3, cPages, paPages); 1847 1450 if (RT_SUCCESS(rc)) 1848 1451 return rc; 1452 # endif 1849 1453 1850 1454 /* … … 1855 1459 if (RT_SUCCESS(rc)) 1856 1460 { 1857 u nsignediPage = cPages;1461 uint32_t iPage = cPages; 1858 1462 AssertMsg(RTR0MemObjAddressR3(Mem.MemObj) == pvR3, ("%p == %p\n", RTR0MemObjAddressR3(Mem.MemObj), pvR3)); 1859 1463 AssertMsg(RTR0MemObjSize(Mem.MemObj) == cb, ("%x == %x\n", RTR0MemObjSize(Mem.MemObj), cb)); … … 1861 1465 while (iPage-- > 0) 1862 1466 { 1863 paPages[iPage].uReserved = 0; 1864 paPages[iPage].Phys = RTR0MemObjGetPagePhysAddr(Mem.MemObj, iPage); 1865 if (RT_UNLIKELY(paPages[iPage].Phys == NIL_RTCCPHYS)) 1467 paPages[iPage] = RTR0MemObjGetPagePhysAddr(Mem.MemObj, iPage); 1468 if (RT_UNLIKELY(paPages[iPage] == NIL_RTCCPHYS)) 1866 1469 { 1867 1470 AssertMsgFailed(("iPage=%d\n", iPage)); … … 1906 1509 * Unlocks the memory pointed to by pv. 1907 1510 * 1908 * @returns 0 on success. 1909 * @returns SUPDRV_ERR_* on failure 1511 * @returns IPRT status code. 1910 1512 * @param pSession Session to which the memory was locked. 1911 1513 * @param pvR3 Memory to unlock. … … 1914 1516 { 1915 1517 dprintf(("SUPR0UnlockMem: pSession=%p pvR3=%p\n", pSession, (void *)pvR3)); 1916 1917 /* SUPR0PageFree will unlock SUPR0PageAlloc allocations; ignore this call */ 1918 if (SUPR0PageWasLockedByPageAlloc(pSession, pvR3)) 1518 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 1519 #ifdef RT_OS_WINDOWS 1520 /* 1521 * Temporary hack for windows - SUPR0PageFree will unlock SUPR0PageAlloc 1522 * allocations; ignore this call. 1523 */ 1524 if (supdrvPageWasLockedByPageAlloc(pSession, pvR3)) 1919 1525 { 1920 1526 dprintf(("Page will be unlocked in SUPR0PageFree -> ignore\n")); 1921 return 0;1922 } 1923 1527 return VINF_SUCCESS; 1528 } 1529 #endif 1924 1530 return supdrvMemRelease(pSession, (RTHCUINTPTR)pvR3, MEMREF_TYPE_LOCKED); 1925 1531 } … … 1930 1536 * backing. 1931 1537 * 1932 * @returns 0 on success. 1933 * @returns SUPDRV_ERR_* on failure. 1538 * @returns IPRT status code. 1934 1539 * @param pSession Session data. 1935 1540 * @param cb Number of bytes to allocate. … … 1947 1552 * Validate input. 1948 1553 */ 1949 if (!pSession || !ppvR3 || !ppvR0 || !pHCPhys) 1554 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 1555 if (!ppvR3 || !ppvR0 || !pHCPhys) 1950 1556 { 1951 1557 dprintf(("Null pointer. All of these should be set: pSession=%p ppvR0=%p ppvR3=%p pHCPhys=%p\n", 1952 1558 pSession, ppvR0, ppvR3, pHCPhys)); 1953 return SUPDRV_ERR_INVALID_PARAM;1954 1955 } 1956 if (cPages == 0|| cPages >= 256)1559 return VERR_INVALID_PARAMETER; 1560 1561 } 1562 if (cPages < 1 || cPages >= 256) 1957 1563 { 1958 1564 dprintf(("Illegal request cPages=%d, must be greater than 0 and smaller than 256\n", cPages)); 1959 return SUPDRV_ERR_INVALID_PARAM;1565 return VERR_INVALID_PARAMETER; 1960 1566 } 1961 1567 … … 2019 1625 * Frees memory allocated using SUPR0ContAlloc(). 2020 1626 * 2021 * @returns 0 on success. 2022 * @returns SUPDRV_ERR_* on failure. 1627 * @returns IPRT status code. 2023 1628 * @param pSession The session to which the memory was allocated. 2024 1629 * @param uPtr Pointer to the memory (ring-3 or ring-0). … … 2027 1632 { 2028 1633 dprintf(("SUPR0ContFree: pSession=%p uPtr=%p\n", pSession, (void *)uPtr)); 1634 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 2029 1635 return supdrvMemRelease(pSession, uPtr, MEMREF_TYPE_CONT); 2030 1636 } … … 2034 1640 * Allocates a chunk of page aligned memory with fixed physical backing below 4GB. 2035 1641 * 2036 * @returns 0 on success. 2037 * @returns SUPDRV_ERR_* on failure. 1642 * @returns IPRT status code. 2038 1643 * @param pSession Session data. 2039 1644 * @param cPages Number of pages to allocate. … … 2042 1647 * @param paPages Where to put the physical addresses of allocated memory. 2043 1648 */ 2044 SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, P SUPPAGEpaPages)1649 SUPR0DECL(int) SUPR0LowAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR0PTR ppvR0, PRTR3PTR ppvR3, PRTHCPHYS paPages) 2045 1650 { 2046 1651 unsigned iPage; … … 2052 1657 * Validate input. 2053 1658 */ 2054 if (!pSession || !ppvR3 || !ppvR0 || !paPages) 1659 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 1660 if (!ppvR3 || !ppvR0 || !paPages) 2055 1661 { 2056 1662 dprintf(("Null pointer. All of these should be set: pSession=%p ppvR3=%p ppvR0=%p paPages=%p\n", 2057 1663 pSession, ppvR3, ppvR0, paPages)); 2058 return SUPDRV_ERR_INVALID_PARAM;1664 return VERR_INVALID_PARAMETER; 2059 1665 2060 1666 } … … 2062 1668 { 2063 1669 dprintf(("Illegal request cPages=%d, must be greater than 0 and smaller than 256.\n", cPages)); 2064 return SUPDRV_ERR_INVALID_PARAM;1670 return VERR_INVALID_PARAMETER; 2065 1671 } 2066 1672 … … 2083 1689 for (iPage = 0; iPage < cPages; iPage++) 2084 1690 { 2085 paPages[iPage].Phys = RTR0MemObjGetPagePhysAddr(Mem.MemObj, iPage); 2086 paPages[iPage].uReserved = 0; 2087 AssertMsg(!(paPages[iPage].Phys & (PAGE_SIZE - 1)), ("iPage=%d Phys=%VHp\n", paPages[iPage].Phys)); 1691 paPages[iPage] = RTR0MemObjGetPagePhysAddr(Mem.MemObj, iPage); 1692 AssertMsg(!(paPages[iPage] & (PAGE_SIZE - 1)), ("iPage=%d Phys=%VHp\n", paPages[iPage])); 2088 1693 } 2089 1694 *ppvR0 = RTR0MemObjAddress(Mem.MemObj); … … 2131 1736 * Frees memory allocated using SUPR0LowAlloc(). 2132 1737 * 2133 * @returns 0 on success. 2134 * @returns SUPDRV_ERR_* on failure. 1738 * @returns IPRT status code. 2135 1739 * @param pSession The session to which the memory was allocated. 2136 1740 * @param uPtr Pointer to the memory (ring-3 or ring-0). … … 2139 1743 { 2140 1744 dprintf(("SUPR0LowFree: pSession=%p uPtr=%p\n", pSession, (void *)uPtr)); 1745 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 2141 1746 return supdrvMemRelease(pSession, uPtr, MEMREF_TYPE_LOW); 2142 1747 } … … 2148 1753 * The memory is fixed and it's possible to query the physical addresses using SUPR0MemGetPhys(). 2149 1754 * 2150 * @returns 0 on success. 2151 * @returns SUPDRV_ERR_* on failure. 1755 * @returns IPRT status code. 2152 1756 * @param pSession The session to associated the allocation with. 2153 1757 * @param cb Number of bytes to allocate. … … 2164 1768 * Validate input. 2165 1769 */ 2166 if (!pSession || !ppvR0 || !ppvR3) 2167 { 2168 dprintf(("Null pointer. All of these should be set: pSession=%p ppvR0=%p ppvR3=%p\n", 2169 pSession, ppvR0, ppvR3)); 2170 return SUPDRV_ERR_INVALID_PARAM; 2171 2172 } 2173 if (cb < 1 || cb >= PAGE_SIZE * 256) 1770 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 1771 AssertPtrReturn(ppvR0, VERR_INVALID_POINTER); 1772 AssertPtrReturn(ppvR3, VERR_INVALID_POINTER); 1773 if (cb < 1 || cb >= _4M) 2174 1774 { 2175 1775 dprintf(("Illegal request cb=%u; must be greater than 0 and smaller than 4MB.\n", cb)); 2176 return SUPDRV_ERR_INVALID_PARAM;1776 return VERR_INVALID_PARAMETER; 2177 1777 } 2178 1778 … … 2195 1795 *ppvR0 = RTR0MemObjAddress(Mem.MemObj); 2196 1796 *ppvR3 = RTR0MemObjAddressR3(Mem.MapObjR3); 2197 return 0;1797 return VINF_SUCCESS; 2198 1798 } 2199 1799 rc2 = RTR0MemObjFree(Mem.MapObjR3, false); … … 2234 1834 * Get the physical addresses of memory allocated using SUPR0MemAlloc(). 2235 1835 * 2236 * @returns 0 on success. 2237 * @returns SUPDRV_ERR_* on failure. 1836 * @returns IPRT status code. 2238 1837 * @param pSession The session to which the memory was allocated. 2239 1838 * @param uPtr The Ring-0 or Ring-3 address returned by SUPR0MemAlloc(). 2240 1839 * @param paPages Where to store the physical addresses. 2241 1840 */ 2242 SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages) 1841 SUPR0DECL(int) SUPR0MemGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, PSUPPAGE paPages) /** @todo switch this bugger to RTHCPHYS */ 2243 1842 { 2244 1843 PSUPDRVBUNDLE pBundle; … … 2249 1848 * Validate input. 2250 1849 */ 2251 if (!pSession) 2252 { 2253 dprintf(("pSession must not be NULL!")); 2254 return SUPDRV_ERR_INVALID_PARAM; 2255 } 2256 if (!uPtr || !paPages) 2257 { 2258 dprintf(("Illegal address uPtr=%p or/and paPages=%p\n", (void *)uPtr, paPages)); 2259 return SUPDRV_ERR_INVALID_PARAM; 2260 } 1850 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 1851 AssertPtrReturn(paPages, VERR_INVALID_POINTER); 1852 AssertReturn(uPtr, VERR_INVALID_PARAMETER); 2261 1853 2262 1854 /* … … 2269 1861 { 2270 1862 unsigned i; 2271 for (i = 0; i < sizeof(pBundle->aMem) / sizeof(pBundle->aMem[0]); i++)1863 for (i = 0; i < RT_ELEMENTS(pBundle->aMem); i++) 2272 1864 { 2273 1865 #ifdef USE_NEW_OS_INTERFACE_FOR_MM … … 2288 1880 } 2289 1881 RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp); 2290 return 0;1882 return VINF_SUCCESS; 2291 1883 } 2292 1884 #else /* !USE_NEW_OS_INTERFACE_FOR_MM */ … … 2305 1897 RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp); 2306 1898 dprintf(("Failed to find %p!!!\n", (void *)uPtr)); 2307 return SUPDRV_ERR_INVALID_PARAM;1899 return VERR_INVALID_PARAMETER; 2308 1900 } 2309 1901 … … 2312 1904 * Free memory allocated by SUPR0MemAlloc(). 2313 1905 * 2314 * @returns 0 on success. 2315 * @returns SUPDRV_ERR_* on failure. 1906 * @returns IPRT status code. 2316 1907 * @param pSession The session owning the allocation. 2317 1908 * @param uPtr The Ring-0 or Ring-3 address returned by SUPR0MemAlloc(). … … 2320 1911 { 2321 1912 dprintf(("SUPR0MemFree: pSession=%p uPtr=%p\n", pSession, (void *)uPtr)); 1913 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 2322 1914 return supdrvMemRelease(pSession, uPtr, MEMREF_TYPE_MEM); 2323 1915 } … … 2329 1921 * The memory is fixed and it's possible to query the physical addresses using SUPR0MemGetPhys(). 2330 1922 * 2331 * @returns 0 on success. 2332 * @returns SUPDRV_ERR_* on failure. 1923 * @returns IPRT status code. 2333 1924 * @param pSession The session to associated the allocation with. 2334 * @param c b Number of bytes to allocate.1925 * @param cPages The number of pages to allocate. 2335 1926 * @param ppvR3 Where to store the address of the Ring-3 mapping. 2336 */ 2337 SUPR0DECL(int) SUPR0PageAlloc(PSUPDRVSESSION pSession, uint32_t cb, PRTR3PTR ppvR3) 1927 * @param paPages Where to store the addresses of the pages. Optional. 1928 */ 1929 SUPR0DECL(int) SUPR0PageAlloc(PSUPDRVSESSION pSession, uint32_t cPages, PRTR3PTR ppvR3, PRTHCPHYS paPages) 2338 1930 { 2339 1931 int rc; 2340 1932 SUPDRVMEMREF Mem = {0}; 2341 dprintf(("SUPR0PageAlloc: pSession=%p cb=%d ppvR3=%p\n", pSession, c b, ppvR3));1933 dprintf(("SUPR0PageAlloc: pSession=%p cb=%d ppvR3=%p\n", pSession, cPages, ppvR3)); 2342 1934 2343 1935 /* 2344 1936 * Validate input. 2345 1937 */ 2346 if (!pSession || !ppvR3) 2347 { 2348 dprintf(("Null pointer. All of these should be set: pSession=%p ppvR3=%p\n", 2349 pSession, ppvR3)); 2350 return SUPDRV_ERR_INVALID_PARAM; 2351 2352 } 2353 if (cb < 1 || cb >= 4096) 2354 { 2355 dprintf(("Illegal request cb=%u; must be greater than 0 and smaller than 16MB.\n", cb)); 2356 return SUPDRV_ERR_INVALID_PARAM; 1938 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 1939 AssertPtrReturn(ppvR3, VERR_INVALID_POINTER); 1940 if (cPages < 1 || cPages >= 4096) 1941 { 1942 dprintf(("SUPR0PageAlloc: Illegal request cb=%u; must be greater than 0 and smaller than 16MB.\n", cPages)); 1943 return VERR_INVALID_PARAMETER; 2357 1944 } 2358 1945 … … 2360 1947 * Let IPRT do the work. 2361 1948 */ 2362 rc = RTR0MemObjAllocPhysNC(&Mem.MemObj, cb* PAGE_SIZE, NIL_RTHCPHYS);1949 rc = RTR0MemObjAllocPhysNC(&Mem.MemObj, (size_t)cPages * PAGE_SIZE, NIL_RTHCPHYS); 2363 1950 if (RT_SUCCESS(rc)) 2364 1951 { … … 2373 1960 { 2374 1961 *ppvR3 = RTR0MemObjAddressR3(Mem.MapObjR3); 2375 dprintf(("SUPR0PageAlloc returned %p\n", *ppvR3)); 2376 return 0; 1962 if (paPages) 1963 { 1964 uint32_t iPage = cPages; 1965 while (iPage-- > 0) 1966 { 1967 paPages[iPage] = RTR0MemObjGetPagePhysAddr(Mem.MapObjR3, iPage); 1968 Assert(paPages[iPage] != NIL_RTHCPHYS); 1969 } 1970 } 1971 return VINF_SUCCESS; 2377 1972 } 2378 1973 rc2 = RTR0MemObjFree(Mem.MapObjR3, false); … … 2386 1981 } 2387 1982 1983 1984 #ifdef RT_OS_WINDOWS 2388 1985 /** 2389 1986 * Check if the pages were locked by SUPR0PageAlloc 1987 * 1988 * This function will be removed along with the lock/unlock hacks when 1989 * we've cleaned up the ring-3 code properly. 2390 1990 * 2391 1991 * @returns boolean 2392 1992 * @param pSession The session to which the memory was allocated. 2393 * @param uPtrThe Ring-3 address returned by SUPR0PageAlloc().2394 */ 2395 SUPR0DECL(bool) SUPR0PageWasLockedByPageAlloc(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr)1993 * @param pvR3 The Ring-3 address returned by SUPR0PageAlloc(). 1994 */ 1995 static bool supdrvPageWasLockedByPageAlloc(PSUPDRVSESSION pSession, RTR3PTR pvR3) 2396 1996 { 2397 1997 PSUPDRVBUNDLE pBundle; 2398 1998 RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER; 2399 dprintf(("SUPR0PageIsLockedByPageAlloc: pSession=%p uPtr=%p\n", pSession, (void *)uPtr)); 2400 2401 /* 2402 * Validate input. 2403 */ 2404 if (!pSession) 2405 { 2406 dprintf(("pSession must not be NULL!")); 2407 return false; 2408 } 2409 if (!uPtr) 2410 { 2411 dprintf(("Illegal address uPtr=%p\n", (void *)uPtr)); 2412 return false; 2413 } 1999 dprintf(("SUPR0PageIsLockedByPageAlloc: pSession=%p pvR3=%p\n", pSession, (void *)pvR3)); 2414 2000 2415 2001 /* … … 2422 2008 { 2423 2009 unsigned i; 2424 for (i = 0; i < sizeof(pBundle->aMem) / sizeof(pBundle->aMem[0]); i++)2010 for (i = 0; i < RT_ELEMENTS(pBundle->aMem); i++) 2425 2011 { 2426 2012 if ( pBundle->aMem[i].eType == MEMREF_TYPE_LOCKED_SUP 2427 2013 && pBundle->aMem[i].MemObj != NIL_RTR0MEMOBJ 2428 && ( (RTHCUINTPTR)RTR0MemObjAddress(pBundle->aMem[i].MemObj) == uPtr 2429 || ( pBundle->aMem[i].MapObjR3 != NIL_RTR0MEMOBJ 2430 && RTR0MemObjAddressR3(pBundle->aMem[i].MapObjR3) == uPtr) 2431 ) 2432 ) 2014 && pBundle->aMem[i].MapObjR3 != NIL_RTR0MEMOBJ 2015 && RTR0MemObjAddressR3(pBundle->aMem[i].MapObjR3) == pvR3) 2433 2016 { 2434 2017 RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp); … … 2442 2025 } 2443 2026 2027 2444 2028 /** 2445 2029 * Get the physical addresses of memory allocated using SUPR0PageAlloc(). 2446 2030 * 2447 * @returns 0 on success. 2448 * @returns SUPDRV_ERR_* on failure. 2031 * This function will be removed along with the lock/unlock hacks when 2032 * we've cleaned up the ring-3 code properly. 2033 * 2034 * @returns IPRT status code. 2449 2035 * @param pSession The session to which the memory was allocated. 2450 * @param uPtrThe Ring-3 address returned by SUPR0PageAlloc().2036 * @param pvR3 The Ring-3 address returned by SUPR0PageAlloc(). 2451 2037 * @param cPages Number of pages in paPages 2452 2038 * @param paPages Where to store the physical addresses. 2453 2039 */ 2454 SUPR0DECL(int) SUPR0PageGetPhys(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr, uint32_t cPages, PSUPPAGEpaPages)2040 static int supdrvPageGetPhys(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t cPages, PRTHCPHYS paPages) 2455 2041 { 2456 2042 PSUPDRVBUNDLE pBundle; 2457 2043 RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER; 2458 dprintf(("SUPR0PageGetPhys: pSession=%p uPtr=%p paPages=%p\n", pSession, (void *)uPtr, paPages)); 2459 2460 /* 2461 * Validate input. 2462 */ 2463 if (!pSession) 2464 { 2465 dprintf(("pSession must not be NULL!")); 2466 return SUPDRV_ERR_INVALID_PARAM; 2467 } 2468 if (!uPtr || !paPages) 2469 { 2470 dprintf(("Illegal address uPtr=%p or/and paPages=%p\n", (void *)uPtr, paPages)); 2471 return SUPDRV_ERR_INVALID_PARAM; 2472 } 2044 dprintf(("supdrvPageGetPhys: pSession=%p pvR3=%p cPages=%#lx paPages=%p\n", pSession, (void *)pvR3, (long)cPages, paPages)); 2473 2045 2474 2046 /* … … 2481 2053 { 2482 2054 unsigned i; 2483 for (i = 0; i < sizeof(pBundle->aMem) / sizeof(pBundle->aMem[0]); i++)2055 for (i = 0; i < RT_ELEMENTS(pBundle->aMem); i++) 2484 2056 { 2485 2057 if ( pBundle->aMem[i].eType == MEMREF_TYPE_LOCKED_SUP 2486 2058 && pBundle->aMem[i].MemObj != NIL_RTR0MEMOBJ 2487 && ( (RTHCUINTPTR)RTR0MemObjAddress(pBundle->aMem[i].MemObj) == uPtr 2488 || ( pBundle->aMem[i].MapObjR3 != NIL_RTR0MEMOBJ 2489 && RTR0MemObjAddressR3(pBundle->aMem[i].MapObjR3) == uPtr) 2490 ) 2491 ) 2059 && pBundle->aMem[i].MapObjR3 != NIL_RTR0MEMOBJ 2060 && RTR0MemObjAddressR3(pBundle->aMem[i].MapObjR3) == pvR3) 2492 2061 { 2493 u nsigned iPage;2494 cPages = RT_MIN( RTR0MemObjSize(pBundle->aMem[i].MemObj) >> PAGE_SHIFT, cPages);2062 uint32_t iPage = RTR0MemObjSize(pBundle->aMem[i].MemObj) >> PAGE_SHIFT; 2063 cPages = RT_MIN(iPage, cPages); 2495 2064 for (iPage = 0; iPage < cPages; iPage++) 2496 { 2497 paPages[iPage].Phys = RTR0MemObjGetPagePhysAddr(pBundle->aMem[i].MemObj, iPage); 2498 paPages[iPage].uReserved = 0; 2499 } 2065 paPages[iPage] = RTR0MemObjGetPagePhysAddr(pBundle->aMem[i].MemObj, iPage); 2500 2066 RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp); 2501 return 0;2067 return VINF_SUCCESS; 2502 2068 } 2503 2069 } … … 2505 2071 } 2506 2072 RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp); 2507 dprintf(("Failed to find %p!!!\n", (void *)uPtr)); 2508 return SUPDRV_ERR_INVALID_PARAM; 2509 } 2510 2073 return VERR_INVALID_PARAMETER; 2074 } 2075 #endif /* RT_OS_WINDOWS */ 2511 2076 2512 2077 /** 2513 2078 * Free memory allocated by SUPR0PageAlloc(). 2514 2079 * 2515 * @returns 0 on success. 2516 * @returns SUPDRV_ERR_* on failure. 2080 * @returns IPRT status code. 2517 2081 * @param pSession The session owning the allocation. 2518 * @param uPtr The Ring-3 address returned by SUPR0PageAlloc(). 2519 */ 2520 SUPR0DECL(int) SUPR0PageFree(PSUPDRVSESSION pSession, RTHCUINTPTR uPtr) 2521 { 2522 dprintf(("SUPR0PageFree: pSession=%p uPtr=%p\n", pSession, (void *)uPtr)); 2523 return supdrvMemRelease(pSession, uPtr, MEMREF_TYPE_LOCKED_SUP); 2082 * @param pvR3 The Ring-3 address returned by SUPR0PageAlloc(). 2083 */ 2084 SUPR0DECL(int) SUPR0PageFree(PSUPDRVSESSION pSession, RTR3PTR pvR3) 2085 { 2086 dprintf(("SUPR0PageFree: pSession=%p pvR3=%p\n", pSession, (void *)pvR3)); 2087 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 2088 return supdrvMemRelease(pSession, (RTHCUINTPTR)pvR3, MEMREF_TYPE_LOCKED_SUP); 2524 2089 } 2525 2090 #endif /* USE_NEW_OS_INTERFACE_FOR_MM */ … … 2529 2094 * Maps the GIP into userspace and/or get the physical address of the GIP. 2530 2095 * 2531 * @returns 0 on success. 2532 * @returns SUPDRV_ERR_* on failure. 2096 * @returns IPRT status code. 2533 2097 * @param pSession Session to which the GIP mapping should belong. 2534 2098 * @param ppGipR3 Where to store the address of the ring-3 mapping. (optional) … … 2539 2103 * and remove the session as a GIP user. 2540 2104 */ 2541 SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGi d)2105 SUPR0DECL(int) SUPR0GipMap(PSUPDRVSESSION pSession, PRTR3PTR ppGipR3, PRTHCPHYS pHCPhysGip) 2542 2106 { 2543 2107 int rc = 0; … … 2545 2109 RTR3PTR pGip = NIL_RTR3PTR; 2546 2110 RTHCPHYS HCPhys = NIL_RTHCPHYS; 2547 dprintf(("SUPR0GipMap: pSession=%p ppGipR3=%p pHCPhysGi d=%p\n", pSession, ppGipR3, pHCPhysGid));2111 dprintf(("SUPR0GipMap: pSession=%p ppGipR3=%p pHCPhysGip=%p\n", pSession, ppGipR3, pHCPhysGip)); 2548 2112 2549 2113 /* 2550 2114 * Validate 2551 2115 */ 2552 if (!ppGipR3 && !pHCPhysGid) 2553 return 0; 2116 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 2117 AssertPtrNullReturn(ppGipR3, VERR_INVALID_POINTER); 2118 AssertPtrNullReturn(pHCPhysGip, VERR_INVALID_POINTER); 2554 2119 2555 2120 RTSemFastMutexRequest(pDevExt->mtxGip); … … 2581 2146 * Get physical address. 2582 2147 */ 2583 if (pHCPhysGi d&& !rc)2148 if (pHCPhysGip && !rc) 2584 2149 HCPhys = pDevExt->HCPhysGip; 2585 2150 … … 2604 2169 #ifdef USE_NEW_OS_INTERFACE_FOR_GIP 2605 2170 rc = RTTimerStart(pDevExt->pGipTimer, 0); 2606 AssertRC(rc); rc = 0;2171 AssertRC(rc); rc = VINF_SUCCESS; 2607 2172 #else 2608 2173 supdrvOSGipResume(pDevExt); … … 2621 2186 * Write returns. 2622 2187 */ 2623 if (pHCPhysGi d)2624 *pHCPhysGi d= HCPhys;2188 if (pHCPhysGip) 2189 *pHCPhysGip = HCPhys; 2625 2190 if (ppGipR3) 2626 2191 *ppGipR3 = pGip; 2627 2192 2628 2193 #ifdef DEBUG_DARWIN_GIP 2629 OSDBGPRINT(("SUPR0GipMap: returns %d *pHCPhysGi d=%lx *ppGip=%p GipMapObjR3\n", rc, (unsigned long)HCPhys, pGip, pSession->GipMapObjR3));2194 OSDBGPRINT(("SUPR0GipMap: returns %d *pHCPhysGip=%lx *ppGip=%p GipMapObjR3\n", rc, (unsigned long)HCPhys, pGip, pSession->GipMapObjR3)); 2630 2195 #else 2631 dprintf(("SUPR0GipMap: returns %d *pHCPhysGi d=%lx *ppGipR3=%p\n", rc, (unsigned long)HCPhys, (void *)(uintptr_t)pGip));2196 dprintf(("SUPR0GipMap: returns %d *pHCPhysGip=%lx *ppGipR3=%p\n", rc, (unsigned long)HCPhys, (void *)(uintptr_t)pGip)); 2632 2197 #endif 2633 2198 return rc; … … 2639 2204 * from this session. 2640 2205 * 2641 * @returns 0 on success. 2642 * @returns SUPDRV_ERR_* on failure. 2206 * @returns IPRT status code. 2643 2207 * @param pSession Session to which the GIP mapping should belong. 2644 2208 */ 2645 2209 SUPR0DECL(int) SUPR0GipUnmap(PSUPDRVSESSION pSession) 2646 2210 { 2647 int rc = 0;2211 int rc = VINF_SUCCESS; 2648 2212 PSUPDRVDEVEXT pDevExt = pSession->pDevExt; 2649 2213 #ifdef DEBUG_DARWIN_GIP … … 2655 2219 dprintf(("SUPR0GipUnmap: pSession=%p\n", pSession)); 2656 2220 #endif 2221 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 2657 2222 2658 2223 RTSemFastMutexRequest(pDevExt->mtxGip); … … 2705 2270 * Adds a memory object to the session. 2706 2271 * 2707 * @returns 0 on success. 2708 * @returns SUPDRV_ERR_* on failure. 2272 * @returns IPRT status code. 2709 2273 * @param pMem Memory tracking structure containing the 2710 2274 * information to track. … … 2722 2286 for (pBundle = &pSession->Bundle; pBundle; pBundle = pBundle->pNext) 2723 2287 { 2724 if (pBundle->cUsed < sizeof(pBundle->aMem) / sizeof(pBundle->aMem[0]))2288 if (pBundle->cUsed < RT_ELEMENTS(pBundle->aMem)) 2725 2289 { 2726 2290 unsigned i; 2727 for (i = 0; i < sizeof(pBundle->aMem) / sizeof(pBundle->aMem[0]); i++)2291 for (i = 0; i < RT_ELEMENTS(pBundle->aMem); i++) 2728 2292 { 2729 2293 #ifdef USE_NEW_OS_INTERFACE_FOR_MM … … 2737 2301 pBundle->aMem[i] = *pMem; 2738 2302 RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp); 2739 return 0;2303 return VINF_SUCCESS; 2740 2304 } 2741 2305 } … … 2751 2315 pBundle = (PSUPDRVBUNDLE)RTMemAllocZ(sizeof(*pBundle)); 2752 2316 if (!pBundle) 2753 return SUPDRV_ERR_NO_MEMORY;2317 return VERR_NO_MEMORY; 2754 2318 2755 2319 /* take last entry. */ 2756 2320 pBundle->cUsed++; 2757 pBundle->aMem[ sizeof(pBundle->aMem) / sizeof(pBundle->aMem[0]) - 1] = *pMem;2321 pBundle->aMem[RT_ELEMENTS(pBundle->aMem) - 1] = *pMem; 2758 2322 2759 2323 /* insert into list. */ … … 2763 2327 RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp); 2764 2328 2765 return 0;2329 return VINF_SUCCESS; 2766 2330 } 2767 2331 … … 2770 2334 * Releases a memory object referenced by pointer and type. 2771 2335 * 2772 * @returns 0 on success. 2773 * @returns SUPDRV_ERR_INVALID_PARAM on failure. 2336 * @returns IPRT status code. 2774 2337 * @param pSession Session data. 2775 2338 * @param uPtr Pointer to memory. This is matched against both the R0 and R3 addresses. … … 2784 2347 * Validate input. 2785 2348 */ 2786 if (!pSession)2787 {2788 dprintf(("pSession must not be NULL!"));2789 return SUPDRV_ERR_INVALID_PARAM;2790 }2791 2349 if (!uPtr) 2792 2350 { 2793 2351 dprintf(("Illegal address %p\n", (void *)uPtr)); 2794 return SUPDRV_ERR_INVALID_PARAM;2352 return VERR_INVALID_PARAMETER; 2795 2353 } 2796 2354 … … 2804 2362 { 2805 2363 unsigned i; 2806 for (i = 0; i < sizeof(pBundle->aMem) / sizeof(pBundle->aMem[0]); i++)2364 for (i = 0; i < RT_ELEMENTS(pBundle->aMem); i++) 2807 2365 { 2808 2366 #ifdef USE_NEW_OS_INTERFACE_FOR_MM … … 2831 2389 AssertRC(rc); /** @todo figure out how to handle this. */ 2832 2390 } 2833 return 0;2391 return VINF_SUCCESS; 2834 2392 } 2835 2393 #else /* !USE_NEW_OS_INTERFACE_FOR_MM */ … … 2865 2423 break; 2866 2424 } 2867 return 0;2425 return VINF_SUCCESS; 2868 2426 } 2869 2427 #endif /* !USE_NEW_OS_INTERFACE_FOR_MM */ … … 2873 2431 RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp); 2874 2432 dprintf(("Failed to find %p!!! (eType=%d)\n", (void *)uPtr, eType)); 2875 return SUPDRV_ERR_INVALID_PARAM;2433 return VERR_INVALID_PARAMETER; 2876 2434 } 2877 2435 … … 2881 2439 * Install IDT for the current CPU. 2882 2440 * 2883 * @returns 0 on success. 2884 * @returns SUPDRV_ERR_NO_MEMORY or SUPDRV_ERROR_IDT_FAILED on failure. 2885 * @param pIn Input data. 2886 * @param pOut Output data. 2887 */ 2888 static int supdrvIOCtl_IdtInstall(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPIDTINSTALL_IN pIn, PSUPIDTINSTALL_OUT pOut) 2441 * @returns One of the following IPRT status codes: 2442 * @retval VINF_SUCCESS on success. 2443 * @retval VERR_IDT_FAILED. 2444 * @retval VERR_NO_MEMORY. 2445 * @param pDevExt The device extension. 2446 * @param pSession The session data. 2447 * @param pReq The request. 2448 */ 2449 static int supdrvIOCtl_IdtInstall(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPIDTINSTALL pReq) 2889 2450 { 2890 2451 PSUPDRVPATCHUSAGE pUsagePre; … … 2901 2462 pUsagePre = (PSUPDRVPATCHUSAGE)RTMemAlloc(sizeof(*pUsagePre)); 2902 2463 if (!pUsagePre) 2903 return SUPDRV_ERR_NO_MEMORY;2464 return VERR_NO_MEMORY; 2904 2465 2905 2466 /* … … 2918 2479 pPatchPre = (PSUPDRVPATCH)RTMemExecAlloc(sizeof(*pPatchPre)); 2919 2480 if (!pPatchPre) 2920 return SUPDRV_ERR_NO_MEMORY;2481 return VERR_NO_MEMORY; 2921 2482 2922 2483 RTSpinlockAcquireNoInts(pDevExt->Spinlock, &SpinlockTmp); … … 2995 2556 RTMemFree(pUsagePre); 2996 2557 2997 p Out->u8Idt = pDevExt->u8Idt;2998 2999 return pPatch ? 0 : SUPDRV_ERR_IDT_FAILED;2558 pReq->u.Out.u8Idt = pDevExt->u8Idt; 2559 2560 return pPatch ? VINF_SUCCESS : VERR_IDT_FAILED; 3000 2561 } 3001 2562 … … 3373 2934 * This will uninstall our IDT patch if we left unreferenced. 3374 2935 * 3375 * @returns 0 indicating success.2936 * @returns VINF_SUCCESS. 3376 2937 * @param pDevExt Device globals. 3377 2938 * @param pSession Session data. … … 3389 2950 3390 2951 /* 3391 * Walk usage list .2952 * Walk usage list, removing patches as their usage count reaches zero. 3392 2953 */ 3393 2954 pUsage = pSession->pPatchUsage; … … 3423 2984 } 3424 2985 3425 return 0;2986 return VINF_SUCCESS; 3426 2987 } 3427 2988 … … 3429 2990 /** 3430 2991 * Remove one patch. 2992 * 2993 * Worker for supdrvIOCtl_IdtRemoveAll. 3431 2994 * 3432 2995 * @param pDevExt Device globals. … … 3540 3103 * This is the 1st step of the loading. 3541 3104 * 3542 * @returns 0 on success. 3543 * @returns SUPDRV_ERR_* on failure. 3105 * @returns IPRT status code. 3544 3106 * @param pDevExt Device globals. 3545 3107 * @param pSession Session data. 3546 * @param pIn Input. 3547 * @param pOut Output. (May overlap pIn.) 3548 */ 3549 static int supdrvIOCtl_LdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDROPEN_IN pIn, PSUPLDROPEN_OUT pOut) 3108 * @param pReq The open request. 3109 */ 3110 static int supdrvIOCtl_LdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDROPEN pReq) 3550 3111 { 3551 3112 PSUPDRVLDRIMAGE pImage; 3552 3113 unsigned cb; 3553 3114 void *pv; 3554 dprintf(("supdrvIOCtl_LdrOpen: szName=%s cbImage=%d\n", p In->szName, pIn->cbImage));3115 dprintf(("supdrvIOCtl_LdrOpen: szName=%s cbImage=%d\n", pReq->u.In.szName, pReq->u.In.cbImage)); 3555 3116 3556 3117 /* … … 3560 3121 for (pImage = pDevExt->pLdrImages; pImage; pImage = pImage->pNext) 3561 3122 { 3562 if (!strcmp(pImage->szName, p In->szName))3123 if (!strcmp(pImage->szName, pReq->u.In.szName)) 3563 3124 { 3564 3125 pImage->cUsage++; 3565 p Out->pvImageBase = pImage->pvImage;3566 p Out->fNeedsLoading = pImage->uState == SUP_IOCTL_LDR_OPEN;3126 pReq->u.Out.pvImageBase = pImage->pvImage; 3127 pReq->u.Out.fNeedsLoading = pImage->uState == SUP_IOCTL_LDR_OPEN; 3567 3128 supdrvLdrAddUsage(pSession, pImage); 3568 3129 RTSemFastMutexRelease(pDevExt->mtxLdr); 3569 return 0;3130 return VINF_SUCCESS; 3570 3131 } 3571 3132 } … … 3575 3136 * Allocate memory. 3576 3137 */ 3577 cb = p In->cbImage + sizeof(SUPDRVLDRIMAGE) + 31;3138 cb = pReq->u.In.cbImage + sizeof(SUPDRVLDRIMAGE) + 31; 3578 3139 pv = RTMemExecAlloc(cb); 3579 3140 if (!pv) 3580 3141 { 3581 3142 RTSemFastMutexRelease(pDevExt->mtxLdr); 3582 return SUPDRV_ERR_NO_MEMORY;3143 return VERR_NO_MEMORY; 3583 3144 } 3584 3145 … … 3588 3149 pImage = (PSUPDRVLDRIMAGE)pv; 3589 3150 pImage->pvImage = ALIGNP(pImage + 1, 32); 3590 pImage->cbImage = p In->cbImage;3151 pImage->cbImage = pReq->u.In.cbImage; 3591 3152 pImage->pfnModuleInit = NULL; 3592 3153 pImage->pfnModuleTerm = NULL; 3593 3154 pImage->uState = SUP_IOCTL_LDR_OPEN; 3594 3155 pImage->cUsage = 1; 3595 strcpy(pImage->szName, p In->szName);3156 strcpy(pImage->szName, pReq->u.In.szName); 3596 3157 3597 3158 pImage->pNext = pDevExt->pLdrImages; … … 3600 3161 supdrvLdrAddUsage(pSession, pImage); 3601 3162 3602 p Out->pvImageBase= pImage->pvImage;3603 p Out->fNeedsLoading = 1;3163 pReq->u.Out.pvImageBase = pImage->pvImage; 3164 pReq->u.Out.fNeedsLoading = true; 3604 3165 RTSemFastMutexRelease(pDevExt->mtxLdr); 3605 return 0;3166 return VINF_SUCCESS; 3606 3167 } 3607 3168 … … 3612 3173 * This is the 2nd step of the loading. 3613 3174 * 3614 * @returns 0 on success. 3615 * @returns SUPDRV_ERR_* on failure. 3175 * @returns IPRT status code. 3616 3176 * @param pDevExt Device globals. 3617 3177 * @param pSession Session data. 3618 * @param p In Input.3619 */ 3620 static int supdrvIOCtl_LdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRLOAD _IN pIn)3178 * @param pReq The request. 3179 */ 3180 static int supdrvIOCtl_LdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRLOAD pReq) 3621 3181 { 3622 3182 PSUPDRVLDRUSAGE pUsage; 3623 3183 PSUPDRVLDRIMAGE pImage; 3624 3184 int rc; 3625 dprintf(("supdrvIOCtl_LdrLoad: pvImageBase=%p cbImage=%d\n", p In->pvImageBase, pIn->cbImage));3185 dprintf(("supdrvIOCtl_LdrLoad: pvImageBase=%p cbImage=%d\n", pReq->u.In.pvImageBase, pReq->u.In.cbImage)); 3626 3186 3627 3187 /* … … 3630 3190 RTSemFastMutexRequest(pDevExt->mtxLdr); 3631 3191 pUsage = pSession->pLdrUsage; 3632 while (pUsage && pUsage->pImage->pvImage != p In->pvImageBase)3192 while (pUsage && pUsage->pImage->pvImage != pReq->u.In.pvImageBase) 3633 3193 pUsage = pUsage->pNext; 3634 3194 if (!pUsage) … … 3636 3196 RTSemFastMutexRelease(pDevExt->mtxLdr); 3637 3197 dprintf(("SUP_IOCTL_LDR_LOAD: couldn't find image!\n")); 3638 return SUPDRV_ERR_INVALID_HANDLE;3198 return VERR_INVALID_HANDLE; 3639 3199 } 3640 3200 pImage = pUsage->pImage; 3641 if (pImage->cbImage != p In->cbImage)3201 if (pImage->cbImage != pReq->u.In.cbImage) 3642 3202 { 3643 3203 RTSemFastMutexRelease(pDevExt->mtxLdr); 3644 dprintf(("SUP_IOCTL_LDR_LOAD: image size mismatch!! %d(prep) != %d(load)\n", pImage->cbImage, p In->cbImage));3645 return SUPDRV_ERR_INVALID_HANDLE;3204 dprintf(("SUP_IOCTL_LDR_LOAD: image size mismatch!! %d(prep) != %d(load)\n", pImage->cbImage, pReq->u.In.cbImage)); 3205 return VERR_INVALID_HANDLE; 3646 3206 } 3647 3207 if (pImage->uState != SUP_IOCTL_LDR_OPEN) … … 3653 3213 return SUPDRV_ERR_ALREADY_LOADED; 3654 3214 } 3655 switch (p In->eEPType)3215 switch (pReq->u.In.eEPType) 3656 3216 { 3657 3217 case EP_NOTHING: 3658 3218 break; 3659 3219 case EP_VMMR0: 3660 if (!p In->EP.VMMR0.pvVMMR0 || !pIn->EP.VMMR0.pvVMMR0Entry)3220 if (!pReq->u.In.EP.VMMR0.pvVMMR0 || !pReq->u.In.EP.VMMR0.pvVMMR0Entry) 3661 3221 { 3662 3222 RTSemFastMutexRelease(pDevExt->mtxLdr); 3663 dprintf(("pvVMMR0=%p or p In->EP.VMMR0.pvVMMR0Entry=%p is NULL!\n",3664 p In->EP.VMMR0.pvVMMR0, pIn->EP.VMMR0.pvVMMR0Entry));3665 return SUPDRV_ERR_INVALID_PARAM;3223 dprintf(("pvVMMR0=%p or pReq->u.In.EP.VMMR0.pvVMMR0Entry=%p is NULL!\n", 3224 pReq->u.In.EP.VMMR0.pvVMMR0, pReq->u.In.EP.VMMR0.pvVMMR0Entry)); 3225 return VERR_INVALID_PARAMETER; 3666 3226 } 3667 if ((uintptr_t)p In->EP.VMMR0.pvVMMR0Entry - (uintptr_t)pImage->pvImage >= pIn->cbImage)3227 if ((uintptr_t)pReq->u.In.EP.VMMR0.pvVMMR0Entry - (uintptr_t)pImage->pvImage >= pReq->u.In.cbImage) 3668 3228 { 3669 3229 RTSemFastMutexRelease(pDevExt->mtxLdr); 3670 3230 dprintf(("SUP_IOCTL_LDR_LOAD: pvVMMR0Entry=%p is outside the image (%p %d bytes)\n", 3671 p In->EP.VMMR0.pvVMMR0Entry, pImage->pvImage, pIn->cbImage));3672 return SUPDRV_ERR_INVALID_PARAM;3231 pReq->u.In.EP.VMMR0.pvVMMR0Entry, pImage->pvImage, pReq->u.In.cbImage)); 3232 return VERR_INVALID_PARAMETER; 3673 3233 } 3674 3234 break; 3675 3235 default: 3676 3236 RTSemFastMutexRelease(pDevExt->mtxLdr); 3677 dprintf(("Invalid eEPType=%d\n", p In->eEPType));3678 return SUPDRV_ERR_INVALID_PARAM;3679 } 3680 if ( p In->pfnModuleInit3681 && (uintptr_t)p In->pfnModuleInit - (uintptr_t)pImage->pvImage >= pIn->cbImage)3237 dprintf(("Invalid eEPType=%d\n", pReq->u.In.eEPType)); 3238 return VERR_INVALID_PARAMETER; 3239 } 3240 if ( pReq->u.In.pfnModuleInit 3241 && (uintptr_t)pReq->u.In.pfnModuleInit - (uintptr_t)pImage->pvImage >= pReq->u.In.cbImage) 3682 3242 { 3683 3243 RTSemFastMutexRelease(pDevExt->mtxLdr); 3684 3244 dprintf(("SUP_IOCTL_LDR_LOAD: pfnModuleInit=%p is outside the image (%p %d bytes)\n", 3685 p In->pfnModuleInit, pImage->pvImage, pIn->cbImage));3686 return SUPDRV_ERR_INVALID_PARAM;3687 } 3688 if ( p In->pfnModuleTerm3689 && (uintptr_t)p In->pfnModuleTerm - (uintptr_t)pImage->pvImage >= pIn->cbImage)3245 pReq->u.In.pfnModuleInit, pImage->pvImage, pReq->u.In.cbImage)); 3246 return VERR_INVALID_PARAMETER; 3247 } 3248 if ( pReq->u.In.pfnModuleTerm 3249 && (uintptr_t)pReq->u.In.pfnModuleTerm - (uintptr_t)pImage->pvImage >= pReq->u.In.cbImage) 3690 3250 { 3691 3251 RTSemFastMutexRelease(pDevExt->mtxLdr); 3692 3252 dprintf(("SUP_IOCTL_LDR_LOAD: pfnModuleTerm=%p is outside the image (%p %d bytes)\n", 3693 p In->pfnModuleTerm, pImage->pvImage, pIn->cbImage));3694 return SUPDRV_ERR_INVALID_PARAM;3253 pReq->u.In.pfnModuleTerm, pImage->pvImage, pReq->u.In.cbImage)); 3254 return VERR_INVALID_PARAMETER; 3695 3255 } 3696 3256 … … 3699 3259 */ 3700 3260 /* no need to do try/except as this is a buffered request. */ 3701 memcpy(pImage->pvImage, &p In->achImage[0], pImage->cbImage);3261 memcpy(pImage->pvImage, &pReq->u.In.achImage[0], pImage->cbImage); 3702 3262 pImage->uState = SUP_IOCTL_LDR_LOAD; 3703 pImage->pfnModuleInit = p In->pfnModuleInit;3704 pImage->pfnModuleTerm = p In->pfnModuleTerm;3705 pImage->offSymbols = p In->offSymbols;3706 pImage->cSymbols = p In->cSymbols;3707 pImage->offStrTab = p In->offStrTab;3708 pImage->cbStrTab = p In->cbStrTab;3263 pImage->pfnModuleInit = pReq->u.In.pfnModuleInit; 3264 pImage->pfnModuleTerm = pReq->u.In.pfnModuleTerm; 3265 pImage->offSymbols = pReq->u.In.offSymbols; 3266 pImage->cSymbols = pReq->u.In.cSymbols; 3267 pImage->offStrTab = pReq->u.In.offStrTab; 3268 pImage->cbStrTab = pReq->u.In.cbStrTab; 3709 3269 3710 3270 /* 3711 3271 * Update any entry points. 3712 3272 */ 3713 switch (p In->eEPType)3273 switch (pReq->u.In.eEPType) 3714 3274 { 3715 3275 default: 3716 3276 case EP_NOTHING: 3717 rc = 0;3277 rc = VINF_SUCCESS; 3718 3278 break; 3719 3279 case EP_VMMR0: 3720 rc = supdrvLdrSetR0EP(pDevExt, p In->EP.VMMR0.pvVMMR0, pIn->EP.VMMR0.pvVMMR0Entry);3280 rc = supdrvLdrSetR0EP(pDevExt, pReq->u.In.EP.VMMR0.pvVMMR0, pReq->u.In.EP.VMMR0.pvVMMR0Entry); 3721 3281 break; 3722 3282 } … … 3745 3305 * Frees a previously loaded (prep'ed) image. 3746 3306 * 3747 * @returns 0 on success. 3748 * @returns SUPDRV_ERR_* on failure. 3307 * @returns IPRT status code. 3749 3308 * @param pDevExt Device globals. 3750 3309 * @param pSession Session data. 3751 * @param p In Input.3752 */ 3753 static int supdrvIOCtl_LdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRFREE _IN pIn)3310 * @param pReq The request. 3311 */ 3312 static int supdrvIOCtl_LdrFree(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRFREE pReq) 3754 3313 { 3755 3314 PSUPDRVLDRUSAGE pUsagePrev; 3756 3315 PSUPDRVLDRUSAGE pUsage; 3757 3316 PSUPDRVLDRIMAGE pImage; 3758 dprintf(("supdrvIOCtl_LdrFree: pvImageBase=%p\n", p In->pvImageBase));3317 dprintf(("supdrvIOCtl_LdrFree: pvImageBase=%p\n", pReq->u.In.pvImageBase)); 3759 3318 3760 3319 /* … … 3764 3323 pUsagePrev = NULL; 3765 3324 pUsage = pSession->pLdrUsage; 3766 while (pUsage && pUsage->pImage->pvImage != p In->pvImageBase)3325 while (pUsage && pUsage->pImage->pvImage != pReq->u.In.pvImageBase) 3767 3326 { 3768 3327 pUsagePrev = pUsage; … … 3773 3332 RTSemFastMutexRelease(pDevExt->mtxLdr); 3774 3333 dprintf(("SUP_IOCTL_LDR_FREE: couldn't find image!\n")); 3775 return SUPDRV_ERR_INVALID_HANDLE;3334 return VERR_INVALID_HANDLE; 3776 3335 } 3777 3336 … … 3810 3369 3811 3370 RTSemFastMutexRelease(pDevExt->mtxLdr); 3812 return 0;3371 return VINF_SUCCESS; 3813 3372 } 3814 3373 … … 3821 3380 * @param pDevExt Device globals. 3822 3381 * @param pSession Session data. 3823 * @param pIn Input. 3824 * @param pOut Output. (May overlap pIn.) 3825 */ 3826 static int supdrvIOCtl_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRGETSYMBOL_IN pIn, PSUPLDRGETSYMBOL_OUT pOut) 3382 * @param pReq The request buffer. 3383 */ 3384 static int supdrvIOCtl_LdrGetSymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PSUPLDRGETSYMBOL pReq) 3827 3385 { 3828 3386 PSUPDRVLDRIMAGE pImage; … … 3831 3389 PSUPLDRSYM paSyms; 3832 3390 const char *pchStrings; 3833 const size_t cbSymbol = strlen(p In->szSymbol) + 1;3391 const size_t cbSymbol = strlen(pReq->u.In.szSymbol) + 1; 3834 3392 void *pvSymbol = NULL; 3835 int rc = SUPDRV_ERR_GENERAL_FAILURE; /** @todo better error code. */3836 dprintf2(("supdrvIOCtl_LdrGetSymbol: pvImageBase=%p szSymbol=\"%s\"\n", p In->pvImageBase, pIn->szSymbol));3393 int rc = VERR_GENERAL_FAILURE; 3394 dprintf2(("supdrvIOCtl_LdrGetSymbol: pvImageBase=%p szSymbol=\"%s\"\n", pReq->u.In.pvImageBase, pReq->u.In.szSymbol)); 3837 3395 3838 3396 /* … … 3841 3399 RTSemFastMutexRequest(pDevExt->mtxLdr); 3842 3400 pUsage = pSession->pLdrUsage; 3843 while (pUsage && pUsage->pImage->pvImage != p In->pvImageBase)3401 while (pUsage && pUsage->pImage->pvImage != pReq->u.In.pvImageBase) 3844 3402 pUsage = pUsage->pNext; 3845 3403 if (!pUsage) … … 3847 3405 RTSemFastMutexRelease(pDevExt->mtxLdr); 3848 3406 dprintf(("SUP_IOCTL_LDR_GET_SYMBOL: couldn't find image!\n")); 3849 return SUPDRV_ERR_INVALID_HANDLE;3407 return VERR_INVALID_HANDLE; 3850 3408 } 3851 3409 pImage = pUsage->pImage; … … 3855 3413 RTSemFastMutexRelease(pDevExt->mtxLdr); 3856 3414 dprintf(("SUP_IOCTL_LDR_GET_SYMBOL: invalid image state %d (%#x)!\n", uState, uState)); NOREF(uState); 3857 return SUPDRV_ERR_ALREADY_LOADED;3415 return VERR_ALREADY_LOADED; 3858 3416 } 3859 3417 … … 3867 3425 if ( paSyms[i].offSymbol < pImage->cbImage /* paranoia */ 3868 3426 && paSyms[i].offName + cbSymbol <= pImage->cbStrTab 3869 && !memcmp(pchStrings + paSyms[i].offName, p In->szSymbol, cbSymbol))3427 && !memcmp(pchStrings + paSyms[i].offName, pReq->u.In.szSymbol, cbSymbol)) 3870 3428 { 3871 3429 pvSymbol = (uint8_t *)pImage->pvImage + paSyms[i].offSymbol; 3872 rc = 0;3430 rc = VINF_SUCCESS; 3873 3431 break; 3874 3432 } 3875 3433 } 3876 3434 RTSemFastMutexRelease(pDevExt->mtxLdr); 3877 p Out->pvSymbol = pvSymbol;3435 pReq->u.Out.pvSymbol = pvSymbol; 3878 3436 return rc; 3879 3437 } … … 3884 3442 * point (i.e. VMMR0Enter()). 3885 3443 * 3886 * @returns 0 on success. 3887 * @returns SUPDRV_ERR_* on failure. 3444 * @returns IPRT status code. 3888 3445 * @param pDevExt Device globals. 3889 3446 * @param pSession Session data. … … 3894 3451 static int supdrvLdrSetR0EP(PSUPDRVDEVEXT pDevExt, void *pvVMMR0, void *pvVMMR0Entry) 3895 3452 { 3896 int rc;3453 int rc = VINF_SUCCESS; 3897 3454 dprintf(("supdrvLdrSetR0EP pvVMMR0=%p pvVMMR0Entry=%p\n", pvVMMR0, pvVMMR0Entry)); 3898 3455 … … 3901 3458 * Check if not yet set. 3902 3459 */ 3903 rc = 0;3904 3460 if (!pDevExt->pvVMMR0) 3905 3461 { … … 3935 3491 { 3936 3492 AssertMsgFailed(("SUP_IOCTL_LDR_SETR0EP: Already set pointing to a different module!\n")); 3937 rc = SUPDRV_ERR_INVALID_PARAM;3493 rc = VERR_INVALID_PARAMETER; 3938 3494 } 3939 3495 } … … 4065 3621 * Gets the current paging mode of the CPU and stores in in pOut. 4066 3622 */ 4067 static int supdrvIOCtl_GetPagingMode(PSUPGETPAGINGMODE_OUT pOut) 4068 { 3623 static SUPPAGINGMODE supdrvIOCtl_GetPagingMode(void) 3624 { 3625 SUPPAGINGMODE enmMode; 3626 4069 3627 RTUINTREG cr0 = ASMGetCR0(); 4070 3628 if ((cr0 & (X86_CR0_PG | X86_CR0_PE)) != (X86_CR0_PG | X86_CR0_PE)) 4071 pOut->enmMode = SUPPAGINGMODE_INVALID;3629 enmMode = SUPPAGINGMODE_INVALID; 4072 3630 else 4073 3631 { … … 4090 3648 { 4091 3649 case 0: 4092 pOut->enmMode = SUPPAGINGMODE_32_BIT;3650 enmMode = SUPPAGINGMODE_32_BIT; 4093 3651 break; 4094 3652 4095 3653 case X86_CR4_PGE: 4096 pOut->enmMode = SUPPAGINGMODE_32_BIT_GLOBAL;3654 enmMode = SUPPAGINGMODE_32_BIT_GLOBAL; 4097 3655 break; 4098 3656 4099 3657 case X86_CR4_PAE: 4100 pOut->enmMode = SUPPAGINGMODE_PAE;3658 enmMode = SUPPAGINGMODE_PAE; 4101 3659 break; 4102 3660 4103 3661 case X86_CR4_PAE | BIT(0): 4104 pOut->enmMode = SUPPAGINGMODE_PAE_NX;3662 enmMode = SUPPAGINGMODE_PAE_NX; 4105 3663 break; 4106 3664 4107 3665 case X86_CR4_PAE | X86_CR4_PGE: 4108 pOut->enmMode = SUPPAGINGMODE_PAE_GLOBAL;3666 enmMode = SUPPAGINGMODE_PAE_GLOBAL; 4109 3667 break; 4110 3668 4111 3669 case X86_CR4_PAE | X86_CR4_PGE | BIT(0): 4112 pOut->enmMode = SUPPAGINGMODE_PAE_GLOBAL;3670 enmMode = SUPPAGINGMODE_PAE_GLOBAL; 4113 3671 break; 4114 3672 4115 3673 case BIT(1) | X86_CR4_PAE: 4116 pOut->enmMode = SUPPAGINGMODE_AMD64;3674 enmMode = SUPPAGINGMODE_AMD64; 4117 3675 break; 4118 3676 4119 3677 case BIT(1) | X86_CR4_PAE | BIT(0): 4120 pOut->enmMode = SUPPAGINGMODE_AMD64_NX;3678 enmMode = SUPPAGINGMODE_AMD64_NX; 4121 3679 break; 4122 3680 4123 3681 case BIT(1) | X86_CR4_PAE | X86_CR4_PGE: 4124 pOut->enmMode = SUPPAGINGMODE_AMD64_GLOBAL;3682 enmMode = SUPPAGINGMODE_AMD64_GLOBAL; 4125 3683 break; 4126 3684 4127 3685 case BIT(1) | X86_CR4_PAE | X86_CR4_PGE | BIT(0): 4128 pOut->enmMode = SUPPAGINGMODE_AMD64_GLOBAL_NX;3686 enmMode = SUPPAGINGMODE_AMD64_GLOBAL_NX; 4129 3687 break; 4130 3688 4131 3689 default: 4132 3690 AssertMsgFailed(("Cannot happen! cr4=%#x fNXEPlusLMA=%d\n", cr4, fNXEPlusLMA)); 4133 pOut->enmMode = SUPPAGINGMODE_INVALID;3691 enmMode = SUPPAGINGMODE_INVALID; 4134 3692 break; 4135 3693 } 4136 3694 } 4137 return 0;3695 return enmMode; 4138 3696 } 4139 3697 … … 4178 3736 *ppvR0 = RTR0MemObjAddress(pMem->u.iprt.MemObj); 4179 3737 *ppvR3 = RTR0MemObjAddressR3(pMem->u.iprt.MapObjR3); 4180 return 0;3738 return VINF_SUCCESS; 4181 3739 } 4182 3740 … … 4304 3862 */ 4305 3863 supdrvGipInit(pDevExt, pGip, HCPhysGip, RTTimeSystemNanoTS(), 1000000000 / u32Interval /*=Hz*/); 4306 return 0;3864 return VINF_SUCCESS; 4307 3865 } 4308 3866 … … 4311 3869 * Terminates the GIP. 4312 3870 * 4313 * @returns negative errno.4314 3871 * @param pDevExt Instance data. GIP stuff may be updated. 4315 3872 */ 4316 static intsupdrvGipDestroy(PSUPDRVDEVEXT pDevExt)3873 static void supdrvGipDestroy(PSUPDRVDEVEXT pDevExt) 4317 3874 { 4318 3875 int rc; … … 4329 3886 { 4330 3887 supdrvGipTerm(pDevExt->pGip); 4331 pDevExt->pGip = 0;3888 pDevExt->pGip = NULL; 4332 3889 } 4333 3890 … … 4355 3912 pDevExt->u32SystemTimerGranularityGrant = 0; 4356 3913 } 4357 4358 return 0;4359 3914 } 4360 3915 … … 4376 3931 * Initializes the GIP data. 4377 3932 * 4378 * @returns VBoxstatus code.3933 * @returns IPRT status code. 4379 3934 * @param pDevExt Pointer to the device instance data. 4380 3935 * @param pGip Pointer to the read-write kernel mapping of the GIP. … … 4432 3987 pDevExt->cGipUsers = 0; 4433 3988 4434 return 0;3989 return VINF_SUCCESS; 4435 3990 } 4436 3991 … … 4600 4155 * @param u64NanoTS The current nanosecond timesamp. 4601 4156 */ 4602 void VBOXCALL 4157 void VBOXCALL supdrvGipUpdate(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS) 4603 4158 { 4604 4159 /* … … 4667 4222 * @param iCpu The CPU index. 4668 4223 */ 4669 void VBOXCALL 4224 void VBOXCALL supdrvGipUpdatePerCpu(PSUPGLOBALINFOPAGE pGip, uint64_t u64NanoTS, unsigned iCpu) 4670 4225 { 4671 4226 PSUPGIPCPU pGipCpu; -
trunk/src/VBox/HostDrivers/Support/SUPLib.cpp
r4765 r4800 42 42 #include <VBox/err.h> 43 43 #include <VBox/param.h> 44 #ifdef VBOX_WITHOUT_IDT_PATCHING 45 # include <VBox/vmm.h> 46 #endif 44 #include <VBox/vmm.h> 47 45 #include <VBox/log.h> 48 46 … … 57 55 #include <iprt/string.h> 58 56 #include <iprt/env.h> 57 #include <iprt/rand.h> 59 58 60 59 #include "SUPLibInternal.h" … … 101 100 PSUPDRVSESSION g_pSession; 102 101 /** R0 SUP Functions used for resolving referenced to the SUPR0 module. */ 103 static PSUPQUERYFUNCS _OUTg_pFunctions;102 static PSUPQUERYFUNCS g_pFunctions; 104 103 105 104 #ifndef VBOX_WITHOUT_IDT_PATCHING … … 113 112 /** Init counter. */ 114 113 static unsigned g_cInits = 0; 114 /** PAGE_ALLOC support indicator. */ 115 static bool g_fSupportsPageAllocLocked = true; 115 116 /** Fake mode indicator. (~0 at first, 0 or 1 after first test) */ 116 117 static uint32_t g_u32FakeMode = ~0; … … 183 184 */ 184 185 int rc = suplibOsInit(cbReserve); 185 if ( VBOX_SUCCESS(rc))186 if (RT_SUCCESS(rc)) 186 187 { 187 188 /* 188 189 * Negotiate the cookie. 189 190 */ 190 SUPCOOKIE_IN In; 191 SUPCOOKIE_OUT Out = {0,0,0,0,0,NIL_RTR0PTR}; 192 strcpy(In.szMagic, SUPCOOKIE_MAGIC); 193 In.u32ReqVersion = SUPDRVIOC_VERSION; 194 In.u32MinVersion = SUPDRVIOC_VERSION & 0xffff0000; 195 rc = suplibOsIOCtl(SUP_IOCTL_COOKIE, &In, sizeof(In), &Out, sizeof(Out)); 196 if (VBOX_SUCCESS(rc)) 191 SUPCOOKIE CookieReq; 192 memset(&CookieReq, 0xff, sizeof(CookieReq)); 193 CookieReq.Hdr.u32Cookie = SUPCOOKIE_INITIAL_COOKIE; 194 CookieReq.Hdr.u32SessionCookie = RTRandU32(); 195 CookieReq.Hdr.cbIn = SUP_IOCTL_COOKIE_SIZE_IN; 196 CookieReq.Hdr.cbOut = SUP_IOCTL_COOKIE_SIZE_OUT; 197 CookieReq.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 198 CookieReq.Hdr.rc = VERR_INTERNAL_ERROR; 199 strcpy(CookieReq.u.In.szMagic, SUPCOOKIE_MAGIC); 200 CookieReq.u.In.u32ReqVersion = SUPDRVIOC_VERSION; 201 CookieReq.u.In.u32MinVersion = SUPDRVIOC_VERSION & 0xffff0000; 202 rc = suplibOsIOCtl(SUP_IOCTL_COOKIE, &CookieReq, SUP_IOCTL_COOKIE_SIZE); 203 if ( RT_SUCCESS(rc) 204 && RT_SUCCESS(CookieReq.Hdr.rc)) 197 205 { 198 if (( Out.u32SessionVersion & 0xffff0000) == (SUPDRVIOC_VERSION & 0xffff0000))206 if ((CookieReq.u.Out.u32SessionVersion & 0xffff0000) == (SUPDRVIOC_VERSION & 0xffff0000)) 199 207 { 200 208 /* 201 209 * Query the functions. 202 210 */ 203 SUPQUERYFUNCS_IN FuncsIn; 204 FuncsIn.u32Cookie = Out.u32Cookie; 205 FuncsIn.u32SessionCookie = Out.u32SessionCookie; 206 unsigned cbFuncsOut = RT_OFFSETOF(SUPQUERYFUNCS_OUT, aFunctions[Out.cFunctions]); 207 PSUPQUERYFUNCS_OUT pFuncsOut = (PSUPQUERYFUNCS_OUT)RTMemAllocZ(cbFuncsOut); 208 if (pFuncsOut) 211 PSUPQUERYFUNCS pFuncsReq = (PSUPQUERYFUNCS)RTMemAllocZ(SUP_IOCTL_QUERY_FUNCS_SIZE(CookieReq.u.Out.cFunctions)); 212 if (pFuncsReq) 209 213 { 210 rc = suplibOsIOCtl(SUP_IOCTL_QUERY_FUNCS, &FuncsIn, sizeof(FuncsIn), pFuncsOut, cbFuncsOut); 211 if (VBOX_SUCCESS(rc)) 214 pFuncsReq->Hdr.u32Cookie = CookieReq.u.Out.u32Cookie; 215 pFuncsReq->Hdr.u32SessionCookie = CookieReq.u.Out.u32SessionCookie; 216 pFuncsReq->Hdr.cbIn = SUP_IOCTL_QUERY_FUNCS_SIZE_IN; 217 pFuncsReq->Hdr.cbOut = SUP_IOCTL_QUERY_FUNCS_SIZE_OUT(CookieReq.u.Out.cFunctions); 218 pFuncsReq->Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 219 pFuncsReq->Hdr.rc = VERR_INTERNAL_ERROR; 220 rc = suplibOsIOCtl(SUP_IOCTL_QUERY_FUNCS(CookieReq.u.Out.cFunctions), pFuncsReq, SUP_IOCTL_QUERY_FUNCS_SIZE(CookieReq.u.Out.cFunctions)); 221 if (RT_SUCCESS(rc)) 222 rc = pFuncsReq->Hdr.rc; 223 if (RT_SUCCESS(rc)) 212 224 { 213 g_u32Cookie = Out.u32Cookie;214 g_u32SessionCookie = Out.u32SessionCookie;215 g_pSession = Out.pSession;216 g_pFunctions = pFuncs Out;225 g_u32Cookie = CookieReq.u.Out.u32Cookie; 226 g_u32SessionCookie = CookieReq.u.Out.u32SessionCookie; 227 g_pSession = CookieReq.u.Out.pSession; 228 g_pFunctions = pFuncsReq; 217 229 if (ppSession) 218 *ppSession = Out.pSession;230 *ppSession = CookieReq.u.Out.pSession; 219 231 220 232 /* … … 224 236 if (!g_pSUPGlobalInfoPage) 225 237 { 226 SUPGIPMAP_IN GipIn = {0}; 227 SUPGIPMAP_OUT GipOut = {NULL, 0}; 228 GipIn.u32Cookie = Out.u32Cookie; 229 GipIn.u32SessionCookie = Out.u32SessionCookie; 230 rc = suplibOsIOCtl(SUP_IOCTL_GIP_MAP, &GipIn, sizeof(GipIn), &GipOut, sizeof(GipOut)); 231 if (VBOX_SUCCESS(rc)) 238 SUPGIPMAP GipMapReq; 239 GipMapReq.Hdr.u32Cookie = g_u32Cookie; 240 GipMapReq.Hdr.u32SessionCookie = g_u32SessionCookie; 241 GipMapReq.Hdr.cbIn = SUP_IOCTL_GIP_MAP_SIZE_IN; 242 GipMapReq.Hdr.cbOut = SUP_IOCTL_GIP_MAP_SIZE_OUT; 243 GipMapReq.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 244 GipMapReq.Hdr.rc = VERR_INTERNAL_ERROR; 245 GipMapReq.u.Out.HCPhysGip = NIL_RTHCPHYS; 246 GipMapReq.u.Out.pGipR0 = NIL_RTR0PTR; 247 GipMapReq.u.Out.pGipR3 = NULL; 248 rc = suplibOsIOCtl(SUP_IOCTL_GIP_MAP, &GipMapReq, SUP_IOCTL_GIP_MAP_SIZE); 249 if (RT_SUCCESS(rc)) 250 rc = pFuncsReq->Hdr.rc; 251 if (RT_SUCCESS(rc)) 232 252 { 233 AssertRelease(Gip Out.pGipR3->u32Magic == SUPGLOBALINFOPAGE_MAGIC);234 AssertRelease(Gip Out.pGipR3->u32Version >= SUPGLOBALINFOPAGE_VERSION);235 ASMAtomicXchgSize(&g_HCPhysSUPGlobalInfoPage, Gip Out.HCPhysGip);236 ASMAtomicCmpXchgPtr((void * volatile *)&g_pSUPGlobalInfoPage, (void *)GipOut.pGipR3, NULL);237 ASMAtomicCmpXchgPtr((void * volatile *)&g_pSUPGlobalInfoPageR0, (void *)Gip Out.pGipR0, NULL);253 AssertRelease(GipMapReq.u.Out.pGipR3->u32Magic == SUPGLOBALINFOPAGE_MAGIC); 254 AssertRelease(GipMapReq.u.Out.pGipR3->u32Version >= SUPGLOBALINFOPAGE_VERSION); 255 ASMAtomicXchgSize(&g_HCPhysSUPGlobalInfoPage, GipMapReq.u.Out.HCPhysGip); 256 ASMAtomicCmpXchgPtr((void * volatile *)&g_pSUPGlobalInfoPage, GipMapReq.u.Out.pGipR3, NULL); 257 ASMAtomicCmpXchgPtr((void * volatile *)&g_pSUPGlobalInfoPageR0, (void *)GipMapReq.u.Out.pGipR0, NULL); 238 258 } 239 else240 rc = VINF_SUCCESS;241 259 } 242 return rc;260 return VINF_SUCCESS; 243 261 } 244 RTMemFree(pFuncsOut); 262 263 /* bailout */ 264 RTMemFree(pFuncsReq); 245 265 } 246 266 else … … 250 270 { 251 271 LogRel(("Support driver version mismatch: SessionVersion=%#x DriverVersion=%#x ClientVersion=%#x\n", 252 Out.u32SessionVersion,Out.u32DriverVersion, SUPDRVIOC_VERSION));272 CookieReq.u.Out.u32SessionVersion, CookieReq.u.Out.u32DriverVersion, SUPDRVIOC_VERSION)); 253 273 rc = VERR_VM_DRIVER_VERSION_MISMATCH; 254 274 } … … 256 276 else 257 277 { 258 if (rc == VERR_INVALID_PARAMETER) /* for pre 0x00040002 drivers */ 259 rc = VERR_VM_DRIVER_VERSION_MISMATCH; 260 if (rc == VERR_VM_DRIVER_VERSION_MISMATCH) 261 LogRel(("Support driver version mismatch: DriverVersion=%#x ClientVersion=%#x\n", 262 Out.u32DriverVersion, SUPDRVIOC_VERSION)); 263 else 264 LogRel(("Support driver version/Cookie negotiations error: rc=%Vrc\n", rc)); 278 if (RT_SUCCESS(rc)) 279 { 280 rc = CookieReq.Hdr.rc; 281 LogRel(("Support driver version mismatch: DriverVersion=%#x ClientVersion=%#x rc=%Rrc\n", 282 CookieReq.u.Out.u32DriverVersion, SUPDRVIOC_VERSION, rc)); 283 if (rc != VERR_VM_DRIVER_VERSION_MISMATCH) 284 rc = VERR_VM_DRIVER_VERSION_MISMATCH; 285 } 286 else 287 { 288 /* for pre 0x00060000 drivers */ 289 LogRel(("Support driver version mismatch: DriverVersion=too-old ClientVersion=%#x\n", SUPDRVIOC_VERSION)); 290 rc = VERR_VM_DRIVER_VERSION_MISMATCH; 291 } 265 292 } 266 293 … … 325 352 326 353 /* fake r0 functions. */ 327 g_pFunctions = (PSUPQUERYFUNCS _OUT)RTMemAllocZ(RT_OFFSETOF(SUPQUERYFUNCS_OUT, aFunctions[RT_ELEMENTS(s_aFakeFunctions)]));354 g_pFunctions = (PSUPQUERYFUNCS)RTMemAllocZ(SUP_IOCTL_QUERY_FUNCS_SIZE(RT_ELEMENTS(s_aFakeFunctions))); 328 355 if (g_pFunctions) 329 356 { 330 g_pFunctions-> cFunctions = RT_ELEMENTS(s_aFakeFunctions);331 memcpy(&g_pFunctions-> aFunctions[0], &s_aFakeFunctions[0], sizeof(s_aFakeFunctions));357 g_pFunctions->u.Out.cFunctions = RT_ELEMENTS(s_aFakeFunctions); 358 memcpy(&g_pFunctions->u.Out.aFunctions[0], &s_aFakeFunctions[0], sizeof(s_aFakeFunctions)); 332 359 g_pSession = (PSUPDRVSESSION)(void *)g_pFunctions; 333 360 if (ppSession) … … 338 365 339 366 /* fake the GIP. */ 340 g_pSUPGlobalInfoPage = (PSUPGLOBALINFOPAGE)RTMemPageAlloc (PAGE_SIZE);367 g_pSUPGlobalInfoPage = (PSUPGLOBALINFOPAGE)RTMemPageAllocZ(PAGE_SIZE); 341 368 if (g_pSUPGlobalInfoPage) 342 369 { … … 399 426 SUPR3DECL(SUPPAGINGMODE) SUPGetPagingMode(void) 400 427 { 428 /* fake */ 429 if (RT_UNLIKELY(g_u32FakeMode)) 430 #ifdef RT_ARCH_AMD64 431 return SUPPAGINGMODE_AMD64_GLOBAL_NX; 432 #else 433 return SUPPAGINGMODE_32_BIT_GLOBAL; 434 #endif 435 401 436 /* 402 437 * Issue IOCtl to the SUPDRV kernel module. 403 438 */ 404 SUPGETPAGINGMODE_IN In; 405 In.u32Cookie = g_u32Cookie; 406 In.u32SessionCookie = g_u32SessionCookie; 407 SUPGETPAGINGMODE_OUT Out = {SUPPAGINGMODE_INVALID}; 439 SUPGETPAGINGMODE Req; 440 Req.Hdr.u32Cookie = g_u32Cookie; 441 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 442 Req.Hdr.cbIn = SUP_IOCTL_GET_PAGING_MODE_SIZE_IN; 443 Req.Hdr.cbOut = SUP_IOCTL_GET_PAGING_MODE_SIZE_OUT; 444 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 445 Req.Hdr.rc = VERR_INTERNAL_ERROR; 446 int rc = suplibOsIOCtl(SUP_IOCTL_GET_PAGING_MODE, &Req, SUP_IOCTL_GET_PAGING_MODE_SIZE); 447 if ( RT_FAILURE(rc) 448 || RT_FAILURE(Req.Hdr.rc)) 449 { 450 LogRel(("SUPGetPagingMode: %Rrc %Rrc\n", rc, Req.Hdr.rc)); 451 Req.u.Out.enmMode = SUPPAGINGMODE_INVALID; 452 } 453 454 return Req.u.Out.enmMode; 455 } 456 457 458 /** 459 * For later. 460 */ 461 static int supCallVMMR0ExFake(PVMR0 pVMR0, unsigned uOperation, void *pvVMMReq, size_t cbVMMReq) 462 { 463 AssertMsgFailed(("%d\n", uOperation)); 464 return VERR_NOT_SUPPORTED; 465 } 466 467 468 SUPR3DECL(int) SUPCallVMMR0Ex(PVMR0 pVMR0, unsigned uOperation, void *pvVMMReq, size_t cbVMMReq) 469 { 470 /* 471 * The following operations don't belong here. 472 */ 473 AssertMsgReturn( uOperation != VMMR0_DO_RAW_RUN 474 && uOperation != VMMR0_DO_HWACC_RUN 475 && uOperation != VMMR0_DO_NOP, 476 ("%#x\n", uOperation), 477 VERR_INTERNAL_ERROR); 478 /* fake */ 479 if (RT_UNLIKELY(g_u32FakeMode)) 480 return supCallVMMR0ExFake(pVMR0, uOperation, pvVMMReq, cbVMMReq); 481 408 482 int rc; 409 if (!g_u32FakeMode) 410 { 411 rc = suplibOsIOCtl(SUP_IOCTL_GET_PAGING_MODE, &In, sizeof(In), &Out, sizeof(Out)); 412 if (VBOX_FAILURE(rc)) 413 Out.enmMode = SUPPAGINGMODE_INVALID; 414 } 415 else 416 #ifdef RT_ARCH_AMD64 417 Out.enmMode = SUPPAGINGMODE_AMD64_GLOBAL_NX; 418 #else 419 Out.enmMode = SUPPAGINGMODE_32_BIT_GLOBAL; 420 #endif 421 422 return Out.enmMode; 423 } 424 425 SUPR3DECL(int) SUPCallVMMR0Ex(PVMR0 pVMR0, unsigned uOperation, void *pvArg, unsigned cbArg) 426 { 427 /* 428 * Issue IOCtl to the SUPDRV kernel module. 429 */ 430 SUPCALLVMMR0_IN In; 431 In.u32Cookie = g_u32Cookie; 432 In.u32SessionCookie = g_u32SessionCookie; 433 In.pVMR0 = pVMR0; 434 In.uOperation = uOperation; 435 In.cbArg = cbArg; 436 In.pvArg = pvArg; 437 Assert(!g_u32FakeMode); 438 SUPCALLVMMR0_OUT Out = {VINF_SUCCESS}; 439 int rc = suplibOsIOCtl(SUP_IOCTL_CALL_VMMR0, &In, sizeof(In), &Out, sizeof(Out)); 440 if (VBOX_SUCCESS(rc)) 441 rc = Out.rc; 483 if (!cbVMMReq) 484 { 485 /* no data. */ 486 SUPCALLVMMR0 Req; 487 Req.Hdr.u32Cookie = g_u32Cookie; 488 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 489 Req.Hdr.cbIn = SUP_IOCTL_CALL_VMMR0_SIZE_IN(0); 490 Req.Hdr.cbOut = SUP_IOCTL_CALL_VMMR0_SIZE_OUT(0); 491 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 492 Req.Hdr.rc = VERR_INTERNAL_ERROR; 493 Req.u.In.pVMR0 = pVMR0; 494 Req.u.In.uOperation = uOperation; 495 Req.u.In.uArg = (uintptr_t)pvVMMReq; 496 rc = suplibOsIOCtl(SUP_IOCTL_CALL_VMMR0(0), &Req, SUP_IOCTL_CALL_VMMR0_SIZE(0)); 497 if (RT_SUCCESS(rc)) 498 rc = Req.Hdr.rc; 499 } 500 else if (SUP_IOCTL_CALL_VMMR0_SIZE(cbVMMReq) < _4K) /* FreeBSD won't copy more than 4K. */ 501 { 502 AssertPtr(pvVMMReq); 503 PSUPCALLVMMR0 pReq = (PSUPCALLVMMR0)alloca(SUP_IOCTL_CALL_VMMR0_SIZE(cbVMMReq)); 504 pReq->Hdr.u32Cookie = g_u32Cookie; 505 pReq->Hdr.u32SessionCookie = g_u32SessionCookie; 506 pReq->Hdr.cbIn = SUP_IOCTL_CALL_VMMR0_SIZE_IN(cbVMMReq); 507 pReq->Hdr.cbOut = SUP_IOCTL_CALL_VMMR0_SIZE_OUT(cbVMMReq); 508 pReq->Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 509 pReq->Hdr.rc = VERR_INTERNAL_ERROR; 510 pReq->u.In.pVMR0 = pVMR0; 511 pReq->u.In.uOperation = uOperation; 512 pReq->u.In.uArg = 0; 513 memcpy(&pReq->abReqPkt[0], pvVMMReq, cbVMMReq); 514 rc = suplibOsIOCtl(SUP_IOCTL_CALL_VMMR0(cbVMMReq), pReq, SUP_IOCTL_CALL_VMMR0_SIZE(cbVMMReq)); 515 if (RT_SUCCESS(rc)) 516 rc = pReq->Hdr.rc; 517 memcpy(pvVMMReq, &pReq->abReqPkt[0], cbVMMReq); 518 } 519 else /** @todo may have to remove the size limits one this request... */ 520 AssertMsgFailedReturn(("cbVMMReq=%#x\n", cbVMMReq), VERR_INTERNAL_ERROR); 442 521 return rc; 443 522 } … … 460 539 return suplibOSIOCtlFast(SUP_IOCTL_FAST_DO_HWACC_RUN); 461 540 } 462 if ( uOperation == VMMR0_DO_NOP)541 if (RT_LIKELY(uOperation == VMMR0_DO_NOP)) 463 542 { 464 543 Assert(!pvArg); 465 544 return suplibOSIOCtlFast(SUP_IOCTL_FAST_DO_NOP); 466 545 } 467 return SUPCallVMMR0Ex(pVMR0, uOperation, pvArg, pvArg ? sizeof(pvArg) : 0);546 AssertMsgFailedReturn(("uOperation=%#x\n", uOperation), VERR_INTERNAL_ERROR); 468 547 #endif 469 548 } … … 472 551 SUPR3DECL(int) SUPSetVMForFastIOCtl(PVMR0 pVMR0) 473 552 { 474 SUPSETVMFORFAST_IN In; 475 In.u32Cookie = g_u32Cookie; 476 In.u32SessionCookie = g_u32SessionCookie; 477 In.pVMR0 = pVMR0; 478 int rc; 479 if (RT_LIKELY(!g_u32FakeMode)) 480 rc = suplibOsIOCtl(SUP_IOCTL_SET_VM_FOR_FAST, &In, sizeof(In), NULL, 0); 481 else 482 rc = VINF_SUCCESS; 553 if (RT_UNLIKELY(g_u32FakeMode)) 554 return VINF_SUCCESS; 555 556 SUPSETVMFORFAST Req; 557 Req.Hdr.u32Cookie = g_u32Cookie; 558 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 559 Req.Hdr.cbIn = SUP_IOCTL_SET_VM_FOR_FAST_SIZE_IN; 560 Req.Hdr.cbOut = SUP_IOCTL_SET_VM_FOR_FAST_SIZE_OUT; 561 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 562 Req.Hdr.rc = VERR_INTERNAL_ERROR; 563 Req.u.In.pVMR0 = pVMR0; 564 int rc = suplibOsIOCtl(SUP_IOCTL_SET_VM_FOR_FAST, &Req, SUP_IOCTL_SET_VM_FOR_FAST_SIZE); 565 if (RT_SUCCESS(rc)) 566 rc = Req.Hdr.rc; 483 567 return rc; 568 } 569 570 571 SUPR3DECL(int) SUPPageAlloc(size_t cPages, void **ppvPages) 572 { 573 /* 574 * Validate. 575 */ 576 AssertPtrReturn(ppvPages, VERR_INVALID_POINTER); 577 *ppvPages = NULL; 578 AssertReturn(cPages > 0, VERR_INVALID_PARAMETER); 579 580 #ifdef RT_OS_WINDOWS 581 /* 582 * Temporary hack for windows until we've sorted out the 583 * locked memory that doesn't need to be accessible from kernel space. 584 */ 585 return SUPPageAllocLockedEx(cPages, ppvPages, NULL); 586 #else 587 /* 588 * Call OS specific worker. 589 */ 590 return suplibOsPageAlloc(cPages, ppvPages); 591 #endif 592 } 593 594 595 SUPR3DECL(int) SUPPageFree(void *pvPages, size_t cPages) 596 { 597 /* 598 * Validate. 599 */ 600 AssertPtrReturn(pvPages, VERR_INVALID_POINTER); 601 AssertReturn(cPages > 0, VERR_INVALID_PARAMETER); 602 603 #ifdef RT_OS_WINDOWS 604 /* 605 * Temporary hack for windows, see above. 606 */ 607 return SUPPageFreeLocked(pvPages, cPages); 608 #else 609 /* 610 * Call OS specific worker. 611 */ 612 return suplibOsPageFree(pvPages, cPages); 613 #endif 484 614 } 485 615 … … 494 624 AssertPtr(paPages); 495 625 496 /* 497 * Issue IOCtl to the SUPDRV kernel module. 498 */ 499 SUPPINPAGES_IN In; 500 In.u32Cookie = g_u32Cookie; 501 In.u32SessionCookie = g_u32SessionCookie; 502 In.pvR3 = pvStart; 503 In.cPages = cPages; AssertRelease(In.cPages == cPages); 504 int rc; 505 if (!g_u32FakeMode) 506 { 507 PSUPPINPAGES_OUT pOut; 508 AssertCompile(sizeof(paPages[0]) == sizeof(pOut->aPages[0])); 509 510 #if 0 511 size_t cbOut = RT_OFFSETOF(SUPPINPAGES_OUT, aPages[cPages]); 512 pOut = (PSUPPINPAGES_OUT)RTMemTmpAllocZ(cbOut); 513 if (!pOut) 514 return VERR_NO_TMP_MEMORY; 515 516 rc = suplibOsIOCtl(SUP_IOCTL_PINPAGES, &In, sizeof(In), pOut, cbOut); 517 if (RT_SUCCESS(rc)) 518 memcpy(paPages, &pOut->aPages[0], sizeof(paPages[0]) * cPages); 519 RTMemTmpFree(pOut); 520 521 #else 522 /* a hack to save some time. */ 523 pOut = (PSUPPINPAGES_OUT)(void*)paPages; 524 Assert(RT_OFFSETOF(SUPPINPAGES_OUT, aPages) == 0 && sizeof(paPages[0]) == sizeof(pOut->aPages[0])); 525 rc = suplibOsIOCtl(SUP_IOCTL_PINPAGES, &In, sizeof(In), pOut, RT_OFFSETOF(SUPPINPAGES_OUT, aPages[cPages])); 526 #endif 527 } 528 else 529 { 530 /* fake a successfull result. */ 626 /* fake */ 627 if (RT_UNLIKELY(g_u32FakeMode)) 628 { 531 629 RTHCPHYS Phys = (uintptr_t)pvStart + PAGE_SIZE * 1024; 532 630 unsigned iPage = cPages; 533 631 while (iPage-- > 0) 534 632 paPages[iPage].Phys = Phys + (iPage << PAGE_SHIFT); 535 rc = VINF_SUCCESS; 536 } 633 return VINF_SUCCESS; 634 } 635 636 /* 637 * Issue IOCtl to the SUPDRV kernel module. 638 */ 639 int rc; 640 PSUPPAGELOCK pReq = (PSUPPAGELOCK)RTMemTmpAllocZ(SUP_IOCTL_PAGE_LOCK_SIZE(cPages)); 641 if (RT_LIKELY(pReq)) 642 { 643 pReq->Hdr.u32Cookie = g_u32Cookie; 644 pReq->Hdr.u32SessionCookie = g_u32SessionCookie; 645 pReq->Hdr.cbIn = SUP_IOCTL_PAGE_LOCK_SIZE_IN; 646 pReq->Hdr.cbOut = SUP_IOCTL_PAGE_LOCK_SIZE_OUT(cPages); 647 pReq->Hdr.fFlags = SUPREQHDR_FLAGS_MAGIC | SUPREQHDR_FLAGS_EXTRA_OUT; 648 pReq->Hdr.rc = VERR_INTERNAL_ERROR; 649 pReq->u.In.pvR3 = pvStart; 650 pReq->u.In.cPages = cPages; AssertRelease(pReq->u.In.cPages == cPages); 651 rc = suplibOsIOCtl(SUP_IOCTL_PAGE_LOCK, pReq, SUP_IOCTL_PAGE_LOCK_SIZE(cPages)); 652 if (RT_SUCCESS(rc)) 653 rc = pReq->Hdr.rc; 654 if (RT_SUCCESS(rc)) 655 { 656 for (uint32_t iPage = 0; iPage < cPages; iPage++) 657 { 658 paPages[iPage].uReserved = 0; 659 paPages[iPage].Phys = pReq->u.Out.aPages[iPage]; 660 Assert(!(paPages[iPage].Phys & ~X86_PTE_PAE_PG_MASK)); 661 } 662 } 663 RTMemTmpFree(pReq); 664 } 665 else 666 rc = VERR_NO_TMP_MEMORY; 537 667 538 668 return rc; … … 548 678 AssertMsg(RT_ALIGN_P(pvStart, PAGE_SIZE) == pvStart, ("pvStart (%p) must be page aligned\n", pvStart)); 549 679 680 /* fake */ 681 if (RT_UNLIKELY(g_u32FakeMode)) 682 return VINF_SUCCESS; 683 550 684 /* 551 685 * Issue IOCtl to the SUPDRV kernel module. 552 686 */ 553 SUPUNPINPAGES_IN In; 554 In.u32Cookie = g_u32Cookie; 555 In.u32SessionCookie = g_u32SessionCookie; 556 In.pvR3 = pvStart; 687 SUPPAGEUNLOCK Req; 688 Req.Hdr.u32Cookie = g_u32Cookie; 689 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 690 Req.Hdr.cbIn = SUP_IOCTL_PAGE_UNLOCK_SIZE_IN; 691 Req.Hdr.cbOut = SUP_IOCTL_PAGE_UNLOCK_SIZE_OUT; 692 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 693 Req.Hdr.rc = VERR_INTERNAL_ERROR; 694 Req.u.In.pvR3 = pvStart; 695 int rc = suplibOsIOCtl(SUP_IOCTL_PAGE_UNLOCK, &Req, SUP_IOCTL_PAGE_UNLOCK_SIZE); 696 if (RT_SUCCESS(rc)) 697 rc = Req.Hdr.rc; 698 return rc; 699 } 700 701 702 SUPR3DECL(int) SUPPageAllocLocked(size_t cPages, void **ppvPages) 703 { 704 return SUPPageAllocLockedEx(cPages, ppvPages, NULL); 705 } 706 707 708 /** 709 * Fallback for SUPPageAllocLockedEx on systems where RTR0MemObjPhysAllocNC isn't supported. 710 */ 711 static int supPageAllocLockedFallback(size_t cPages, void **ppvPages, PSUPPAGE paPages) 712 { 713 int rc = suplibOsPageAlloc(cPages, ppvPages); 714 if (RT_SUCCESS(rc)) 715 { 716 if (!paPages) 717 paPages = (PSUPPAGE)alloca(sizeof(paPages[0]) * cPages); 718 rc = SUPPageLock(*ppvPages, cPages, paPages); 719 if (RT_FAILURE(rc)) 720 suplibOsPageFree(*ppvPages, cPages); 721 } 722 return rc; 723 } 724 725 726 SUPR3DECL(int) SUPPageAllocLockedEx(size_t cPages, void **ppvPages, PSUPPAGE paPages) 727 { 728 /* 729 * Validate. 730 */ 731 AssertPtrReturn(ppvPages, VERR_INVALID_POINTER); 732 *ppvPages = NULL; 733 AssertReturn(cPages > 0, VERR_INVALID_PARAMETER); 734 735 /* fake */ 736 if (RT_UNLIKELY(g_u32FakeMode)) 737 { 738 *ppvPages = RTMemPageAllocZ((size_t)cPages * PAGE_SIZE); 739 if (!*ppvPages) 740 return VERR_NO_MEMORY; 741 if (paPages) 742 for (size_t iPage = 0; iPage < cPages; iPage++) 743 { 744 paPages[iPage].uReserved = 0; 745 paPages[iPage].Phys = (iPage + 1234) << PAGE_SHIFT; 746 Assert(!(paPages[iPage].Phys & ~X86_PTE_PAE_PG_MASK)); 747 } 748 return VINF_SUCCESS; 749 } 750 751 /* use fallback? */ 752 if (!g_fSupportsPageAllocLocked) 753 return supPageAllocLockedFallback(cPages, ppvPages, paPages); 754 755 /* 756 * Issue IOCtl to the SUPDRV kernel module. 757 */ 557 758 int rc; 558 if (!g_u32FakeMode) 559 rc = suplibOsIOCtl(SUP_IOCTL_UNPINPAGES, &In, sizeof(In), NULL, 0); 759 PSUPPAGEALLOC pReq = (PSUPPAGEALLOC)RTMemTmpAllocZ(SUP_IOCTL_PAGE_ALLOC_SIZE(cPages)); 760 if (pReq) 761 { 762 pReq->Hdr.u32Cookie = g_u32Cookie; 763 pReq->Hdr.u32SessionCookie = g_u32SessionCookie; 764 pReq->Hdr.cbIn = SUP_IOCTL_PAGE_ALLOC_SIZE_IN; 765 pReq->Hdr.cbOut = SUP_IOCTL_PAGE_ALLOC_SIZE_OUT(cPages); 766 pReq->Hdr.fFlags = SUPREQHDR_FLAGS_MAGIC | SUPREQHDR_FLAGS_EXTRA_OUT; 767 pReq->Hdr.rc = VERR_INTERNAL_ERROR; 768 pReq->u.In.cPages = cPages; AssertRelease(pReq->u.In.cPages == cPages); 769 rc = suplibOsIOCtl(SUP_IOCTL_PAGE_ALLOC, pReq, SUP_IOCTL_PAGE_ALLOC_SIZE(cPages)); 770 if (RT_SUCCESS(rc)) 771 { 772 rc = pReq->Hdr.rc; 773 if (RT_SUCCESS(rc)) 774 { 775 *ppvPages = pReq->u.Out.pvR3; 776 if (paPages) 777 for (size_t iPage = 0; iPage < cPages; iPage++) 778 { 779 paPages[iPage].uReserved = 0; 780 paPages[iPage].Phys = pReq->u.Out.aPages[iPage]; 781 Assert(!(paPages[iPage].Phys & ~X86_PTE_PAE_PG_MASK)); 782 } 783 } 784 else if (rc == VERR_NOT_SUPPORTED) 785 { 786 g_fSupportsPageAllocLocked = false; 787 rc = supPageAllocLockedFallback(cPages, ppvPages, paPages); 788 } 789 } 790 791 RTMemTmpFree(pReq); 792 } 560 793 else 561 rc = VINF_SUCCESS; 562 794 rc = VERR_NO_TMP_MEMORY; 563 795 return rc; 564 796 } 565 797 566 798 799 SUPR3DECL(int) SUPPageFreeLocked(void *pvPages, size_t cPages) 800 { 801 /* 802 * Validate. 803 */ 804 AssertPtrReturn(pvPages, VERR_INVALID_POINTER); 805 AssertReturn(cPages > 0, VERR_INVALID_PARAMETER); 806 807 /* fake */ 808 if (RT_UNLIKELY(g_u32FakeMode)) 809 { 810 RTMemPageFree(pvPages); 811 return VINF_SUCCESS; 812 } 813 814 /* 815 * Issue IOCtl to the SUPDRV kernel module. 816 */ 817 int rc; 818 if (g_fSupportsPageAllocLocked) 819 { 820 SUPPAGEFREE Req; 821 Req.Hdr.u32Cookie = g_u32Cookie; 822 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 823 Req.Hdr.cbIn = SUP_IOCTL_PAGE_FREE_SIZE_IN; 824 Req.Hdr.cbOut = SUP_IOCTL_PAGE_FREE_SIZE_OUT; 825 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 826 Req.Hdr.rc = VERR_INTERNAL_ERROR; 827 Req.u.In.pvR3 = pvPages; 828 rc = suplibOsIOCtl(SUP_IOCTL_PAGE_FREE, &Req, SUP_IOCTL_PAGE_FREE_SIZE); 829 if (RT_SUCCESS(rc)) 830 rc = Req.Hdr.rc; 831 } 832 else 833 { 834 /* fallback */ 835 rc = SUPPageUnlock(pvPages); 836 if (RT_SUCCESS(rc)) 837 rc = suplibOsPageFree(pvPages, cPages); 838 } 839 return rc; 840 } 841 842 567 843 SUPR3DECL(void *) SUPContAlloc(size_t cPages, PRTHCPHYS pHCPhys) 568 844 { … … 576 852 * Validate. 577 853 */ 578 AssertMsg(cPages > 0 && cPages < 256, ("cPages=%d must be > 0 and < 256\n", cPages)); 579 AssertPtr(pHCPhys); 854 AssertPtrReturn(pHCPhys, NULL); 580 855 *pHCPhys = NIL_RTHCPHYS; 581 AssertPtrNull (pR0Ptr);856 AssertPtrNullReturn(pR0Ptr, NULL); 582 857 if (pR0Ptr) 583 858 *pR0Ptr = NIL_RTR0PTR; 859 AssertPtrNullReturn(pHCPhys, NULL); 860 AssertMsgReturn(cPages > 0 && cPages < 256, ("cPages=%d must be > 0 and < 256\n", cPages), NULL); 861 862 /* fake */ 863 if (RT_UNLIKELY(g_u32FakeMode)) 864 { 865 void *pv = RTMemPageAllocZ(cPages * PAGE_SIZE); 866 if (pR0Ptr) 867 *pR0Ptr = (RTR0PTR)pv; 868 if (pHCPhys) 869 *pHCPhys = (uintptr_t)pv + (PAGE_SHIFT * 1024); 870 return pv; 871 } 584 872 585 873 /* 586 874 * Issue IOCtl to the SUPDRV kernel module. 587 875 */ 588 SUPCONTALLOC_IN In; 589 In.u32Cookie = g_u32Cookie; 590 In.u32SessionCookie = g_u32SessionCookie; 591 In.cPages = cPages; 592 SUPCONTALLOC_OUT Out; 593 int rc; 594 if (!g_u32FakeMode) 595 rc = suplibOsIOCtl(SUP_IOCTL_CONT_ALLOC, &In, sizeof(In), &Out, sizeof(Out)); 596 else 597 { 598 rc = SUPPageAlloc(In.cPages, &Out.pvR3); 599 Out.HCPhys = (uintptr_t)Out.pvR3 + (PAGE_SHIFT * 1024); 600 Out.pvR0 = (uintptr_t)Out.pvR3; 601 } 602 if (VBOX_SUCCESS(rc)) 603 { 604 *pHCPhys = (RTHCPHYS)Out.HCPhys; 876 SUPCONTALLOC Req; 877 Req.Hdr.u32Cookie = g_u32Cookie; 878 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 879 Req.Hdr.cbIn = SUP_IOCTL_CONT_ALLOC_SIZE_IN; 880 Req.Hdr.cbOut = SUP_IOCTL_CONT_ALLOC_SIZE_OUT; 881 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 882 Req.Hdr.rc = VERR_INTERNAL_ERROR; 883 Req.u.In.cPages = cPages; 884 int rc = suplibOsIOCtl(SUP_IOCTL_CONT_ALLOC, &Req, SUP_IOCTL_CONT_ALLOC_SIZE); 885 if ( RT_SUCCESS(rc) 886 && RT_SUCCESS(Req.Hdr.rc)) 887 { 888 *pHCPhys = Req.u.Out.HCPhys; 605 889 if (pR0Ptr) 606 *pR0Ptr = Out.pvR0;607 return Out.pvR3;890 *pR0Ptr = Req.u.Out.pvR0; 891 return Req.u.Out.pvR3; 608 892 } 609 893 … … 617 901 * Validate. 618 902 */ 619 AssertPtr(pv);620 903 if (!pv) 621 904 return VINF_SUCCESS; 905 AssertPtrReturn(pv, VERR_INVALID_POINTER); 906 AssertReturn(cPages > 0, VERR_INVALID_PARAMETER); 907 908 /* fake */ 909 if (RT_UNLIKELY(g_u32FakeMode)) 910 { 911 RTMemPageFree(pv); 912 return VINF_SUCCESS; 913 } 622 914 623 915 /* 624 916 * Issue IOCtl to the SUPDRV kernel module. 625 917 */ 626 SUPCONTFREE_IN In; 627 In.u32Cookie = g_u32Cookie; 628 In.u32SessionCookie = g_u32SessionCookie; 629 In.pvR3 = pv; 918 SUPCONTFREE Req; 919 Req.Hdr.u32Cookie = g_u32Cookie; 920 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 921 Req.Hdr.cbIn = SUP_IOCTL_CONT_FREE_SIZE_IN; 922 Req.Hdr.cbOut = SUP_IOCTL_CONT_FREE_SIZE_OUT; 923 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 924 Req.Hdr.rc = VERR_INTERNAL_ERROR; 925 Req.u.In.pvR3 = pv; 926 int rc = suplibOsIOCtl(SUP_IOCTL_CONT_FREE, &Req, SUP_IOCTL_CONT_FREE_SIZE); 927 if (RT_SUCCESS(rc)) 928 rc = Req.Hdr.rc; 929 return rc; 930 } 931 932 933 SUPR3DECL(int) SUPLowAlloc(size_t cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages) 934 { 935 /* 936 * Validate. 937 */ 938 AssertPtrReturn(ppvPages, VERR_INVALID_POINTER); 939 *ppvPages = NULL; 940 AssertPtrReturn(paPages, VERR_INVALID_POINTER); 941 AssertMsgReturn(cPages > 0 && cPages < 256, ("cPages=%d must be > 0 and < 256\n", cPages), VERR_INVALID_PARAMETER); 942 943 /* fake */ 944 if (RT_UNLIKELY(g_u32FakeMode)) 945 { 946 *ppvPages = RTMemPageAllocZ((size_t)cPages * PAGE_SIZE); 947 if (!*ppvPages) 948 return VERR_NO_LOW_MEMORY; 949 950 /* fake physical addresses. */ 951 RTHCPHYS Phys = (uintptr_t)*ppvPages + PAGE_SIZE * 1024; 952 unsigned iPage = cPages; 953 while (iPage-- > 0) 954 paPages[iPage].Phys = Phys + (iPage << PAGE_SHIFT); 955 return VINF_SUCCESS; 956 } 957 958 /* 959 * Issue IOCtl to the SUPDRV kernel module. 960 */ 630 961 int rc; 631 if (!g_u32FakeMode) 632 rc = suplibOsIOCtl(SUP_IOCTL_CONT_FREE, &In, sizeof(In), NULL, 0); 962 PSUPLOWALLOC pReq = (PSUPLOWALLOC)RTMemTmpAllocZ(SUP_IOCTL_LOW_ALLOC_SIZE(cPages)); 963 if (pReq) 964 { 965 pReq->Hdr.u32Cookie = g_u32Cookie; 966 pReq->Hdr.u32SessionCookie = g_u32SessionCookie; 967 pReq->Hdr.cbIn = SUP_IOCTL_LOW_ALLOC_SIZE_IN; 968 pReq->Hdr.cbOut = SUP_IOCTL_LOW_ALLOC_SIZE_OUT(cPages); 969 pReq->Hdr.fFlags = SUPREQHDR_FLAGS_MAGIC | SUPREQHDR_FLAGS_EXTRA_OUT; 970 pReq->Hdr.rc = VERR_INTERNAL_ERROR; 971 pReq->u.In.cPages = cPages; AssertRelease(pReq->u.In.cPages == cPages); 972 rc = suplibOsIOCtl(SUP_IOCTL_LOW_ALLOC, pReq, SUP_IOCTL_LOW_ALLOC_SIZE(cPages)); 973 if (RT_SUCCESS(rc)) 974 rc = pReq->Hdr.rc; 975 if (RT_SUCCESS(rc)) 976 { 977 *ppvPages = pReq->u.Out.pvR3; 978 if (ppvPagesR0) 979 *ppvPagesR0 = pReq->u.Out.pvR0; 980 if (paPages) 981 for (size_t iPage = 0; iPage < cPages; iPage++) 982 { 983 paPages[iPage].uReserved = 0; 984 paPages[iPage].Phys = pReq->u.Out.aPages[iPage]; 985 Assert(!(paPages[iPage].Phys & ~X86_PTE_PAE_PG_MASK)); 986 Assert(paPages[iPage].Phys <= UINT32_C(0xffffff000)); 987 } 988 } 989 RTMemTmpFree(pReq); 990 } 633 991 else 634 rc = SUPPageFree(pv, cPages);992 rc = VERR_NO_TMP_MEMORY; 635 993 636 994 return rc; … … 638 996 639 997 640 SUPR3DECL(int) SUPLow Alloc(size_t cPages, void **ppvPages, PRTR0PTR ppvPagesR0, PSUPPAGE paPages)998 SUPR3DECL(int) SUPLowFree(void *pv, size_t cPages) 641 999 { 642 1000 /* 643 1001 * Validate. 644 1002 */ 645 AssertMsg(cPages > 0 && cPages < 256, ("cPages=%d must be > 0 and < 256\n", cPages));646 AssertPtr(ppvPages);647 *ppvPages = NULL;648 AssertPtr(paPages);649 650 int rc;651 if (!g_u32FakeMode)652 {653 /*654 * Issue IOCtl to the SUPDRV kernel module.655 */656 SUPLOWALLOC_IN In;657 In.u32Cookie = g_u32Cookie;658 In.u32SessionCookie = g_u32SessionCookie;659 In.cPages = cPages;660 size_t cbOut = RT_OFFSETOF(SUPLOWALLOC_OUT, aPages[cPages]);661 PSUPLOWALLOC_OUT pOut = (PSUPLOWALLOC_OUT)RTMemTmpAllocZ(cbOut);662 if (pOut)663 {664 rc = suplibOsIOCtl(SUP_IOCTL_LOW_ALLOC, &In, sizeof(In), pOut, cbOut);665 if (VBOX_SUCCESS(rc))666 {667 *ppvPages = pOut->pvR3;668 if (ppvPagesR0)669 *ppvPagesR0 = pOut->pvR0;670 AssertCompile(sizeof(paPages[0]) == sizeof(pOut->aPages[0]));671 memcpy(paPages, &pOut->aPages[0], sizeof(paPages[0]) * cPages);672 #ifdef VBOX_STRICT673 for (unsigned i = 0; i < cPages; i++)674 AssertReleaseMsg( paPages[i].Phys <= 0xfffff000675 && !(paPages[i].Phys & PAGE_OFFSET_MASK)676 && paPages[i].Phys > 0,677 ("[%d]=%VHp\n", paPages[i].Phys));678 #endif679 }680 RTMemTmpFree(pOut);681 }682 else683 rc = VERR_NO_TMP_MEMORY;684 }685 else686 {687 rc = SUPPageAlloc(cPages, ppvPages);688 if (VBOX_SUCCESS(rc))689 {690 /* fake physical addresses. */691 RTHCPHYS Phys = (uintptr_t)*ppvPages + PAGE_SIZE * 1024;692 unsigned iPage = cPages;693 while (iPage-- > 0)694 paPages[iPage].Phys = Phys + (iPage << PAGE_SHIFT);695 }696 }697 698 return rc;699 }700 701 702 SUPR3DECL(int) SUPLowFree(void *pv, size_t cPages)703 {704 /*705 * Validate.706 */707 AssertPtr(pv);708 1003 if (!pv) 709 1004 return VINF_SUCCESS; 1005 AssertPtrReturn(pv, VERR_INVALID_POINTER); 1006 AssertReturn(cPages > 0, VERR_INVALID_PARAMETER); 1007 1008 /* fake */ 1009 if (RT_UNLIKELY(g_u32FakeMode)) 1010 { 1011 RTMemPageFree(pv); 1012 return VINF_SUCCESS; 1013 } 710 1014 711 1015 /* 712 1016 * Issue IOCtl to the SUPDRV kernel module. 713 1017 */ 714 SUPLOWFREE_IN In; 715 In.u32Cookie = g_u32Cookie; 716 In.u32SessionCookie = g_u32SessionCookie; 717 In.pvR3 = pv; 718 int rc; 719 if (!g_u32FakeMode) 720 rc = suplibOsIOCtl(SUP_IOCTL_LOW_FREE, &In, sizeof(In), NULL, 0); 721 else 722 rc = SUPPageFree(pv, cPages); 723 1018 SUPCONTFREE Req; 1019 Req.Hdr.u32Cookie = g_u32Cookie; 1020 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 1021 Req.Hdr.cbIn = SUP_IOCTL_LOW_FREE_SIZE_IN; 1022 Req.Hdr.cbOut = SUP_IOCTL_LOW_FREE_SIZE_OUT; 1023 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 1024 Req.Hdr.rc = VERR_INTERNAL_ERROR; 1025 Req.u.In.pvR3 = pv; 1026 int rc = suplibOsIOCtl(SUP_IOCTL_LOW_FREE, &Req, SUP_IOCTL_LOW_FREE_SIZE); 1027 if (RT_SUCCESS(rc)) 1028 rc = Req.Hdr.rc; 724 1029 return rc; 725 }726 727 SUPR3DECL(int) SUPPageAlloc(size_t cPages, void **ppvPages)728 {729 /*730 * Validate.731 */732 if (cPages == 0)733 {734 AssertMsgFailed(("Invalid param cPages=0, must be > 0\n"));735 return VERR_INVALID_PARAMETER;736 }737 AssertPtr(ppvPages);738 if (!ppvPages)739 return VERR_INVALID_PARAMETER;740 *ppvPages = NULL;741 742 #ifdef RT_OS_WINDOWS743 SUPALLOCPAGE_IN In;744 SUPALLOCPAGE_OUT Out;745 746 In.u32Cookie = g_u32Cookie;747 In.u32SessionCookie = g_u32SessionCookie;748 In.cPages = cPages;749 Out.u32Cookie = g_u32Cookie;750 int rc = suplibOsIOCtl(SUP_IOCTL_PAGE_ALLOC, &In, sizeof(In), &Out, sizeof(Out));751 if (VBOX_SUCCESS(rc))752 *ppvPages = Out.pvR3;753 754 return rc;755 #else756 /*757 * Call OS specific worker.758 */759 return suplibOsPageAlloc(cPages, ppvPages);760 #endif761 }762 763 764 SUPR3DECL(int) SUPPageFree(void *pvPages, size_t cPages)765 {766 /*767 * Validate.768 */769 AssertPtr(pvPages);770 if (!pvPages)771 return VINF_SUCCESS;772 773 #ifdef RT_OS_WINDOWS774 SUPFREEPAGE_IN In;775 776 In.u32Cookie = g_u32Cookie;777 In.u32SessionCookie = g_u32SessionCookie;778 In.pvR3 = pvPages;779 return suplibOsIOCtl(SUP_IOCTL_PAGE_FREE, &In, sizeof(In), NULL, 0);780 #else781 /*782 * Call OS specific worker.783 */784 return suplibOsPageFree(pvPages, cPages);785 #endif786 }787 788 SUPR3DECL(int) SUPPageAllocLocked(size_t cPages, void **ppvPages)789 {790 /*791 * Validate.792 */793 if (cPages == 0)794 {795 AssertMsgFailed(("Invalid param cPages=0, must be > 0\n"));796 return VERR_INVALID_PARAMETER;797 }798 AssertPtr(ppvPages);799 if (!ppvPages)800 return VERR_INVALID_PARAMETER;801 *ppvPages = NULL;802 803 SUPALLOCPAGE_IN In;804 SUPALLOCPAGE_OUT Out;805 806 In.u32Cookie = g_u32Cookie;807 In.u32SessionCookie = g_u32SessionCookie;808 In.cPages = cPages;809 Out.u32Cookie = g_u32Cookie;810 int rc = suplibOsIOCtl(SUP_IOCTL_PAGE_ALLOC, &In, sizeof(In), &Out, sizeof(Out));811 if (VBOX_SUCCESS(rc))812 *ppvPages = Out.pvR3;813 814 return rc;815 }816 817 SUPR3DECL(int) SUPPageFreeLocked(void *pvPages, size_t cPages)818 {819 /*820 * Validate.821 */822 AssertPtr(pvPages);823 if (!pvPages)824 return VINF_SUCCESS;825 826 SUPFREEPAGE_IN In;827 828 In.u32Cookie = g_u32Cookie;829 In.u32SessionCookie = g_u32SessionCookie;830 In.pvR3 = pvPages;831 return suplibOsIOCtl(SUP_IOCTL_PAGE_FREE, &In, sizeof(In), NULL, 0);832 1030 } 833 1031 … … 841 1039 int rc = supLoadModule(pszFilename, pszModule, ppvImageBase); 842 1040 #ifndef VBOX_WITHOUT_IDT_PATCHING 843 if ( VBOX_SUCCESS(rc)1041 if ( RT_SUCCESS(rc) 844 1042 && !strcmp(pszModule, "VMMR0.r0")) 845 1043 { 846 1044 rc = supInstallIDTE(); 847 if ( VBOX_FAILURE(rc))1045 if (RT_FAILURE(rc)) 848 1046 SUPFreeModule(*ppvImageBase); 849 1047 } … … 953 1151 { 954 1152 /* UNI */ 955 SUPIDTINSTALL_IN In; 956 In.u32Cookie = g_u32Cookie; 957 In.u32SessionCookie = g_u32SessionCookie; 958 SUPIDTINSTALL_OUT Out = {3}; 959 960 rc = suplibOsIOCtl(SUP_IOCTL_IDT_INSTALL, &In, sizeof(In), &Out, sizeof(Out)); 961 if (VBOX_SUCCESS(rc)) 1153 SUPIDTINSTALL Req; 1154 Req.Hdr.u32Cookie = g_u32Cookie; 1155 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 1156 Req.Hdr.cbIn = SUP_IOCTL_IDT_INSTALL_SIZE_IN; 1157 Req.Hdr.cbOut = SUP_IOCTL_IDT_INSTALL_SIZE_OUT; 1158 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 1159 Req.Hdr.rc = VERR_INTERNAL_ERROR; 1160 rc = suplibOsIOCtl(SUP_IOCTL_IDT_INSTALL, &Req, SUP_IOCTL_IDT_INSTALL_SIZE); 1161 if (RT_SUCCESS(rc)) 1162 rc = Req.Hdr.rc; 1163 if (RT_SUCCESS(rc)) 962 1164 { 963 g_u8Interrupt = Out.u8Idt;964 rc = suplibGenerateCallVMMR0( Out.u8Idt);1165 g_u8Interrupt = Req.u.Out.u8Idt; 1166 rc = suplibGenerateCallVMMR0(Req.u.Out.u8Idt); 965 1167 } 966 1168 } … … 981 1183 /* Change CPU */ 982 1184 int rc2 = RTThreadSetAffinity(u64Mask); 983 if ( VBOX_FAILURE(rc2))1185 if (RT_FAILURE(rc2)) 984 1186 { 985 1187 u64AffMaskPatched &= ~u64Mask; 986 Log (("SUPLoadVMM: Failed to set affinity to cpu no. %d, rc=%Vrc.\n", i, rc2));1188 LogRel(("SUPLoadVMM: Failed to set affinity to cpu no. %d, rc=%Vrc.\n", i, rc2)); 987 1189 continue; 988 1190 } 989 1191 990 1192 /* Patch the CPU. */ 991 SUPIDTINSTALL_IN In; 992 In.u32Cookie = g_u32Cookie; 993 In.u32SessionCookie = g_u32SessionCookie; 994 SUPIDTINSTALL_OUT Out = {3}; 995 996 rc2 = suplibOsIOCtl(SUP_IOCTL_IDT_INSTALL, &In, sizeof(In), &Out, sizeof(Out)); 997 if (VBOX_SUCCESS(rc2)) 1193 SUPIDTINSTALL Req; 1194 Req.Hdr.u32Cookie = g_u32Cookie; 1195 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 1196 Req.Hdr.cbIn = SUP_IOCTL_IDT_INSTALL_SIZE_IN; 1197 Req.Hdr.cbOut = SUP_IOCTL_IDT_INSTALL_SIZE_OUT; 1198 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 1199 Req.Hdr.rc = VERR_INTERNAL_ERROR; 1200 rc2 = suplibOsIOCtl(SUP_IOCTL_IDT_INSTALL, &Req, SUP_IOCTL_IDT_INSTALL_SIZE); 1201 if (RT_SUCCESS(rc2)) 1202 rc2 = Req.Hdr.rc; 1203 if (RT_SUCCESS(rc2)) 998 1204 { 999 1205 if (!cCpusPatched) 1000 1206 { 1001 g_u8Interrupt = Out.u8Idt; 1002 rc2 = suplibGenerateCallVMMR0(Out.u8Idt); 1003 if (VBOX_FAILURE(rc)) 1004 rc2 = rc; 1207 g_u8Interrupt = Req.u.Out.u8Idt; 1208 rc2 = suplibGenerateCallVMMR0(Req.u.Out.u8Idt); 1209 if (RT_FAILURE(rc2)) 1210 { 1211 LogRel(("suplibGenerateCallVMMR0 failed with rc=%Vrc.\n", i, rc2)); 1212 rc = rc2; 1213 } 1005 1214 } 1006 1215 else 1007 Assert(g_u8Interrupt == Out.u8Idt);1216 Assert(g_u8Interrupt == Req.u.Out.u8Idt); 1008 1217 cCpusPatched++; 1009 1218 } … … 1011 1220 { 1012 1221 1013 Log (("SUPLoadVMM: Failed to patch cpu no. %d, rc=%Vrc.\n", i, rc2));1014 if ( VBOX_SUCCESS(rc))1222 LogRel(("SUPLoadVMM: Failed to patch cpu no. %d, rc=%Vrc.\n", i, rc2)); 1223 if (RT_SUCCESS(rc)) 1015 1224 rc = rc2; 1016 1225 } … … 1018 1227 1019 1228 /* Fail if no CPUs was patched! */ 1020 if ( VBOX_SUCCESS(rc) && cCpusPatched <= 0)1229 if (RT_SUCCESS(rc) && cCpusPatched <= 0) 1021 1230 rc = VERR_GENERAL_FAILURE; 1022 1231 /* Ignore failures if a CPU was patched. */ 1023 else if (VBOX_FAILURE(rc) && cCpusPatched > 0) 1024 { 1025 /** @todo add an eventlog/syslog line out this. */ 1232 else if (RT_FAILURE(rc) && cCpusPatched > 0) 1026 1233 rc = VINF_SUCCESS; 1027 }1028 1234 1029 1235 /* Set/restore the thread affinity. */ 1030 if ( VBOX_SUCCESS(rc))1236 if (RT_SUCCESS(rc)) 1031 1237 { 1032 1238 rc = RTThreadSetAffinity(u64AffMaskPatched); … … 1105 1311 1106 1312 /* iterate the function table. */ 1107 int c = g_pFunctions-> cFunctions;1108 PSUPFUNC pFunc = &g_pFunctions-> aFunctions[0];1313 int c = g_pFunctions->u.Out.cFunctions; 1314 PSUPFUNC pFunc = &g_pFunctions->u.Out.aFunctions[0]; 1109 1315 while (c-- > 0) 1110 1316 { … … 1133 1339 * Despair. 1134 1340 */ 1135 c = g_pFunctions-> cFunctions;1136 pFunc = &g_pFunctions-> aFunctions[0];1341 c = g_pFunctions->u.Out.cFunctions; 1342 pFunc = &g_pFunctions->u.Out.aFunctions[0]; 1137 1343 while (c-- > 0) 1138 1344 { 1139 AssertMsg2("%d: %s\n", g_pFunctions-> cFunctions - c, pFunc->szName);1345 AssertMsg2("%d: %s\n", g_pFunctions->u.Out.cFunctions - c, pFunc->szName); 1140 1346 pFunc++; 1141 1347 } … … 1224 1430 AssertPtrReturn(pszModule, VERR_INVALID_PARAMETER); 1225 1431 AssertPtrReturn(ppvImageBase, VERR_INVALID_PARAMETER); 1226 AssertReturn(strlen(pszModule) < SIZEOFMEMB(SUPLDROPEN_IN,szName), VERR_FILENAME_TOO_LONG);1432 AssertReturn(strlen(pszModule) < RT_SIZEOFMEMB(SUPLDROPEN, u.In.szName), VERR_FILENAME_TOO_LONG); 1227 1433 1228 1434 const bool fIsVMMR0 = !strcmp(pszModule, "VMMR0.r0"); … … 1234 1440 RTLDRMOD hLdrMod; 1235 1441 int rc = RTLdrOpen(pszFilename, &hLdrMod); 1236 if (! VBOX_SUCCESS(rc))1442 if (!RT_SUCCESS(rc)) 1237 1443 return rc; 1238 1444 … … 1242 1448 CalcArgs.cbImage = RTLdrSize(hLdrMod); 1243 1449 rc = RTLdrEnumSymbols(hLdrMod, 0, NULL, 0, supLoadModuleCalcSizeCB, &CalcArgs); 1244 if ( VBOX_SUCCESS(rc))1450 if (RT_SUCCESS(rc)) 1245 1451 { 1246 1452 const uint32_t offSymTab = RT_ALIGN_32(CalcArgs.cbImage, 8); … … 1251 1457 * Open the R0 image. 1252 1458 */ 1253 SUPLDROPEN_IN OpenIn; 1254 OpenIn.u32Cookie = g_u32Cookie; 1255 OpenIn.u32SessionCookie = g_u32SessionCookie; 1256 OpenIn.cbImage = cbImage; 1257 strcpy(OpenIn.szName, pszModule); 1258 SUPLDROPEN_OUT OpenOut; 1459 SUPLDROPEN OpenReq; 1460 OpenReq.Hdr.u32Cookie = g_u32Cookie; 1461 OpenReq.Hdr.u32SessionCookie = g_u32SessionCookie; 1462 OpenReq.Hdr.cbIn = SUP_IOCTL_LDR_OPEN_SIZE_IN; 1463 OpenReq.Hdr.cbOut = SUP_IOCTL_LDR_OPEN_SIZE_OUT; 1464 OpenReq.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 1465 OpenReq.Hdr.rc = VERR_INTERNAL_ERROR; 1466 OpenReq.u.In.cbImage = cbImage; 1467 strcpy(OpenReq.u.In.szName, pszModule); 1259 1468 if (!g_u32FakeMode) 1260 rc = suplibOsIOCtl(SUP_IOCTL_LDR_OPEN, &OpenIn, sizeof(OpenIn), &OpenOut, sizeof(OpenOut)); 1469 { 1470 rc = suplibOsIOCtl(SUP_IOCTL_LDR_OPEN, &OpenReq, SUP_IOCTL_LDR_OPEN_SIZE); 1471 if (RT_SUCCESS(rc)) 1472 rc = OpenReq.Hdr.rc; 1473 } 1261 1474 else 1262 1475 { 1263 Open Out.fNeedsLoading = true;1264 Open Out.pvImageBase = 0xef423420;1476 OpenReq.u.Out.fNeedsLoading = true; 1477 OpenReq.u.Out.pvImageBase = 0xef423420; 1265 1478 } 1266 *ppvImageBase = (void *)Open Out.pvImageBase;1267 if ( VBOX_SUCCESS(rc)1268 && Open Out.fNeedsLoading)1479 *ppvImageBase = (void *)OpenReq.u.Out.pvImageBase; 1480 if ( RT_SUCCESS(rc) 1481 && OpenReq.u.Out.fNeedsLoading) 1269 1482 { 1270 1483 /* … … 1272 1485 * Allocate memory for the image bits. 1273 1486 */ 1274 unsigned cbIn = RT_OFFSETOF(SUPLDRLOAD_IN, achImage[cbImage]); 1275 PSUPLDRLOAD_IN pIn = (PSUPLDRLOAD_IN)RTMemTmpAlloc(cbIn); 1276 if (pIn) 1487 PSUPLDRLOAD pLoadReq = (PSUPLDRLOAD)RTMemTmpAlloc(SUP_IOCTL_LDR_LOAD_SIZE(cbImage)); 1488 if (pLoadReq) 1277 1489 { 1278 1490 /* 1279 1491 * Get the image bits. 1280 1492 */ 1281 rc = RTLdrGetBits(hLdrMod, &p In->achImage[0], (uintptr_t)OpenOut.pvImageBase,1493 rc = RTLdrGetBits(hLdrMod, &pLoadReq->u.In.achImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, 1282 1494 supLoadModuleResolveImport, (void *)pszModule); 1283 1495 1284 if ( VBOX_SUCCESS(rc))1496 if (RT_SUCCESS(rc)) 1285 1497 { 1286 1498 /* … … 1291 1503 RTUINTPTR ModuleTerm = 0; 1292 1504 if (fIsVMMR0) 1293 rc = RTLdrGetSymbolEx(hLdrMod, &p In->achImage[0], (uintptr_t)OpenOut.pvImageBase, "VMMR0Entry", &VMMR0Entry);1294 if ( VBOX_SUCCESS(rc))1505 rc = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.achImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, "VMMR0Entry", &VMMR0Entry); 1506 if (RT_SUCCESS(rc)) 1295 1507 { 1296 int rc2 = RTLdrGetSymbolEx(hLdrMod, &p In->achImage[0], (uintptr_t)OpenOut.pvImageBase, "ModuleInit", &ModuleInit);1297 if ( VBOX_FAILURE(rc2))1508 int rc2 = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.achImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, "ModuleInit", &ModuleInit); 1509 if (RT_FAILURE(rc2)) 1298 1510 ModuleInit = 0; 1299 1511 1300 rc2 = RTLdrGetSymbolEx(hLdrMod, &p In->achImage[0], (uintptr_t)OpenOut.pvImageBase, "ModuleTerm", &ModuleTerm);1301 if ( VBOX_FAILURE(rc2))1512 rc2 = RTLdrGetSymbolEx(hLdrMod, &pLoadReq->u.In.achImage[0], (uintptr_t)OpenReq.u.Out.pvImageBase, "ModuleTerm", &ModuleTerm); 1513 if (RT_FAILURE(rc2)) 1302 1514 ModuleTerm = 0; 1303 1515 } 1304 if ( VBOX_SUCCESS(rc))1516 if (RT_SUCCESS(rc)) 1305 1517 { 1306 1518 /* … … 1309 1521 SUPLDRCREATETABSARGS CreateArgs; 1310 1522 CreateArgs.cbImage = CalcArgs.cbImage; 1311 CreateArgs.pSym = (PSUPLDRSYM)&p In->achImage[offSymTab];1312 CreateArgs.pszBase = (char *)&p In->achImage[offStrTab];1523 CreateArgs.pSym = (PSUPLDRSYM)&pLoadReq->u.In.achImage[offSymTab]; 1524 CreateArgs.pszBase = (char *)&pLoadReq->u.In.achImage[offStrTab]; 1313 1525 CreateArgs.psz = CreateArgs.pszBase; 1314 1526 rc = RTLdrEnumSymbols(hLdrMod, 0, NULL, 0, supLoadModuleCreateTabsCB, &CreateArgs); 1315 if ( VBOX_SUCCESS(rc))1527 if (RT_SUCCESS(rc)) 1316 1528 { 1317 1529 AssertRelease((size_t)(CreateArgs.psz - CreateArgs.pszBase) <= CalcArgs.cbStrings); 1318 AssertRelease((size_t)(CreateArgs.pSym - (PSUPLDRSYM)&p In->achImage[offSymTab]) <= CalcArgs.cSymbols);1530 AssertRelease((size_t)(CreateArgs.pSym - (PSUPLDRSYM)&pLoadReq->u.In.achImage[offSymTab]) <= CalcArgs.cSymbols); 1319 1531 1320 1532 /* 1321 1533 * Upload the image. 1322 1534 */ 1323 pIn->u32Cookie = g_u32Cookie; 1324 pIn->u32SessionCookie = g_u32SessionCookie; 1325 pIn->pfnModuleInit = (RTR0PTR)ModuleInit; 1326 pIn->pfnModuleTerm = (RTR0PTR)ModuleTerm; 1535 pLoadReq->Hdr.u32Cookie = g_u32Cookie; 1536 pLoadReq->Hdr.u32SessionCookie = g_u32SessionCookie; 1537 pLoadReq->Hdr.cbIn = SUP_IOCTL_LDR_LOAD_SIZE_IN(cbImage); 1538 pLoadReq->Hdr.cbOut = SUP_IOCTL_LDR_LOAD_SIZE_OUT; 1539 pLoadReq->Hdr.fFlags = SUPREQHDR_FLAGS_MAGIC | SUPREQHDR_FLAGS_EXTRA_IN; 1540 pLoadReq->Hdr.rc = VERR_INTERNAL_ERROR; 1541 1542 pLoadReq->u.In.pfnModuleInit = (RTR0PTR)ModuleInit; 1543 pLoadReq->u.In.pfnModuleTerm = (RTR0PTR)ModuleTerm; 1327 1544 if (fIsVMMR0) 1328 1545 { 1329 p In->eEPType = pIn->EP_VMMR0;1330 p In->EP.VMMR0.pvVMMR0 = OpenOut.pvImageBase;1331 p In->EP.VMMR0.pvVMMR0Entry = (RTR0PTR)VMMR0Entry;1546 pLoadReq->u.In.eEPType = pLoadReq->u.In.EP_VMMR0; 1547 pLoadReq->u.In.EP.VMMR0.pvVMMR0 = OpenReq.u.Out.pvImageBase; 1548 pLoadReq->u.In.EP.VMMR0.pvVMMR0Entry = (RTR0PTR)VMMR0Entry; 1332 1549 } 1333 1550 else 1334 p In->eEPType = pIn->EP_NOTHING;1335 p In->offStrTab = offStrTab;1336 p In->cbStrTab = (uint32_t)CalcArgs.cbStrings;1337 AssertRelease(p In->cbStrTab == CalcArgs.cbStrings);1338 p In->offSymbols = offSymTab;1339 p In->cSymbols = CalcArgs.cSymbols;1340 p In->cbImage = cbImage;1341 p In->pvImageBase = OpenOut.pvImageBase;1551 pLoadReq->u.In.eEPType = pLoadReq->u.In.EP_NOTHING; 1552 pLoadReq->u.In.offStrTab = offStrTab; 1553 pLoadReq->u.In.cbStrTab = (uint32_t)CalcArgs.cbStrings; 1554 AssertRelease(pLoadReq->u.In.cbStrTab == CalcArgs.cbStrings); 1555 pLoadReq->u.In.offSymbols = offSymTab; 1556 pLoadReq->u.In.cSymbols = CalcArgs.cSymbols; 1557 pLoadReq->u.In.cbImage = cbImage; 1558 pLoadReq->u.In.pvImageBase = OpenReq.u.Out.pvImageBase; 1342 1559 if (!g_u32FakeMode) 1343 rc = suplibOsIOCtl(SUP_IOCTL_LDR_LOAD, pIn, cbIn, NULL, 0); 1560 { 1561 rc = suplibOsIOCtl(SUP_IOCTL_LDR_LOAD, pLoadReq, SUP_IOCTL_LDR_LOAD_SIZE(cbImage)); 1562 if (RT_SUCCESS(rc)) 1563 rc = pLoadReq->Hdr.rc; 1564 } 1344 1565 else 1345 1566 rc = VINF_SUCCESS; 1346 if ( VBOX_SUCCESS(rc)1347 || rc == VERR_ALREADY_LOADED /* this is because of acompeting process. */1567 if ( RT_SUCCESS(rc) 1568 || rc == VERR_ALREADY_LOADED /* A competing process. */ 1348 1569 ) 1349 1570 { 1350 1571 if (fIsVMMR0) 1351 g_pvVMMR0 = Open Out.pvImageBase;1352 RTMemTmpFree(p In);1572 g_pvVMMR0 = OpenReq.u.Out.pvImageBase; 1573 RTMemTmpFree(pLoadReq); 1353 1574 RTLdrClose(hLdrMod); 1354 1575 return VINF_SUCCESS; … … 1357 1578 } 1358 1579 } 1359 RTMemTmpFree(p In);1580 RTMemTmpFree(pLoadReq); 1360 1581 } 1361 1582 else 1362 1583 { 1363 AssertMsgFailed(("failed to allocated %d bytes for SUPLDRLOAD_IN structure!\n", cbIn));1584 AssertMsgFailed(("failed to allocated %d bytes for SUPLDRLOAD_IN structure!\n", SUP_IOCTL_LDR_LOAD_SIZE(cbImage))); 1364 1585 rc = VERR_NO_TMP_MEMORY; 1365 1586 } 1366 1587 } 1367 else if ( VBOX_SUCCESS(rc) && fIsVMMR0)1368 g_pvVMMR0 = Open Out.pvImageBase;1588 else if (RT_SUCCESS(rc) && fIsVMMR0) 1589 g_pvVMMR0 = OpenReq.u.Out.pvImageBase; 1369 1590 } 1370 1591 RTLdrClose(hLdrMod); … … 1375 1596 SUPR3DECL(int) SUPFreeModule(void *pvImageBase) 1376 1597 { 1598 /* fake */ 1599 if (RT_UNLIKELY(g_u32FakeMode)) 1600 { 1601 #ifndef VBOX_WITHOUT_IDT_PATCHING 1602 g_u8Interrupt = 3; 1603 RTMemExecFree(*(void **)&g_pfnCallVMMR0); 1604 g_pfnCallVMMR0 = NULL; 1605 #endif 1606 g_pvVMMR0 = NIL_RTR0PTR; 1607 return VINF_SUCCESS; 1608 } 1609 1610 #ifndef VBOX_WITHOUT_IDT_PATCHING 1377 1611 /* 1378 1612 * There is one special module. When this is freed we'll … … 1382 1616 * first unload will free it. 1383 1617 */ 1384 if ((RTR0PTR)pvImageBase == g_pvVMMR0) 1385 { 1386 /* 1387 * This is the point where we remove the IDT hook. We do 1388 * that before unloading the R0 VMM part. 1389 */ 1390 if (g_u32FakeMode) 1391 { 1392 #ifndef VBOX_WITHOUT_IDT_PATCHING 1393 g_u8Interrupt = 3; 1394 RTMemExecFree(*(void **)&g_pfnCallVMMR0); 1395 g_pfnCallVMMR0 = NULL; 1396 #endif 1397 g_pvVMMR0 = NIL_RTR0PTR; 1398 return VINF_SUCCESS; 1399 } 1400 1401 #ifndef VBOX_WITHOUT_IDT_PATCHING 1402 /* 1403 * Uninstall IDT entry. 1404 */ 1405 int rc = 0; 1406 if (g_u8Interrupt != 3) 1407 { 1408 SUPIDTREMOVE_IN In; 1409 In.u32Cookie = g_u32Cookie; 1410 In.u32SessionCookie = g_u32SessionCookie; 1411 rc = suplibOsIOCtl(SUP_IOCTL_IDT_REMOVE, &In, sizeof(In), NULL, 0); 1412 g_u8Interrupt = 3; 1413 RTMemExecFree(*(void **)&g_pfnCallVMMR0); 1414 g_pfnCallVMMR0 = NULL; 1415 } 1416 #endif 1417 } 1618 if ( (RTR0PTR)pvImageBase == g_pvVMMR0 1619 && g_u8Interrupt != 3) 1620 { 1621 SUPIDTREMOVE Req; 1622 Req.Hdr.u32Cookie = g_u32Cookie; 1623 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 1624 Req.Hdr.cbIn = SUP_IOCTL_IDT_REMOVE_SIZE_IN; 1625 Req.Hdr.cbOut = SUP_IOCTL_IDT_REMOVE_SIZE_OUT; 1626 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 1627 Req.Hdr.rc = VERR_INTERNAL_ERROR; 1628 int rc = suplibOsIOCtl(SUP_IOCTL_IDT_REMOVE, &Req, SUP_IOCTL_IDT_REMOVE_SIZE); 1629 if (RT_SUCCESS(rc)) 1630 rc = Req.Hdr.rc; 1631 AssertRC(rc); 1632 g_u8Interrupt = 3; 1633 RTMemExecFree(*(void **)&g_pfnCallVMMR0); 1634 g_pfnCallVMMR0 = NULL; 1635 } 1636 #endif /* VBOX_WITHOUT_IDT_PATCHING */ 1418 1637 1419 1638 /* 1420 1639 * Free the requested module. 1421 1640 */ 1422 SUPLDRFREE_IN In; 1423 In.u32Cookie = g_u32Cookie; 1424 In.u32SessionCookie = g_u32SessionCookie; 1425 In.pvImageBase = (RTR0PTR)pvImageBase; 1426 int rc = VINF_SUCCESS; 1427 if (!g_u32FakeMode) 1428 rc = suplibOsIOCtl(SUP_IOCTL_LDR_FREE, &In, sizeof(In), NULL, 0); 1429 if ( VBOX_SUCCESS(rc) 1641 SUPLDRFREE Req; 1642 Req.Hdr.u32Cookie = g_u32Cookie; 1643 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 1644 Req.Hdr.cbIn = SUP_IOCTL_LDR_FREE_SIZE_IN; 1645 Req.Hdr.cbOut = SUP_IOCTL_LDR_FREE_SIZE_OUT; 1646 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 1647 Req.Hdr.rc = VERR_INTERNAL_ERROR; 1648 Req.u.In.pvImageBase = (RTR0PTR)pvImageBase; 1649 int rc = suplibOsIOCtl(SUP_IOCTL_LDR_FREE, &Req, SUP_IOCTL_LDR_FREE_SIZE); 1650 if (RT_SUCCESS(rc)) 1651 rc = Req.Hdr.rc; 1652 if ( RT_SUCCESS(rc) 1430 1653 && (RTR0PTR)pvImageBase == g_pvVMMR0) 1431 1654 g_pvVMMR0 = NIL_RTR0PTR; … … 1438 1661 *ppvValue = NULL; 1439 1662 1663 /* fake */ 1664 if (RT_UNLIKELY(g_u32FakeMode)) 1665 { 1666 *ppvValue = (void *)(uintptr_t)0xdeadf00d; 1667 return VINF_SUCCESS; 1668 } 1669 1440 1670 /* 1441 1671 * Do ioctl. 1442 1672 */ 1443 size_t cchSymbol = strlen(pszSymbol); 1444 const size_t cbIn = RT_OFFSETOF(SUPLDRGETSYMBOL_IN, szSymbol[cchSymbol + 1]); 1445 SUPLDRGETSYMBOL_OUT Out = { NIL_RTR0PTR }; 1446 PSUPLDRGETSYMBOL_IN pIn = (PSUPLDRGETSYMBOL_IN)alloca(cbIn); 1447 pIn->u32Cookie = g_u32Cookie; 1448 pIn->u32SessionCookie = g_u32SessionCookie; 1449 pIn->pvImageBase = (RTR0PTR)pvImageBase; 1450 memcpy(pIn->szSymbol, pszSymbol, cchSymbol + 1); 1451 int rc; 1452 if (RT_LIKELY(!g_u32FakeMode)) 1453 rc = suplibOsIOCtl(SUP_IOCTL_LDR_GET_SYMBOL, pIn, cbIn, &Out, sizeof(Out)); 1454 else 1455 { 1456 rc = VINF_SUCCESS; 1457 Out.pvSymbol = 0xdeadf00d; 1458 } 1459 if (VBOX_SUCCESS(rc)) 1460 *ppvValue = (void *)Out.pvSymbol; 1673 SUPLDRGETSYMBOL Req; 1674 Req.Hdr.u32Cookie = g_u32Cookie; 1675 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 1676 Req.Hdr.cbIn = SUP_IOCTL_LDR_GET_SYMBOL_SIZE_IN; 1677 Req.Hdr.cbOut = SUP_IOCTL_LDR_GET_SYMBOL_SIZE_OUT; 1678 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 1679 Req.Hdr.rc = VERR_INTERNAL_ERROR; 1680 Req.u.In.pvImageBase = (RTR0PTR)pvImageBase; 1681 size_t cchSymbol = strlen(pszSymbol); 1682 if (cchSymbol >= sizeof(Req.u.In.szSymbol)) 1683 return VERR_SYMBOL_NOT_FOUND; 1684 memcpy(Req.u.In.szSymbol, pszSymbol, cchSymbol + 1); 1685 int rc = suplibOsIOCtl(SUP_IOCTL_LDR_GET_SYMBOL, &Req, SUP_IOCTL_LDR_GET_SYMBOL_SIZE); 1686 if (RT_SUCCESS(rc)) 1687 rc = Req.Hdr.rc; 1688 if (RT_SUCCESS(rc)) 1689 *ppvValue = (void *)Req.u.Out.pvSymbol; 1461 1690 return rc; 1462 1691 } -
trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h
r4071 r4800 44 44 int suplibOsInit(size_t cbReserve); 45 45 int suplibOsTerm(void); 46 int suplibOsIOCtl(u nsigned uFunction, void *pvIn, size_t cbIn, void *pvOut, size_t cbOut);46 int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq); 47 47 #ifdef VBOX_WITHOUT_IDT_PATCHING 48 int suplibOSIOCtlFast(u nsigneduFunction);48 int suplibOSIOCtlFast(uintptr_t uFunction); 49 49 #endif 50 50 int suplibOsPageAlloc(size_t cPages, void **ppvPages); -
trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp
r4071 r4800 271 271 g_iMajorDeviceNo = -1; 272 272 273 rc = supdrvDeleteDevExt(&g_DevExt); 274 AssertRC(rc); 273 supdrvDeleteDevExt(&g_DevExt); 275 274 276 275 rc = RTSpinlockDestroy(g_Spinlock); … … 385 384 if (!pSession) 386 385 { 387 OSDBGPRINT(("VBoxSupDrvClose: WHAT?!? pSession == NULL! This must be a mistake... pid=%d (close)\n", 386 OSDBGPRINT(("VBoxSupDrvClose: WHAT?!? pSession == NULL! This must be a mistake... pid=%d (close)\n", 388 387 (int)Process)); 389 388 return EINVAL; … … 428 427 if (!pSession) 429 428 { 430 OSDBGPRINT(("VBoxSupDrvIOCtl: WHAT?!? pSession == NULL! This must be a mistake... pid=%d iCmd=%#x\n", 429 OSDBGPRINT(("VBoxSupDrvIOCtl: WHAT?!? pSession == NULL! This must be a mistake... pid=%d iCmd=%#x\n", 431 430 (int)Process, iCmd)); 432 431 return EINVAL; -
trunk/src/VBox/HostDrivers/Support/darwin/SUPLib-darwin.cpp
r4071 r4800 171 171 172 172 173 /**174 * Installs anything required by the support library.175 *176 * @returns 0 on success.177 * @returns error code on failure.178 */179 173 int suplibOsInstall(void) 180 174 { 181 // int rc = mknod(DEVICE_NAME, S_IFCHR, );182 183 175 return VERR_NOT_IMPLEMENTED; 184 176 } 185 177 186 178 187 /**188 * Installs anything required by the support library.189 *190 * @returns 0 on success.191 * @returns error code on failure.192 */193 179 int suplibOsUninstall(void) 194 180 { 195 // int rc = unlink(DEVICE_NAME);196 197 181 return VERR_NOT_IMPLEMENTED; 198 182 } 199 183 200 184 201 /** 202 * Send a I/O Control request to the device. 203 * 204 * @returns 0 on success. 205 * @returns VBOX error code on failure. 206 * @param uFunction IO Control function. 207 * @param pvIn Input data buffer. 208 * @param cbIn Size of input data. 209 * @param pvOut Output data buffer. 210 * @param cbOut Size of output data. 211 */ 212 int suplibOsIOCtl(unsigned uFunction, void *pvIn, size_t cbIn, void *pvOut, size_t cbOut) 185 int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq) 213 186 { 214 187 AssertMsg(g_hDevice != -1, ("SUPLIB not initiated successfully!\n")); 215 /* 216 * Issue device iocontrol. 217 */ 218 SUPDRVIOCTLDATA Args; 219 Args.pvIn = pvIn; 220 Args.cbIn = cbIn; 221 Args.pvOut = pvOut; 222 Args.cbOut = cbOut; 223 224 if (ioctl(g_hDevice, uFunction, &Args) >= 0) 225 return 0; 226 /* This is the reverse operation of the one found in SUPDrv-linux.c */ 227 switch (errno) 228 { 229 case EACCES: return VERR_GENERAL_FAILURE; 230 case EINVAL: return VERR_INVALID_PARAMETER; 231 case ENOSYS: return VERR_INVALID_MAGIC; 232 case ENXIO: return VERR_INVALID_HANDLE; 233 case EFAULT: return VERR_INVALID_POINTER; 234 case ENOLCK: return VERR_LOCK_FAILED; 235 case EEXIST: return VERR_ALREADY_LOADED; 236 } 237 188 189 if (RT_LIKELY(ioctl(g_hDevice, uFunction, pvReq) >= 0)) 190 return VINF_SUCCESS; 238 191 return RTErrConvertFromErrno(errno); 239 192 } 240 193 241 194 #ifdef VBOX_WITHOUT_IDT_PATCHING 242 int suplibOSIOCtlFast(u nsigneduFunction)195 int suplibOSIOCtlFast(uintptr_t uFunction) 243 196 { 244 197 int rc = ioctl(g_hDevice, uFunction, NULL); … … 250 203 251 204 252 /**253 * Allocate a number of zero-filled pages in user space.254 *255 * @returns VBox status code.256 * @param cPages Number of pages to allocate.257 * @param ppvPages Where to return the base pointer.258 */259 205 int suplibOsPageAlloc(size_t cPages, void **ppvPages) 260 206 { … … 269 215 270 216 271 /**272 * Frees pages allocated by suplibOsPageAlloc().273 *274 * @returns VBox status code.275 * @param pvPages Pointer to pages.276 */277 217 int suplibOsPageFree(void *pvPages, size_t /* cPages */) 278 218 { -
trunk/src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c
r4016 r4800 217 217 } 218 218 219 rc = supdrvDeleteDevExt(&g_DevExt); 220 AssertRC(rc); 219 supdrvDeleteDevExt(&g_DevExt); 221 220 222 221 rc = RTSpinlockDestroy(g_Spinlock); … … 306 305 cch = RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, va); 307 306 va_end(va); 308 307 309 308 printf("%s", szMsg); 310 309 -
trunk/src/VBox/HostDrivers/Support/freebsd/SUPLib-freebsd.cpp
r4071 r4800 96 96 97 97 98 /**99 * Installs anything required by the support library.100 *101 * @returns 0 on success.102 * @returns error code on failure.103 */104 98 int suplibOsInstall(void) 105 99 { 106 // int rc = mknod(DEVICE_NAME, S_IFCHR, );107 108 100 return VERR_NOT_IMPLEMENTED; 109 101 } 110 102 111 103 112 /**113 * Installs anything required by the support library.114 *115 * @returns 0 on success.116 * @returns error code on failure.117 */118 104 int suplibOsUninstall(void) 119 105 { 120 // int rc = unlink(DEVICE_NAME);121 122 106 return VERR_NOT_IMPLEMENTED; 123 107 } 124 108 125 109 126 /** 127 * Send a I/O Control request to the device. 128 * 129 * @returns 0 on success. 130 * @returns VBOX error code on failure. 131 * @param uFunction IO Control function. 132 * @param pvIn Input data buffer. 133 * @param cbIn Size of input data. 134 * @param pvOut Output data buffer. 135 * @param cbOut Size of output data. 136 */ 137 int suplibOsIOCtl(unsigned uFunction, void *pvIn, size_t cbIn, void *pvOut, size_t cbOut) 110 int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq) 138 111 { 139 112 AssertMsg(g_hDevice != -1, ("SUPLIB not initiated successfully!\n")); 140 /*141 * Issue device iocontrol.142 */143 SUPDRVIOCTLDATA Args;144 Args.pvIn = pvIn;145 Args.cbIn = cbIn;146 Args.pvOut = pvOut;147 Args.cbOut = cbOut;148 113 149 if (ioctl(g_hDevice, uFunction, &Args) >= 0) 150 return 0; 151 /* This is the reverse operation of the one found in SUPDrv-linux.c */ 152 switch (errno) 153 { 154 case EACCES: return VERR_GENERAL_FAILURE; 155 case EINVAL: return VERR_INVALID_PARAMETER; 156 case ENOSYS: return VERR_INVALID_MAGIC; 157 case ENXIO: return VERR_INVALID_HANDLE; 158 case EFAULT: return VERR_INVALID_POINTER; 159 case ENOLCK: return VERR_LOCK_FAILED; 160 case EEXIST: return VERR_ALREADY_LOADED; 161 } 162 114 if (RT_LIKELY(ioctl((g_hDevice, uFunction, pvReq) >= 0)) 115 return VINF_SUCCESS; 163 116 return RTErrConvertFromErrno(errno); 164 117 } 165 118 166 119 #ifdef VBOX_WITHOUT_IDT_PATCHING 167 int suplibOSIOCtlFast(u nsigneduFunction)120 int suplibOSIOCtlFast(uintptr_t uFunction) 168 121 { 169 122 int rc = ioctl(g_hDevice, uFunction, NULL); … … 175 128 176 129 177 /**178 * Allocate a number of zero-filled pages in user space.179 *180 * @returns VBox status code.181 * @param cPages Number of pages to allocate.182 * @param ppvPages Where to return the base pointer.183 */184 130 int suplibOsPageAlloc(size_t cPages, void **ppvPages) 185 131 { … … 191 137 192 138 193 /**194 * Frees pages allocated by suplibOsPageAlloc().195 *196 * @returns VBox status code.197 * @param pvPages Pointer to pages.198 */199 139 int suplibOsPageFree(void *pvPages, size_t /* cPages */) 200 140 { -
trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c
r4791 r4800 66 66 #endif 67 67 68 #include <iprt/mem.h> 69 70 68 71 /* devfs defines */ 69 72 #if defined(CONFIG_DEVFS_FS) && !defined(CONFIG_VBOXDRV_AS_MISC) … … 236 239 * Device extention & session data association structure. 237 240 */ 238 static SUPDRVDEVEXT g_DevExt;241 static SUPDRVDEVEXT g_DevExt; 239 242 240 243 /** Timer structure for the GIP update. */ 241 static struct timer_list g_GipTimer;244 static struct timer_list g_GipTimer; 242 245 /** Pointer to the page structure for the GIP. */ 243 struct page *g_pGipPage;246 struct page *g_pGipPage; 244 247 245 248 /** Registered devfs device handle. */ 246 249 #if defined(CONFIG_DEVFS_FS) && !defined(CONFIG_VBOXDRV_AS_MISC) 247 250 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) 248 static void *g_hDevFsVBoxDrv = NULL;251 static void *g_hDevFsVBoxDrv = NULL; 249 252 # else 250 static devfs_handle_t g_hDevFsVBoxDrv = NULL;253 static devfs_handle_t g_hDevFsVBoxDrv = NULL; 251 254 # endif 252 255 #endif … … 254 257 #ifndef CONFIG_VBOXDRV_AS_MISC 255 258 /** Module major number */ 256 #define DEVICE_MAJOR 234259 #define DEVICE_MAJOR 234 257 260 /** Saved major device number */ 258 static int g_iModuleMajor;261 static int g_iModuleMajor; 259 262 #endif /* !CONFIG_VBOXDRV_AS_MISC */ 260 263 261 264 /** The module name. */ 262 #define DEVICE_NAME "vboxdrv"265 #define DEVICE_NAME "vboxdrv" 263 266 264 267 #ifdef RT_ARCH_AMD64 … … 281 284 * Internal Functions * 282 285 *******************************************************************************/ 283 static int VBox SupDrvInit(void);284 static void VBox SupDrvUnload(void);285 static int VBox SupDrvCreate(struct inode *pInode, struct file *pFilp);286 static int VBox SupDrvClose(struct inode *pInode, struct file *pFilp);287 static int VBox SupDrvDeviceControl(struct inode *pInode, struct file *pFilp,288 unsigned int IOCmd, unsigned long IOArg);286 static int VBoxDrvLinuxInit(void); 287 static void VBoxDrvLinuxUnload(void); 288 static int VBoxDrvLinuxCreate(struct inode *pInode, struct file *pFilp); 289 static int VBoxDrvLinuxClose(struct inode *pInode, struct file *pFilp); 290 static int VBoxDrvLinuxIOCtl(struct inode *pInode, struct file *pFilp, unsigned int uCmd, unsigned long ulArg); 291 static int VBoxDrvLinuxIOCtlSlow(struct inode *pInode, struct file *pFilp, unsigned int uCmd, unsigned long ulArg); 289 292 #ifndef USE_NEW_OS_INTERFACE_FOR_MM 290 static RTR3PTR VBox SupDrvMapUser(struct page **papPages, unsigned cPages, unsigned fProt, pgprot_t pgFlags);293 static RTR3PTR VBoxDrvLinuxMapUser(struct page **papPages, unsigned cPages, unsigned fProt, pgprot_t pgFlags); 291 294 #endif /* !USE_NEW_OS_INTERFACE_FOR_MM */ 292 static int VBox SupDrvInitGip(PSUPDRVDEVEXT pDevExt);293 static int VBox SupDrvTermGip(PSUPDRVDEVEXT pDevExt);294 static void VBox SupGipTimer(unsigned long ulUser);295 static int VBoxDrvLinuxInitGip(PSUPDRVDEVEXT pDevExt); 296 static int VBoxDrvLinuxTermGip(PSUPDRVDEVEXT pDevExt); 297 static void VBoxDrvLinuxGipTimer(unsigned long ulUser); 295 298 #ifdef CONFIG_SMP 296 static void VBox SupGipTimerPerCpu(unsigned long ulUser);297 static void VBox SupGipResumePerCpu(void *pvUser);298 #endif 299 static int VBox SupDrvErr2LinuxErr(int);299 static void VBoxDrvLinuxGipTimerPerCpu(unsigned long ulUser); 300 static void VBoxDrvLinuxGipResumePerCpu(void *pvUser); 301 #endif 302 static int VBoxDrvLinuxErr2LinuxErr(int); 300 303 301 304 … … 304 307 { 305 308 owner: THIS_MODULE, 306 open: VBox SupDrvCreate,307 release: VBox SupDrvClose,308 ioctl: VBox SupDrvDeviceControl,309 open: VBoxDrvLinuxCreate, 310 release: VBoxDrvLinuxClose, 311 ioctl: VBoxDrvLinuxIOCtl, 309 312 }; 310 313 … … 433 436 * @returns appropriate status code. 434 437 */ 435 static int __init VBox SupDrvInit(void)438 static int __init VBoxDrvLinuxInit(void) 436 439 { 437 440 int rc; … … 617 620 * Create the GIP page. 618 621 */ 619 rc = VBox SupDrvInitGip(&g_DevExt);622 rc = VBoxDrvLinuxInitGip(&g_DevExt); 620 623 if (!rc) 621 624 { … … 654 657 * Unload the module. 655 658 */ 656 static void __exit VBox SupDrvUnload(void)659 static void __exit VBoxDrvLinuxUnload(void) 657 660 { 658 661 int rc; 659 dprintf(("VBox SupDrvUnload\n"));662 dprintf(("VBoxDrvLinuxUnload\n")); 660 663 661 664 /* … … 686 689 * Destroy GIP, delete the device extension and terminate IPRT. 687 690 */ 688 VBox SupDrvTermGip(&g_DevExt);691 VBoxDrvLinuxTermGip(&g_DevExt); 689 692 supdrvDeleteDevExt(&g_DevExt); 690 693 RTR0Term(); … … 698 701 * @param pFilp Associated file pointer. 699 702 */ 700 static int VBox SupDrvCreate(struct inode *pInode, struct file *pFilp)703 static int VBoxDrvLinuxCreate(struct inode *pInode, struct file *pFilp) 701 704 { 702 705 int rc; 703 706 PSUPDRVSESSION pSession; 704 dprintf(("VBox SupDrvCreate: pFilp=%p\n", pFilp));707 dprintf(("VBoxDrvLinuxCreate: pFilp=%p\n", pFilp)); 705 708 706 709 /* … … 716 719 } 717 720 718 dprintf(("VBox SupDrvCreate: g_DevExt=%p pSession=%p rc=%d\n", &g_DevExt, pSession, rc));721 dprintf(("VBoxDrvLinuxCreate: g_DevExt=%p pSession=%p rc=%d\n", &g_DevExt, pSession, rc)); 719 722 pFilp->private_data = pSession; 720 723 721 return VBox SupDrvErr2LinuxErr(rc);724 return VBoxDrvLinuxErr2LinuxErr(rc); 722 725 } 723 726 … … 729 732 * @param pFilp Associated file pointer. 730 733 */ 731 static int VBox SupDrvClose(struct inode *pInode, struct file *pFilp)732 { 733 dprintf(("VBox SupDrvClose: pFilp=%p private_data=%p\n", pFilp, pFilp->private_data));734 static int VBoxDrvLinuxClose(struct inode *pInode, struct file *pFilp) 735 { 736 dprintf(("VBoxDrvLinuxClose: pFilp=%p private_data=%p\n", pFilp, pFilp->private_data)); 734 737 supdrvCloseSession(&g_DevExt, (PSUPDRVSESSION)pFilp->private_data); 735 738 pFilp->private_data = NULL; … … 743 746 * @param pInode Pointer to inode info structure. 744 747 * @param pFilp Associated file pointer. 745 * @param IOCmd The function specified to ioctl(). 746 * @param IOArg The argument specified to ioctl(). 747 */ 748 static int VBoxSupDrvDeviceControl(struct inode *pInode, struct file *pFilp, 749 unsigned int IOCmd, unsigned long IOArg) 748 * @param uCmd The function specified to ioctl(). 749 * @param ulArg The argument specified to ioctl(). 750 */ 751 static int VBoxDrvLinuxIOCtl(struct inode *pInode, struct file *pFilp, unsigned int uCmd, unsigned long ulArg) 752 { 753 #ifdef VBOX_WITHOUT_IDT_PATCHING 754 /* 755 * Deal with the two high-speed IOCtl that takes it's arguments from 756 * the session and iCmd, and only returns a VBox status code. 757 */ 758 if (RT_LIKELY( uCmd == SUP_IOCTL_FAST_DO_RAW_RUN 759 || uCmd == SUP_IOCTL_FAST_DO_HWACC_RUN 760 || uCmd == SUP_IOCTL_FAST_DO_NOP)) 761 return supdrvIOCtlFast(iCmd, &g_DevExt, (PSUPDRVSESSION)pFilp->private_data); 762 #endif 763 return VBoxDrvLinuxIOCtlSlow(pInode, pFilp, uCmd, ulArg); 764 } 765 766 767 /** 768 * Device I/O Control entry point. 769 * 770 * @param pInode Pointer to inode info structure. 771 * @param pFilp Associated file pointer. 772 * @param uCmd The function specified to ioctl(). 773 * @param ulArg The argument specified to ioctl(). 774 */ 775 static int VBoxDrvLinuxIOCtlSlow(struct inode *pInode, struct file *pFilp, unsigned int uCmd, unsigned long ulArg) 750 776 { 751 777 int rc; 752 SUPDRVIOCTLDATA Args; 753 void *pvBuf = NULL; 754 int cbBuf = 0; 755 unsigned cbOut = 0; 756 757 dprintf2(("VBoxSupDrvDeviceControl: pFilp=%p IOCmd=%x IOArg=%p\n", pFilp, IOCmd, (void *)IOArg)); 758 759 /* 760 * Copy ioctl data structure from user space. 761 */ 762 if (_IOC_SIZE(IOCmd) != sizeof(SUPDRVIOCTLDATA)) 763 { 764 dprintf(("VBoxSupDrvDeviceControl: incorrect input length! cbArgs=%d\n", _IOC_SIZE(IOCmd))); 778 SUPREQHDR Hdr; 779 PSUPREQHDR pHdr; 780 uint32_t cbBuf; 781 782 dprintf2(("VBoxDrvLinuxIOCtl: pFilp=%p uCmd=%#x ulArg=%p\n", pFilp, uCmd, (void *)ulArg)); 783 784 /* 785 * Read the header. 786 */ 787 if (RT_UNLIKELY(copy_from_user(&Hdr, (void *)ulArg, sizeof(Hdr)))) 788 { 789 dprintf(("VBoxDrvLinuxIOCtl: copy_from_user(,%#lx,) failed; uCmd=%#x.\n", ulArg, uCmd)); 790 return -EFAULT; 791 } 792 if (RT_UNLIKELY((Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC)) 793 { 794 dprintf(("VBoxDrvLinuxIOCtl: bad header magic %#x; uCmd=%#x\n", Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK, uCmd)); 765 795 return -EINVAL; 766 796 } 767 if (copy_from_user(&Args, (void *)IOArg, _IOC_SIZE(IOCmd))) 768 { 769 dprintf(("VBoxSupDrvDeviceControl: copy_from_user(&Args) failed.\n")); 797 798 /* 799 * Buffer the request. 800 */ 801 cbBuf = RT_MAX(Hdr.cbIn, Hdr.cbOut); 802 if (RT_UNLIKELY(cbBuf > _1M*16)) 803 { 804 dprintf(("VBoxDrvLinuxIOCtl: too big cbBuf=%#x; uCmd=%#x\n", cbBuf, uCmd)); 805 return -E2BIG; 806 } 807 if (RT_UNLIKELY(cbBuf != _IOC_SIZE(uCmd) && _IOC_SIZE(uCmd))) 808 { 809 dprintf(("VBoxDrvLinuxIOCtl: bad ioctl cbBuf=%#x _IOC_SIZE=%#x; uCmd=%#x.\n", cbBuf, _IOC_SIZE(uCmd), uCmd)); 810 return -EINVAL; 811 } 812 pHdr = RTMemAlloc(cbBuf); 813 if (RT_UNLIKELY(!pHdr)) 814 { 815 OSDBGPRINT(("VBoxDrvLinuxIOCtl: failed to allocate buffer of %d bytes for uCmd=%#x.\n", cbBuf, uCmd)); 816 return -ENOMEM; 817 } 818 if (RT_UNLIKELY(copy_from_user(pHdr, (void *)ulArg, Hdr.cbIn))) 819 { 820 dprintf(("VBoxDrvLinuxIOCtl: copy_from_user(,%#lx, %#x) failed; uCmd=%#x.\n", ulArg, Hdr.cbIn, uCmd)); 821 RTMemFree(pHdr); 770 822 return -EFAULT; 771 823 } 772 824 773 825 /* 774 * Allocate and copy user space input data buffer to kernel space. 775 */ 776 if (Args.cbIn > 0 || Args.cbOut > 0) 777 { 778 cbBuf = max(Args.cbIn, Args.cbOut); 779 pvBuf = vmalloc(cbBuf); 780 if (pvBuf == NULL) 826 * Process the IOCtl. 827 */ 828 rc = supdrvIOCtl(uCmd, &g_DevExt, (PSUPDRVSESSION)pFilp->private_data, pHdr); 829 830 /* 831 * Copy ioctl data and output buffer back to user space. 832 */ 833 if (RT_LIKELY(!rc)) 834 { 835 uint32_t cbOut = pHdr->cbOut; 836 if (RT_UNLIKELY(cbOut > cbBuf)) 781 837 { 782 dprintf(("VBoxSupDrvDeviceControl: failed to allocate buffer of %d bytes.\n", cbBuf));783 return -ENOMEM;838 OSDBGPRINT(("VBoxDrvLinuxIOCtl: too much output! %#x > %#x; uCmd=%#x!\n", cbOut, cbBuf, uCmd)); 839 cbOut = cbBuf; 784 840 } 785 786 if (copy_from_user(pvBuf, (void *)Args.pvIn, Args.cbIn)) 841 if (RT_UNLIKELY(copy_to_user((void *)ulArg, pHdr, cbOut))) 787 842 { 788 dprintf(("VBoxSupDrvDeviceControl: copy_from_user(pvBuf) failed.\n"));789 vfree(pvBuf);790 r eturn-EFAULT;843 /* this is really bad! */ 844 OSDBGPRINT(("VBoxDrvLinuxIOCtl: copy_to_user(%#lx,,%#x); uCmd=%#x!\n", ulArg, cbOut, uCmd)); 845 rc = -EFAULT; 791 846 } 792 847 } 793 794 /* 795 * Process the IOCtl. 796 */ 797 rc = supdrvIOCtl(IOCmd, &g_DevExt, (PSUPDRVSESSION)pFilp->private_data, 798 pvBuf, Args.cbIn, pvBuf, Args.cbOut, &cbOut); 799 800 /* 801 * Copy ioctl data and output buffer back to user space. 802 */ 803 if (rc) 804 { 805 dprintf(("VBoxSupDrvDeviceControl: pFilp=%p IOCmd=%x IOArg=%p failed, rc=%d (linux rc=%d)\n", 806 pFilp, IOCmd, (void *)IOArg, rc, VBoxSupDrvErr2LinuxErr(rc))); 807 rc = VBoxSupDrvErr2LinuxErr(rc); 808 } 809 else if (cbOut > 0) 810 { 811 if (pvBuf != NULL && cbOut <= cbBuf) 812 { 813 if (copy_to_user((void *)Args.pvOut, pvBuf, cbOut)) 814 { 815 dprintf(("copy_to_user failed.\n")); 816 rc = -EFAULT; 817 } 818 } 819 else 820 { 821 dprintf(("WHAT!?! supdrvIOCtl messed up! cbOut=%d cbBuf=%d pvBuf=%p\n", cbOut, cbBuf, pvBuf)); 822 rc = -EPERM; 823 } 824 } 825 826 if (pvBuf) 827 vfree(pvBuf); 828 829 dprintf2(("VBoxSupDrvDeviceControl: returns %d\n", rc)); 848 else 849 { 850 dprintf(("VBoxDrvLinuxIOCtl: pFilp=%p uCmd=%#x ulArg=%p failed, rc=%d\n", pFilp, uCmd, (void *)ulArg, rc)); 851 rc = -EINVAL; 852 } 853 RTMemFree(pHdr); 854 855 dprintf2(("VBoxDrvLinuxIOCtl: returns %d\n", rc)); 830 856 return rc; 831 857 } … … 871 897 * @param cPages Number of pages. 872 898 */ 873 static int VBox SupDrvOrder(unsigned long cPages)899 static int VBoxDrvOrder(unsigned long cPages) 874 900 { 875 901 int iOrder; … … 1010 1036 unsigned cbAligned = RT_ALIGN(pMem->cb, PAGE_SIZE); 1011 1037 unsigned cPages = cbAligned >> PAGE_SHIFT; 1012 unsigned cOrder = VBox SupDrvOrder(cPages);1038 unsigned cOrder = VBoxDrvOrder(cPages); 1013 1039 unsigned long ulAddr; 1014 1040 dma_addr_t HCPhys; … … 1160 1186 MY_CHANGE_PAGE_ATTR(&pMem->u.cont.paPages[iPage], 1, PAGE_KERNEL); 1161 1187 } 1162 __free_pages(pMem->u.cont.paPages, VBox SupDrvOrder(pMem->u.cont.cPages));1188 __free_pages(pMem->u.cont.paPages, VBoxDrvOrder(pMem->u.cont.cPages)); 1163 1189 1164 1190 pMem->u.cont.cPages = 0; … … 1182 1208 const unsigned cPages = cbAligned >> PAGE_SHIFT; 1183 1209 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 22) 1184 unsigned cOrder = VBox SupDrvOrder(cPages);1210 unsigned cOrder = VBoxDrvOrder(cPages); 1185 1211 struct page *paPages; 1186 1212 #endif … … 1258 1284 */ 1259 1285 if (ppvR3) 1260 *ppvR3 = pMem->pvR3 = VBox SupDrvMapUser(papPages, cPages, PROT_READ | PROT_WRITE | PROT_EXEC, pgFlags);1286 *ppvR3 = pMem->pvR3 = VBoxDrvLinuxMapUser(papPages, cPages, PROT_READ | PROT_WRITE | PROT_EXEC, pgFlags); 1261 1287 if (pMem->pvR3 || !ppvR3) 1262 1288 return 0; … … 1347 1373 #else 1348 1374 if (cPages > 0) 1349 __free_pages(papPages[0], VBox SupDrvOrder(cPages));1375 __free_pages(papPages[0], VBoxDrvOrder(cPages)); 1350 1376 #endif 1351 1377 /* Free the page pointer array. */ … … 1367 1393 * @param pgFlags The page level protection. 1368 1394 */ 1369 static RTR3PTR VBox SupDrvMapUser(struct page **papPages, unsigned cPages, unsigned fProt, pgprot_t pgFlags)1395 static RTR3PTR VBoxDrvLinuxMapUser(struct page **papPages, unsigned cPages, unsigned fProt, pgprot_t pgFlags) 1370 1396 { 1371 1397 int rc = SUPDRV_ERR_NO_MEMORY; … … 1416 1442 /* no, cleanup! */ 1417 1443 if (rc) 1418 dprintf(("VBox SupDrvMapUser: remap_[page|pfn]_range failed! rc=%d\n", rc));1444 dprintf(("VBoxDrvLinuxMapUser: remap_[page|pfn]_range failed! rc=%d\n", rc)); 1419 1445 else 1420 dprintf(("VBox SupDrvMapUser: find_vma failed!\n"));1446 dprintf(("VBoxDrvLinuxMapUser: find_vma failed!\n")); 1421 1447 1422 1448 MY_DO_MUNMAP(current->mm, ulAddr, cPages << PAGE_SHIFT); … … 1441 1467 * @param pDevExt Instance data. GIP stuff may be updated. 1442 1468 */ 1443 static int VBox SupDrvInitGip(PSUPDRVDEVEXT pDevExt)1469 static int VBoxDrvLinuxInitGip(PSUPDRVDEVEXT pDevExt) 1444 1470 { 1445 1471 struct page *pPage; … … 1449 1475 unsigned i; 1450 1476 #endif 1451 dprintf(("VBox SupDrvInitGip:\n"));1477 dprintf(("VBoxDrvLinuxInitGip:\n")); 1452 1478 1453 1479 /* … … 1457 1483 if (!pPage) 1458 1484 { 1459 dprintf(("VBox SupDrvInitGip: failed to allocate the GIP page\n"));1485 dprintf(("VBoxDrvLinuxInitGip: failed to allocate the GIP page\n")); 1460 1486 return -ENOMEM; 1461 1487 } … … 1475 1501 #ifdef TICK_NSEC 1476 1502 pDevExt->u64LastMonotime = (uint64_t)pDevExt->ulLastJiffies * TICK_NSEC; 1477 dprintf(("VBox SupDrvInitGIP: TICK_NSEC=%ld HZ=%d jiffies=%ld now=%lld\n",1503 dprintf(("VBoxDrvInitGIP: TICK_NSEC=%ld HZ=%d jiffies=%ld now=%lld\n", 1478 1504 TICK_NSEC, HZ, pDevExt->ulLastJiffies, pDevExt->u64LastMonotime)); 1479 1505 #else 1480 1506 pDevExt->u64LastMonotime = (uint64_t)pDevExt->ulLastJiffies * (1000000 / HZ); 1481 dprintf(("VBox SupDrvInitGIP: TICK_NSEC=%d HZ=%d jiffies=%ld now=%lld\n",1507 dprintf(("VBoxDrvInitGIP: TICK_NSEC=%d HZ=%d jiffies=%ld now=%lld\n", 1482 1508 (int)(1000000 / HZ), HZ, pDevExt->ulLastJiffies, pDevExt->u64LastMonotime)); 1483 1509 #endif … … 1490 1516 init_timer(&g_GipTimer); 1491 1517 g_GipTimer.data = (unsigned long)pDevExt; 1492 g_GipTimer.function = VBox SupGipTimer;1518 g_GipTimer.function = VBoxDrvLinuxGipTimer; 1493 1519 g_GipTimer.expires = jiffies; 1494 1520 #ifdef CONFIG_SMP … … 1500 1526 init_timer(&pDevExt->aCPUs[i].Timer); 1501 1527 pDevExt->aCPUs[i].Timer.data = i; 1502 pDevExt->aCPUs[i].Timer.function = VBox SupGipTimerPerCpu;1528 pDevExt->aCPUs[i].Timer.function = VBoxDrvLinuxGipTimerPerCpu; 1503 1529 pDevExt->aCPUs[i].Timer.expires = jiffies; 1504 1530 } … … 1515 1541 * @param pDevExt Instance data. GIP stuff may be updated. 1516 1542 */ 1517 static int VBox SupDrvTermGip(PSUPDRVDEVEXT pDevExt)1543 static int VBoxDrvLinuxTermGip(PSUPDRVDEVEXT pDevExt) 1518 1544 { 1519 1545 struct page *pPage; … … 1522 1548 unsigned i; 1523 1549 #endif 1524 dprintf(("VBox SupDrvTermGip:\n"));1550 dprintf(("VBoxDrvLinuxTermGip:\n")); 1525 1551 1526 1552 /* … … 1565 1591 * @param ulUser The device extension pointer. 1566 1592 */ 1567 static void VBox SupGipTimer(unsigned long ulUser)1593 static void VBoxDrvLinuxGipTimer(unsigned long ulUser) 1568 1594 { 1569 1595 PSUPDRVDEVEXT pDevExt; … … 1620 1646 * @param iTimerCPU The APIC ID of this timer. 1621 1647 */ 1622 static void VBox SupGipTimerPerCpu(unsigned long iTimerCPU)1648 static void VBoxDrvLinuxGipTimerPerCpu(unsigned long iTimerCPU) 1623 1649 { 1624 1650 PSUPDRVDEVEXT pDevExt; … … 1779 1805 { 1780 1806 mod_timer(&g_GipTimer, jiffies); 1781 smp_call_function(VBox SupGipResumePerCpu, pDevExt, 0 /* retry */, 1 /* wait */);1807 smp_call_function(VBoxDrvLinuxGipResumePerCpu, pDevExt, 0 /* retry */, 1 /* wait */); 1782 1808 } 1783 1809 #endif … … 1793 1819 * @param pvUser Pointer to the device instance. 1794 1820 */ 1795 static void VBox SupGipResumePerCpu(void *pvUser)1821 static void VBoxDrvLinuxGipResumePerCpu(void *pvUser) 1796 1822 { 1797 1823 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pvUser; … … 1869 1895 * @param rc supdrv error code (SUPDRV_ERR_* defines). 1870 1896 */ 1871 static int VBox SupDrvErr2LinuxErr(int rc)1897 static int VBoxDrvLinuxErr2LinuxErr(int rc) 1872 1898 { 1873 1899 switch (rc) … … 1940 1966 1941 1967 1942 module_init(VBox SupDrvInit);1943 module_exit(VBox SupDrvUnload);1968 module_init(VBoxDrvLinuxInit); 1969 module_exit(VBoxDrvLinuxUnload); 1944 1970 1945 1971 MODULE_AUTHOR("innotek GmbH"); -
trunk/src/VBox/HostDrivers/Support/linux/SUPLib-linux.cpp
r4071 r4800 201 201 * @returns VBOX error code on failure. 202 202 * @param uFunction IO Control function. 203 * @param pvIn Input data buffer. 204 * @param cbIn Size of input data. 205 * @param pvOut Output data buffer. 206 * @param cbOut Size of output data. 207 */ 208 int suplibOsIOCtl(unsigned uFunction, void *pvIn, size_t cbIn, void *pvOut, size_t cbOut) 203 * @param pvReq The request buffer. 204 * @param cbReq The size of the request buffer. 205 */ 206 int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq) 209 207 { 210 208 AssertMsg(g_hDevice != -1, ("SUPLIB not initiated successfully!\n")); 209 211 210 /* 212 211 * Issue device iocontrol. 213 212 */ 214 SUPDRVIOCTLDATA Args; 215 Args.pvIn = pvIn; 216 Args.cbIn = cbIn; 217 Args.pvOut = pvOut; 218 Args.cbOut = cbOut; 219 220 if (ioctl(g_hDevice, uFunction, &Args) >= 0) 213 if (RT_LIKELY(ioctl(g_hDevice, uFunction, pvReq) >= 0)) 221 214 return VINF_SUCCESS; 222 215 -
trunk/src/VBox/HostDrivers/Support/os2/SUPLib-os2.cpp
r4071 r4800 131 131 132 132 133 int suplibOsIOCtl(u nsigned uFunction, void *pvIn, size_t cbIn, void *pvOut, size_t cbOut)133 int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq) 134 134 { 135 135 AssertMsg(g_hDevice != (HFILE)-1, ("SUPLIB not initiated successfully!\n")); 136 136 137 SUPDRVIOCTLDATA Args; 138 Args.pvIn = pvIn; 139 Args.cbIn = cbIn; 140 Args.pvOut = pvOut; 141 Args.cbOut = cbOut; 142 Args.rc = VERR_INTERNAL_ERROR; 143 144 ULONG cbReturned = sizeof(Args); 137 ULONG cbReturned = sizeof(SUPREQHDR); 145 138 int rc = DosDevIOCtl(g_hDevice, SUP_CTL_CATEGORY, uFunction, 146 & Args, sizeof(Args), &cbReturned,139 &cbIn, cbReturned, &cbReturned, 147 140 NULL, 0, NULL); 148 141 if (RT_LIKELY(rc == NO_ERROR)) 149 rc = Args.rc; 150 else 151 rc = RTErrConvertFromOS2(rc); 152 return rc; 142 return VINF_SUCCESS; 143 return RTErrConvertFromOS2(rc); 153 144 } 154 145 155 146 156 147 #ifdef VBOX_WITHOUT_IDT_PATCHING 157 int suplibOSIOCtlFast(u nsigneduFunction)148 int suplibOSIOCtlFast(uintptr_t uFunction) 158 149 { 159 150 int32_t rcRet = VERR_INTERNAL_ERROR; -
trunk/src/VBox/HostDrivers/Support/solaris/SUPDrv-solaris.c
r4717 r4800 235 235 break; 236 236 } 237 237 238 238 if (instance >= DEVICE_MAXINSTANCES) 239 239 { … … 241 241 return ENXIO; 242 242 } 243 243 244 244 *pDev = makedevice(getmajor(*pDev), instance); 245 245 246 246 return VBoxSupDrvErr2SolarisErr(rc); 247 247 } … … 290 290 if (!pSession) 291 291 { 292 OSDBGPRINT(("VBoxDrvSolarisClose: WHAT?!? pSession == NULL! This must be a mistake... pid=%d (close)\n", 292 OSDBGPRINT(("VBoxDrvSolarisClose: WHAT?!? pSession == NULL! This must be a mistake... pid=%d (close)\n", 293 293 (int)Process)); 294 294 return DDI_FAILURE; … … 328 328 int instance = 0; 329 329 vbox_devstate_t *pState; 330 330 331 331 switch (enmCmd) 332 332 { … … 340 340 return DDI_FAILURE; 341 341 } 342 342 343 343 pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, instance); 344 344 345 345 /* 346 346 * Initialize IPRT R0 driver, which internally calls OS-specific r0 init. … … 425 425 ddi_remove_minor_node(pDip, NULL); 426 426 ddi_soft_state_free(g_pVBoxDrvSolarisState, instance); 427 428 rc = supdrvDeleteDevExt(&g_DevExt); 429 AssertRC(rc); 427 428 supdrvDeleteDevExt(&g_DevExt); 430 429 431 430 rc = RTSpinlockDestroy(g_Spinlock); … … 478 477 if (!pSession) 479 478 { 480 OSDBGPRINT(("VBoxSupDrvIOCtl: WHAT?!? pSession == NULL! This must be a mistake... pid=%d iCmd=%#x\n", 479 OSDBGPRINT(("VBoxSupDrvIOCtl: WHAT?!? pSession == NULL! This must be a mistake... pid=%d iCmd=%#x\n", 481 480 (int)Process, Cmd)); 482 481 return EINVAL; … … 502 501 * @returns Solaris errno. 503 502 * 504 * @param pSession The session. 505 * @param Cmd The IOCtl command. 506 * @param Mode Information bitfield (for specifying ownership of data) 507 * @param pArgs Pointer to the kernel copy of the SUPDRVIOCTLDATA buffer. 508 */ 509 static int VBoxDrvSolarisIOCtlSlow(PSUPDRVSESSION pSession, int Cmd, int Mode, intptr_t pArgs) 510 { 511 int rc; 512 void *pvBuf = NULL; 513 unsigned long cbBuf = 0; 514 unsigned cbOut = 0; 515 PSUPDRVIOCTLDATA pArgData = (PSUPDRVIOCTLDATA)pArgs; 516 517 /* 518 * Allocate and copy user space input data buffer to kernel space. 519 */ 520 if (pArgData->cbIn > 0 || pArgData->cbOut > 0) 521 { 522 cbBuf = max(pArgData->cbIn, pArgData->cbOut); 523 pvBuf = RTMemTmpAlloc(cbBuf); 524 525 if (pvBuf == NULL) 503 * @param pSession The session. 504 * @param Cmd The IOCtl command. 505 * @param Mode Information bitfield (for specifying ownership of data) 506 * @param iArg User space address of the request buffer. 507 */ 508 static int VBoxDrvSolarisIOCtlSlow(PSUPDRVSESSION pSession, int iCmd, int Mode, intptr_t iArg) 509 { 510 int rc; 511 uint32_t cbBuf = 0; 512 SUPREQHDR Hdr; 513 PSUPREQHDR pHdr; 514 515 516 /* 517 * Read the header. 518 */ 519 rc = ddi_copyin(&Hdr, (void *)iArg, sizeof(Hdr), Mode); 520 if (RT_UNLIKELY(rc)) 521 { 522 dprintf(("VBoxDrvSolarisIOCtlSlow: ddi_copyin(,%#lx,) failed; iCmd=%#x. rc=%d\n", iArg, iCmd, rc)); 523 return EFAULT; 524 } 525 if (RT_UNLIKELY((Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC)) 526 { 527 dprintf(("VBoxDrvSolarisIOCtlSlow: bad header magic %#x; iCmd=%#x\n", Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK, iCmd)); 528 return EINVAL; 529 } 530 531 /* 532 * Buffer the request. 533 */ 534 cbBuf = RT_MAX(Hdr.cbIn, Hdr.cbOut); 535 if (RT_UNLIKELY(cbBuf > _1M*16)) 536 { 537 dprintf(("VBoxDrvSolarisIOCtlSlow: too big cbBuf=%#x; iCmd=%#x\n", cbBuf, iCmd)); 538 return E2BIG; 539 } 540 if (RT_UNLIKELY(cbBuf < sizeof(Hdr))) 541 { 542 dprintf(("VBoxDrvSolarisIOCtlSlow: bad ioctl cbBuf=%#x; iCmd=%#x.\n", cbBuf, iCmd)); 543 return EINVAL; 544 } 545 pHdr = RTMemAlloc(cbBuf); 546 if (RT_UNLIKELY(!pHdr)) 547 { 548 OSDBGPRINT(("VBoxDrvSolarisIOCtlSlow: failed to allocate buffer of %d bytes for iCmd=%#x.\n", cbBuf, iCmd)); 549 return ENOMEM; 550 } 551 rc = ddi_copyin(pHdr, (void *)iArg, cbBuf, Mode); 552 if (RT_UNLIKELY(rc)) 553 { 554 dprintf(("VBoxDrvSolarisIOCtlSlow: copy_from_user(,%#lx, %#x) failed; iCmd=%#x. rc=%d\n", iArg, Hdr.cbIn, iCmd, rc)); 555 RTMemFree(pHdr); 556 return EFAULT; 557 } 558 559 /* 560 * Process the IOCtl. 561 */ 562 rc = supdrvIOCtl(Cmd, &g_DevExt, pSession, pHdr); 563 564 /* 565 * Copy ioctl data and output buffer back to user space. 566 */ 567 if (RT_LIKELY(!rc)) 568 { 569 uint32_t cbOut = pHdr->cbOut; 570 if (RT_UNLIKELY(cbOut > cbBuf)) 526 571 { 527 OSDBGPRINT(("VBoxDrvSolarisIOCtlSlow: failed to allocate buffer of %d bytes.\n", cbBuf));528 return ENOMEM;572 OSDBGPRINT(("VBoxDrvSolarisIOCtlSlow: too much output! %#x > %#x; iCmd=%#x!\n", cbOut, cbBuf, iCmd)); 573 cbOut = cbBuf; 529 574 } 530 531 rc = ddi_copyin(pArgData->pvIn, pvBuf, pArgData->cbIn, Mode); 532 533 if (rc != 0) 575 rc = ddi_copyout(pHdr, (void *)iArg, cbOut, Mode); 576 if (RT_UNLIKELY(rc != 0)) 534 577 { 535 OSDBGPRINT(("VBoxDrvSolarisIOCtlSlow: ddi_copyin(%p,%d) failed.\n", pArgData->pvIn, pArgData->cbIn)); 536 537 RTMemTmpFree(pvBuf); 538 return EFAULT; 578 /* this is really bad */ 579 OSDBGPRINT(("VBoxDrvSolarisIOCtlSlow: ddi_copyout(,%p,%d) failed. rc=%d\n", (void *)iArg, cbBuf, rc)); 580 rc = EFAULT; 539 581 } 540 582 } 541 542 /* 543 * Process the IOCtl. 544 */ 545 rc = supdrvIOCtl(Cmd, &g_DevExt, pSession, pvBuf, pArgData->cbIn, pvBuf, pArgData->cbOut, &cbOut); 546 547 /* 548 * Copy ioctl data and output buffer back to user space. 549 */ 550 if (rc != 0) 551 rc = VBoxSupDrvErr2SolarisErr(rc); 552 else if (cbOut > 0) 553 { 554 if (pvBuf != NULL && cbOut <= cbBuf) 555 { 556 rc = ddi_copyout(pvBuf, pArgData->pvOut, cbOut, Mode); 557 if (rc != 0) 558 { 559 OSDBGPRINT(("VBoxDrvSolarisIOCtlSlow: ddi_copyout(,%p,%d) failed.\n", pArgData->pvOut, cbBuf)); 560 rc = EFAULT; 561 } 562 } 563 else 564 { 565 OSDBGPRINT(("WHAT!?! supdrvIOCtl messed up! cbOut=%d cbBuf=%d pvBuf=%p\n", cbOut, cbBuf, pvBuf)); 566 rc = EPERM; 567 } 568 } 569 570 if (pvBuf) 571 RTMemTmpFree(pvBuf); 572 583 else 584 rc = EINVAL; 585 586 RTMemTmpFree(pHdr); 573 587 return rc; 574 588 } -
trunk/src/VBox/HostDrivers/Support/solaris/SUPLib-solaris.cpp
r4178 r4800 103 103 104 104 105 /**106 * Installs anything required by the support library.107 *108 * @returns 0 on success.109 * @returns error code on failure.110 */111 105 int suplibOsInstall(void) 112 106 { 113 // int rc = mknod(DEVICE_NAME, S_IFCHR, );114 115 107 return VERR_NOT_IMPLEMENTED; 116 108 } 117 109 118 /**119 * Installs anything required by the support library.120 *121 * @returns 0 on success.122 * @returns error code on failure.123 */124 110 int suplibOsUninstall(void) 125 111 { 126 // int rc = unlink(DEVICE_NAME);127 128 112 return VERR_NOT_IMPLEMENTED; 129 113 } 130 114 131 /** 132 * Send a I/O Control request to the device. 133 * 134 * @returns 0 on success. 135 * @returns VBOX error code on failure. 136 * @param uFunction IO Control function. 137 * @param pvIn Input data buffer. 138 * @param cbIn Size of input data. 139 * @param pvOut Output data buffer. 140 * @param cbOut Size of output data. 141 */ 142 int suplibOsIOCtl(unsigned uFunction, void *pvIn, size_t cbIn, void *pvOut, size_t cbOut) 115 116 int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq) 143 117 { 144 118 AssertMsg(g_hDevice != -1, ("SUPLIB not initiated successfully!\n")); 119 145 120 /* 146 121 * Issue device iocontrol. 147 122 */ 148 SUPDRVIOCTLDATA Args; 149 Args.pvIn = pvIn; 150 Args.cbIn = cbIn; 151 Args.pvOut = pvOut; 152 Args.cbOut = cbOut; 123 if (RT_LIKELY(ioctl(g_hDevice, uFunction, &pvReq) >= 0)) 124 return VINF_SUCCESS; 153 125 154 if (ioctl(g_hDevice, uFunction, &Args) >= 0)155 return 0;156 157 126 /* This is the reverse operation of the one found in SUPDrv-solaris.c */ 158 127 switch (errno) … … 174 143 175 144 #ifdef VBOX_WITHOUT_IDT_PATCHING 176 int suplibOSIOCtlFast(u nsigneduFunction)145 int suplibOSIOCtlFast(uintptr_t uFunction) 177 146 { 178 147 int rc = ioctl(g_hDevice, uFunction, NULL); … … 184 153 185 154 186 /**187 * Allocate a number of zero-filled pages in user space.188 *189 * @returns VBox status code.190 * @param cPages Number of pages to allocate.191 * @param ppvPages Where to return the base pointer.192 */193 155 int suplibOsPageAlloc(size_t cPages, void **ppvPages) 194 156 { … … 200 162 201 163 202 /**203 * Frees pages allocated by suplibOsPageAlloc().204 *205 * @returns VBox status code.206 * @param pvPages Pointer to pages.207 */208 164 int suplibOsPageFree(void *pvPages, size_t /* cPages */) 209 165 { -
trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp
r4755 r4800 58 58 * Internal Functions * 59 59 *******************************************************************************/ 60 static void _stdcall VBox SupDrvUnload(PDRIVER_OBJECT pDrvObj);61 static NTSTATUS _stdcall VBox SupDrvCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp);62 static NTSTATUS _stdcall VBox SupDrvClose(PDEVICE_OBJECT pDevObj, PIRP pIrp);63 static NTSTATUS _stdcall VBox SupDrvDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp);64 static int VBox SupDrvDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack);65 static NTSTATUS _stdcall VBox SupDrvNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp);66 static NTSTATUS VBox SupDrvErr2NtStatus(int rc);67 static NTSTATUS VBox SupDrvGipInit(PSUPDRVDEVEXT pDevExt);68 static void VBox SupDrvGipTerm(PSUPDRVDEVEXT pDevExt);69 static void _stdcall VBox SupDrvGipTimer(IN PKDPC pDpc, IN PVOID pvUser, IN PVOID SystemArgument1, IN PVOID SystemArgument2);70 static void _stdcall VBox SupDrvGipPerCpuDpc(IN PKDPC pDpc, IN PVOID pvUser, IN PVOID SystemArgument1, IN PVOID SystemArgument2);60 static void _stdcall VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj); 61 static NTSTATUS _stdcall VBoxDrvNtCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp); 62 static NTSTATUS _stdcall VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp); 63 static NTSTATUS _stdcall VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp); 64 static int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack); 65 static NTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp); 66 static NTSTATUS VBoxDrvNtErr2NtStatus(int rc); 67 static NTSTATUS VBoxDrvNtGipInit(PSUPDRVDEVEXT pDevExt); 68 static void VBoxDrvNtGipTerm(PSUPDRVDEVEXT pDevExt); 69 static void _stdcall VBoxDrvNtGipTimer(IN PKDPC pDpc, IN PVOID pvUser, IN PVOID SystemArgument1, IN PVOID SystemArgument2); 70 static void _stdcall VBoxDrvNtGipPerCpuDpc(IN PKDPC pDpc, IN PVOID pvUser, IN PVOID SystemArgument1, IN PVOID SystemArgument2); 71 71 72 72 … … 118 118 * Inititalize the GIP. 119 119 */ 120 rc = VBox SupDrvGipInit(pDevExt);120 rc = VBoxDrvNtGipInit(pDevExt); 121 121 if (NT_SUCCESS(rc)) 122 122 { … … 124 124 * Setup the driver entry points in pDrvObj. 125 125 */ 126 pDrvObj->DriverUnload = VBox SupDrvUnload;127 pDrvObj->MajorFunction[IRP_MJ_CREATE] = VBox SupDrvCreate;128 pDrvObj->MajorFunction[IRP_MJ_CLOSE] = VBox SupDrvClose;129 pDrvObj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VBox SupDrvDeviceControl;130 pDrvObj->MajorFunction[IRP_MJ_READ] = VBox SupDrvNotSupportedStub;131 pDrvObj->MajorFunction[IRP_MJ_WRITE] = VBox SupDrvNotSupportedStub;126 pDrvObj->DriverUnload = VBoxDrvNtUnload; 127 pDrvObj->MajorFunction[IRP_MJ_CREATE] = VBoxDrvNtCreate; 128 pDrvObj->MajorFunction[IRP_MJ_CLOSE] = VBoxDrvNtClose; 129 pDrvObj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VBoxDrvNtDeviceControl; 130 pDrvObj->MajorFunction[IRP_MJ_READ] = VBoxDrvNtNotSupportedStub; 131 pDrvObj->MajorFunction[IRP_MJ_WRITE] = VBoxDrvNtNotSupportedStub; 132 132 /* more? */ 133 133 dprintf(("VBoxDrv::DriverEntry returning STATUS_SUCCESS\n")); 134 134 return STATUS_SUCCESS; 135 135 } 136 dprintf(("VBox SupDrvGipInit failed with rc=%#x!\n", rc));136 dprintf(("VBoxDrvNtGipInit failed with rc=%#x!\n", rc)); 137 137 138 138 supdrvDeleteDevExt(pDevExt); … … 141 141 { 142 142 dprintf(("supdrvInitDevExit failed with vrc=%d!\n", vrc)); 143 rc = VBox SupDrvErr2NtStatus(vrc);143 rc = VBoxDrvNtErr2NtStatus(vrc); 144 144 } 145 145 … … 166 166 * @param pDrvObj Driver object. 167 167 */ 168 void _stdcall VBox SupDrvUnload(PDRIVER_OBJECT pDrvObj)169 { 170 dprintf(("VBox SupDrvUnload\n"));168 void _stdcall VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj) 169 { 170 dprintf(("VBoxDrvNtUnload\n")); 171 171 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDrvObj->DeviceObject->DeviceExtension; 172 172 … … 182 182 * Terminate the GIP page and delete the device extension. 183 183 */ 184 VBox SupDrvGipTerm(pDevExt);184 VBoxDrvNtGipTerm(pDevExt); 185 185 supdrvDeleteDevExt(pDevExt); 186 186 IoDeleteDevice(pDrvObj->DeviceObject); … … 194 194 * @param pIrp Request packet. 195 195 */ 196 NTSTATUS _stdcall VBox SupDrvCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp)197 { 198 dprintf(("VBox SupDrvCreate\n"));196 NTSTATUS _stdcall VBoxDrvNtCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp) 197 { 198 dprintf(("VBoxDrvNtCreate\n")); 199 199 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp); 200 200 PFILE_OBJECT pFileObj = pStack->FileObject; … … 228 228 } 229 229 230 NTSTATUS rcNt = pIrp->IoStatus.Status = VBox SupDrvErr2NtStatus(rc);230 NTSTATUS rcNt = pIrp->IoStatus.Status = VBoxDrvNtErr2NtStatus(rc); 231 231 pIrp->IoStatus.Information = 0; 232 232 IoCompleteRequest(pIrp, IO_NO_INCREMENT); … … 242 242 * @param pIrp Request packet. 243 243 */ 244 NTSTATUS _stdcall VBox SupDrvClose(PDEVICE_OBJECT pDevObj, PIRP pIrp)244 NTSTATUS _stdcall VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp) 245 245 { 246 246 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension; 247 247 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp); 248 248 PFILE_OBJECT pFileObj = pStack->FileObject; 249 dprintf(("VBox SupDrvClose: pDevExt=%p pFileObj=%p pSession=%p\n",249 dprintf(("VBoxDrvNtClose: pDevExt=%p pFileObj=%p pSession=%p\n", 250 250 pDevExt, pFileObj, pFileObj->FsContext)); 251 251 supdrvCloseSession(pDevExt, (PSUPDRVSESSION)pFileObj->FsContext); … … 265 265 * @param pIrp Request packet. 266 266 */ 267 NTSTATUS _stdcall VBox SupDrvDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)267 NTSTATUS _stdcall VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp) 268 268 { 269 269 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension; … … 300 300 #endif /* VBOX_WITHOUT_IDT_PATCHING */ 301 301 302 return VBox SupDrvDeviceControlSlow(pDevExt, pSession, pIrp, pStack);303 } 304 305 306 /** 307 * Worker for VBox SupDrvDeviceControl that takes the slow IOCtl functions.302 return VBoxDrvNtDeviceControlSlow(pDevExt, pSession, pIrp, pStack); 303 } 304 305 306 /** 307 * Worker for VBoxDrvNtDeviceControl that takes the slow IOCtl functions. 308 308 * 309 309 * @returns NT status code. … … 314 314 * @param pStack The stack location containing the DeviceControl parameters. 315 315 */ 316 static int VBox SupDrvDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack)317 { 318 NTSTATUS rcNt = STATUS_NOT_SUPPORTED;316 static int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack) 317 { 318 NTSTATUS rcNt; 319 319 unsigned cbOut = 0; 320 320 int rc = 0; 321 dprintf2(("VBox SupDrvDeviceControlSlow(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n",321 dprintf2(("VBoxDrvNtDeviceControlSlow(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n", 322 322 pDevExt, pIrp, pStack->Parameters.DeviceIoControl.IoControlCode, 323 323 pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength, … … 332 332 if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED) 333 333 { 334 char *pBuf = (char *)pIrp->AssociatedIrp.SystemBuffer; 335 336 /* 337 * Do the job. 338 */ 339 rc = supdrvIOCtl(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, 340 pBuf, pStack->Parameters.DeviceIoControl.InputBufferLength, 341 pBuf, pStack->Parameters.DeviceIoControl.OutputBufferLength, 342 &cbOut); 343 rcNt = VBoxSupDrvErr2NtStatus(rc); 344 345 /* sanity check. */ 346 AssertMsg(cbOut <= pStack->Parameters.DeviceIoControl.OutputBufferLength, 347 ("cbOut is too large! cbOut=%d max=%d! ioctl=%#x\n", 348 cbOut, pStack->Parameters.DeviceIoControl.OutputBufferLength, 349 pStack->Parameters.DeviceIoControl.IoControlCode)); 350 if (cbOut > pStack->Parameters.DeviceIoControl.OutputBufferLength) 351 cbOut = pStack->Parameters.DeviceIoControl.OutputBufferLength; 352 dprintf2(("VBoxSupDrvDeviceControlSlow: returns %#x cbOut=%d rc=%#x\n", rcNt, cbOut, rc)); 334 /* Verify that the sizes in the request header are correct. */ 335 PSUPREQHDR pHdr = (PSUPREQHDR)pIrp->AssociatedIrp.SystemBuffer; 336 if ( pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) 337 && pStack->Parameters.DeviceIoControl.InputBufferLength == pHdr->cbIn 338 && pStack->Parameters.DeviceIoControl.OutputBufferLength == pHdr->cbOut) 339 { 340 /* 341 * Do the job. 342 */ 343 rc = supdrvIOCtl(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr); 344 if (!rc) 345 { 346 rcNt = STATUS_SUCCESS; 347 cbOut = pHdr->cbOut; 348 if (cbOut > pStack->Parameters.DeviceIoControl.OutputBufferLength) 349 { 350 cbOut = pStack->Parameters.DeviceIoControl.OutputBufferLength; 351 OSDBGPRINT(("VBoxDrvLinuxIOCtl: too much output! %#x > %#x; uCmd=%#x!\n", 352 pHdr->cbOut, cbOut, pStack->Parameters.DeviceIoControl.IoControlCode)); 353 } 354 } 355 else 356 rcNt = STATUS_INVALID_PARAMETER; 357 dprintf2(("VBoxDrvNtDeviceControlSlow: returns %#x cbOut=%d rc=%#x\n", rcNt, cbOut, rc)); 358 } 359 else 360 { 361 dprintf(("VBoxDrvNtDeviceControlSlow: Mismatching sizes (%#x) - Hdr=%#lx/%#lx Irp=%#lx/%#lx!\n", 362 pStack->Parameters.DeviceIoControl.IoControlCode, 363 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbIn : 0, 364 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbOut : 0, 365 pStack->Parameters.DeviceIoControl.InputBufferLength, 366 pStack->Parameters.DeviceIoControl.OutputBufferLength)); 367 rcNt = STATUS_INVALID_PARAMETER; 368 } 353 369 } 354 370 else 355 dprintf(("VBoxSupDrvDeviceControlSlow: not buffered request (%#x) - not supported\n", 371 { 372 dprintf(("VBoxDrvNtDeviceControlSlow: not buffered request (%#x) - not supported\n", 356 373 pStack->Parameters.DeviceIoControl.IoControlCode)); 374 rcNt = STATUS_NOT_SUPPORTED; 375 } 357 376 } 358 377 #ifdef RT_ARCH_AMD64 359 378 else 360 dprintf(("VBoxSupDrvDeviceControlSlow: WOW64 req - not supported\n")); 379 { 380 dprintf(("VBoxDrvNtDeviceControlSlow: WOW64 req - not supported\n")); 381 rcNt = STATUS_NOT_SUPPORTED; 382 } 361 383 #endif 362 384 363 385 /* complete the request. */ 364 386 pIrp->IoStatus.Status = rcNt; 365 pIrp->IoStatus.Information = NT_SUCCESS(rcNt) ? cbOut : rc; /* does this rc passing actually work?!? */387 pIrp->IoStatus.Information = cbOut; 366 388 IoCompleteRequest(pIrp, IO_NO_INCREMENT); 367 389 return rcNt; … … 376 398 * @param pIrp IRP. 377 399 */ 378 NTSTATUS _stdcall VBox SupDrvNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp)379 { 380 dprintf(("VBox SupDrvNotSupportedStub\n"));400 NTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp) 401 { 402 dprintf(("VBoxDrvNtNotSupportedStub\n")); 381 403 pDevObj = pDevObj; 382 404 … … 808 830 * @param pDevExt Instance data. GIP stuff may be updated. 809 831 */ 810 static NTSTATUS VBox SupDrvGipInit(PSUPDRVDEVEXT pDevExt)832 static NTSTATUS VBoxDrvNtGipInit(PSUPDRVDEVEXT pDevExt) 811 833 { 812 834 dprintf2(("VBoxSupDrvTermGip:\n")); … … 850 872 */ 851 873 KeInitializeTimerEx(&pDevExt->GipTimer, SynchronizationTimer); 852 KeInitializeDpc(&pDevExt->GipDpc, VBox SupDrvGipTimer, pDevExt);874 KeInitializeDpc(&pDevExt->GipDpc, VBoxDrvNtGipTimer, pDevExt); 853 875 854 876 /* … … 862 884 for (unsigned i = 0; i < RT_ELEMENTS(pDevExt->aGipCpuDpcs); i++) 863 885 { 864 KeInitializeDpc(&pDevExt->aGipCpuDpcs[i], VBox SupDrvGipPerCpuDpc, pGip);886 KeInitializeDpc(&pDevExt->aGipCpuDpcs[i], VBoxDrvNtGipPerCpuDpc, pGip); 865 887 KeSetImportanceDpc(&pDevExt->aGipCpuDpcs[i], HighImportance); 866 888 if (pfnKeSetTargetProcessorDpc) … … 868 890 } 869 891 870 dprintf(("VBox SupDrvGipInit: ulClockFreq=%ld ulClockInterval=%ld ulClockIntervalActual=%ld Phys=%x%08x\n",892 dprintf(("VBoxDrvNtGipInit: ulClockFreq=%ld ulClockInterval=%ld ulClockIntervalActual=%ld Phys=%x%08x\n", 871 893 ulClockFreq, ulClockInterval, ulClockIntervalActual, Phys.HighPart, Phys.LowPart)); 872 894 return STATUS_SUCCESS; … … 898 920 * @param pDevExt Instance data. GIP stuff may be updated. 899 921 */ 900 static void VBox SupDrvGipTerm(PSUPDRVDEVEXT pDevExt)922 static void VBoxDrvNtGipTerm(PSUPDRVDEVEXT pDevExt) 901 923 { 902 924 dprintf(("VBoxSupDrvTermGip:\n")); … … 941 963 * The pvUser parameter is the pDevExt pointer. 942 964 */ 943 static void _stdcall VBox SupDrvGipTimer(IN PKDPC pDpc, IN PVOID pvUser, IN PVOID SystemArgument1, IN PVOID SystemArgument2)965 static void _stdcall VBoxDrvNtGipTimer(IN PKDPC pDpc, IN PVOID pvUser, IN PVOID SystemArgument1, IN PVOID SystemArgument2) 944 966 { 945 967 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pvUser; … … 982 1004 * The pvUser parameter is the pGip pointer. 983 1005 */ 984 static void _stdcall VBox SupDrvGipPerCpuDpc(IN PKDPC pDpc, IN PVOID pvUser, IN PVOID SystemArgument1, IN PVOID SystemArgument2)1006 static void _stdcall VBoxDrvNtGipPerCpuDpc(IN PKDPC pDpc, IN PVOID pvUser, IN PVOID SystemArgument1, IN PVOID SystemArgument2) 985 1007 { 986 1008 PSUPGLOBALINFOPAGE pGip = (PSUPGLOBALINFOPAGE)pvUser; … … 1173 1195 * @param rc supdrv error code (SUPDRV_ERR_* defines). 1174 1196 */ 1175 static NTSTATUS VBox SupDrvErr2NtStatus(int rc)1197 static NTSTATUS VBoxDrvNtErr2NtStatus(int rc) 1176 1198 { 1177 1199 switch (rc) -
trunk/src/VBox/HostDrivers/Support/win/SUPLib-win.cpp
r4071 r4800 21 21 *******************************************************************************/ 22 22 #define LOG_GROUP LOG_GROUP_SUP 23 #include < windows.h>23 #include <Windows.h> 24 24 25 25 #include <VBox/sup.h> … … 32 32 #include <iprt/string.h> 33 33 #include "SUPLibInternal.h" 34 #include "SUPDRVIOC.h" 34 35 35 36 … … 603 604 * @returns VBOX error code on failure. 604 605 * @param uFunction IO Control function. 605 * @param pvIn Input data buffer. 606 * @param cbIn Size of input data. 607 * @param pvOut Output data buffer. 608 * @param cbOut Size of output data. 609 */ 610 int suplibOsIOCtl(unsigned uFunction, void *pvIn, size_t cbIn, void *pvOut, size_t cbOut) 606 * @param pvIn The request buffer. 607 * @param cbReq The size of the request buffer. 608 */ 609 int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq) 611 610 { 612 611 AssertMsg(g_hDevice != INVALID_HANDLE_VALUE, ("SUPLIB not initiated successfully!\n")); 613 /* 614 * Issue device I/O control. 615 */ 616 DWORD cbReturned = (ULONG)cbOut; 617 if (DeviceIoControl(g_hDevice, uFunction, pvIn, (ULONG)cbIn, pvOut, (ULONG)cbOut, &cbReturned, NULL)) 612 613 /* 614 * Issue the device I/O control. 615 */ 616 PSUPREQHDR pHdr = (PSUPREQHDR)pvReq; 617 Assert(cbReq == RT_MAX(pHdr->cbIn, pHdr->cbOut)); 618 DWORD cbReturned = (ULONG)pHdr->cbOut; 619 if (DeviceIoControl(g_hDevice, uFunction, pvReq, pHdr->cbIn, pvReq, cbReturned, &cbReturned, NULL)) 618 620 return 0; 621 619 622 return suplibConvertWin32Err(GetLastError()); 620 623 }
Note:
See TracChangeset
for help on using the changeset viewer.