VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/freebsd/SUPLib-freebsd.cpp@ 4821

Last change on this file since 4821 was 4811, checked in by vboxsync, 18 years ago

Split VMMR0Entry into VMMR0EntryInt, VMMR0EntryFast and VMMr0EntryEx. This will prevent the SUPCallVMMR0Ex path from causing harm and messing up the paths that has to be optimized.

File size: 3.4 KB
Line 
1/** @file
2 * SUPLib - FreeBSD Hosts,
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#define LOG_GROUP LOG_GROUP_SUP
22#include <VBox/types.h>
23#include <VBox/sup.h>
24#include <VBox/param.h>
25#include <VBox/err.h>
26#include <VBox/log.h>
27#include <iprt/path.h>
28#include <iprt/assert.h>
29#include <iprt/mem.h>
30#include <iprt/err.h>
31#include <iprt/string.h>
32#include "SUPLibInternal.h"
33#include "SUPDRVIOC.h"
34
35#include <sys/fcntl.h>
36#include <sys/ioctl.h>
37#include <errno.h>
38#include <unistd.h>
39#include <stdlib.h>
40
41
42/*******************************************************************************
43* Defined Constants And Macros *
44*******************************************************************************/
45/** BSD Device name. */
46#define DEVICE_NAME "/dev/vboxdrv"
47
48
49/*******************************************************************************
50* Global Variables *
51*******************************************************************************/
52/** Handle to the open device. */
53static int g_hDevice = -1;
54
55
56int suplibOsInit(size_t cbReserve)
57{
58 /*
59 * Check if already initialized.
60 */
61 if (g_hDevice >= 0)
62 return VINF_SUCCESS;
63
64 /*
65 * Try open the BSD device.
66 */
67 g_hDevice = open(DEVICE_NAME, O_RDWR, 0);
68 if (g_hDevice < 0)
69 {
70 int rc = errno;
71 LogRel(("Failed to open \"%s\", errno=%d\n", rc));
72 return RTErrConvertFromErrno(rc);
73 }
74
75 /*
76 * We're done.
77 */
78 NOREF(cbReserve);
79 return VINF_SUCCESS;
80}
81
82
83int suplibOsTerm(void)
84{
85 /*
86 * Check if we're initited at all.
87 */
88 if (g_hDevice >= 0)
89 {
90 if (close(g_hDevice))
91 AssertFailed();
92 g_hDevice = -1;
93 }
94 return VINF_SUCCESS;
95}
96
97
98int suplibOsInstall(void)
99{
100 return VERR_NOT_IMPLEMENTED;
101}
102
103
104int suplibOsUninstall(void)
105{
106 return VERR_NOT_IMPLEMENTED;
107}
108
109
110int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq)
111{
112 AssertMsg(g_hDevice != -1, ("SUPLIB not initiated successfully!\n"));
113
114 if (RT_LIKELY(ioctl((g_hDevice, uFunction, pvReq) >= 0))
115 return VINF_SUCCESS;
116 return RTErrConvertFromErrno(errno);
117}
118
119
120int suplibOSIOCtlFast(uintptr_t uFunction)
121{
122 int rc = ioctl(g_hDevice, uFunction, NULL);
123 if (rc == -1)
124 rc = errno;
125 return rc;
126}
127
128
129int suplibOsPageAlloc(size_t cPages, void **ppvPages)
130{
131 *ppvPages = RTMemPageAllocZ(cPages << PAGE_SHIFT);
132 if (*ppvPages)
133 return VINF_SUCCESS;
134 return RTErrConvertFromErrno(errno);
135}
136
137
138int suplibOsPageFree(void *pvPages, size_t /* cPages */)
139{
140 RTMemPageFree(pvPages);
141 return VINF_SUCCESS;
142}
143
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