VirtualBox

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

Last change on this file since 1193 was 1193, checked in by vboxsync, 18 years ago

Ported the support driver to OS/2.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1/** @file
2 *
3 * VBox host drivers - Ring-0 support drivers - OS/2 host:
4 * OS/2 implementations for support library
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#define INCL_BASE
28#define INCL_ERRORS
29#include <os2.h>
30#undef RT_MAX
31
32#include <VBox/types.h>
33#include <VBox/sup.h>
34#include <VBox/param.h>
35#include <VBox/err.h>
36#include <iprt/path.h>
37#include <iprt/assert.h>
38#include <iprt/err.h>
39#include "SUPLibInternal.h"
40#include "SUPDRVIOC.h"
41
42#include <errno.h>
43#include <unistd.h>
44#include <stdlib.h>
45
46
47/*******************************************************************************
48* Defined Constants And Macros *
49*******************************************************************************/
50/** OS/2 Device name. */
51#define DEVICE_NAME "/dev/vboxdrv$"
52
53
54
55/*******************************************************************************
56* Global Variables *
57*******************************************************************************/
58/** Handle to the open device. */
59static HFILE g_hDevice = (HFILE)-1;
60
61
62/*******************************************************************************
63* Internal Functions *
64*******************************************************************************/
65
66
67/**
68 * Initialize the OS specific part of the library.
69 * On Linux this involves:
70 * - loading the module.
71 * - open driver.
72 *
73 * @returns 0 on success.
74 * @returns current -1 on failure but this must be changed to proper error codes.
75 * @param cbReserve Ignored on OS/2.
76 */
77int suplibOsInit(size_t cbReserve)
78{
79 /*
80 * Check if already initialized.
81 */
82 if (g_hDevice != (HFILE)-1)
83 return 0;
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 return RTErrConvertFromOS2(rc);
100 g_hDevice = hDevice;
101
102 NOREF(cbReserve);
103 return VINF_SUCCESS;
104}
105
106
107int suplibOsTerm(void)
108{
109 /*
110 * Check if we're initited at all.
111 */
112 if (g_hDevice != (HFILE)-1)
113 {
114 APIRET rc = DosClose(g_hDevice);
115 AssertMsg(rc == NO_ERROR, ("%d\n", rc)); NOREF(rc);
116 g_hDevice = (HFILE)-1;
117 }
118
119 return 0;
120}
121
122
123int suplibOsInstall(void)
124{
125 /** @remark OS/2: Not supported */
126 return VERR_NOT_SUPPORTED;
127}
128
129
130int suplibOsUninstall(void)
131{
132 /** @remark OS/2: Not supported */
133 return VERR_NOT_SUPPORTED;
134}
135
136
137int suplibOsIOCtl(unsigned uFunction, void *pvIn, size_t cbIn, void *pvOut, size_t cbOut)
138{
139 AssertMsg(g_hDevice != (HFILE)-1, ("SUPLIB not initiated successfully!\n"));
140
141 SUPDRVIOCTLDATA Args;
142 Args.pvIn = pvIn;
143 Args.cbIn = cbIn;
144 Args.pvOut = pvOut;
145 Args.cbOut = cbOut;
146 Args.rc = VERR_INTERNAL_ERROR;
147
148 ULONG cbReturned = sizeof(Args);
149 int rc = DosDevIOCtl(g_hDevice, SUP_CTL_CATEGORY, uFunction,
150 &Args, sizeof(Args), &cbReturned,
151 NULL, 0, NULL);
152 if (RT_LIKELY(rc == NO_ERROR))
153 rc = Args.rc;
154 else
155 rc = RTErrConvertFromOS2(rc);
156 return rc;
157}
158
159
160#ifdef VBOX_WITHOUT_IDT_PATCHING
161int suplibOSIOCtlFast(unsigned uFunction)
162{
163 int32_t rcRet = VERR_INTERNAL_ERROR;
164 ULONG cbRet = sizeof(rcRet);
165 int rc = DosDevIOCtl(g_hDevice, SUP_CTL_CATEGORY_FAST, uFunction,
166 NULL, 0, NULL,
167 &rcRet, sizeof(rcRet), &cbRet);
168 if (RT_LIKELY(rc == NO_ERROR))
169 rc = rcRet;
170 else
171 rc = RTErrConvertFromOS2(rc);
172 return rc;
173}
174#endif
175
176
177int suplibOsPageAlloc(size_t cPages, void **ppvPages)
178{
179 *ppvPages = NULL;
180 int rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
181 if (rc == ERROR_INVALID_PARAMETER)
182 rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
183 if (!rc)
184 rc = VINF_SUCCESS;
185 else
186 rc = RTErrConvertFromOS2(rc);
187 return rc;
188}
189
190
191int suplibOsPageFree(void *pvPages)
192{
193 if (pvPages)
194 {
195 int rc = DosFreeMem(pvPages);
196 Assert(!rc);
197 }
198 return VINF_SUCCESS;
199}
200
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