VirtualBox

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

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

build fix

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