VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/SysHlp.cpp@ 486

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

More logging

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/** @file
2 *
3 * VBoxGuestLib - A support library for VirtualBox guest additions:
4 * Physical memory heap
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung 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 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23#include <VBox/VBoxGuestLib.h>
24#include "SysHlp.h"
25
26#define LOG_GROUP LOG_GROUP_HGCM
27#include <VBox/log.h>
28#include <iprt/assert.h>
29
30#ifndef VBGL_VBOXGUEST
31
32#if defined (__LINUX__) && !defined (__KERNEL__)
33# include <unistd.h>
34# include <errno.h>
35# include <sys/fcntl.h>
36# include <sys/ioctl.h>
37#endif
38
39#ifndef __WIN__
40extern "C" DECLVBGL(void *) vboxadd_cmc_open (void);
41extern "C" DECLVBGL(void) vboxadd_cmc_close (void *);
42extern "C" DECLVBGL(int) vboxadd_cmc_call (void *opaque, uint32_t func, void *data);
43#endif
44
45int vbglDriverOpen (VBGLDRIVER *pDriver)
46{
47#ifdef __WIN__
48 UNICODE_STRING uszDeviceName;
49 RtlInitUnicodeString (&uszDeviceName, L"\\Device\\VBoxGuest");
50
51 PDEVICE_OBJECT pDeviceObject = NULL;
52 PFILE_OBJECT pFileObject = NULL;
53
54 NTSTATUS rc = IoGetDeviceObjectPointer (&uszDeviceName, FILE_ALL_ACCESS,
55 &pFileObject, &pDeviceObject);
56
57 if (NT_SUCCESS (rc))
58 {
59 Log(("vbglDriverOpen VBoxGuest successful pDeviceObject=%x\n", pDeviceObject));
60 pDriver->pDeviceObject = pDeviceObject;
61 pDriver->pFileObject = pFileObject;
62 return VINF_SUCCESS;
63 }
64 /** @todo return RTErrConvertFromNtStatus(rc)! */
65 Log(("vbglDriverOpen VBoxGuest failed with ntstatus=%x\n", rc));
66 return rc;
67#else
68 void *opaque;
69
70 opaque = vboxadd_cmc_open ();
71 if (!opaque)
72 {
73 return VERR_NOT_IMPLEMENTED;
74 }
75 pDriver->opaque = opaque;
76 return VINF_SUCCESS;
77#endif
78}
79
80int vbglDriverIOCtl (VBGLDRIVER *pDriver, uint32_t u32Function, void *pvData, uint32_t cbData)
81{
82#ifdef __WIN__
83 IO_STATUS_BLOCK ioStatusBlock;
84
85 KEVENT event;
86 KeInitializeEvent (&event, NotificationEvent, FALSE);
87
88 PIRP irp = IoBuildDeviceIoControlRequest (u32Function,
89 pDriver->pDeviceObject,
90 pvData,
91 cbData,
92 pvData,
93 cbData,
94 FALSE,
95 &event,
96 &ioStatusBlock);
97 if (irp == NULL)
98 {
99 Log(("vbglDriverIOCtl: IoBuildDeviceIoControlRequest failed\n"));
100 return VERR_NO_MEMORY;
101 }
102
103 NTSTATUS rc = IoCallDriver (pDriver->pDeviceObject, irp);
104
105 if (!NT_SUCCESS(rc))
106 Log(("vbglDriverIOCtl: IoCallDriver failed with ntstatus=%x\n", rc));
107
108 return NT_SUCCESS(rc)? VINF_SUCCESS: VERR_VBGL_IOCTL_FAILED;
109#else
110 return vboxadd_cmc_call (pDriver->opaque, u32Function, pvData);
111#endif
112}
113
114void vbglDriverClose (VBGLDRIVER *pDriver)
115{
116#ifdef __WIN__
117 Log(("vbglDriverClose pDeviceObject=%x\n", pDriver->pDeviceObject));
118 ObDereferenceObject (pDriver->pFileObject);
119#else
120 vboxadd_cmc_close (pDriver->opaque);
121#endif
122}
123
124#endif /* !VBGL_VBOXGUEST */
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