VirtualBox

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

Last change on this file since 56743 was 56293, checked in by vboxsync, 10 years ago

HostDrivers: Updated (C) year.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/* $Id: SUPLib-freebsd.cpp 56293 2015-06-09 14:23:56Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - FreeBSD specific parts.
4 */
5
6/*
7 * Copyright (C) 2006-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#define LOG_GROUP LOG_GROUP_SUP
31#ifdef IN_SUP_HARDENED_R3
32# undef DEBUG /* Warning: disables RT_STRICT */
33# define LOG_DISABLED
34# define RTLOG_REL_DISABLED
35# include <iprt/log.h>
36#endif
37
38#include <VBox/types.h>
39#include <VBox/sup.h>
40#include <VBox/param.h>
41#include <VBox/err.h>
42#include <VBox/log.h>
43#include <iprt/path.h>
44#include <iprt/assert.h>
45#include <iprt/mem.h>
46#include <iprt/err.h>
47#include <iprt/string.h>
48#include "../SUPLibInternal.h"
49#include "../SUPDrvIOC.h"
50
51#include <sys/fcntl.h>
52#include <sys/ioctl.h>
53#include <errno.h>
54#include <unistd.h>
55#include <stdlib.h>
56#include <stdio.h>
57
58/*******************************************************************************
59* Defined Constants And Macros *
60*******************************************************************************/
61/** System device name. */
62#define DEVICE_NAME_SYS "/dev/vboxdrv"
63/** User device name. */
64#define DEVICE_NAME_USR "/dev/vboxdrvu"
65
66
67
68int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited, bool fUnrestricted, SUPINITOP *penmWhat, PRTERRINFO pErrInfo)
69{
70 /*
71 * Nothing to do if pre-inited.
72 */
73 if (fPreInited)
74 return VINF_SUCCESS;
75
76 /*
77 * Try open the BSD device.
78 */
79 int hDevice = open(fUnrestricted ? DEVICE_NAME_SYS : DEVICE_NAME_USR, O_RDWR, 0);
80 if (hDevice < 0)
81 {
82 int rc;
83 switch (errno)
84 {
85 case ENODEV: rc = VERR_VM_DRIVER_LOAD_ERROR; break;
86 case EPERM:
87 case EACCES: rc = VERR_VM_DRIVER_NOT_ACCESSIBLE; break;
88 case ENOENT: rc = VERR_VM_DRIVER_NOT_INSTALLED; break;
89 default: rc = VERR_VM_DRIVER_OPEN_ERROR; break;
90 }
91 LogRel(("Failed to open \"%s\", errno=%d, rc=%Rrc\n", fUnrestricted ? DEVICE_NAME_SYS : DEVICE_NAME_USR, errno, rc));
92 return rc;
93 }
94
95 /*
96 * Mark the file handle close on exec.
97 */
98 if (fcntl(hDevice, F_SETFD, FD_CLOEXEC) != 0)
99 {
100#ifdef IN_SUP_HARDENED_R3
101 int rc = VERR_INTERNAL_ERROR;
102#else
103 int err = errno;
104 int rc = RTErrConvertFromErrno(err);
105 LogRel(("suplibOSInit: setting FD_CLOEXEC failed, errno=%d (%Rrc)\n", err, rc));
106#endif
107 close(hDevice);
108 return rc;
109 }
110
111 /*
112 * We're done.
113 */
114 pThis->hDevice = hDevice;
115 pThis->fUnrestricted = fUnrestricted;
116 return VINF_SUCCESS;
117}
118
119
120#ifndef IN_SUP_HARDENED_R3
121
122int suplibOsTerm(PSUPLIBDATA pThis)
123{
124 /*
125 * Check if we're inited at all.
126 */
127 if (pThis->hDevice != (intptr_t)NIL_RTFILE)
128 {
129 if (close(pThis->hDevice))
130 AssertFailed();
131 pThis->hDevice = (intptr_t)NIL_RTFILE;
132 }
133 return VINF_SUCCESS;
134}
135
136
137int suplibOsInstall(void)
138{
139 return VERR_NOT_IMPLEMENTED;
140}
141
142
143int suplibOsUninstall(void)
144{
145 return VERR_NOT_IMPLEMENTED;
146}
147
148
149int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq)
150{
151 if (RT_LIKELY(ioctl(pThis->hDevice, uFunction, pvReq) >= 0))
152 return VINF_SUCCESS;
153 return RTErrConvertFromErrno(errno);
154}
155
156
157int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction, uintptr_t idCpu)
158{
159 int rc = ioctl(pThis->hDevice, uFunction, idCpu);
160 if (rc == -1)
161 rc = errno;
162 return rc;
163}
164
165
166int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages)
167{
168 NOREF(pThis);
169 *ppvPages = RTMemPageAllocZ(cPages << PAGE_SHIFT);
170 if (*ppvPages)
171 return VINF_SUCCESS;
172 return RTErrConvertFromErrno(errno);
173}
174
175
176int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t cPages)
177{
178 NOREF(pThis);
179 RTMemPageFree(pvPages, cPages * PAGE_SIZE);
180 return VINF_SUCCESS;
181}
182
183#endif /* !IN_SUP_HARDENED_R3 */
184
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