Changeset 6538 in vbox for trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp
- Timestamp:
- Jan 28, 2008 7:50:14 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp
r6470 r6538 34 34 #include <iprt/asm.h> 35 35 #include <iprt/string.h> 36 #include <iprt/file.h> 37 #include <iprt/assert.h> 38 #include <iprt/mem.h> 39 #include <iprt/alloca.h> 36 #ifdef VBOX_VBGLR3_XFREE86 37 /* Definitions for X server library functions such as xf86open and mappings to C functions. */ 38 /* Make the headers C++-compatible */ 39 # define class xf86_vbox_class 40 # define bool xf86_vbox_bool 41 # define private xf86_vbox_private 42 # define new xf86_vbox_new 43 extern "C" 44 { 45 # include "xf86.h" 46 # include "xf86_OSproc.h" 47 # include "xf86Resources.h" 48 # include "xf86_ansic.h" 49 } 50 # undef class 51 # undef bool 52 # undef private 53 # undef new 54 #else 55 # include <iprt/file.h> 56 # include <iprt/assert.h> 57 # include <iprt/thread.h> 58 #endif 40 59 #include <VBox/VBoxGuest.h> 41 60 #include "VBGLR3Internal.h" … … 46 65 *******************************************************************************/ 47 66 /** The VBoxGuest device handle. */ 67 #ifdef VBOX_VBGLR3_XFREE86 68 static int g_File = -1; 69 #else 48 70 static RTFILE g_File = NIL_RTFILE; 49 71 #endif 72 /** 73 * A counter of the number of times the library has been initialised, for use with 74 * X.org drivers, where the library may be shared by multiple independant modules 75 * inside a single process space. 76 */ 77 static uint32_t g_cInits = 0; 50 78 51 79 VBGLR3DECL(int) VbglR3Init(void) 52 80 { 53 if (g_File != NIL_RTFILE) 81 uint32_t cInits = ASMAtomicIncU32(&g_cInits); 82 #ifdef VBOX_VBGLR3_XFREE86 83 if (1 != cInits) 54 84 return VINF_SUCCESS; 85 if (-1 != g_File) 86 return VERR_INTERNAL_ERROR; 87 #else 88 Assert(cInits > 0); 89 if (1 > cInits) 90 { 91 /* This will not work when the library is shared inside a multi-threaded 92 process. Hopefully no-one will try that, as we can't use the threads 93 APIs here. */ 94 if (NIL_RTFILE == g_File) 95 return VERR_INTERNAL_ERROR; 96 return VINF_SUCCESS; 97 } 98 if (NIL_RTFILE != g_File) 99 return VERR_INTERNAL_ERROR; 100 #endif 55 101 56 102 #if defined(RT_OS_OS2) … … 105 151 g_File = hf; 106 152 107 /* PORTME */ 153 #elif defined(VBOX_VBGLR3_XFREE86) 154 int File = open(VBOXGUEST_DEVICE_NAME, O_RDWR); 155 if (-1 == File) 156 { 157 return VERR_UNRESOLVED_ERROR; 158 } 159 g_File = File; 160 108 161 #else 109 162 /* the default implemenation. (linux, solaris) */ … … 122 175 VBGLR3DECL(void) VbglR3Term(void) 123 176 { 177 uint32_t cInits = ASMAtomicDecU32(&g_cInits); 178 if (cInits > 0) 179 return; 180 #ifndef VBOX_VBGLR3_XFREE86 181 AssertReturnVoid(0 == cInits); 124 182 RTFILE File = g_File; 125 183 g_File = NIL_RTFILE; 126 if (File == NIL_RTFILE) 184 AssertReturnVoid(NIL_RTFILE != File); 185 #else 186 int File = g_File; 187 g_File = -1; 188 if (-1 == File) 127 189 return; 190 #endif 128 191 #if defined(RT_OS_OS2) 129 192 APIRET rc = DosClose(File); 130 193 AssertMsg(!rc, ("%ld\n", rc)); 194 #elif defined(VBOX_VBGLR3_XFREE86) 195 /* if (-1 == close(File)) 196 { 197 int iErr = errno; 198 AssertRC(RTErrConvertFromErrno(iErr)); 199 } */ 200 close(File); /* iprt is not available here. */ 201 File = -1; 131 202 #else 132 203 int rc = RTFileClose(File); … … 171 242 int rc = ioctl((int)g_File, iFunction, &Hdr); 172 243 if (rc == -1) 244 { 173 245 rc = errno; 174 return rc; 246 return RTErrConvertFromErrno(rc); 247 } 248 return VINF_SUCCESS; 175 249 176 250 #else 177 251 /* Default implementation - PORTME: Do not use this without testings that error passing works! */ 252 # ifdef VBOX_VBGLR3_XFREE86 253 int rc = ioctl(g_File, (int) iFunction, pvData); 254 if (rc == -1) 255 { 256 rc = errno; 257 return RTErrConvertFromErrno(rc); 258 } 259 return VINF_SUCCESS; 260 # else 178 261 int rc2 = VERR_INTERNAL_ERROR; 179 262 int rc = RTFileIoCtl(g_File, (int)iFunction, pvData, cbData, &rc2); … … 181 264 rc = rc2; 182 265 return rc; 183 #endif 184 } 185 266 # endif 267 #endif 268 } 269
Note:
See TracChangeset
for help on using the changeset viewer.