VirtualBox

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

Last change on this file since 18195 was 13865, checked in by vboxsync, 16 years ago

SUP: pass idCpu up on all platforms (save OS/2), handle it in ring-0 on solaris, linux and freebsd.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.5 KB
Line 
1/* $Id: SUPLib-os2.cpp 13865 2008-11-05 14:14:11Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - OS/2 specific parts.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#define INCL_BASE
35#define INCL_ERRORS
36#include <os2.h>
37#undef RT_MAX
38
39#ifdef IN_SUP_HARDENED_R3
40# undef DEBUG /* Warning: disables RT_STRICT */
41# define LOG_DISABLED
42 /** @todo RTLOGREL_DISABLED */
43# include <iprt/log.h>
44# undef LogRelIt
45# define LogRelIt(pvInst, fFlags, iGroup, fmtargs) do { } while (0)
46#endif
47
48#include <VBox/types.h>
49#include <VBox/sup.h>
50#include <VBox/param.h>
51#include <VBox/err.h>
52#include <VBox/log.h>
53#include <iprt/path.h>
54#include <iprt/assert.h>
55#include <iprt/err.h>
56#include "../SUPLibInternal.h"
57#include "../SUPDrvIOC.h"
58
59#include <errno.h>
60#include <unistd.h>
61#include <stdlib.h>
62
63
64/*******************************************************************************
65* Defined Constants And Macros *
66*******************************************************************************/
67/** OS/2 Device name. */
68#define DEVICE_NAME "/dev/vboxdrv$"
69
70
71
72int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited)
73{
74 /*
75 * Nothing to do if pre-inited.
76 */
77 if (fPreInited)
78 return VINF_SUCCESS;
79
80 /*
81 * Try open the device.
82 */
83 ULONG ulAction = 0;
84 HFILE hDevice = (HFILE)-1;
85 APIRET rc = DosOpen((PCSZ)DEVICE_NAME,
86 &hDevice,
87 &ulAction,
88 0,
89 FILE_NORMAL,
90 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
91 OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
92 NULL);
93 if (rc)
94 {
95 int vrc;
96 switch (rc)
97 {
98 case ERROR_FILE_NOT_FOUND:
99 case ERROR_PATH_NOT_FOUND: vrc = VERR_VM_DRIVER_NOT_INSTALLED; break;
100 default: vrc = VERR_VM_DRIVER_OPEN_ERROR; break;
101 }
102 LogRel(("Failed to open \"%s\", rc=%d, vrc=%Rrc\n", DEVICE_NAME, rc, vrc));
103 return vrc;
104 }
105
106 pThis->hDevice = (RTFILE)hDevice;
107 return VINF_SUCCESS;
108}
109
110
111#ifndef IN_SUP_HARDENED_R3
112
113int suplibOsTerm(PSUPLIBDATA pThis)
114{
115 /*
116 * Check if we're initited at all.
117 */
118 if (pThis->hDevice != NIL_RTFILE)
119 {
120 APIRET rc = DosClose((HFILE)pThis->hDevice);
121 AssertMsg(rc == NO_ERROR, ("%d\n", rc)); NOREF(rc);
122 pThis->hDevice = NIL_RTFILE;
123 }
124
125 return 0;
126}
127
128
129int suplibOsInstall(void)
130{
131 /** @remark OS/2: Not supported */
132 return VERR_NOT_SUPPORTED;
133}
134
135
136int suplibOsUninstall(void)
137{
138 /** @remark OS/2: Not supported */
139 return VERR_NOT_SUPPORTED;
140}
141
142
143int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq)
144{
145 ULONG cbReturned = sizeof(SUPREQHDR);
146 int rc = DosDevIOCtl((HFILE)pThis->hDevice, SUP_CTL_CATEGORY, uFunction,
147 pvReq, cbReturned, &cbReturned,
148 NULL, 0, NULL);
149 if (RT_LIKELY(rc == NO_ERROR))
150 return VINF_SUCCESS;
151 return RTErrConvertFromOS2(rc);
152}
153
154
155int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction, uintptr_t idCpu)
156{
157 NOREF(idCpu);
158 int32_t rcRet = VERR_INTERNAL_ERROR;
159 int rc = DosDevIOCtl((HFILE)pThis->hDevice, SUP_CTL_CATEGORY_FAST, uFunction,
160 NULL, 0, NULL,
161 NULL, 0, NULL);
162 if (RT_LIKELY(rc == NO_ERROR))
163 rc = rcRet;
164 else
165 rc = RTErrConvertFromOS2(rc);
166 return rc;
167}
168
169
170int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages)
171{
172 NOREF(pThis);
173 *ppvPages = NULL;
174 int rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
175 if (rc == ERROR_INVALID_PARAMETER)
176 rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
177 if (!rc)
178 rc = VINF_SUCCESS;
179 else
180 rc = RTErrConvertFromOS2(rc);
181 return rc;
182}
183
184
185int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t /* cPages */)
186{
187 NOREF(pThis);
188 if (pvPages)
189 {
190 int rc = DosFreeMem(pvPages);
191 Assert(!rc); NOREF(rc);
192 }
193 return VINF_SUCCESS;
194}
195
196#endif /* !IN_SUP_HARDENED_R3 */
197
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