VirtualBox

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

Last change on this file since 58697 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

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