VirtualBox

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

Last change on this file since 11347 was 10720, checked in by vboxsync, 17 years ago

Fixed issue in fast (METHOD_NEITHER) ioctls.
Write the last error to pVM->vmm.s.iLastGCRc instead of writing it to a user buffer.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.9 KB
Line 
1/* $Id: SUPLib-os2.cpp 10720 2008-07-17 12:06:56Z vboxsync $ */
2/** @file
3 * SUPLib - Support Library, OS/2 backend.
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/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#define INCL_BASE
36#define INCL_ERRORS
37#include <os2.h>
38#undef RT_MAX
39
40#include <VBox/types.h>
41#include <VBox/sup.h>
42#include <VBox/param.h>
43#include <VBox/err.h>
44#include <VBox/log.h>
45#include <iprt/path.h>
46#include <iprt/assert.h>
47#include <iprt/err.h>
48#include "../SUPLibInternal.h"
49#include "../SUPDrvIOC.h"
50
51#include <errno.h>
52#include <unistd.h>
53#include <stdlib.h>
54
55
56/*******************************************************************************
57* Defined Constants And Macros *
58*******************************************************************************/
59/** OS/2 Device name. */
60#define DEVICE_NAME "/dev/vboxdrv$"
61
62
63
64/*******************************************************************************
65* Global Variables *
66*******************************************************************************/
67/** Handle to the open device. */
68static HFILE g_hDevice = (HFILE)-1;
69
70
71/*******************************************************************************
72* Internal Functions *
73*******************************************************************************/
74
75
76/**
77 * Initialize the OS specific part of the library.
78 * On Linux this involves:
79 * - loading the module.
80 * - open driver.
81 *
82 * @returns 0 on success.
83 * @returns current -1 on failure but this must be changed to proper error codes.
84 * @param cbReserve Ignored on OS/2.
85 */
86int suplibOsInit(size_t cbReserve)
87{
88 /*
89 * Check if already initialized.
90 */
91 if (g_hDevice != (HFILE)-1)
92 return 0;
93
94 /*
95 * Try open the device.
96 */
97 ULONG ulAction = 0;
98 HFILE hDevice = (HFILE)-1;
99 APIRET rc = DosOpen((PCSZ)DEVICE_NAME,
100 &hDevice,
101 &ulAction,
102 0,
103 FILE_NORMAL,
104 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
105 OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
106 NULL);
107 if (rc)
108 {
109 int vrc;
110 switch (rc)
111 {
112 case ERROR_FILE_NOT_FOUND:
113 case ERROR_PATH_NOT_FOUND: vrc = VERR_VM_DRIVER_NOT_INSTALLED; break;
114 default: vrc = VERR_VM_DRIVER_OPEN_ERROR; break;
115 }
116 LogRel(("Failed to open \"%s\", rc=%d, vrc=%Vrc\n", DEVICE_NAME, rc, vrc));
117 return vrc;
118 }
119 g_hDevice = hDevice;
120
121 NOREF(cbReserve);
122 return VINF_SUCCESS;
123}
124
125
126int suplibOsTerm(void)
127{
128 /*
129 * Check if we're initited at all.
130 */
131 if (g_hDevice != (HFILE)-1)
132 {
133 APIRET rc = DosClose(g_hDevice);
134 AssertMsg(rc == NO_ERROR, ("%d\n", rc)); NOREF(rc);
135 g_hDevice = (HFILE)-1;
136 }
137
138 return 0;
139}
140
141
142int suplibOsInstall(void)
143{
144 /** @remark OS/2: Not supported */
145 return VERR_NOT_SUPPORTED;
146}
147
148
149int suplibOsUninstall(void)
150{
151 /** @remark OS/2: Not supported */
152 return VERR_NOT_SUPPORTED;
153}
154
155
156int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq)
157{
158 AssertMsg(g_hDevice != (HFILE)-1, ("SUPLIB not initiated successfully!\n"));
159
160 ULONG cbReturned = sizeof(SUPREQHDR);
161 int rc = DosDevIOCtl(g_hDevice, SUP_CTL_CATEGORY, uFunction,
162 pvReq, cbReturned, &cbReturned,
163 NULL, 0, NULL);
164 if (RT_LIKELY(rc == NO_ERROR))
165 return VINF_SUCCESS;
166 return RTErrConvertFromOS2(rc);
167}
168
169
170int suplibOsIOCtlFast(uintptr_t uFunction)
171{
172 int32_t rcRet = VERR_INTERNAL_ERROR;
173 int rc = DosDevIOCtl(g_hDevice, SUP_CTL_CATEGORY_FAST, uFunction,
174 NULL, 0, NULL,
175 NULL, 0, NULL);
176 if (RT_LIKELY(rc == NO_ERROR))
177 rc = rcRet;
178 else
179 rc = RTErrConvertFromOS2(rc);
180 return rc;
181}
182
183
184int suplibOsPageAlloc(size_t cPages, void **ppvPages)
185{
186 *ppvPages = NULL;
187 int rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
188 if (rc == ERROR_INVALID_PARAMETER)
189 rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
190 if (!rc)
191 rc = VINF_SUCCESS;
192 else
193 rc = RTErrConvertFromOS2(rc);
194 return rc;
195}
196
197
198int suplibOsPageFree(void *pvPages, size_t /* cPages */)
199{
200 if (pvPages)
201 {
202 int rc = DosFreeMem(pvPages);
203 Assert(!rc); NOREF(rc);
204 }
205 return VINF_SUCCESS;
206}
207
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