VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 2 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: SUPLib-os2.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - OS/2 specific parts.
4 */
5
6/*
7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#define INCL_BASE
42#define INCL_ERRORS
43#include <os2.h>
44#undef RT_MAX
45
46#ifdef IN_SUP_HARDENED_R3
47# undef DEBUG /* Warning: disables RT_STRICT */
48# define LOG_DISABLED
49# define RTLOG_REL_DISABLED
50# include <iprt/log.h>
51#endif
52
53#include <VBox/types.h>
54#include <VBox/sup.h>
55#include <VBox/param.h>
56#include <VBox/err.h>
57#include <VBox/log.h>
58#include <iprt/path.h>
59#include <iprt/assert.h>
60#include <iprt/err.h>
61#include "../SUPLibInternal.h"
62#include "../SUPDrvIOC.h"
63
64#include <errno.h>
65#include <unistd.h>
66#include <stdlib.h>
67
68
69/*********************************************************************************************************************************
70* Defined Constants And Macros *
71*********************************************************************************************************************************/
72/** OS/2 Device name. */
73#define DEVICE_NAME "/dev/vboxdrv$"
74
75
76
77DECLHIDDEN(int) suplibOsInit(PSUPLIBDATA pThis, bool fPreInited, uint32_t fFlags, SUPINITOP *penmWhat, PRTERRINFO pErrInfo)
78{
79 /*
80 * Nothing to do if pre-inited.
81 */
82 if (fPreInited)
83 return VINF_SUCCESS;
84
85 /*
86 * Try open the device.
87 */
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 {
100 int vrc;
101 switch (rc)
102 {
103 case ERROR_FILE_NOT_FOUND:
104 case ERROR_PATH_NOT_FOUND: vrc = VERR_VM_DRIVER_NOT_INSTALLED; break;
105 default: vrc = VERR_VM_DRIVER_OPEN_ERROR; break;
106 }
107 LogRel(("Failed to open \"%s\", rc=%d, vrc=%Rrc\n", DEVICE_NAME, rc, vrc));
108 return vrc;
109 }
110
111 pThis->hDevice = hDevice;
112 pThis->fUnrestricted = true;
113 RT_NOREF(fFlags);
114 return VINF_SUCCESS;
115}
116
117
118DECLHIDDEN(int) suplibOsTerm(PSUPLIBDATA pThis)
119{
120 /*
121 * Check if we're inited at all.
122 */
123 if (pThis->hDevice != (intptr_t)NIL_RTFILE)
124 {
125 APIRET rc = DosClose((HFILE)pThis->hDevice);
126 AssertMsg(rc == NO_ERROR, ("%d\n", rc)); NOREF(rc);
127 pThis->hDevice = (intptr_t)NIL_RTFILE;
128 }
129
130 return 0;
131}
132
133
134#ifndef IN_SUP_HARDENED_R3
135
136DECLHIDDEN(int) suplibOsInstall(void)
137{
138 /** @remark OS/2: Not supported */
139 return VERR_NOT_SUPPORTED;
140}
141
142
143DECLHIDDEN(int) suplibOsUninstall(void)
144{
145 /** @remark OS/2: Not supported */
146 return VERR_NOT_SUPPORTED;
147}
148
149
150DECLHIDDEN(int) suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq)
151{
152 ULONG cbReturned = sizeof(SUPREQHDR);
153 int rc = DosDevIOCtl((HFILE)pThis->hDevice, SUP_CTL_CATEGORY, uFunction,
154 pvReq, cbReturned, &cbReturned,
155 NULL, 0, NULL);
156 if (RT_LIKELY(rc == NO_ERROR))
157 return VINF_SUCCESS;
158 return RTErrConvertFromOS2(rc);
159}
160
161
162DECLHIDDEN(int) suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction, uintptr_t idCpu)
163{
164 NOREF(idCpu);
165 int32_t rcRet = VERR_INTERNAL_ERROR;
166 int rc = DosDevIOCtl((HFILE)pThis->hDevice, SUP_CTL_CATEGORY_FAST, uFunction,
167 NULL, 0, NULL,
168 NULL, 0, NULL);
169 if (RT_LIKELY(rc == NO_ERROR))
170 rc = rcRet;
171 else
172 rc = RTErrConvertFromOS2(rc);
173 return rc;
174}
175
176
177DECLHIDDEN(int) suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, uint32_t fFlags, void **ppvPages)
178{
179 RT_NOREF(pThis, fFlags);
180 *ppvPages = NULL;
181 int rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
182 if (rc == ERROR_INVALID_PARAMETER)
183 rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
184 if (!rc)
185 rc = VINF_SUCCESS;
186 else
187 rc = RTErrConvertFromOS2(rc);
188 return rc;
189}
190
191
192DECLHIDDEN(int) suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t /* cPages */)
193{
194 NOREF(pThis);
195 if (pvPages)
196 {
197 int rc = DosFreeMem(pvPages);
198 Assert(!rc); NOREF(rc);
199 }
200 return VINF_SUCCESS;
201}
202
203#endif /* !IN_SUP_HARDENED_R3 */
204
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