Changeset 1193 in vbox for trunk/src/VBox/HostDrivers/Support/os2/SUPLib-os2.cpp
- Timestamp:
- Mar 4, 2007 8:52:45 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/os2/SUPLib-os2.cpp
-
Property svn:keywords
changed from
Author Date Id Revision
toId
r1 r1193 25 25 * Header Files * 26 26 *******************************************************************************/ 27 #define INCL_BASE 28 #define INCL_ERRORS 29 #include <os2.h> 30 #undef RT_MAX 31 27 32 #include <VBox/types.h> 28 33 #include <VBox/sup.h> … … 35 40 #include "SUPDRVIOC.h" 36 41 37 #include <sys/fcntl.h>38 #include <sys/ioctl.h>39 42 #include <errno.h> 40 43 #include <unistd.h> 41 44 #include <stdlib.h> 42 #include <string.h>43 45 44 46 … … 47 49 *******************************************************************************/ 48 50 /** OS/2 Device name. */ 49 #define DEVICE_NAME "/dev/ $vboxdrv"51 #define DEVICE_NAME "/dev/vboxdrv$" 50 52 51 53 … … 55 57 *******************************************************************************/ 56 58 /** Handle to the open device. */ 57 static int g_hDevice = -1; 58 /** Flags whether or not we've loaded the kernel module. */ 59 static bool g_fLoadedModule = false; 59 static HFILE g_hDevice = (HFILE)-1; 60 60 61 61 … … 80 80 * Check if already initialized. 81 81 */ 82 if (g_hDevice >= 0)82 if (g_hDevice != (HFILE)-1) 83 83 return 0; 84 84 85 #if 086 85 /* 87 86 * Try open the device. 88 87 */ 89 g_hDevice = open(DEVICE_NAME, O_RDWR, 0); 90 if (g_hDevice < 0) 91 { 92 /* 93 * Try load the device. 94 */ 95 //todo suplibOsLoadKernelModule(); 96 g_hDevice = open(DEVICE_NAME, O_RDWR, 0); 97 if (g_hDevice < 0) 98 return RTErrConvertFromErrno(errno); 99 } 100 101 /* 102 * Check driver version. 103 */ 104 /** @todo implement driver version checking. */ 105 106 /* 107 * We're done. 108 */ 88 ULONG ulAction = 0; 89 HFILE hDevice = (HFILE)-1; 90 APIRET rc = DosOpen((PCSZ)DEVICE_NAME, 91 &hDevice, 92 &ulAction, 93 0, 94 FILE_NORMAL, 95 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, 96 OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE, 97 NULL); 98 if (rc) 99 return RTErrConvertFromOS2(rc); 100 g_hDevice = hDevice; 101 109 102 NOREF(cbReserve); 110 return 0; 111 #else 112 NOREF(cbReserve); 113 return VERR_NOT_IMPLEMENTED; 114 #endif 103 return VINF_SUCCESS; 115 104 } 116 105 … … 121 110 * Check if we're initited at all. 122 111 */ 123 if (g_hDevice >= 0)112 if (g_hDevice != (HFILE)-1) 124 113 { 125 if (close(g_hDevice))126 AssertFailed();127 g_hDevice = -1;114 APIRET rc = DosClose(g_hDevice); 115 AssertMsg(rc == NO_ERROR, ("%d\n", rc)); NOREF(rc); 116 g_hDevice = (HFILE)-1; 128 117 } 129 118 130 /*131 * If we started the service we might consider stopping it too.132 *133 * Since this won't work unless the the process starting it is the134 * last user we might wanna skip this...135 */136 if (g_fLoadedModule)137 {138 //todo kernel module unloading.139 //suplibOsStopService();140 //g_fStartedService = false;141 }142 143 119 return 0; 144 120 } 145 121 146 122 147 /**148 * Installs anything required by the support library.149 *150 * @returns 0 on success.151 * @returns error code on failure.152 */153 123 int suplibOsInstall(void) 154 124 { 155 // int rc = mknod(DEVICE_NAME, S_IFCHR, ); 156 157 return VERR_NOT_IMPLEMENTED; 158 } 159 160 161 /** 162 * Installs anything required by the support library. 163 * 164 * @returns 0 on success. 165 * @returns error code on failure. 166 */ 125 /** @remark OS/2: Not supported */ 126 return VERR_NOT_SUPPORTED; 127 } 128 129 167 130 int suplibOsUninstall(void) 168 131 { 169 // int rc = unlink(DEVICE_NAME); 170 171 return VERR_NOT_IMPLEMENTED; 172 } 173 174 175 /** 176 * Send a I/O Control request to the device. 177 * 178 * @returns 0 on success. 179 * @returns VBOX error code on failure. 180 * @param uFunction IO Control function. 181 * @param pvIn Input data buffer. 182 * @param cbIn Size of input data. 183 * @param pvOut Output data buffer. 184 * @param cbOut Size of output data. 185 */ 186 int suplibOsIOCtl(unsigned uFunction, void *pvIn, size_t cbIn, void *pvOut, size_t cbOut) 187 { 188 #if 0 189 AssertMsg(g_hDevice != -1, ("SUPLIB not initiated successfully!\n")); 190 /* 191 * Issue device iocontrol. 192 */ 132 /** @remark OS/2: Not supported */ 133 return VERR_NOT_SUPPORTED; 134 } 135 136 137 int suplibOsIOCtl(unsigned uFunction, void *pvIn, size_t cbIn, void *pvOut, size_t cbOut) 138 { 139 AssertMsg(g_hDevice != (HFILE)-1, ("SUPLIB not initiated successfully!\n")); 140 193 141 SUPDRVIOCTLDATA Args; 194 142 Args.pvIn = pvIn; … … 196 144 Args.pvOut = pvOut; 197 145 Args.cbOut = cbOut; 198 199 if (ioctl(g_hDevice, uFunction, &Args) >= 0) 200 return 0; 201 /* This is the reverse operation of the one found in SUPDrv-linux.c */ 202 switch (errno) 146 Args.rc = VERR_INTERNAL_ERROR; 147 148 ULONG cbReturned = sizeof(Args); 149 int rc = DosDevIOCtl(g_hDevice, SUP_CTL_CATEGORY, uFunction, 150 &Args, sizeof(Args), &cbReturned, 151 NULL, 0, NULL); 152 if (RT_LIKELY(rc == NO_ERROR)) 153 rc = Args.rc; 154 else 155 rc = RTErrConvertFromOS2(rc); 156 return rc; 157 } 158 159 160 #ifdef VBOX_WITHOUT_IDT_PATCHING 161 int suplibOSIOCtlFast(unsigned uFunction) 162 { 163 int32_t rcRet = VERR_INTERNAL_ERROR; 164 ULONG cbRet = sizeof(rcRet); 165 int rc = DosDevIOCtl(g_hDevice, SUP_CTL_CATEGORY_FAST, uFunction, 166 NULL, 0, NULL, 167 &rcRet, sizeof(rcRet), &cbRet); 168 if (RT_LIKELY(rc == NO_ERROR)) 169 rc = rcRet; 170 else 171 rc = RTErrConvertFromOS2(rc); 172 return rc; 173 } 174 #endif 175 176 177 int suplibOsPageAlloc(size_t cPages, void **ppvPages) 178 { 179 *ppvPages = NULL; 180 int rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY); 181 if (rc == ERROR_INVALID_PARAMETER) 182 rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY); 183 if (!rc) 184 rc = VINF_SUCCESS; 185 else 186 rc = RTErrConvertFromOS2(rc); 187 return rc; 188 } 189 190 191 int suplibOsPageFree(void *pvPages) 192 { 193 if (pvPages) 203 194 { 204 case EACCES: return VERR_GENERAL_FAILURE; 205 case EINVAL: return VERR_INVALID_PARAMETER; 206 case ENOSYS: return VERR_INVALID_MAGIC; 207 case ENXIO: return VERR_INVALID_HANDLE; 208 case EFAULT: return VERR_INVALID_POINTER; 209 case ENOLCK: return VERR_LOCK_FAILED; 210 case EEXIST: return VERR_ALREADY_LOADED; 195 int rc = DosFreeMem(pvPages); 196 Assert(!rc); 211 197 } 212 213 return RTErrConvertFromErrno(errno);214 #else215 return VERR_NOT_IMPLEMENTED;216 #endif217 }218 219 220 /**221 * Allocate a number of zero-filled pages in user space.222 *223 * @returns VBox status code.224 * @param cPages Number of pages to allocate.225 * @param ppvPages Where to return the base pointer.226 */227 int suplibOsPageAlloc(size_t cPages, void **ppvPages)228 {229 if (!posix_memalign(ppvPages, PAGE_SIZE, cPages << PAGE_SHIFT))230 {231 memset(*ppvPages, 0, cPages << PAGE_SHIFT);232 return VINF_SUCCESS;233 }234 return RTErrConvertFromErrno(errno);235 }236 237 238 /**239 * Frees pages allocated by suplibOsPageAlloc().240 *241 * @returns VBox status code.242 * @param pvPages Pointer to pages.243 */244 int suplibOsPageFree(void *pvPages)245 {246 free(pvPages);247 198 return VINF_SUCCESS; 248 199 } 249 200 250 251 252 253 -
Property svn:keywords
changed from
Note:
See TracChangeset
for help on using the changeset viewer.