1 | /* $Id: SUPLib-solaris.cpp 8155 2008-04-18 15:16:47Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Support Library - Solaris Specific Back-End.
|
---|
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 | /*******************************************************************************
|
---|
33 | * Header Files *
|
---|
34 | *******************************************************************************/
|
---|
35 | #define LOG_GROUP LOG_GROUP_SUP
|
---|
36 | #include <VBox/types.h>
|
---|
37 | #include <VBox/sup.h>
|
---|
38 | #include <VBox/param.h>
|
---|
39 | #include <VBox/err.h>
|
---|
40 | #include <VBox/log.h>
|
---|
41 | #include <iprt/path.h>
|
---|
42 | #include <iprt/assert.h>
|
---|
43 | #include <iprt/mem.h>
|
---|
44 | #include <iprt/err.h>
|
---|
45 | #include <iprt/string.h>
|
---|
46 | #include "SUPLibInternal.h"
|
---|
47 | #include "SUPDRVIOC.h"
|
---|
48 |
|
---|
49 | #include <sys/fcntl.h>
|
---|
50 | #include <sys/ioctl.h>
|
---|
51 |
|
---|
52 | #include <fcntl.h>
|
---|
53 | #include <errno.h>
|
---|
54 | #include <unistd.h>
|
---|
55 | #include <sys/mman.h>
|
---|
56 | #include <stdlib.h>
|
---|
57 | #include <stdio.h>
|
---|
58 |
|
---|
59 |
|
---|
60 | /*******************************************************************************
|
---|
61 | * Defined Constants And Macros *
|
---|
62 | *******************************************************************************/
|
---|
63 | /** Solaris device link. */
|
---|
64 | #define DEVICE_NAME "/dev/vboxdrv"
|
---|
65 |
|
---|
66 |
|
---|
67 | /*******************************************************************************
|
---|
68 | * Global Variables *
|
---|
69 | *******************************************************************************/
|
---|
70 | /** Handle to the open device. */
|
---|
71 | static int g_hDevice = -1;
|
---|
72 |
|
---|
73 |
|
---|
74 | int suplibOsInit(size_t cbReserve)
|
---|
75 | {
|
---|
76 | /*
|
---|
77 | * Check if already initialized.
|
---|
78 | */
|
---|
79 | if (g_hDevice >= 0)
|
---|
80 | return VINF_SUCCESS;
|
---|
81 |
|
---|
82 | /*
|
---|
83 | * Try to open the device.
|
---|
84 | */
|
---|
85 | g_hDevice = open(DEVICE_NAME, O_RDWR, 0);
|
---|
86 | if (g_hDevice < 0)
|
---|
87 | {
|
---|
88 | int rc;
|
---|
89 | switch (errno)
|
---|
90 | {
|
---|
91 | case ENODEV: rc = VERR_VM_DRIVER_LOAD_ERROR; break;
|
---|
92 | case EPERM:
|
---|
93 | case EACCES: rc = VERR_VM_DRIVER_NOT_ACCESSIBLE; break;
|
---|
94 | case ENOENT: rc = VERR_VM_DRIVER_NOT_INSTALLED; break;
|
---|
95 | default: rc = VERR_VM_DRIVER_OPEN_ERROR; break;
|
---|
96 | }
|
---|
97 | LogRel(("Failed to open \"%s\", errno=%d, rc=%Vrc\n", DEVICE_NAME, errno, rc));
|
---|
98 | return rc;
|
---|
99 | }
|
---|
100 |
|
---|
101 | /*
|
---|
102 | * Mark the file handle close on exec.
|
---|
103 | */
|
---|
104 | if (fcntl(g_hDevice, F_SETFD, FD_CLOEXEC) != 0)
|
---|
105 | {
|
---|
106 | int rc = errno;
|
---|
107 | LogRel(("suplibOSInit: setting FD_CLOEXEC failed, errno=%d\n", rc));
|
---|
108 | close(g_hDevice);
|
---|
109 | g_hDevice = -1;
|
---|
110 | return RTErrConvertFromErrno(rc);
|
---|
111 | }
|
---|
112 |
|
---|
113 | /*
|
---|
114 | * Avoid unused parameter warning
|
---|
115 | */
|
---|
116 | NOREF(cbReserve);
|
---|
117 |
|
---|
118 | return VINF_SUCCESS;
|
---|
119 | }
|
---|
120 |
|
---|
121 |
|
---|
122 | int suplibOsTerm(void)
|
---|
123 | {
|
---|
124 | /*
|
---|
125 | * Check if we're initialized
|
---|
126 | */
|
---|
127 | if (g_hDevice >= 0)
|
---|
128 | {
|
---|
129 | if (close(g_hDevice))
|
---|
130 | AssertFailed();
|
---|
131 | g_hDevice = -1;
|
---|
132 | }
|
---|
133 |
|
---|
134 | return VINF_SUCCESS;
|
---|
135 | }
|
---|
136 |
|
---|
137 |
|
---|
138 | int suplibOsInstall(void)
|
---|
139 | {
|
---|
140 | return VERR_NOT_IMPLEMENTED;
|
---|
141 | }
|
---|
142 |
|
---|
143 | int suplibOsUninstall(void)
|
---|
144 | {
|
---|
145 | return VERR_NOT_IMPLEMENTED;
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq)
|
---|
150 | {
|
---|
151 | AssertMsg(g_hDevice != -1, ("SUPLIB not initiated successfully!\n"));
|
---|
152 | if (RT_LIKELY(ioctl(g_hDevice, uFunction, pvReq) >= 0))
|
---|
153 | return VINF_SUCCESS;
|
---|
154 | return RTErrConvertFromErrno(errno);
|
---|
155 | }
|
---|
156 |
|
---|
157 |
|
---|
158 | int suplibOsIOCtlFast(uintptr_t uFunction)
|
---|
159 | {
|
---|
160 | int rc = ioctl(g_hDevice, uFunction, NULL);
|
---|
161 | if (rc == -1)
|
---|
162 | rc = errno;
|
---|
163 | return rc;
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | int suplibOsPageAlloc(size_t cPages, void **ppvPages)
|
---|
168 | {
|
---|
169 | *ppvPages = mmap(NULL, cPages * PAGE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE,
|
---|
170 | MAP_PRIVATE | MAP_ANON, -1, 0);
|
---|
171 | if (*ppvPages != (void *)-1)
|
---|
172 | return VINF_SUCCESS;
|
---|
173 | return RTErrConvertFromErrno(errno);
|
---|
174 | }
|
---|
175 |
|
---|
176 |
|
---|
177 | int suplibOsPageFree(void *pvPages, size_t cPages)
|
---|
178 | {
|
---|
179 | munmap(pvPages, cPages * PAGE_SIZE);
|
---|
180 | return VINF_SUCCESS;
|
---|
181 | }
|
---|
182 |
|
---|