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