VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/solaris/SUPLib-solaris.cpp@ 44173

Last change on this file since 44173 was 44173, checked in by vboxsync, 12 years ago

SUPDrv,SUPLib: Introducing /dev/vboxdrvu on darwin (other platforms soon to follow).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.0 KB
Line 
1/* $Id: SUPLib-solaris.cpp 44173 2012-12-19 18:12:31Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - Solaris specific parts.
4 */
5
6/*
7 * Copyright (C) 2006-2007 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 /** @todo RTLOGREL_DISABLED */
35# include <iprt/log.h>
36# undef LogRelIt
37# define LogRelIt(pvInst, fFlags, iGroup, fmtargs) do { } while (0)
38#endif
39
40#include <VBox/types.h>
41#include <VBox/sup.h>
42#include <VBox/param.h>
43#include <VBox/err.h>
44#include <VBox/log.h>
45#include <iprt/path.h>
46#include <iprt/assert.h>
47#include <iprt/mem.h>
48#include <iprt/err.h>
49#include <iprt/string.h>
50#include "../SUPLibInternal.h"
51#include "../SUPDrvIOC.h"
52
53#include <sys/fcntl.h>
54#include <sys/ioctl.h>
55
56#include <fcntl.h>
57#include <errno.h>
58#include <unistd.h>
59#include <sys/mman.h>
60#include <stdlib.h>
61#include <stdio.h>
62
63
64/*******************************************************************************
65* Defined Constants And Macros *
66*******************************************************************************/
67/** Solaris device link - system. */
68#define DEVICE_NAME_SYS "/dev/vboxdrv"
69/** Solaris device link - user. */
70#define DEVICE_NAME_USR "/dev/vboxdrvu"
71
72
73
74int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited, bool fUnrestricted)
75{
76 /*
77 * Nothing to do if pre-inited.
78 */
79 if (fPreInited)
80 return VINF_SUCCESS;
81
82 /*
83 * Open dummy files to preallocate file descriptors, see @bugref{4650}.
84 */
85 for (int i = 0; i < SUPLIB_FLT_DUMMYFILES; i++)
86 {
87 pThis->ahDummy[i] = -1;
88 int hDummy = open("/dev/null", O_RDWR, 0);
89 if (hDummy >= 0)
90 {
91 if (fcntl(hDummy, F_SETFD, FD_CLOEXEC) == 0)
92 pThis->ahDummy[i] = hDummy;
93 else
94 {
95 close(hDummy);
96 LogRel(("Failed to set close on exec [%d] /dev/null! errno=%d\n", i, errno));
97 }
98 }
99 else
100 LogRel(("Failed to open[%d] /dev/null! errno=%d\n", i, errno));
101 }
102
103 /*
104 * Try to open the device.
105 */
106 int hDevice = open(fUnrestricted ? DEVICE_NAME_SYS : DEVICE_NAME_USR, O_RDWR, 0);
107 if (hDevice < 0)
108 {
109 int rc;
110 switch (errno)
111 {
112 case ENODEV: rc = VERR_VM_DRIVER_LOAD_ERROR; break;
113 case EPERM:
114 case EACCES: rc = VERR_VM_DRIVER_NOT_ACCESSIBLE; break;
115 case ENOENT: rc = VERR_VM_DRIVER_NOT_INSTALLED; break;
116 default: rc = VERR_VM_DRIVER_OPEN_ERROR; break;
117 }
118 LogRel(("Failed to open \"%s\", errno=%d, rc=%Rrc\n", DEVICE_NAME, errno, rc));
119 return rc;
120 }
121
122 /*
123 * Mark the file handle close on exec.
124 */
125 if (fcntl(hDevice, F_SETFD, FD_CLOEXEC) != 0)
126 {
127#ifdef IN_SUP_HARDENED_R3
128 int rc = VERR_INTERNAL_ERROR;
129#else
130 int err = errno;
131 int rc = RTErrConvertFromErrno(err);
132 LogRel(("suplibOSInit: setting FD_CLOEXEC failed, errno=%d (%Rrc)\n", err, rc));
133#endif
134 close(hDevice);
135 return rc;
136 }
137
138 pThis->hDevice = hDevice;
139 pThis->fUnrestricted = fUnrestricted;
140 return VINF_SUCCESS;
141}
142
143
144#ifndef IN_SUP_HARDENED_R3
145
146int suplibOsTerm(PSUPLIBDATA pThis)
147{
148 /*
149 * Close the dummy files first.
150 */
151 for (int i = 0; i < SUPLIB_FLT_DUMMYFILES; i++)
152 {
153 if (pThis->ahDummy[i] != -1)
154 {
155 close(pThis->ahDummy[i]);
156 pThis->ahDummy[i] = -1;
157 }
158 }
159
160 /*
161 * Check if we're initialized
162 */
163 if (pThis->hDevice != (intptr_t)NIL_RTFILE)
164 {
165 if (close(pThis->hDevice))
166 AssertFailed();
167 pThis->hDevice = (intptr_t)NIL_RTFILE;
168 }
169
170 return VINF_SUCCESS;
171}
172
173
174int suplibOsInstall(void)
175{
176 return VERR_NOT_IMPLEMENTED;
177}
178
179int suplibOsUninstall(void)
180{
181 return VERR_NOT_IMPLEMENTED;
182}
183
184
185int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq)
186{
187 if (RT_LIKELY(ioctl(pThis->hDevice, uFunction, pvReq) >= 0))
188 return VINF_SUCCESS;
189 return RTErrConvertFromErrno(errno);
190}
191
192
193int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction, uintptr_t idCpu)
194{
195 int rc = ioctl(pThis->hDevice, uFunction, idCpu);
196 if (rc == -1)
197 rc = errno;
198 return rc;
199}
200
201
202int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages)
203{
204 NOREF(pThis);
205 *ppvPages = mmap(NULL, cPages * PAGE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE,
206 MAP_PRIVATE | MAP_ANON, -1, 0);
207 if (*ppvPages != (void *)-1)
208 return VINF_SUCCESS;
209 if (errno == EAGAIN)
210 return VERR_NO_MEMORY;
211 return RTErrConvertFromErrno(errno);
212}
213
214
215int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t cPages)
216{
217 NOREF(pThis);
218 munmap(pvPages, cPages * PAGE_SIZE);
219 return VINF_SUCCESS;
220}
221
222#endif /* !IN_SUP_HARDENED_R3 */
223
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