VirtualBox

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

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

Added a LogRel with additional driver open info. Return the VERR_VM_DRIVER_* stuff on Solaris, Darwin, FreeBSD and OS/2 as well.

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