VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/solaris/DynLoadLibSolaris.cpp

Last change on this file was 98292, checked in by vboxsync, 16 months ago

Main/src-server: rc -> hrc/vrc. Enabled scm rc checks. bugref:10223

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 2.5 KB
Line 
1/* $Id: DynLoadLibSolaris.cpp 98292 2023-01-25 01:14:53Z vboxsync $ */
2/** @file
3 * Dynamically load libraries for Solaris hosts.
4 */
5
6/*
7 * Copyright (C) 2008-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#include "DynLoadLibSolaris.h"
29
30#include <iprt/errcore.h>
31#include <iprt/ldr.h>
32
33
34/** -=-=-=-=-= LIB DLPI -=-=-=-=-=-=- **/
35
36/**
37 * Global pointer to the libdlpi module. This should only be set once all needed libraries
38 * and symbols have been successfully loaded.
39 */
40static RTLDRMOD g_hLibDlpi = NIL_RTLDRMOD;
41
42/**
43 * Whether we have tried to load libdlpi yet. This flag should only be set
44 * to "true" after we have either loaded both libraries and all symbols which we need,
45 * or failed to load something and unloaded.
46 */
47static bool g_fCheckedForLibDlpi = false;
48
49/** All the symbols we need from libdlpi.
50 * @{
51 */
52int (*g_pfnLibDlpiWalk)(dlpi_walkfunc_t *, void *, uint_t);
53int (*g_pfnLibDlpiOpen)(const char *, dlpi_handle_t *, uint_t);
54void (*g_pfnLibDlpiClose)(dlpi_handle_t);
55/** @} */
56
57bool VBoxSolarisLibDlpiFound(void)
58{
59 RTLDRMOD hLibDlpi;
60
61 if (g_fCheckedForLibDlpi)
62 return g_hLibDlpi != NIL_RTLDRMOD;
63 g_fCheckedForLibDlpi = true;
64 int vrc = RTLdrLoad(LIB_DLPI, &hLibDlpi);
65 if (RT_SUCCESS(vrc))
66 {
67 /*
68 * Unfortunately; we cannot make use of dlpi_get_physaddr because it requires us to
69 * open the VNIC/link which requires root permissions :/
70 */
71 vrc = RTLdrGetSymbol(hLibDlpi, "dlpi_walk", (void **)&g_pfnLibDlpiWalk);
72 vrc |= RTLdrGetSymbol(hLibDlpi, "dlpi_close", (void **)&g_pfnLibDlpiClose);
73 vrc |= RTLdrGetSymbol(hLibDlpi, "dlpi_open", (void **)&g_pfnLibDlpiOpen);
74 if (RT_SUCCESS(vrc))
75 {
76 g_hLibDlpi = hLibDlpi;
77 return true;
78 }
79
80 RTLdrClose(hLibDlpi);
81 }
82 hLibDlpi = NIL_RTLDRMOD;
83 return false;
84}
85
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use