VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-os2.cpp@ 41943

Last change on this file since 41943 was 40806, checked in by vboxsync, 13 years ago

RTSpinlock: Redid the interface, eliminating NoInts and Tmp. Whether a spinlock is interrupt safe or not is now defined at creation time, preventing stupid bugs arrising from calling the wrong acquire and/or release methods somewhere. The saved flags are stored in the spinlock strucutre, eliminating the annoying Tmp variable. Needs testing on each platform before fixing the build burn.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.2 KB
Line 
1/* $Id: VBoxGuest-os2.cpp 40806 2012-04-06 21:05:19Z vboxsync $ */
2/** @file
3 * VBoxGuest - OS/2 specifics.
4 */
5
6/*
7 * Copyright (C) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
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 *
18 * This code is based on:
19 *
20 * VBoxDrv - OS/2 specifics.
21 *
22 * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
23 *
24 * Permission is hereby granted, free of charge, to any person
25 * obtaining a copy of this software and associated documentation
26 * files (the "Software"), to deal in the Software without
27 * restriction, including without limitation the rights to use,
28 * copy, modify, merge, publish, distribute, sublicense, and/or sell
29 * copies of the Software, and to permit persons to whom the
30 * Software is furnished to do so, subject to the following
31 * conditions:
32 *
33 * The above copyright notice and this permission notice shall be
34 * included in all copies or substantial portions of the Software.
35 *
36 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
37 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
38 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
39 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
40 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
41 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
42 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
43 * OTHER DEALINGS IN THE SOFTWARE.
44 */
45
46
47/*******************************************************************************
48* Header Files *
49*******************************************************************************/
50#include <os2ddk/bsekee.h>
51
52#include "VBoxGuestInternal.h"
53#include <VBox/version.h>
54#include <iprt/initterm.h>
55#include <iprt/string.h>
56#include <iprt/spinlock.h>
57#include <iprt/process.h>
58#include <iprt/assert.h>
59#include <iprt/log.h>
60#include <iprt/memobj.h>
61#include <iprt/mem.h>
62#include <iprt/param.h>
63
64
65/*******************************************************************************
66* Global Variables *
67*******************************************************************************/
68/**
69 * Device extention & session data association structure.
70 */
71static VBOXGUESTDEVEXT g_DevExt;
72/** The memory object for the MMIO memory. */
73static RTR0MEMOBJ g_MemObjMMIO = NIL_RTR0MEMOBJ;
74/** The memory mapping object the MMIO memory. */
75static RTR0MEMOBJ g_MemMapMMIO = NIL_RTR0MEMOBJ;
76
77/** Spinlock protecting g_apSessionHashTab. */
78static RTSPINLOCK g_Spinlock = NIL_RTSPINLOCK;
79/** Hash table */
80static PVBOXGUESTSESSION g_apSessionHashTab[19];
81/** Calculates the index into g_apSessionHashTab.*/
82#define SESSION_HASH(sfn) ((sfn) % RT_ELEMENTS(g_apSessionHashTab))
83
84RT_C_DECLS_BEGIN
85/* Defined in VBoxGuestA-os2.asm */
86extern uint32_t g_PhysMMIOBase;
87extern uint32_t g_cbMMIO; /* 0 currently not set. */
88extern uint16_t g_IOPortBase;
89extern uint8_t g_bInterruptLine;
90extern uint8_t g_bPciBusNo;
91extern uint8_t g_bPciDevFunNo;
92extern RTFAR16 g_fpfnVBoxGuestOs2IDCService16;
93extern RTFAR16 g_fpfnVBoxGuestOs2IDCService16Asm;
94#ifdef DEBUG_READ
95/* (debugging) */
96extern uint16_t g_offLogHead;
97extern uint16_t volatile g_offLogTail;
98extern uint16_t const g_cchLogMax;
99extern char g_szLog[];
100#endif
101/* (init only:) */
102extern char g_szInitText[];
103extern uint16_t g_cchInitText;
104extern uint16_t g_cchInitTextMax;
105RT_C_DECLS_END
106
107
108/*******************************************************************************
109* Internal Functions *
110*******************************************************************************/
111static int vboxGuestOS2MapMemory(void);
112static VBOXOSTYPE vboxGuestOS2DetectVersion(void);
113
114/* in VBoxGuestA-os2.asm */
115DECLASM(int) VBoxGuestOS2SetIRQ(uint8_t bIRQ);
116
117
118/**
119 * 32-bit Ring-0 initialization.
120 *
121 * This is called from VBoxGuestA-os2.asm upon the first open call to the vboxgst$ device.
122 *
123 * @returns 0 on success, non-zero on failure.
124 * @param pszArgs Pointer to the device arguments.
125 */
126DECLASM(int) VBoxGuestOS2Init(const char *pszArgs)
127{
128 Log(("VBoxGuestOS2Init: pszArgs='%s' MMIO=0x%RX32 IOPort=0x%RX16 Int=%#x Bus=%#x Dev=%#x Fun=%d\n",
129 pszArgs, g_PhysMMIOBase, g_IOPortBase, g_bInterruptLine, g_bPciBusNo, g_bPciDevFunNo >> 3, g_bPciDevFunNo & 7));
130
131 /*
132 * Initialize the runtime.
133 */
134 int rc = RTR0Init(0);
135 if (RT_SUCCESS(rc))
136 {
137 /*
138 * Process the commandline. Later.
139 */
140 bool fVerbose = true;
141
142 /*
143 * Map the MMIO memory if found.
144 */
145 rc = vboxGuestOS2MapMemory();
146 if (RT_SUCCESS(rc))
147 {
148 /*
149 * Initialize the device extension.
150 */
151 if (g_MemMapMMIO != NIL_RTR0MEMOBJ)
152 rc = VBoxGuestInitDevExt(&g_DevExt, g_IOPortBase,
153 RTR0MemObjAddress(g_MemMapMMIO),
154 RTR0MemObjSize(g_MemMapMMIO),
155 vboxGuestOS2DetectVersion(),
156 0);
157 else
158 rc = VBoxGuestInitDevExt(&g_DevExt, g_IOPortBase, NULL, 0,
159 vboxGuestOS2DetectVersion(),
160 0);
161 if (RT_SUCCESS(rc))
162 {
163 /*
164 * Initialize the session hash table.
165 */
166 rc = RTSpinlockCreate(&g_Spinlock, RTSPINLOCK_FLAGS_INTERRUPT_SAFE, "VBoxGuestOS2");
167 if (RT_SUCCESS(rc))
168 {
169 /*
170 * Configure the interrupt handler.
171 */
172 if (g_bInterruptLine)
173 {
174 rc = VBoxGuestOS2SetIRQ(g_bInterruptLine);
175 if (rc)
176 {
177 Log(("VBoxGuestOS2SetIRQ(%d) -> %d\n", g_bInterruptLine, rc));
178 rc = RTErrConvertFromOS2(rc);
179 }
180 }
181 if (RT_SUCCESS(rc))
182 {
183 /*
184 * Success
185 */
186 if (fVerbose)
187 {
188 strcpy(&g_szInitText[0],
189 "\r\n"
190 "VirtualBox Guest Additions Driver for OS/2 version " VBOX_VERSION_STRING "\r\n"
191 "Copyright (C) 2008-2010 Oracle Corporation\r\n");
192 g_cchInitText = strlen(&g_szInitText[0]);
193 }
194 Log(("VBoxGuestOS2Init: Successfully loaded\n%s", g_szInitText));
195 return VINF_SUCCESS;
196 }
197
198 g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: SetIrq failed for IRQ %#d, rc=%Rrc\n",
199 g_bInterruptLine, rc);
200 }
201 else
202 g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: RTSpinlockCreate failed, rc=%Rrc\n", rc);
203 VBoxGuestDeleteDevExt(&g_DevExt);
204 }
205 else
206 g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: VBoxGuestOS2InitDevExt failed, rc=%Rrc\n", rc);
207
208 int rc2 = RTR0MemObjFree(g_MemObjMMIO, true /* fFreeMappings */); AssertRC(rc2);
209 g_MemObjMMIO = g_MemMapMMIO = NIL_RTR0MEMOBJ;
210 }
211 else
212 g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: VBoxGuestOS2MapMMIO failed, rc=%Rrc\n", rc);
213 RTR0Term();
214 }
215 else
216 g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: RTR0Init failed, rc=%Rrc\n", rc);
217
218 RTLogBackdoorPrintf("VBoxGuestOS2Init: failed rc=%Rrc - %s", rc, &g_szInitText[0]);
219 return rc;
220}
221
222
223/**
224 * Maps the VMMDev memory.
225 *
226 * @returns VBox status code.
227 * @retval VERR_VERSION_MISMATCH The VMMDev memory didn't meet our expectations.
228 *
229 * @param pDevExt The device extension.
230 */
231static int vboxGuestOS2MapMemory(void)
232{
233 const RTCCPHYS PhysMMIOBase = g_PhysMMIOBase;
234
235 /*
236 * Did we find any MMIO region (0 or NIL)?
237 */
238 if ( !PhysMMIOBase
239 || PhysMMIOBase == NIL_RTCCPHYS)
240 {
241 Assert(g_MemMapMMIO != NIL_RTR0MEMOBJ);
242 return VINF_SUCCESS;
243 }
244
245 /*
246 * Create a physical memory object for it.
247 *
248 * Since we don't know the actual size (OS/2 doesn't at least), we make
249 * a qualified guess using the VMMDEV_RAM_SIZE.
250 */
251 size_t cb = RT_ALIGN_Z(VMMDEV_RAM_SIZE, PAGE_SIZE);
252 int rc = RTR0MemObjEnterPhys(&g_MemObjMMIO, PhysMMIOBase, cb, RTMEM_CACHE_POLICY_DONT_CARE);
253 if (RT_FAILURE(rc))
254 {
255 cb = _4K;
256 rc = RTR0MemObjEnterPhys(&g_MemObjMMIO, PhysMMIOBase, cb, RTMEM_CACHE_POLICY_DONT_CARE);
257 }
258 if (RT_FAILURE(rc))
259 {
260 Log(("vboxGuestOS2MapMemory: RTR0MemObjEnterPhys(,%RCp,%zx) -> %Rrc\n",
261 PhysMMIOBase, cb, rc));
262 return rc;
263 }
264
265 /*
266 * Map the object into kernel space.
267 *
268 * We want a normal mapping with normal caching, which good in two ways. First
269 * since the API doesn't have any flags indicating how the mapping should be cached.
270 * And second, because PGM doesn't necessarily respect the cache/writethru bits
271 * anyway for normal RAM.
272 */
273 rc = RTR0MemObjMapKernel(&g_MemMapMMIO, g_MemObjMMIO, (void *)-1, 0,
274 RTMEM_PROT_READ | RTMEM_PROT_WRITE);
275 if (RT_SUCCESS(rc))
276 {
277 /*
278 * Validate the VMM memory.
279 */
280 VMMDevMemory *pVMMDev = (VMMDevMemory *)RTR0MemObjAddress(g_MemMapMMIO);
281 Assert(pVMMDev);
282 if ( pVMMDev->u32Version == VMMDEV_MEMORY_VERSION
283 && pVMMDev->u32Size >= 32 /* just for checking sanity */)
284 {
285 /*
286 * Did we hit the correct size? If not we'll have to
287 * redo the mapping using the correct size.
288 */
289 if (RT_ALIGN_32(pVMMDev->u32Size, PAGE_SIZE) == cb)
290 return VINF_SUCCESS;
291
292 Log(("vboxGuestOS2MapMemory: Actual size %#RX32 (tried %#zx)\n", pVMMDev->u32Size, cb));
293 cb = RT_ALIGN_32(pVMMDev->u32Size, PAGE_SIZE);
294
295 rc = RTR0MemObjFree(g_MemObjMMIO, true); AssertRC(rc);
296 g_MemObjMMIO = g_MemMapMMIO = NIL_RTR0MEMOBJ;
297
298 rc = RTR0MemObjEnterPhys(&g_MemObjMMIO, PhysMMIOBase, cb, RTMEM_CACHE_POLICY_DONT_CARE);
299 if (RT_SUCCESS(rc))
300 {
301 rc = RTR0MemObjMapKernel(&g_MemMapMMIO, g_MemObjMMIO, (void *)-1, 0,
302 RTMEM_PROT_READ | RTMEM_PROT_WRITE);
303 if (RT_SUCCESS(rc))
304 return VINF_SUCCESS;
305
306 Log(("vboxGuestOS2MapMemory: RTR0MemObjMapKernel [%RCp,%zx] -> %Rrc (2nd)\n",
307 PhysMMIOBase, cb, rc));
308 }
309 else
310 Log(("vboxGuestOS2MapMemory: RTR0MemObjEnterPhys(,%RCp,%zx) -> %Rrc (2nd)\n",
311 PhysMMIOBase, cb, rc));
312 }
313 else
314 {
315 rc = VERR_VERSION_MISMATCH;
316 LogRel(("vboxGuestOS2MapMemory: Bogus VMMDev memory; u32Version=%RX32 (expected %RX32) u32Size=%RX32\n",
317 pVMMDev->u32Version, VMMDEV_MEMORY_VERSION, pVMMDev->u32Size));
318 }
319 }
320 else
321 Log(("vboxGuestOS2MapMemory: RTR0MemObjMapKernel [%RCp,%zx] -> %Rrc\n",
322 PhysMMIOBase, cb, rc));
323
324 int rc2 = RTR0MemObjFree(g_MemObjMMIO, true /* fFreeMappings */); AssertRC(rc2);
325 g_MemObjMMIO = g_MemMapMMIO = NIL_RTR0MEMOBJ;
326 return rc;
327}
328
329
330/**
331 * Called fromn VBoxGuestOS2Init to determine which OS/2 version this is.
332 *
333 * @returns VBox OS/2 type.
334 */
335static VBOXOSTYPE vboxGuestOS2DetectVersion(void)
336{
337 VBOXOSTYPE enmOSType = VBOXOSTYPE_OS2;
338
339#if 0 /** @todo dig up the version stuff from GIS later and verify that the numbers are actually decimal. */
340 unsigned uMajor, uMinor;
341 if (uMajor == 2)
342 {
343 if (uMinor >= 30 && uMinor < 40)
344 enmOSType = VBOXOSTYPE_OS2Warp3;
345 else if (uMinor >= 40 && uMinor < 45)
346 enmOSType = VBOXOSTYPE_OS2Warp4;
347 else if (uMinor >= 45 && uMinor < 50)
348 enmOSType = VBOXOSTYPE_OS2Warp45;
349 }
350#endif
351 return enmOSType;
352}
353
354
355DECLASM(int) VBoxGuestOS2Open(uint16_t sfn)
356{
357 int rc;
358 PVBOXGUESTSESSION pSession;
359
360 /*
361 * Create a new session.
362 */
363 rc = VBoxGuestCreateUserSession(&g_DevExt, &pSession);
364 if (RT_SUCCESS(rc))
365 {
366 pSession->sfn = sfn;
367
368 /*
369 * Insert it into the hash table.
370 */
371 unsigned iHash = SESSION_HASH(sfn);
372 RTSpinlockAcquire(g_Spinlock);
373 pSession->pNextHash = g_apSessionHashTab[iHash];
374 g_apSessionHashTab[iHash] = pSession;
375 RTSpinlockReleaseNoInts(g_Spinlock);
376 }
377
378 Log(("VBoxGuestOS2Open: g_DevExt=%p pSession=%p rc=%d pid=%d\n", &g_DevExt, pSession, rc, (int)RTProcSelf()));
379 return rc;
380}
381
382
383DECLASM(int) VBoxGuestOS2Close(uint16_t sfn)
384{
385 Log(("VBoxGuestOS2Close: pid=%d sfn=%d\n", (int)RTProcSelf(), sfn));
386
387 /*
388 * Remove from the hash table.
389 */
390 PVBOXGUESTSESSION pSession;
391 const RTPROCESS Process = RTProcSelf();
392 const unsigned iHash = SESSION_HASH(sfn);
393 RTSpinlockAcquire(g_Spinlock);
394
395 pSession = g_apSessionHashTab[iHash];
396 if (pSession)
397 {
398 if ( pSession->sfn == sfn
399 && pSession->Process == Process)
400 {
401 g_apSessionHashTab[iHash] = pSession->pNextHash;
402 pSession->pNextHash = NULL;
403 }
404 else
405 {
406 PVBOXGUESTSESSION pPrev = pSession;
407 pSession = pSession->pNextHash;
408 while (pSession)
409 {
410 if ( pSession->sfn == sfn
411 && pSession->Process == Process)
412 {
413 pPrev->pNextHash = pSession->pNextHash;
414 pSession->pNextHash = NULL;
415 break;
416 }
417
418 /* next */
419 pPrev = pSession;
420 pSession = pSession->pNextHash;
421 }
422 }
423 }
424 RTSpinlockReleaseNoInts(g_Spinlock);
425 if (!pSession)
426 {
427 Log(("VBoxGuestIoctl: WHUT?!? pSession == NULL! This must be a mistake... pid=%d sfn=%d\n", (int)Process, sfn));
428 return VERR_INVALID_PARAMETER;
429 }
430
431 /*
432 * Close the session.
433 */
434 VBoxGuestCloseSession(&g_DevExt, pSession);
435 return 0;
436}
437
438
439DECLASM(int) VBoxGuestOS2IOCtlFast(uint16_t sfn, uint8_t iFunction, int32_t *prc)
440{
441 /*
442 * Find the session.
443 */
444 const RTPROCESS Process = RTProcSelf();
445 const unsigned iHash = SESSION_HASH(sfn);
446 PVBOXGUESTSESSION pSession;
447
448 RTSpinlockAcquire(g_Spinlock);
449 pSession = g_apSessionHashTab[iHash];
450 if (pSession && pSession->Process != Process)
451 {
452 do pSession = pSession->pNextHash;
453 while ( pSession
454 && ( pSession->sfn != sfn
455 || pSession->Process != Process));
456 }
457 RTSpinlockReleaseNoInts(g_Spinlock);
458 if (RT_UNLIKELY(!pSession))
459 {
460 Log(("VBoxGuestIoctl: WHAT?!? pSession == NULL! This must be a mistake... pid=%d\n", (int)Process));
461 return VERR_INVALID_PARAMETER;
462 }
463
464 /*
465 * Dispatch the fast IOCtl.
466 */
467 *prc = VBoxGuestCommonIOCtlFast(iFunction, &g_DevExt, pSession);
468 return 0;
469}
470
471
472/**
473 * 32-bit IDC service routine.
474 *
475 * @returns VBox status code.
476 * @param u32Session The session handle (PVBOXGUESTSESSION).
477 * @param iFunction The requested function.
478 * @param pvData The input/output data buffer. The caller ensures that this
479 * cannot be swapped out, or that it's acceptable to take a
480 * page in fault in the current context. If the request doesn't
481 * take input or produces output, apssing NULL is okay.
482 * @param cbData The size of the data buffer.
483 * @param pcbDataReturned Where to store the amount of data that's returned.
484 * This can be NULL if pvData is NULL.
485 *
486 * @remark This is called from the 16-bit thunker as well as directly from the 32-bit clients.
487 */
488DECLASM(int) VBoxGuestOS2IDCService(uint32_t u32Session, unsigned iFunction, void *pvData, size_t cbData, size_t *pcbDataReturned)
489{
490 PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)u32Session;
491 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
492 AssertMsgReturn(pSession->sfn == 0xffff, ("%RX16\n", pSession->sfn), VERR_INVALID_HANDLE);
493 AssertMsgReturn(pSession->pDevExt == &g_DevExt, ("%p != %p\n", pSession->pDevExt, &g_DevExt), VERR_INVALID_HANDLE);
494
495 int rc;
496 switch (iFunction)
497 {
498 default:
499 rc = VBoxGuestCommonIOCtl(iFunction, &g_DevExt, pSession, pvData, cbData, pcbDataReturned);
500 break;
501
502 case VBOXGUEST_IOCTL_OS2_IDC_DISCONNECT:
503 pSession->sfn = 0;
504 VBoxGuestCloseSession(&g_DevExt, pSession);
505 rc = VINF_SUCCESS;
506 break;
507 }
508 return rc;
509}
510
511
512/**
513 * Worker for VBoxGuestOS2IDC, it creates the kernel session.
514 *
515 * @returns Pointer to the session.
516 */
517DECLASM(PVBOXGUESTSESSION) VBoxGuestOS2IDCConnect(void)
518{
519 PVBOXGUESTSESSION pSession;
520 int rc = VBoxGuestCreateKernelSession(&g_DevExt, &pSession);
521 if (RT_SUCCESS(rc))
522 {
523 pSession->sfn = 0xffff;
524 return pSession;
525 }
526 return NULL;
527}
528
529
530DECLASM(int) VBoxGuestOS2IOCtl(uint16_t sfn, uint8_t iCat, uint8_t iFunction, void *pvParm, void *pvData, uint16_t *pcbParm, uint16_t *pcbData)
531{
532 /*
533 * Find the session.
534 */
535 const RTPROCESS Process = RTProcSelf();
536 const unsigned iHash = SESSION_HASH(sfn);
537 PVBOXGUESTSESSION pSession;
538
539 RTSpinlockAcquire(g_Spinlock);
540 pSession = g_apSessionHashTab[iHash];
541 if (pSession && pSession->Process != Process)
542 {
543 do pSession = pSession->pNextHash;
544 while ( pSession
545 && ( pSession->sfn != sfn
546 || pSession->Process != Process));
547 }
548 RTSpinlockReleaseNoInts(g_Spinlock);
549 if (!pSession)
550 {
551 Log(("VBoxGuestIoctl: WHAT?!? pSession == NULL! This must be a mistake... pid=%d\n", (int)Process));
552 return VERR_INVALID_PARAMETER;
553 }
554
555 /*
556 * Verify the category and dispatch the IOCtl.
557 *
558 * The IOCtl call uses the parameter buffer as generic data input/output
559 * buffer similar to the one unix ioctl buffer argument. While the data
560 * buffer is used for passing the VBox status code back to the caller
561 * since the status codes that OS/2 accepts thru the DosDevIOCtl API is
562 * severely restricted.
563 */
564 if (RT_LIKELY(iCat == VBOXGUEST_IOCTL_CATEGORY))
565 {
566 Log(("VBoxGuestOS2IOCtl: pSession=%p iFunction=%#x pvParm=%p pvData=%p *pcbParm=%d *pcbData=%d\n", pSession, iFunction, pvParm, pvData, *pcbParm, *pcbData));
567 Assert(pvParm || !*pcbData);
568 Assert(pvData);
569 Assert(*pcbData == sizeof(int32_t)); /* the return code */
570
571 /*
572 * Lock the buffers.
573 */
574 int32_t rc;
575 KernVMLock_t ParmLock;
576 if (pvParm)
577 {
578 Assert(*pcbData);
579 rc = KernVMLock(VMDHL_WRITE, pvParm, *pcbParm, &ParmLock, (KernPageList_t *)-1, NULL);
580 AssertMsgReturn(!rc, ("KernVMLock(VMDHL_WRITE, %p, %#x, &p, NULL, NULL) -> %d\n", pvParm, *pcbParm, &ParmLock, rc), VERR_LOCK_FAILED);
581 }
582
583#if 0 /* don't bother locking it since it's only 4 bytes (the return code). */
584 KernVMLock_t DataLock;
585 if (pvData)
586 {
587 Assert(*pcbData);
588 rc = KernVMLock(VMDHL_WRITE, pvData, *pcbData, &DataLock, (KernPageList_t *)-1, NULL);
589 if (rc)
590 {
591 AssertMsgFailed(("KernVMLock(VMDHL_WRITE, %p, %#x, &p, NULL, NULL) -> %d\n", pvData, *pcbData, &DataLock, rc));
592 KernVMUnlock(&ParmLock);
593 return VERR_LOCK_FAILED;
594 }
595 }
596#endif
597
598 /*
599 * Process the IOCtl.
600 */
601 size_t cbDataReturned;
602 rc = VBoxGuestCommonIOCtl(iFunction, &g_DevExt, pSession, pvParm, *pcbParm, &cbDataReturned);
603
604 /*
605 * Unlock the buffers.
606 */
607 if (pvParm)
608 {
609 int rc2 = KernVMUnlock(&ParmLock);
610 AssertMsg(!rc2, ("rc2=%d\n", rc2)); NOREF(rc2);
611 AssertMsg(cbDataReturned < _64K, ("cbDataReturned=%d\n", cbDataReturned));
612 *pcbParm = cbDataReturned;
613 }
614#if 0
615 if (pvData)
616 {
617 int rc2 = KernVMUnlock(&DataLock);
618 AssertMsg(!rc2, ("rc2=%d\n", rc2));
619 }
620#else
621 rc = KernCopyOut(pvData, &rc, sizeof(int32_t));
622 AssertMsgReturn(!rc, ("KernCopyOut(%p, %p, sizeof(int32_t)) -> %d\n", pvData, &rc, rc), VERR_LOCK_FAILED);
623#endif
624
625 Log2(("VBoxGuestOS2IOCtl: returns VINF_SUCCESS / %d\n", rc));
626 return VINF_SUCCESS;
627 }
628 return VERR_NOT_SUPPORTED;
629}
630
631
632/**
633 * 32-bit ISR, called by 16-bit assembly thunker in VBoxGuestA-os2.asm.
634 *
635 * @returns true if it's our interrupt, false it isn't.
636 */
637DECLASM(bool) VBoxGuestOS2ISR(void)
638{
639 Log(("VBoxGuestOS2ISR\n"));
640
641 return VBoxGuestCommonISR(&g_DevExt);
642}
643
644
645void VBoxGuestNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt)
646{
647 /* No polling on OS/2 */
648 NOREF(pDevExt);
649}
650
651
652#ifdef DEBUG_READ /** @todo figure out this one once and for all... */
653
654/**
655 * Callback for writing to the log buffer.
656 *
657 * @returns number of bytes written.
658 * @param pvArg Unused.
659 * @param pachChars Pointer to an array of utf-8 characters.
660 * @param cbChars Number of bytes in the character array pointed to by pachChars.
661 */
662static DECLCALLBACK(size_t) vboxGuestNativeLogOutput(void *pvArg, const char *pachChars, size_t cbChars)
663{
664 size_t cchWritten = 0;
665 while (cbChars-- > 0)
666 {
667 const uint16_t offLogHead = g_offLogHead;
668 const uint16_t offLogHeadNext = (offLogHead + 1) & (g_cchLogMax - 1);
669 if (offLogHeadNext == g_offLogTail)
670 break; /* no */
671 g_szLog[offLogHead] = *pachChars++;
672 g_offLogHead = offLogHeadNext;
673 cchWritten++;
674 }
675 return cchWritten;
676}
677
678
679int SUPR0Printf(const char *pszFormat, ...)
680{
681 va_list va;
682
683#if 0 //def DEBUG_bird
684 va_start(va, pszFormat);
685 RTLogComPrintfV(pszFormat, va);
686 va_end(va);
687#endif
688
689 va_start(va, pszFormat);
690 int cch = RTLogFormatV(vboxGuestNativeLogOutput, NULL, pszFormat, va);
691 va_end(va);
692
693 return cch;
694}
695
696#endif /* DEBUG_READ */
697
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