VirtualBox

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

Last change on this file since 92613 was 92613, checked in by vboxsync, 3 years ago

SUP,IPRT,++: Adding SUPSECMAIN_FLAGS_DRIVERLESS_IEM_ALLOWED and SUPR3INIT_F_DRIVERLESS_NEM_FALLBACK to SUPLib and RTR3INIT_FLAGS_TRY_SUPLIB to RTR3Init*, the latter probably reflects the actual state there a lot better. Currently only the TRY_SUPLIB option works, the other two aren't really implemented in SUPLib yet. bugref:10138

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* $Id: SUPLib-os2.cpp 92613 2021-11-26 21:53:47Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - OS/2 specific parts.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#define INCL_BASE
32#define INCL_ERRORS
33#include <os2.h>
34#undef RT_MAX
35
36#ifdef IN_SUP_HARDENED_R3
37# undef DEBUG /* Warning: disables RT_STRICT */
38# define LOG_DISABLED
39# define RTLOG_REL_DISABLED
40# include <iprt/log.h>
41#endif
42
43#include <VBox/types.h>
44#include <VBox/sup.h>
45#include <VBox/param.h>
46#include <VBox/err.h>
47#include <VBox/log.h>
48#include <iprt/path.h>
49#include <iprt/assert.h>
50#include <iprt/err.h>
51#include "../SUPLibInternal.h"
52#include "../SUPDrvIOC.h"
53
54#include <errno.h>
55#include <unistd.h>
56#include <stdlib.h>
57
58
59/*********************************************************************************************************************************
60* Defined Constants And Macros *
61*********************************************************************************************************************************/
62/** OS/2 Device name. */
63#define DEVICE_NAME "/dev/vboxdrv$"
64
65
66
67DECLHIDDEN(int) suplibOsInit(PSUPLIBDATA pThis, bool fPreInited, uint32_t fFlags, SUPINITOP *penmWhat, PRTERRINFO pErrInfo)
68{
69 /*
70 * Nothing to do if pre-inited.
71 */
72 if (fPreInited)
73 return VINF_SUCCESS;
74
75 /*
76 * Try open the device.
77 */
78 ULONG ulAction = 0;
79 HFILE hDevice = (HFILE)-1;
80 APIRET rc = DosOpen((PCSZ)DEVICE_NAME,
81 &hDevice,
82 &ulAction,
83 0,
84 FILE_NORMAL,
85 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
86 OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
87 NULL);
88 if (rc)
89 {
90 int vrc;
91 switch (rc)
92 {
93 case ERROR_FILE_NOT_FOUND:
94 case ERROR_PATH_NOT_FOUND: vrc = VERR_VM_DRIVER_NOT_INSTALLED; break;
95 default: vrc = VERR_VM_DRIVER_OPEN_ERROR; break;
96 }
97 LogRel(("Failed to open \"%s\", rc=%d, vrc=%Rrc\n", DEVICE_NAME, rc, vrc));
98 return vrc;
99 }
100
101 pThis->hDevice = hDevice;
102 pThis->fUnrestricted = true;
103 RT_NOREF(fFlags);
104 return VINF_SUCCESS;
105}
106
107
108DECLHIDDEN(int) suplibOsTerm(PSUPLIBDATA pThis)
109{
110 /*
111 * Check if we're inited at all.
112 */
113 if (pThis->hDevice != (intptr_t)NIL_RTFILE)
114 {
115 APIRET rc = DosClose((HFILE)pThis->hDevice);
116 AssertMsg(rc == NO_ERROR, ("%d\n", rc)); NOREF(rc);
117 pThis->hDevice = (intptr_t)NIL_RTFILE;
118 }
119
120 return 0;
121}
122
123
124#ifndef IN_SUP_HARDENED_R3
125
126DECLHIDDEN(int) suplibOsInstall(void)
127{
128 /** @remark OS/2: Not supported */
129 return VERR_NOT_SUPPORTED;
130}
131
132
133DECLHIDDEN(int) suplibOsUninstall(void)
134{
135 /** @remark OS/2: Not supported */
136 return VERR_NOT_SUPPORTED;
137}
138
139
140DECLHIDDEN(int) 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
152DECLHIDDEN(int) 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
167DECLHIDDEN(int) suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, uint32_t fFlags, void **ppvPages)
168{
169 RT_NOREF(pThis, fFlags);
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
182DECLHIDDEN(int) 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