VirtualBox

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

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

oops.

File size: 3.7 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.215389.xyz. 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 * Mark the file handle close on exec.
77 */
78 if (fcntl(g_hDevice, F_SETFD, FD_CLOEXEC) != 0)
79 {
80 int rc = errno;
81 LogRel(("suplibOSInit: setting FD_CLOEXEC failed, errno=%d\n", rc));
82 close(g_hDevice);
83 g_hDevice = -1;
84 return RTErrConvertFromErrno(rc);
85 }
86
87 /*
88 * We're done.
89 */
90 NOREF(cbReserve);
91 return VINF_SUCCESS;
92}
93
94
95int suplibOsTerm(void)
96{
97 /*
98 * Check if we're initited at all.
99 */
100 if (g_hDevice >= 0)
101 {
102 if (close(g_hDevice))
103 AssertFailed();
104 g_hDevice = -1;
105 }
106 return VINF_SUCCESS;
107}
108
109
110int suplibOsInstall(void)
111{
112 return VERR_NOT_IMPLEMENTED;
113}
114
115
116int suplibOsUninstall(void)
117{
118 return VERR_NOT_IMPLEMENTED;
119}
120
121
122int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq)
123{
124 AssertMsg(g_hDevice != -1, ("SUPLIB not initiated successfully!\n"));
125
126 if (RT_LIKELY(ioctl(g_hDevice, uFunction, pvReq) >= 0))
127 return VINF_SUCCESS;
128 return RTErrConvertFromErrno(errno);
129}
130
131
132int suplibOsIOCtlFast(uintptr_t uFunction)
133{
134 int rc = ioctl(g_hDevice, uFunction, NULL);
135 if (rc == -1)
136 rc = errno;
137 return rc;
138}
139
140
141int suplibOsPageAlloc(size_t cPages, void **ppvPages)
142{
143 *ppvPages = RTMemPageAllocZ(cPages << PAGE_SHIFT);
144 if (*ppvPages)
145 return VINF_SUCCESS;
146 return RTErrConvertFromErrno(errno);
147}
148
149
150int suplibOsPageFree(void *pvPages, size_t /* cPages */)
151{
152 RTMemPageFree(pvPages);
153 return VINF_SUCCESS;
154}
155
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