VirtualBox

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

Last change on this file since 26362 was 26362, checked in by vboxsync, 15 years ago

Solaris/SUPLib: fix for #4650 (fix fd table from growing on vboxflt close)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.8 KB
Line 
1/* $Id: SUPLib-solaris.cpp 26362 2010-02-09 13:20:03Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - Solaris specific parts.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#define LOG_GROUP LOG_GROUP_SUP
35#ifdef IN_SUP_HARDENED_R3
36# undef DEBUG /* Warning: disables RT_STRICT */
37# define LOG_DISABLED
38 /** @todo RTLOGREL_DISABLED */
39# include <iprt/log.h>
40# undef LogRelIt
41# define LogRelIt(pvInst, fFlags, iGroup, fmtargs) do { } while (0)
42#endif
43
44#include <VBox/types.h>
45#include <VBox/sup.h>
46#include <VBox/param.h>
47#include <VBox/err.h>
48#include <VBox/log.h>
49#include <iprt/path.h>
50#include <iprt/assert.h>
51#include <iprt/mem.h>
52#include <iprt/err.h>
53#include <iprt/string.h>
54#include "../SUPLibInternal.h"
55#include "../SUPDrvIOC.h"
56
57#include <sys/fcntl.h>
58#include <sys/ioctl.h>
59
60#include <fcntl.h>
61#include <errno.h>
62#include <unistd.h>
63#include <sys/mman.h>
64#include <stdlib.h>
65#include <stdio.h>
66
67
68/*******************************************************************************
69* Defined Constants And Macros *
70*******************************************************************************/
71/** Solaris device link. */
72#define DEVICE_NAME "/dev/vboxdrv"
73
74
75
76int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited)
77{
78 /*
79 * Nothing to do if pre-inited.
80 */
81 if (fPreInited)
82 return VINF_SUCCESS;
83
84#ifdef VBOXFLT_DUMMYFILES
85 /*
86 * Open dummy files to preallocate file descriptors, see #4650.
87 */
88 for (int i = 0; i < VBOXFLT_DUMMYFILES; i++)
89 {
90 int hDummy = open("/dev/null", O_RDWR, 0);
91 fcntl(hDummy, F_SETFD, FD_CLOEXEC);
92 if (hDummy >= 0)
93 pThis->hDummy[i] = hDummy;
94 else
95 {
96 pThis->hDummy[i] = -1;
97 LogRel(("Failed to open[%d] /dev/null! errno=%d\n", i, errno));
98 }
99 }
100#endif
101
102 /*
103 * Try to open the device.
104 */
105 int hDevice = open(DEVICE_NAME, O_RDWR, 0);
106 if (hDevice < 0)
107 {
108 int rc;
109 switch (errno)
110 {
111 case ENODEV: rc = VERR_VM_DRIVER_LOAD_ERROR; break;
112 case EPERM:
113 case EACCES: rc = VERR_VM_DRIVER_NOT_ACCESSIBLE; break;
114 case ENOENT: rc = VERR_VM_DRIVER_NOT_INSTALLED; break;
115 default: rc = VERR_VM_DRIVER_OPEN_ERROR; break;
116 }
117 LogRel(("Failed to open \"%s\", errno=%d, rc=%Rrc\n", DEVICE_NAME, errno, rc));
118 return rc;
119 }
120
121 /*
122 * Mark the file handle close on exec.
123 */
124 if (fcntl(hDevice, F_SETFD, FD_CLOEXEC) != 0)
125 {
126#ifdef IN_SUP_HARDENED_R3
127 int rc = VERR_INTERNAL_ERROR;
128#else
129 int err = errno;
130 int rc = RTErrConvertFromErrno(err);
131 LogRel(("suplibOSInit: setting FD_CLOEXEC failed, errno=%d (%Rrc)\n", err, rc));
132#endif
133 close(hDevice);
134 return rc;
135 }
136
137 pThis->hDevice = hDevice;
138 return VINF_SUCCESS;
139}
140
141
142#ifndef IN_SUP_HARDENED_R3
143
144int suplibOsTerm(PSUPLIBDATA pThis)
145{
146#ifdef VBOXFLT_DUMMYFILES
147 /*
148 * Close the dummy files first.
149 */
150 for (int i = 0; i < VBOXFLT_DUMMYFILES; i++)
151 {
152 if (pThis->hDummy[i] != -1)
153 {
154 close(pThis->hDummy[i]);
155 pThis->hDummy[i] = -1;
156 }
157 }
158#endif
159
160 /*
161 * Check if we're initialized
162 */
163 if (pThis->hDevice != NIL_RTFILE)
164 {
165 if (close(pThis->hDevice))
166 AssertFailed();
167 pThis->hDevice = 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.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette