VirtualBox

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

Last change on this file since 4873 was 4873, checked in by vboxsync, 18 years ago

rc not errno.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1/* $Id: SUPLib-solaris.cpp 4873 2007-09-17 20:24:48Z vboxsync $ */
2/** @file
3 *
4 * VBox host drivers - Ring-0 support drivers - Solaris host:
5 * Solaris implementations for support library
6 */
7
8/*
9 * Copyright (C) 2006-2007 innotek GmbH
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.215389.xyz. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License as published by the Free Software Foundation,
15 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
16 * distribution. VirtualBox OSE is distributed in the hope that it will
17 * be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20
21/*******************************************************************************
22* Header Files *
23*******************************************************************************/
24#define LOG_GROUP LOG_GROUP_SUP
25#include <VBox/types.h>
26#include <VBox/sup.h>
27#include <VBox/param.h>
28#include <VBox/err.h>
29#include <VBox/log.h>
30#include <iprt/path.h>
31#include <iprt/assert.h>
32#include <iprt/mem.h>
33#include <iprt/err.h>
34#include <iprt/string.h>
35#include "SUPLibInternal.h"
36#include "SUPDRVIOC.h"
37
38#include <sys/fcntl.h>
39#include <sys/ioctl.h>
40
41#include <fcntl.h>
42#include <errno.h>
43#include <unistd.h>
44#include <stdlib.h>
45#include <stdio.h>
46
47
48/*******************************************************************************
49* Defined Constants And Macros *
50*******************************************************************************/
51#define DEVICE_NAME "/devices/pseudo/vboxdrv@0:0"
52
53
54/*******************************************************************************
55* Global Variables *
56*******************************************************************************/
57/** Handle to the open device. */
58static int g_hDevice = -1;
59
60
61int suplibOsInit(size_t cbReserve)
62{
63 /*
64 * Check if already initialized.
65 */
66 if (g_hDevice >= 0)
67 return VINF_SUCCESS;
68
69 /*
70 * Try to open the device.
71 */
72 g_hDevice = open(DEVICE_NAME, O_RDWR, 0);
73 if (g_hDevice < 0)
74 {
75 int rc = errno;
76 LogRel(("Failed to open \"%s\", errno=%d\n", rc));
77 return RTErrConvertFromErrno(rc);
78 }
79
80 /*
81 * Mark the file handle close on exec.
82 */
83 if (fcntl(g_hDevice, F_SETFD, FD_CLOEXEC) != 0)
84 {
85 int rc = errno;
86 LogRel(("suplibOSInit: setting FD_CLOEXEC failed, errno=%d\n", rc));
87 close(g_hDevice);
88 g_hDevice = -1;
89 return RTErrConvertFromErrno(rc);
90 }
91
92 /*
93 * Avoid unused parameter warning
94 */
95 NOREF(cbReserve);
96
97 return VINF_SUCCESS;
98}
99
100
101int suplibOsTerm(void)
102{
103 /*
104 * Check if we're initialized
105 */
106 if (g_hDevice >= 0)
107 {
108 if (close(g_hDevice))
109 AssertFailed();
110 g_hDevice = -1;
111 }
112
113 return VINF_SUCCESS;
114}
115
116
117int suplibOsInstall(void)
118{
119 return VERR_NOT_IMPLEMENTED;
120}
121
122int suplibOsUninstall(void)
123{
124 return VERR_NOT_IMPLEMENTED;
125}
126
127
128int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq)
129{
130 AssertMsg(g_hDevice != -1, ("SUPLIB not initiated successfully!\n"));
131 if (RT_LIKELY(ioctl(g_hDevice, uFunction, pvReq) >= 0))
132 return VINF_SUCCESS;
133 return RTErrConvertFromErrno(errno);
134}
135
136
137int suplibOSIOCtlFast(uintptr_t uFunction)
138{
139 int rc = ioctl(g_hDevice, uFunction, NULL);
140 if (rc == -1)
141 rc = errno;
142 return rc;
143}
144
145
146int suplibOsPageAlloc(size_t cPages, void **ppvPages)
147{
148 *ppvPages = RTMemPageAllocZ(cPages << PAGE_SHIFT);
149 if (*ppvPages)
150 return VINF_SUCCESS;
151 return RTErrConvertFromErrno(errno);
152}
153
154
155int suplibOsPageFree(void *pvPages, size_t /* cPages */)
156{
157 RTMemPageFree(pvPages);
158 return VINF_SUCCESS;
159}
160
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