VirtualBox

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

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

Split VMMR0Entry into VMMR0EntryInt, VMMR0EntryFast and VMMr0EntryEx. This will prevent the SUPCallVMMR0Ex path from causing harm and messing up the paths that has to be optimized.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.0 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.215389.xyz. 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
147int suplibOSIOCtlFast(uintptr_t uFunction)
148{
149 int32_t rcRet = VERR_INTERNAL_ERROR;
150 ULONG cbRet = sizeof(rcRet);
151 int rc = DosDevIOCtl(g_hDevice, SUP_CTL_CATEGORY_FAST, uFunction,
152 NULL, 0, NULL,
153 &rcRet, sizeof(rcRet), &cbRet);
154 if (RT_LIKELY(rc == NO_ERROR))
155 rc = rcRet;
156 else
157 rc = RTErrConvertFromOS2(rc);
158 return rc;
159}
160
161
162int suplibOsPageAlloc(size_t cPages, void **ppvPages)
163{
164 *ppvPages = NULL;
165 int rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
166 if (rc == ERROR_INVALID_PARAMETER)
167 rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
168 if (!rc)
169 rc = VINF_SUCCESS;
170 else
171 rc = RTErrConvertFromOS2(rc);
172 return rc;
173}
174
175
176int suplibOsPageFree(void *pvPages, size_t /* cPages */)
177{
178 if (pvPages)
179 {
180 int rc = DosFreeMem(pvPages);
181 Assert(!rc);
182 }
183 return VINF_SUCCESS;
184}
185
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