Changeset 10484 in vbox
- Timestamp:
- Jul 10, 2008 8:49:07 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 33159
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp
r10476 r10484 24 24 * Header Files * 25 25 *******************************************************************************/ 26 #ifdef RT_OS_OS2 26 #if defined(RT_OS_WINDOWS) 27 # include <Windows.h> 28 29 #elif defined(RT_OS_OS2) 27 30 # define INCL_BASE 28 31 # define INCL_ERRORS 29 32 # include <os2.h> 33 30 34 #elif defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) 31 35 # include <sys/types.h> … … 87 91 * processed calling us more than once. 88 92 */ 89 #ifndef RT_OS_WINDOWS 90 #ifndef VBOX_VBGLR3_XFREE86 93 #ifdef RT_OS_WINDOWS 94 if (g_hFile == INVALID_HANDLE_VALUE) 95 #elif !defined (VBOX_VBGLR3_XFREE86) 91 96 if (g_File == NIL_RTFILE) 92 97 #else 93 98 if (g_File == -1) 94 99 #endif 95 100 return VERR_INTERNAL_ERROR; 96 #else 97 if (g_hFile == NULL) 101 return VINF_SUCCESS; 102 } 103 #if defined(RT_OS_WINDOWS) 104 if (g_hFile != INVALID_HANDLE_VALUE) 105 #elif !defined(VBOX_VBGLR3_XFREE86) 106 if (g_File != NIL_RTFILE) 107 #else 108 if (g_File != -1) 109 #endif 98 110 return VERR_INTERNAL_ERROR; 99 #endif 100 return VINF_SUCCESS; 101 } 102 103 #ifndef RT_OS_WINDOWS 104 #ifndef VBOX_VBGLR3_XFREE86 105 if (g_File != NIL_RTFILE) 106 #else 107 if (g_File != -1) 108 #endif 109 return VERR_INTERNAL_ERROR; 110 #else 111 if (g_hFile != INVALID_HANDLE_VALUE) 112 return VERR_INTERNAL_ERROR; 113 #endif 114 115 #if defined(RT_OS_OS2) 111 112 #if defined(RT_OS_WINDOWS) 113 /* 114 * Have to use CreateFile here as we want to specify FILE_FLAG_OVERLAPPED 115 * and possible some other bits not availble thru iprt/file.h. 116 */ 117 HANDLE hFile = CreateFile(VBOXGUEST_DEVICE_NAME, 118 GENERIC_READ | GENERIC_WRITE, 119 FILE_SHARE_READ | FILE_SHARE_WRITE, 120 NULL, 121 OPEN_EXISTING, 122 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 123 NULL); 124 125 if (hFile == INVALID_HANDLE_VALUE) 126 return VERR_OPEN_FAILED; 127 g_hFile = hFile; 128 129 #elif defined(RT_OS_OS2) 116 130 /* 117 131 * We might wish to compile this with Watcom, so stick to … … 164 178 g_File = hf; 165 179 166 #elif defined(VBOX_VBGLR3_XFREE86) && !defined(RT_OS_FREEBSD)167 int File = xf86open(VBOXGUEST_DEVICE_NAME, XF86_O_RDWR);168 if (File == -1)169 return VERR_OPEN_FAILED;170 g_File = File;171 172 180 #elif defined(RT_OS_FREEBSD) 173 181 /* 174 * Try open the BSD device. 182 * Try open the BSD device. The device cloning makes this a bit of work. 175 183 */ 176 184 # if defined(VBOX_VBGLR3_XFREE86) … … 205 213 g_File = File; 206 214 207 #elif defined(RT_OS_WINDOWS) 208 209 /* 210 * Open a handle to the shadow device. 211 */ 212 g_hFile = CreateFile(VBOXGUEST_DEVICE_NAME, 213 GENERIC_READ | GENERIC_WRITE, 214 FILE_SHARE_READ | FILE_SHARE_WRITE, 215 NULL, 216 OPEN_EXISTING, 217 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 218 NULL); 219 220 if (g_hFile == INVALID_HANDLE_VALUE) 215 #elif defined(VBOX_VBGLR3_XFREE86) && !defined(RT_OS_FREEBSD) 216 int File = xf86open(VBOXGUEST_DEVICE_NAME, XF86_O_RDWR); 217 if (File == -1) 221 218 return VERR_OPEN_FAILED; 219 g_File = File; 222 220 223 221 #else … … 250 248 VBGLR3DECL(void) VbglR3Term(void) 251 249 { 250 /* 251 * Decrement the reference count and see if we're the last one out. 252 */ 252 253 uint32_t cInits = ASMAtomicDecU32(&g_cInits); 253 254 if (cInits > 0) 254 255 return; 255 #ifndef RT_OS_WINDOWS 256 #ifndef VBOX_VBGLR3_XFREE86 257 AssertReturnVoid(!cInits); 258 RTFILE File = g_File; 259 g_File = NIL_RTFILE; 260 AssertReturnVoid(File != NIL_RTFILE); 261 #else 262 int File = g_File; 263 g_File = -1; 264 if (File == -1) 265 return; 266 #endif 267 #else 268 /* Nothing to do here yet. */ 269 270 #endif 271 272 #if defined(RT_OS_OS2) 256 #if !defined(VBOX_VBGLR3_XFREE86) 257 AssertReturnVoid(!cInits); 258 259 # if defined(RT_OS_WINDOWS) 260 HANDLE hFile = g_hFile; 261 g_hFile = INVALID_HANDLE_VALUE; 262 AssertReturnVoid(hFile != INVALID_HANDLE_VALUE); 263 BOOL fRc = CloseHandle(hFile); 264 Assert(fRc); NOREF(fRc); 265 266 # elif defined(RT_OS_OS2) 267 268 RTFILE File = g_File; 269 g_File = NIL_RTFILE; 270 AssertReturnVoid(File != NIL_RTFILE); 273 271 APIRET rc = DosClose(File); 274 272 AssertMsg(!rc, ("%ld\n", rc)); 275 273 276 #elif defined(VBOX_VBGLR3_XFREE86) 277 xf86close(File); 278 File = -1; 279 280 #elif defined(RT_OS_WINDOWS) 281 if (INVALID_HANDLE_VALUE != g_hFile) 282 { 283 CloseHandle (g_hFile); 284 g_hFile = INVALID_HANDLE_VALUE; 285 } 286 287 #else 274 # else /* The IPRT case. */ 275 RTFILE File = g_File; 276 g_File = NIL_RTFILE; 277 AssertReturnVoid(File != NIL_RTFILE); 288 278 int rc = RTFileClose(File); 289 279 AssertRC(rc); 290 #endif 280 # endif 281 282 #else /* VBOX_VBGLR3_XFREE86 */ 283 int File = g_File; 284 g_File = -1; 285 if (File == -1) 286 return; 287 xf86close(File); 288 #endif /* VBOX_VBGLR3_XFREE86 */ 291 289 } 292 290 … … 308 306 int vbglR3DoIOCtl(unsigned iFunction, void *pvData, size_t cbData) 309 307 { 310 #ifdef RT_OS_OS2 308 #if defined(RT_OS_WINDOWS) 309 DWORD cbReturned = 0; 310 if (!DeviceIoControl(g_hFile, iFunction, pvData, cbData, pvData, cbData, &cbReturned, NULL)) 311 { 312 /** @todo The passing of error codes needs to be tested and fixed (as does *all* the other hosts except for 313 * OS, Michael and Ramshankar!). The idea is that the VBox status codes in ring-0 should be 314 * transfered without loss down to ring-3. However, it's not vitally important right now (obviously, since 315 * the other guys has been ignoring it for 1+ years now). */ 316 DWORD LastErr = GetLastError(); 317 return RTErrConvertFromWin32(LastErr); 318 } 319 320 return VINF_SUCCESS; 321 322 #elif defined(RT_OS_OS2) 311 323 ULONG cbOS2Parm = cbData; 312 324 int32_t vrc = VERR_INTERNAL_ERROR; … … 334 346 return VINF_SUCCESS; 335 347 336 #elif defined(RT_OS_WINDOWS)337 338 DWORD cbReturned = 0;339 if (FALSE == DeviceIoControl(g_hFile, iFunction, pvData, cbData,340 pvData, cbData, &cbReturned, NULL))341 return GetLastError(); /* @todo Add better error lookup. */342 343 return VINF_SUCCESS;344 345 348 #elif defined(VBOX_VBGLR3_XFREE86) 346 349 /* PORTME - This is preferred over the RTFileIOCtl variant below, just be careful with the (int). */
Note:
See TracChangeset
for help on using the changeset viewer.