VirtualBox

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

Last change on this file since 28800 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: SUPLib-os2.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - OS/2 specific parts.
4 */
5
6/*
7 * Copyright (C) 2006-2007 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)
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 = (RTFILE)hDevice;
103 return VINF_SUCCESS;
104}
105
106
107#ifndef IN_SUP_HARDENED_R3
108
109int suplibOsTerm(PSUPLIBDATA pThis)
110{
111 /*
112 * Check if we're initited at all.
113 */
114 if (pThis->hDevice != NIL_RTFILE)
115 {
116 APIRET rc = DosClose((HFILE)pThis->hDevice);
117 AssertMsg(rc == NO_ERROR, ("%d\n", rc)); NOREF(rc);
118 pThis->hDevice = NIL_RTFILE;
119 }
120
121 return 0;
122}
123
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