VirtualBox

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

Last change on this file since 66573 was 66573, checked in by vboxsync, 8 years ago

supR3HardenedFatalMsgV: close driver, postpone fork. bugref:8838

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/* $Id: SUPLib-os2.cpp 66573 2017-04-14 13:24:58Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - OS/2 specific parts.
4 */
5
6/*
7 * Copyright (C) 2006-2016 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
67int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited, bool fUnrestricted, 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 return VINF_SUCCESS;
104}
105
106
107int suplibOsTerm(PSUPLIBDATA pThis)
108{
109 /*
110 * Check if we're inited at all.
111 */
112 if (pThis->hDevice != (intptr_t)NIL_RTFILE)
113 {
114 APIRET rc = DosClose((HFILE)pThis->hDevice);
115 AssertMsg(rc == NO_ERROR, ("%d\n", rc)); NOREF(rc);
116 pThis->hDevice = (intptr_t)NIL_RTFILE;
117 }
118
119 return 0;
120}
121
122
123#ifndef IN_SUP_HARDENED_R3
124
125int suplibOsInstall(void)
126{
127 /** @remark OS/2: Not supported */
128 return VERR_NOT_SUPPORTED;
129}
130
131
132int suplibOsUninstall(void)
133{
134 /** @remark OS/2: Not supported */
135 return VERR_NOT_SUPPORTED;
136}
137
138
139int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq)
140{
141 ULONG cbReturned = sizeof(SUPREQHDR);
142 int rc = DosDevIOCtl((HFILE)pThis->hDevice, SUP_CTL_CATEGORY, uFunction,
143 pvReq, cbReturned, &cbReturned,
144 NULL, 0, NULL);
145 if (RT_LIKELY(rc == NO_ERROR))
146 return VINF_SUCCESS;
147 return RTErrConvertFromOS2(rc);
148}
149
150
151int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction, uintptr_t idCpu)
152{
153 NOREF(idCpu);
154 int32_t rcRet = VERR_INTERNAL_ERROR;
155 int rc = DosDevIOCtl((HFILE)pThis->hDevice, SUP_CTL_CATEGORY_FAST, uFunction,
156 NULL, 0, NULL,
157 NULL, 0, NULL);
158 if (RT_LIKELY(rc == NO_ERROR))
159 rc = rcRet;
160 else
161 rc = RTErrConvertFromOS2(rc);
162 return rc;
163}
164
165
166int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages)
167{
168 NOREF(pThis);
169 *ppvPages = NULL;
170 int rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
171 if (rc == ERROR_INVALID_PARAMETER)
172 rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
173 if (!rc)
174 rc = VINF_SUCCESS;
175 else
176 rc = RTErrConvertFromOS2(rc);
177 return rc;
178}
179
180
181int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t /* cPages */)
182{
183 NOREF(pThis);
184 if (pvPages)
185 {
186 int rc = DosFreeMem(pvPages);
187 Assert(!rc); NOREF(rc);
188 }
189 return VINF_SUCCESS;
190}
191
192#endif /* !IN_SUP_HARDENED_R3 */
193
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