VirtualBox

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

Last change on this file since 7206 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

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