VirtualBox

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

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

VBoxDrv-win.cpp: Keep the error info string from failed VBoxDrv and VBoxDrvStub open operations so userland can give us better messages to work on. Fixeds a couple of odd bugs.

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