VirtualBox

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

Last change on this file since 19889 was 13865, checked in by vboxsync, 16 years ago

SUP: pass idCpu up on all platforms (save OS/2), handle it in ring-0 on solaris, linux and freebsd.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.0 KB
Line 
1/* $Id: SUPLib-solaris.cpp 13865 2008-11-05 14:14:11Z 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.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 * 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
85 /*
86 * Try to open the device.
87 */
88 int hDevice = open(DEVICE_NAME, O_RDWR, 0);
89 if (hDevice < 0)
90 {
91 int rc;
92 switch (errno)
93 {
94 case ENODEV: rc = VERR_VM_DRIVER_LOAD_ERROR; break;
95 case EPERM:
96 case EACCES: rc = VERR_VM_DRIVER_NOT_ACCESSIBLE; break;
97 case ENOENT: rc = VERR_VM_DRIVER_NOT_INSTALLED; break;
98 default: rc = VERR_VM_DRIVER_OPEN_ERROR; break;
99 }
100 LogRel(("Failed to open \"%s\", errno=%d, rc=%Rrc\n", DEVICE_NAME, errno, rc));
101 return rc;
102 }
103
104 /*
105 * Mark the file handle close on exec.
106 */
107 if (fcntl(hDevice, F_SETFD, FD_CLOEXEC) != 0)
108 {
109#ifdef IN_SUP_HARDENED_R3
110 int rc = VERR_INTERNAL_ERROR;
111#else
112 int err = errno;
113 int rc = RTErrConvertFromErrno(err);
114 LogRel(("suplibOSInit: setting FD_CLOEXEC failed, errno=%d (%Rrc)\n", err, rc));
115#endif
116 close(hDevice);
117 return rc;
118 }
119
120 pThis->hDevice = hDevice;
121 return VINF_SUCCESS;
122}
123
124
125#ifndef IN_SUP_HARDENED_R3
126
127int suplibOsTerm(PSUPLIBDATA pThis)
128{
129 /*
130 * Check if we're initialized
131 */
132 if (pThis->hDevice != NIL_RTFILE)
133 {
134 if (close(pThis->hDevice))
135 AssertFailed();
136 pThis->hDevice = NIL_RTFILE;
137 }
138
139 return VINF_SUCCESS;
140}
141
142
143int suplibOsInstall(void)
144{
145 return VERR_NOT_IMPLEMENTED;
146}
147
148int suplibOsUninstall(void)
149{
150 return VERR_NOT_IMPLEMENTED;
151}
152
153
154int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq)
155{
156 if (RT_LIKELY(ioctl(pThis->hDevice, uFunction, pvReq) >= 0))
157 return VINF_SUCCESS;
158 return RTErrConvertFromErrno(errno);
159}
160
161
162int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction, uintptr_t idCpu)
163{
164 int rc = ioctl(pThis->hDevice, uFunction, idCpu);
165 if (rc == -1)
166 rc = errno;
167 return rc;
168}
169
170
171int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages)
172{
173 NOREF(pThis);
174 *ppvPages = mmap(NULL, cPages * PAGE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE,
175 MAP_PRIVATE | MAP_ANON, -1, 0);
176 if (*ppvPages != (void *)-1)
177 return VINF_SUCCESS;
178 return RTErrConvertFromErrno(errno);
179}
180
181
182int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t cPages)
183{
184 NOREF(pThis);
185 munmap(pvPages, cPages * PAGE_SIZE);
186 return VINF_SUCCESS;
187}
188
189#endif /* !IN_SUP_HARDENED_R3 */
190
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