VirtualBox

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

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

Redid the supdrv interface. works on windows and linux while the other OSes still needs some adjusting/testing. internal networking is temporarily broken as the SUPCallVMMR0Ex interface is being reworked (this is what all this is really about).

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette