Changeset 11725 in vbox for trunk/src/VBox/HostDrivers/Support/freebsd/SUPLib-freebsd.cpp
- Timestamp:
- Aug 27, 2008 10:21:47 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/freebsd/SUPLib-freebsd.cpp
r10256 r11725 1 /* $Id: $ */ 1 2 /** @file 2 * SUPLib - FreeBSD Hosts,3 * VirtualBox Support Library - FreeBSD specific parts. 3 4 */ 4 5 … … 28 29 */ 29 30 30 31 31 /******************************************************************************* 32 32 * Header Files * 33 33 *******************************************************************************/ 34 34 #define LOG_GROUP LOG_GROUP_SUP 35 #ifdef IN_SUP_HARDENED_R3 36 # undef DEBUG /* Warning: disables RT_STRICT */ 37 # define LOG_DISABLED 38 /** @todo RTLOGREL_DISABLED */ 39 # include <iprt/log.h> 40 # undef LogRelIt 41 # define LogRelIt(pvInst, fFlags, iGroup, fmtargs) do { } while (0) 42 #endif 43 35 44 #include <VBox/types.h> 36 45 #include <VBox/sup.h> … … 60 69 61 70 62 /*******************************************************************************63 * Global Variables *64 *******************************************************************************/65 /** Handle to the open device. */66 static int g_hDevice = -1;67 71 68 69 int suplibOsInit(size_t cbReserve) 72 int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited) 70 73 { 71 74 /* 72 * Check if already initialized.75 * Nothing to do if pre-inited. 73 76 */ 74 if ( g_hDevice >= 0)77 if (fPreInited) 75 78 return VINF_SUCCESS; 76 79 … … 78 81 * Try open the BSD device. 79 82 */ 83 int hDevice = -1; 80 84 char szDevice[sizeof(DEVICE_NAME) + 16]; 81 85 for (unsigned iUnit = 0; iUnit < 1024; iUnit++) … … 83 87 errno = 0; 84 88 RTStrPrintf(szDevice, sizeof(szDevice), DEVICE_NAME "%d", iUnit); 85 g_hDevice = open(szDevice, O_RDWR, 0);86 if ( g_hDevice >= 0 || errno != EBUSY)89 hDevice = open(szDevice, O_RDWR, 0); 90 if (hDevice >= 0 || errno != EBUSY) 87 91 break; 88 92 } 89 if ( g_hDevice < 0)93 if (hDevice < 0) 90 94 { 91 95 int rc; … … 105 109 * Mark the file handle close on exec. 106 110 */ 107 if (fcntl( g_hDevice, F_SETFD, FD_CLOEXEC) != 0)111 if (fcntl(hDevice, F_SETFD, FD_CLOEXEC) != 0) 108 112 { 109 int rc = errno; 110 LogRel(("suplibOSInit: setting FD_CLOEXEC failed, errno=%d\n", rc)); 111 close(g_hDevice); 112 g_hDevice = -1; 113 return RTErrConvertFromErrno(rc); 113 #ifdef IN_SUP_HARDENED_R3 114 int rc = VERR_INTERNAL_ERROR; 115 #else 116 int err = errno; 117 int rc = RTErrConvertFromErrno(err); 118 LogRel(("suplibOSInit: setting FD_CLOEXEC failed, errno=%d (%Rrc)\n", err, rc)); 119 #endif 120 close(hDevice); 121 return rc; 114 122 } 115 123 … … 117 125 * We're done. 118 126 */ 119 NOREF(cbReserve);127 pThis->hDevice = hDevice; 120 128 return VINF_SUCCESS; 121 129 } 122 130 123 131 124 int suplibOsTerm(void) 132 #ifndef IN_SUP_HARDENED_R3 133 134 int suplibOsTerm(PSUPLIBDATA pThis) 125 135 { 126 136 /* 127 137 * Check if we're initited at all. 128 138 */ 129 if ( g_hDevice >= 0)139 if (pThis->hDevice != NIL_RTFILE) 130 140 { 131 if (close( g_hDevice))141 if (close(pThis->hDevice)) 132 142 AssertFailed(); 133 g_hDevice = -1;143 pThis->hDevice = NIL_RTFILE; 134 144 } 135 145 return VINF_SUCCESS; … … 149 159 150 160 151 int suplibOsIOCtl( uintptr_t uFunction, void *pvReq, size_t cbReq)161 int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq) 152 162 { 153 AssertMsg(g_hDevice != -1, ("SUPLIB not initiated successfully!\n")); 154 155 if (RT_LIKELY(ioctl(g_hDevice, uFunction, pvReq) >= 0)) 163 if (RT_LIKELY(ioctl(pThis->hDevice, uFunction, pvReq) >= 0)) 156 164 return VINF_SUCCESS; 157 165 return RTErrConvertFromErrno(errno); … … 159 167 160 168 161 int suplibOsIOCtlFast( uintptr_t uFunction)169 int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction) 162 170 { 163 int rc = ioctl( g_hDevice, uFunction, NULL);171 int rc = ioctl(pThis->hDevice, uFunction, NULL); 164 172 if (rc == -1) 165 173 rc = errno; … … 168 176 169 177 170 int suplibOsPageAlloc( size_t cPages, void **ppvPages)178 int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages) 171 179 { 180 NOREF(pThis); 172 181 *ppvPages = RTMemPageAllocZ(cPages << PAGE_SHIFT); 173 182 if (*ppvPages) … … 177 186 178 187 179 int suplibOsPageFree( void *pvPages, size_t /* cPages */)188 int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t /* cPages */) 180 189 { 190 NOREF(pThis); 181 191 RTMemPageFree(pvPages); 182 192 return VINF_SUCCESS; 183 193 } 184 194 195 #endif /* !IN_SUP_HARDENED_R3 */ 196
Note:
See TracChangeset
for help on using the changeset viewer.