VirtualBox

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

Last change on this file since 49839 was 49636, checked in by vboxsync, 11 years ago

HostDrivers/Support: Solaris zone todo.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 6.2 KB
Line 
1/* $Id: SUPLib-solaris.cpp 49636 2013-11-24 12:51: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
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/** @todo r=ramshankar: This breaks accessing the driver from non-global zones. We should check
68 using getzoneid() != GLOBAL_ZONE and use /dev/vboxdrv[u] instead when we're in a zone. */
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
74
75
76int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited, bool fUnrestricted)
77{
78 /*
79 * Nothing to do if pre-inited.
80 */
81 if (fPreInited)
82 return VINF_SUCCESS;
83
84 /*
85 * Open dummy files to preallocate file descriptors, see @bugref{4650}.
86 */
87 for (int i = 0; i < SUPLIB_FLT_DUMMYFILES; i++)
88 {
89 pThis->ahDummy[i] = -1;
90 int hDummy = open("/dev/null", O_RDWR, 0);
91 if (hDummy >= 0)
92 {
93 if (fcntl(hDummy, F_SETFD, FD_CLOEXEC) == 0)
94 pThis->ahDummy[i] = hDummy;
95 else
96 {
97 close(hDummy);
98 LogRel(("Failed to set close on exec [%d] /dev/null! errno=%d\n", i, errno));
99 }
100 }
101 else
102 LogRel(("Failed to open[%d] /dev/null! errno=%d\n", i, errno));
103 }
104
105 /*
106 * Try to open the device.
107 */
108 const char *pszDeviceNm = fUnrestricted ? DEVICE_NAME_SYS : DEVICE_NAME_USR;
109 int hDevice = open(pszDeviceNm, O_RDWR, 0);
110 if (hDevice < 0)
111 {
112 int rc;
113 switch (errno)
114 {
115 case ENODEV: rc = VERR_VM_DRIVER_LOAD_ERROR; break;
116 case EPERM:
117 case EACCES: rc = VERR_VM_DRIVER_NOT_ACCESSIBLE; break;
118 case ENOENT: rc = VERR_VM_DRIVER_NOT_INSTALLED; break;
119 default: rc = VERR_VM_DRIVER_OPEN_ERROR; break;
120 }
121 LogRel(("Failed to open \"%s\", errno=%d, rc=%Rrc\n", pszDeviceNm, errno, rc));
122 return rc;
123 }
124
125 /*
126 * Mark the file handle close on exec.
127 */
128 if (fcntl(hDevice, F_SETFD, FD_CLOEXEC) != 0)
129 {
130#ifdef IN_SUP_HARDENED_R3
131 int rc = VERR_INTERNAL_ERROR;
132#else
133 int err = errno;
134 int rc = RTErrConvertFromErrno(err);
135 LogRel(("suplibOSInit: setting FD_CLOEXEC failed, errno=%d (%Rrc)\n", err, rc));
136#endif
137 close(hDevice);
138 return rc;
139 }
140
141 pThis->hDevice = hDevice;
142 pThis->fUnrestricted = fUnrestricted;
143 return VINF_SUCCESS;
144}
145
146
147#ifndef IN_SUP_HARDENED_R3
148
149int suplibOsTerm(PSUPLIBDATA pThis)
150{
151 /*
152 * Close the dummy files first.
153 */
154 for (int i = 0; i < SUPLIB_FLT_DUMMYFILES; i++)
155 {
156 if (pThis->ahDummy[i] != -1)
157 {
158 close(pThis->ahDummy[i]);
159 pThis->ahDummy[i] = -1;
160 }
161 }
162
163 /*
164 * Check if we're initialized
165 */
166 if (pThis->hDevice != (intptr_t)NIL_RTFILE)
167 {
168 if (close(pThis->hDevice))
169 AssertFailed();
170 pThis->hDevice = (intptr_t)NIL_RTFILE;
171 }
172
173 return VINF_SUCCESS;
174}
175
176
177int suplibOsInstall(void)
178{
179 return VERR_NOT_IMPLEMENTED;
180}
181
182int suplibOsUninstall(void)
183{
184 return VERR_NOT_IMPLEMENTED;
185}
186
187
188int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq)
189{
190 if (RT_LIKELY(ioctl(pThis->hDevice, uFunction, pvReq) >= 0))
191 return VINF_SUCCESS;
192 return RTErrConvertFromErrno(errno);
193}
194
195
196int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction, uintptr_t idCpu)
197{
198 int rc = ioctl(pThis->hDevice, uFunction, idCpu);
199 if (rc == -1)
200 rc = errno;
201 return rc;
202}
203
204
205int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages)
206{
207 NOREF(pThis);
208 *ppvPages = mmap(NULL, cPages * PAGE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE,
209 MAP_PRIVATE | MAP_ANON, -1, 0);
210 if (*ppvPages != (void *)-1)
211 return VINF_SUCCESS;
212 if (errno == EAGAIN)
213 return VERR_NO_MEMORY;
214 return RTErrConvertFromErrno(errno);
215}
216
217
218int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t cPages)
219{
220 NOREF(pThis);
221 munmap(pvPages, cPages * PAGE_SIZE);
222 return VINF_SUCCESS;
223}
224
225#endif /* !IN_SUP_HARDENED_R3 */
226
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