1 | /** @file
|
---|
2 | * SUPLib - FreeBSD Hosts,
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License as published by the Free Software Foundation,
|
---|
12 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 |
|
---|
18 | /*******************************************************************************
|
---|
19 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 | #define LOG_GROUP LOG_GROUP_SUP
|
---|
22 | #include <VBox/types.h>
|
---|
23 | #include <VBox/sup.h>
|
---|
24 | #include <VBox/param.h>
|
---|
25 | #include <VBox/err.h>
|
---|
26 | #include <VBox/log.h>
|
---|
27 | #include <iprt/path.h>
|
---|
28 | #include <iprt/assert.h>
|
---|
29 | #include <iprt/mem.h>
|
---|
30 | #include <iprt/err.h>
|
---|
31 | #include <iprt/string.h>
|
---|
32 | #include "SUPLibInternal.h"
|
---|
33 | #include "SUPDRVIOC.h"
|
---|
34 |
|
---|
35 | #include <sys/fcntl.h>
|
---|
36 | #include <sys/ioctl.h>
|
---|
37 | #include <errno.h>
|
---|
38 | #include <unistd.h>
|
---|
39 | #include <stdlib.h>
|
---|
40 |
|
---|
41 |
|
---|
42 | /*******************************************************************************
|
---|
43 | * Defined Constants And Macros *
|
---|
44 | *******************************************************************************/
|
---|
45 | /** BSD Device name. */
|
---|
46 | #define DEVICE_NAME "/dev/vboxdrv"
|
---|
47 |
|
---|
48 |
|
---|
49 | /*******************************************************************************
|
---|
50 | * Global Variables *
|
---|
51 | *******************************************************************************/
|
---|
52 | /** Handle to the open device. */
|
---|
53 | static int g_hDevice = -1;
|
---|
54 |
|
---|
55 |
|
---|
56 | int suplibOsInit(size_t cbReserve)
|
---|
57 | {
|
---|
58 | /*
|
---|
59 | * Check if already initialized.
|
---|
60 | */
|
---|
61 | if (g_hDevice >= 0)
|
---|
62 | return VINF_SUCCESS;
|
---|
63 |
|
---|
64 | /*
|
---|
65 | * Try open the BSD device.
|
---|
66 | */
|
---|
67 | g_hDevice = open(DEVICE_NAME, O_RDWR, 0);
|
---|
68 | if (g_hDevice < 0)
|
---|
69 | {
|
---|
70 | int rc = errno;
|
---|
71 | LogRel(("Failed to open \"%s\", errno=%d\n", rc));
|
---|
72 | return RTErrConvertFromErrno(rc);
|
---|
73 | }
|
---|
74 |
|
---|
75 | /*
|
---|
76 | * We're done.
|
---|
77 | */
|
---|
78 | NOREF(cbReserve);
|
---|
79 | return VINF_SUCCESS;
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | int suplibOsTerm(void)
|
---|
84 | {
|
---|
85 | /*
|
---|
86 | * Check if we're initited at all.
|
---|
87 | */
|
---|
88 | if (g_hDevice >= 0)
|
---|
89 | {
|
---|
90 | if (close(g_hDevice))
|
---|
91 | AssertFailed();
|
---|
92 | g_hDevice = -1;
|
---|
93 | }
|
---|
94 | return VINF_SUCCESS;
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | int suplibOsInstall(void)
|
---|
99 | {
|
---|
100 | return VERR_NOT_IMPLEMENTED;
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | int suplibOsUninstall(void)
|
---|
105 | {
|
---|
106 | return VERR_NOT_IMPLEMENTED;
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq)
|
---|
111 | {
|
---|
112 | AssertMsg(g_hDevice != -1, ("SUPLIB not initiated successfully!\n"));
|
---|
113 |
|
---|
114 | if (RT_LIKELY(ioctl((g_hDevice, uFunction, pvReq) >= 0))
|
---|
115 | return VINF_SUCCESS;
|
---|
116 | return RTErrConvertFromErrno(errno);
|
---|
117 | }
|
---|
118 |
|
---|
119 | #ifdef VBOX_WITHOUT_IDT_PATCHING
|
---|
120 | int suplibOSIOCtlFast(uintptr_t uFunction)
|
---|
121 | {
|
---|
122 | int rc = ioctl(g_hDevice, uFunction, NULL);
|
---|
123 | if (rc == -1)
|
---|
124 | rc = errno;
|
---|
125 | return rc;
|
---|
126 | }
|
---|
127 | #endif
|
---|
128 |
|
---|
129 |
|
---|
130 | int suplibOsPageAlloc(size_t cPages, void **ppvPages)
|
---|
131 | {
|
---|
132 | *ppvPages = RTMemPageAllocZ(cPages << PAGE_SHIFT);
|
---|
133 | if (*ppvPages)
|
---|
134 | return VINF_SUCCESS;
|
---|
135 | return RTErrConvertFromErrno(errno);
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | int suplibOsPageFree(void *pvPages, size_t /* cPages */)
|
---|
140 | {
|
---|
141 | RTMemPageFree(pvPages);
|
---|
142 | return VINF_SUCCESS;
|
---|
143 | }
|
---|
144 |
|
---|