VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/os2/SUPLib-os2.cpp@ 54934

Last change on this file since 54934 was 53002, checked in by vboxsync, 10 years ago

VBoxDrv-win.cpp: Keep the error info string from failed VBoxDrv and VBoxDrvStub open operations so userland can give us better messages to work on. Fixeds a couple of odd bugs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1/* $Id: SUPLib-os2.cpp 53002 2014-10-08 23:46:15Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - OS/2 specific parts.
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#define INCL_BASE
31#define INCL_ERRORS
32#include <os2.h>
33#undef RT_MAX
34
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
44#include <VBox/types.h>
45#include <VBox/sup.h>
46#include <VBox/param.h>
47#include <VBox/err.h>
48#include <VBox/log.h>
49#include <iprt/path.h>
50#include <iprt/assert.h>
51#include <iprt/err.h>
52#include "../SUPLibInternal.h"
53#include "../SUPDrvIOC.h"
54
55#include <errno.h>
56#include <unistd.h>
57#include <stdlib.h>
58
59
60/*******************************************************************************
61* Defined Constants And Macros *
62*******************************************************************************/
63/** OS/2 Device name. */
64#define DEVICE_NAME "/dev/vboxdrv$"
65
66
67
68int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited, bool fUnrestricted, SUPINITOP *penmWhat, PRTERRINFO pErrInfo)
69{
70 /*
71 * Nothing to do if pre-inited.
72 */
73 if (fPreInited)
74 return VINF_SUCCESS;
75
76 /*
77 * Try open the device.
78 */
79 ULONG ulAction = 0;
80 HFILE hDevice = (HFILE)-1;
81 APIRET rc = DosOpen((PCSZ)DEVICE_NAME,
82 &hDevice,
83 &ulAction,
84 0,
85 FILE_NORMAL,
86 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
87 OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
88 NULL);
89 if (rc)
90 {
91 int vrc;
92 switch (rc)
93 {
94 case ERROR_FILE_NOT_FOUND:
95 case ERROR_PATH_NOT_FOUND: vrc = VERR_VM_DRIVER_NOT_INSTALLED; break;
96 default: vrc = VERR_VM_DRIVER_OPEN_ERROR; break;
97 }
98 LogRel(("Failed to open \"%s\", rc=%d, vrc=%Rrc\n", DEVICE_NAME, rc, vrc));
99 return vrc;
100 }
101
102 pThis->hDevice = hDevice;
103 pThis->fUnrestricted = true;
104 return VINF_SUCCESS;
105}
106
107
108#ifndef IN_SUP_HARDENED_R3
109
110int suplibOsTerm(PSUPLIBDATA pThis)
111{
112 /*
113 * Check if we're inited at all.
114 */
115 if (pThis->hDevice != (intptr_t)NIL_RTFILE)
116 {
117 APIRET rc = DosClose((HFILE)pThis->hDevice);
118 AssertMsg(rc == NO_ERROR, ("%d\n", rc)); NOREF(rc);
119 pThis->hDevice = (intptr_t)NIL_RTFILE;
120 }
121
122 return 0;
123}
124
125
126int suplibOsInstall(void)
127{
128 /** @remark OS/2: Not supported */
129 return VERR_NOT_SUPPORTED;
130}
131
132
133int suplibOsUninstall(void)
134{
135 /** @remark OS/2: Not supported */
136 return VERR_NOT_SUPPORTED;
137}
138
139
140int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq)
141{
142 ULONG cbReturned = sizeof(SUPREQHDR);
143 int rc = DosDevIOCtl((HFILE)pThis->hDevice, SUP_CTL_CATEGORY, uFunction,
144 pvReq, cbReturned, &cbReturned,
145 NULL, 0, NULL);
146 if (RT_LIKELY(rc == NO_ERROR))
147 return VINF_SUCCESS;
148 return RTErrConvertFromOS2(rc);
149}
150
151
152int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction, uintptr_t idCpu)
153{
154 NOREF(idCpu);
155 int32_t rcRet = VERR_INTERNAL_ERROR;
156 int rc = DosDevIOCtl((HFILE)pThis->hDevice, SUP_CTL_CATEGORY_FAST, uFunction,
157 NULL, 0, NULL,
158 NULL, 0, NULL);
159 if (RT_LIKELY(rc == NO_ERROR))
160 rc = rcRet;
161 else
162 rc = RTErrConvertFromOS2(rc);
163 return rc;
164}
165
166
167int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages)
168{
169 NOREF(pThis);
170 *ppvPages = NULL;
171 int rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
172 if (rc == ERROR_INVALID_PARAMETER)
173 rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
174 if (!rc)
175 rc = VINF_SUCCESS;
176 else
177 rc = RTErrConvertFromOS2(rc);
178 return rc;
179}
180
181
182int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t /* cPages */)
183{
184 NOREF(pThis);
185 if (pvPages)
186 {
187 int rc = DosFreeMem(pvPages);
188 Assert(!rc); NOREF(rc);
189 }
190 return VINF_SUCCESS;
191}
192
193#endif /* !IN_SUP_HARDENED_R3 */
194
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette