VirtualBox

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

Last change on this file since 58089 was 58089, checked in by vboxsync, 10 years ago

VBoxGuest,VBoxService,Doxyfile.Core: fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.5 KB
Line 
1/* $Id: VBoxGuest-os2.cpp 58089 2015-10-07 12:33:00Z vboxsync $ */
2/** @file
3 * VBoxGuest - OS/2 specifics.
4 */
5
6/*
7 * Copyright (C) 2007-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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-2012 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 = VGDrvCommonInitDevExt(&g_DevExt, g_IOPortBase,
153 RTR0MemObjAddress(g_MemMapMMIO),
154 RTR0MemObjSize(g_MemMapMMIO),
155 vboxGuestOS2DetectVersion(),
156 0);
157 else
158 rc = VGDrvCommonInitDevExt(&g_DevExt, g_IOPortBase, NULL, 0, vboxGuestOS2DetectVersion(), 0);
159 if (RT_SUCCESS(rc))
160 {
161 /*
162 * Initialize the session hash table.
163 */
164 rc = RTSpinlockCreate(&g_Spinlock, RTSPINLOCK_FLAGS_INTERRUPT_SAFE, "VBoxGuestOS2");
165 if (RT_SUCCESS(rc))
166 {
167 /*
168 * Configure the interrupt handler.
169 */
170 if (g_bInterruptLine)
171 {
172 rc = VBoxGuestOS2SetIRQ(g_bInterruptLine);
173 if (rc)
174 {
175 Log(("VBoxGuestOS2SetIRQ(%d) -> %d\n", g_bInterruptLine, rc));
176 rc = RTErrConvertFromOS2(rc);
177 }
178 }
179 if (RT_SUCCESS(rc))
180 {
181 /*
182 * Success
183 */
184 if (fVerbose)
185 {
186 strcpy(&g_szInitText[0],
187 "\r\n"
188 "VirtualBox Guest Additions Driver for OS/2 version " VBOX_VERSION_STRING "\r\n"
189 "Copyright (C) 2008-" VBOX_C_YEAR " " VBOX_VENDOR "\r\n");
190 g_cchInitText = strlen(&g_szInitText[0]);
191 }
192 Log(("VBoxGuestOS2Init: Successfully loaded\n%s", g_szInitText));
193 return VINF_SUCCESS;
194 }
195
196 g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: SetIrq failed for IRQ %#d, rc=%Rrc\n",
197 g_bInterruptLine, rc);
198 }
199 else
200 g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: RTSpinlockCreate failed, rc=%Rrc\n", rc);
201 VGDrvCommonDeleteDevExt(&g_DevExt);
202 }
203 else
204 g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: VBoxGuestOS2InitDevExt failed, rc=%Rrc\n", rc);
205
206 int rc2 = RTR0MemObjFree(g_MemObjMMIO, true /* fFreeMappings */); AssertRC(rc2);
207 g_MemObjMMIO = g_MemMapMMIO = NIL_RTR0MEMOBJ;
208 }
209 else
210 g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: VBoxGuestOS2MapMMIO failed, rc=%Rrc\n", rc);
211 RTR0Term();
212 }
213 else
214 g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: RTR0Init failed, rc=%Rrc\n", rc);
215
216 RTLogBackdoorPrintf("VBoxGuestOS2Init: failed rc=%Rrc - %s", rc, &g_szInitText[0]);
217 return rc;
218}
219
220
221/**
222 * Maps the VMMDev memory.
223 *
224 * @returns VBox status code.
225 * @retval VERR_VERSION_MISMATCH The VMMDev memory didn't meet our expectations.
226 */
227static int vboxGuestOS2MapMemory(void)
228{
229 const RTCCPHYS PhysMMIOBase = g_PhysMMIOBase;
230
231 /*
232 * Did we find any MMIO region (0 or NIL)?
233 */
234 if ( !PhysMMIOBase
235 || PhysMMIOBase == NIL_RTCCPHYS)
236 {
237 Assert(g_MemMapMMIO != NIL_RTR0MEMOBJ);
238 return VINF_SUCCESS;
239 }
240
241 /*
242 * Create a physical memory object for it.
243 *
244 * Since we don't know the actual size (OS/2 doesn't at least), we make
245 * a qualified guess using the VMMDEV_RAM_SIZE.
246 */
247 size_t cb = RT_ALIGN_Z(VMMDEV_RAM_SIZE, PAGE_SIZE);
248 int rc = RTR0MemObjEnterPhys(&g_MemObjMMIO, PhysMMIOBase, cb, RTMEM_CACHE_POLICY_DONT_CARE);
249 if (RT_FAILURE(rc))
250 {
251 cb = _4K;
252 rc = RTR0MemObjEnterPhys(&g_MemObjMMIO, PhysMMIOBase, cb, RTMEM_CACHE_POLICY_DONT_CARE);
253 }
254 if (RT_FAILURE(rc))
255 {
256 Log(("vboxGuestOS2MapMemory: RTR0MemObjEnterPhys(,%RCp,%zx) -> %Rrc\n",
257 PhysMMIOBase, cb, rc));
258 return rc;
259 }
260
261 /*
262 * Map the object into kernel space.
263 *
264 * We want a normal mapping with normal caching, which good in two ways. First
265 * since the API doesn't have any flags indicating how the mapping should be cached.
266 * And second, because PGM doesn't necessarily respect the cache/writethru bits
267 * anyway for normal RAM.
268 */
269 rc = RTR0MemObjMapKernel(&g_MemMapMMIO, g_MemObjMMIO, (void *)-1, 0,
270 RTMEM_PROT_READ | RTMEM_PROT_WRITE);
271 if (RT_SUCCESS(rc))
272 {
273 /*
274 * Validate the VMM memory.
275 */
276 VMMDevMemory *pVMMDev = (VMMDevMemory *)RTR0MemObjAddress(g_MemMapMMIO);
277 Assert(pVMMDev);
278 if ( pVMMDev->u32Version == VMMDEV_MEMORY_VERSION
279 && pVMMDev->u32Size >= 32 /* just for checking sanity */)
280 {
281 /*
282 * Did we hit the correct size? If not we'll have to
283 * redo the mapping using the correct size.
284 */
285 if (RT_ALIGN_32(pVMMDev->u32Size, PAGE_SIZE) == cb)
286 return VINF_SUCCESS;
287
288 Log(("vboxGuestOS2MapMemory: Actual size %#RX32 (tried %#zx)\n", pVMMDev->u32Size, cb));
289 cb = RT_ALIGN_32(pVMMDev->u32Size, PAGE_SIZE);
290
291 rc = RTR0MemObjFree(g_MemObjMMIO, true); AssertRC(rc);
292 g_MemObjMMIO = g_MemMapMMIO = NIL_RTR0MEMOBJ;
293
294 rc = RTR0MemObjEnterPhys(&g_MemObjMMIO, PhysMMIOBase, cb, RTMEM_CACHE_POLICY_DONT_CARE);
295 if (RT_SUCCESS(rc))
296 {
297 rc = RTR0MemObjMapKernel(&g_MemMapMMIO, g_MemObjMMIO, (void *)-1, 0,
298 RTMEM_PROT_READ | RTMEM_PROT_WRITE);
299 if (RT_SUCCESS(rc))
300 return VINF_SUCCESS;
301
302 Log(("vboxGuestOS2MapMemory: RTR0MemObjMapKernel [%RCp,%zx] -> %Rrc (2nd)\n",
303 PhysMMIOBase, cb, rc));
304 }
305 else
306 Log(("vboxGuestOS2MapMemory: RTR0MemObjEnterPhys(,%RCp,%zx) -> %Rrc (2nd)\n",
307 PhysMMIOBase, cb, rc));
308 }
309 else
310 {
311 rc = VERR_VERSION_MISMATCH;
312 LogRel(("vboxGuestOS2MapMemory: Bogus VMMDev memory; u32Version=%RX32 (expected %RX32) u32Size=%RX32\n",
313 pVMMDev->u32Version, VMMDEV_MEMORY_VERSION, pVMMDev->u32Size));
314 }
315 }
316 else
317 Log(("vboxGuestOS2MapMemory: RTR0MemObjMapKernel [%RCp,%zx] -> %Rrc\n",
318 PhysMMIOBase, cb, rc));
319
320 int rc2 = RTR0MemObjFree(g_MemObjMMIO, true /* fFreeMappings */); AssertRC(rc2);
321 g_MemObjMMIO = g_MemMapMMIO = NIL_RTR0MEMOBJ;
322 return rc;
323}
324
325
326/**
327 * Called fromn VBoxGuestOS2Init to determine which OS/2 version this is.
328 *
329 * @returns VBox OS/2 type.
330 */
331static VBOXOSTYPE vboxGuestOS2DetectVersion(void)
332{
333 VBOXOSTYPE enmOSType = VBOXOSTYPE_OS2;
334
335#if 0 /** @todo dig up the version stuff from GIS later and verify that the numbers are actually decimal. */
336 unsigned uMajor, uMinor;
337 if (uMajor == 2)
338 {
339 if (uMinor >= 30 && uMinor < 40)
340 enmOSType = VBOXOSTYPE_OS2Warp3;
341 else if (uMinor >= 40 && uMinor < 45)
342 enmOSType = VBOXOSTYPE_OS2Warp4;
343 else if (uMinor >= 45 && uMinor < 50)
344 enmOSType = VBOXOSTYPE_OS2Warp45;
345 }
346#endif
347 return enmOSType;
348}
349
350
351DECLASM(int) VBoxGuestOS2Open(uint16_t sfn)
352{
353 int rc;
354 PVBOXGUESTSESSION pSession;
355
356 /*
357 * Create a new session.
358 */
359 rc = VGDrvCommonCreateUserSession(&g_DevExt, &pSession);
360 if (RT_SUCCESS(rc))
361 {
362 pSession->sfn = sfn;
363
364 /*
365 * Insert it into the hash table.
366 */
367 unsigned iHash = SESSION_HASH(sfn);
368 RTSpinlockAcquire(g_Spinlock);
369 pSession->pNextHash = g_apSessionHashTab[iHash];
370 g_apSessionHashTab[iHash] = pSession;
371 RTSpinlockRelease(g_Spinlock);
372 }
373
374 Log(("VBoxGuestOS2Open: g_DevExt=%p pSession=%p rc=%d pid=%d\n", &g_DevExt, pSession, rc, (int)RTProcSelf()));
375 return rc;
376}
377
378
379DECLASM(int) VBoxGuestOS2Close(uint16_t sfn)
380{
381 Log(("VBoxGuestOS2Close: pid=%d sfn=%d\n", (int)RTProcSelf(), sfn));
382
383 /*
384 * Remove from the hash table.
385 */
386 PVBOXGUESTSESSION pSession;
387 const RTPROCESS Process = RTProcSelf();
388 const unsigned iHash = SESSION_HASH(sfn);
389 RTSpinlockAcquire(g_Spinlock);
390
391 pSession = g_apSessionHashTab[iHash];
392 if (pSession)
393 {
394 if ( pSession->sfn == sfn
395 && pSession->Process == Process)
396 {
397 g_apSessionHashTab[iHash] = pSession->pNextHash;
398 pSession->pNextHash = NULL;
399 }
400 else
401 {
402 PVBOXGUESTSESSION pPrev = pSession;
403 pSession = pSession->pNextHash;
404 while (pSession)
405 {
406 if ( pSession->sfn == sfn
407 && pSession->Process == Process)
408 {
409 pPrev->pNextHash = pSession->pNextHash;
410 pSession->pNextHash = NULL;
411 break;
412 }
413
414 /* next */
415 pPrev = pSession;
416 pSession = pSession->pNextHash;
417 }
418 }
419 }
420 RTSpinlockRelease(g_Spinlock);
421 if (!pSession)
422 {
423 Log(("VBoxGuestIoctl: WHUT?!? pSession == NULL! This must be a mistake... pid=%d sfn=%d\n", (int)Process, sfn));
424 return VERR_INVALID_PARAMETER;
425 }
426
427 /*
428 * Close the session.
429 */
430 VGDrvCommonCloseSession(&g_DevExt, pSession);
431 return 0;
432}
433
434
435DECLASM(int) VBoxGuestOS2IOCtlFast(uint16_t sfn, uint8_t iFunction, int32_t *prc)
436{
437 /*
438 * Find the session.
439 */
440 const RTPROCESS Process = RTProcSelf();
441 const unsigned iHash = SESSION_HASH(sfn);
442 PVBOXGUESTSESSION pSession;
443
444 RTSpinlockAcquire(g_Spinlock);
445 pSession = g_apSessionHashTab[iHash];
446 if (pSession && pSession->Process != Process)
447 {
448 do pSession = pSession->pNextHash;
449 while ( pSession
450 && ( pSession->sfn != sfn
451 || pSession->Process != Process));
452 }
453 RTSpinlockRelease(g_Spinlock);
454 if (RT_UNLIKELY(!pSession))
455 {
456 Log(("VBoxGuestIoctl: WHAT?!? pSession == NULL! This must be a mistake... pid=%d\n", (int)Process));
457 return VERR_INVALID_PARAMETER;
458 }
459
460 /*
461 * Dispatch the fast IOCtl.
462 */
463 *prc = VGDrvCommonIoCtlFast(iFunction, &g_DevExt, pSession);
464 return 0;
465}
466
467
468/**
469 * 32-bit IDC service routine.
470 *
471 * @returns VBox status code.
472 * @param u32Session The session handle (PVBOXGUESTSESSION).
473 * @param iFunction The requested function.
474 * @param pvData The input/output data buffer. The caller ensures that this
475 * cannot be swapped out, or that it's acceptable to take a
476 * page in fault in the current context. If the request doesn't
477 * take input or produces output, apssing NULL is okay.
478 * @param cbData The size of the data buffer.
479 * @param pcbDataReturned Where to store the amount of data that's returned.
480 * This can be NULL if pvData is NULL.
481 *
482 * @remark This is called from the 16-bit thunker as well as directly from the 32-bit clients.
483 */
484DECLASM(int) VBoxGuestOS2IDCService(uint32_t u32Session, unsigned iFunction, void *pvData, size_t cbData, size_t *pcbDataReturned)
485{
486 PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)u32Session;
487 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
488 AssertMsgReturn(pSession->sfn == 0xffff, ("%RX16\n", pSession->sfn), VERR_INVALID_HANDLE);
489 AssertMsgReturn(pSession->pDevExt == &g_DevExt, ("%p != %p\n", pSession->pDevExt, &g_DevExt), VERR_INVALID_HANDLE);
490
491 int rc;
492 switch (iFunction)
493 {
494 default:
495 rc = VGDrvCommonIoCtl(iFunction, &g_DevExt, pSession, pvData, cbData, pcbDataReturned);
496 break;
497
498 case VBOXGUEST_IOCTL_OS2_IDC_DISCONNECT:
499 pSession->sfn = 0;
500 VGDrvCommonCloseSession(&g_DevExt, pSession);
501 rc = VINF_SUCCESS;
502 break;
503 }
504 return rc;
505}
506
507
508/**
509 * Worker for VBoxGuestOS2IDC, it creates the kernel session.
510 *
511 * @returns Pointer to the session.
512 */
513DECLASM(PVBOXGUESTSESSION) VBoxGuestOS2IDCConnect(void)
514{
515 PVBOXGUESTSESSION pSession;
516 int rc = VGDrvCommonCreateKernelSession(&g_DevExt, &pSession);
517 if (RT_SUCCESS(rc))
518 {
519 pSession->sfn = 0xffff;
520 return pSession;
521 }
522 return NULL;
523}
524
525
526DECLASM(int) VBoxGuestOS2IOCtl(uint16_t sfn, uint8_t iCat, uint8_t iFunction, void *pvParm, void *pvData, uint16_t *pcbParm, uint16_t *pcbData)
527{
528 /*
529 * Find the session.
530 */
531 const RTPROCESS Process = RTProcSelf();
532 const unsigned iHash = SESSION_HASH(sfn);
533 PVBOXGUESTSESSION pSession;
534
535 RTSpinlockAcquire(g_Spinlock);
536 pSession = g_apSessionHashTab[iHash];
537 if (pSession && pSession->Process != Process)
538 {
539 do pSession = pSession->pNextHash;
540 while ( pSession
541 && ( pSession->sfn != sfn
542 || pSession->Process != Process));
543 }
544 RTSpinlockRelease(g_Spinlock);
545 if (!pSession)
546 {
547 Log(("VBoxGuestIoctl: WHAT?!? pSession == NULL! This must be a mistake... pid=%d\n", (int)Process));
548 return VERR_INVALID_PARAMETER;
549 }
550
551 /*
552 * Verify the category and dispatch the IOCtl.
553 *
554 * The IOCtl call uses the parameter buffer as generic data input/output
555 * buffer similar to the one unix ioctl buffer argument. While the data
556 * buffer is used for passing the VBox status code back to the caller
557 * since the status codes that OS/2 accepts thru the DosDevIOCtl API is
558 * severely restricted.
559 */
560 if (RT_LIKELY(iCat == VBOXGUEST_IOCTL_CATEGORY))
561 {
562 Log(("VBoxGuestOS2IOCtl: pSession=%p iFunction=%#x pvParm=%p pvData=%p *pcbParm=%d *pcbData=%d\n", pSession, iFunction, pvParm, pvData, *pcbParm, *pcbData));
563 Assert(pvParm || !*pcbData);
564 Assert(pvData);
565 Assert(*pcbData == sizeof(int32_t)); /* the return code */
566
567 /*
568 * Lock the buffers.
569 */
570 int32_t rc;
571 KernVMLock_t ParmLock;
572 if (pvParm)
573 {
574 Assert(*pcbData);
575 rc = KernVMLock(VMDHL_WRITE, pvParm, *pcbParm, &ParmLock, (KernPageList_t *)-1, NULL);
576 AssertMsgReturn(!rc, ("KernVMLock(VMDHL_WRITE, %p, %#x, &p, NULL, NULL) -> %d\n", pvParm, *pcbParm, &ParmLock, rc), VERR_LOCK_FAILED);
577 }
578
579#if 0 /* don't bother locking it since it's only 4 bytes (the return code). */
580 KernVMLock_t DataLock;
581 if (pvData)
582 {
583 Assert(*pcbData);
584 rc = KernVMLock(VMDHL_WRITE, pvData, *pcbData, &DataLock, (KernPageList_t *)-1, NULL);
585 if (rc)
586 {
587 AssertMsgFailed(("KernVMLock(VMDHL_WRITE, %p, %#x, &p, NULL, NULL) -> %d\n", pvData, *pcbData, &DataLock, rc));
588 KernVMUnlock(&ParmLock);
589 return VERR_LOCK_FAILED;
590 }
591 }
592#endif
593
594 /*
595 * Process the IOCtl.
596 */
597 size_t cbDataReturned;
598 rc = VGDrvCommonIoCtl(iFunction, &g_DevExt, pSession, pvParm, *pcbParm, &cbDataReturned);
599
600 /*
601 * Unlock the buffers.
602 */
603 if (pvParm)
604 {
605 int rc2 = KernVMUnlock(&ParmLock);
606 AssertMsg(!rc2, ("rc2=%d\n", rc2)); NOREF(rc2);
607 AssertMsg(cbDataReturned < _64K, ("cbDataReturned=%d\n", cbDataReturned));
608 *pcbParm = cbDataReturned;
609 }
610#if 0
611 if (pvData)
612 {
613 int rc2 = KernVMUnlock(&DataLock);
614 AssertMsg(!rc2, ("rc2=%d\n", rc2));
615 }
616#else
617 rc = KernCopyOut(pvData, &rc, sizeof(int32_t));
618 AssertMsgReturn(!rc, ("KernCopyOut(%p, %p, sizeof(int32_t)) -> %d\n", pvData, &rc, rc), VERR_LOCK_FAILED);
619#endif
620
621 Log2(("VBoxGuestOS2IOCtl: returns VINF_SUCCESS / %d\n", rc));
622 return VINF_SUCCESS;
623 }
624 return VERR_NOT_SUPPORTED;
625}
626
627
628/**
629 * 32-bit ISR, called by 16-bit assembly thunker in VBoxGuestA-os2.asm.
630 *
631 * @returns true if it's our interrupt, false it isn't.
632 */
633DECLASM(bool) VBoxGuestOS2ISR(void)
634{
635 Log(("VBoxGuestOS2ISR\n"));
636
637 return VGDrvCommonISR(&g_DevExt);
638}
639
640
641void VGDrvNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt)
642{
643 /* No polling on OS/2 */
644 NOREF(pDevExt);
645}
646
647
648#ifdef DEBUG_READ /** @todo figure out this one once and for all... */
649
650/**
651 * Callback for writing to the log buffer.
652 *
653 * @returns number of bytes written.
654 * @param pvArg Unused.
655 * @param pachChars Pointer to an array of utf-8 characters.
656 * @param cbChars Number of bytes in the character array pointed to by pachChars.
657 */
658static DECLCALLBACK(size_t) vboxGuestNativeLogOutput(void *pvArg, const char *pachChars, size_t cbChars)
659{
660 size_t cchWritten = 0;
661 while (cbChars-- > 0)
662 {
663 const uint16_t offLogHead = g_offLogHead;
664 const uint16_t offLogHeadNext = (offLogHead + 1) & (g_cchLogMax - 1);
665 if (offLogHeadNext == g_offLogTail)
666 break; /* no */
667 g_szLog[offLogHead] = *pachChars++;
668 g_offLogHead = offLogHeadNext;
669 cchWritten++;
670 }
671 return cchWritten;
672}
673
674
675int SUPR0Printf(const char *pszFormat, ...)
676{
677 va_list va;
678
679#if 0 //def DEBUG_bird
680 va_start(va, pszFormat);
681 RTLogComPrintfV(pszFormat, va);
682 va_end(va);
683#endif
684
685 va_start(va, pszFormat);
686 int cch = RTLogFormatV(vboxGuestNativeLogOutput, NULL, pszFormat, va);
687 va_end(va);
688
689 return cch;
690}
691
692#endif /* DEBUG_READ */
693
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