VirtualBox

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

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

Changed the Linux Additions to compile everything from source (no more binaries linked in) and cleaned up those files to compile as plain C.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 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__
40# ifdef __cplusplus
41extern "C" {
42# endif
43extern DECLVBGL(void *) vboxadd_cmc_open (void);
44extern DECLVBGL(void) vboxadd_cmc_close (void *);
45extern DECLVBGL(int) vboxadd_cmc_call (void *opaque, uint32_t func, void *data);
46# ifdef __cplusplus
47}
48# endif
49#endif
50
51int vbglDriverOpen (VBGLDRIVER *pDriver)
52{
53#ifdef __WIN__
54 UNICODE_STRING uszDeviceName;
55 RtlInitUnicodeString (&uszDeviceName, L"\\Device\\VBoxGuest");
56
57 PDEVICE_OBJECT pDeviceObject = NULL;
58 PFILE_OBJECT pFileObject = NULL;
59
60 NTSTATUS rc = IoGetDeviceObjectPointer (&uszDeviceName, FILE_ALL_ACCESS,
61 &pFileObject, &pDeviceObject);
62
63 if (NT_SUCCESS (rc))
64 {
65 Log(("vbglDriverOpen VBoxGuest successful pDeviceObject=%x\n", pDeviceObject));
66 pDriver->pDeviceObject = pDeviceObject;
67 pDriver->pFileObject = pFileObject;
68 return VINF_SUCCESS;
69 }
70 /** @todo return RTErrConvertFromNtStatus(rc)! */
71 Log(("vbglDriverOpen VBoxGuest failed with ntstatus=%x\n", rc));
72 return rc;
73#else
74 void *opaque;
75
76 opaque = (void *) vboxadd_cmc_open ();
77 if (!opaque)
78 {
79 return VERR_NOT_IMPLEMENTED;
80 }
81 pDriver->opaque = opaque;
82 return VINF_SUCCESS;
83#endif
84}
85
86int vbglDriverIOCtl (VBGLDRIVER *pDriver, uint32_t u32Function, void *pvData, uint32_t cbData)
87{
88#ifdef __WIN__
89 IO_STATUS_BLOCK ioStatusBlock;
90
91 KEVENT event;
92 KeInitializeEvent (&event, NotificationEvent, FALSE);
93
94 PIRP irp = IoBuildDeviceIoControlRequest (u32Function,
95 pDriver->pDeviceObject,
96 pvData,
97 cbData,
98 pvData,
99 cbData,
100 FALSE,
101 &event,
102 &ioStatusBlock);
103 if (irp == NULL)
104 {
105 Log(("vbglDriverIOCtl: IoBuildDeviceIoControlRequest failed\n"));
106 return VERR_NO_MEMORY;
107 }
108
109 NTSTATUS rc = IoCallDriver (pDriver->pDeviceObject, irp);
110
111 if (!NT_SUCCESS(rc))
112 Log(("vbglDriverIOCtl: IoCallDriver failed with ntstatus=%x\n", rc));
113
114 return NT_SUCCESS(rc)? VINF_SUCCESS: VERR_VBGL_IOCTL_FAILED;
115#else
116 return vboxadd_cmc_call (pDriver->opaque, u32Function, pvData);
117#endif
118}
119
120void vbglDriverClose (VBGLDRIVER *pDriver)
121{
122#ifdef __WIN__
123 Log(("vbglDriverClose pDeviceObject=%x\n", pDriver->pDeviceObject));
124 ObDereferenceObject (pDriver->pFileObject);
125#else
126 vboxadd_cmc_close (pDriver->opaque);
127#endif
128}
129
130#endif /* !VBGL_VBOXGUEST */
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