VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/initterm-r0drv.cpp@ 25877

Last change on this file since 25877 was 24179, checked in by vboxsync, 15 years ago

iprt/initterm.h,SUPDrv-solaris.c: Added RTR0TermForced so the module containing IPRT can make sure it's really terminated and that modules not calling RTR0Term doesn't create trouble (other than debug assertions). Use this for SUPDrv on Solaris.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1/* $Id: initterm-r0drv.cpp 24179 2009-10-30 10:26:43Z vboxsync $ */
2/** @file
3 * IPRT - Initialization & Termination, R0 Driver, Common.
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#include <iprt/initterm.h>
36#include "internal/iprt.h"
37
38#include <iprt/asm.h>
39#include <iprt/assert.h>
40#include <iprt/err.h>
41#include <iprt/mp.h>
42#include <iprt/thread.h>
43#ifndef IN_GUEST /* play safe for now */
44# include "r0drv/mp-r0drv.h"
45# include "r0drv/power-r0drv.h"
46#endif
47
48#include "internal/initterm.h"
49#include "internal/thread.h"
50
51
52/*******************************************************************************
53* Global Variables *
54*******************************************************************************/
55/** Count of current IPRT users.
56 * In ring-0 several drivers / kmods / kexts / wossnames may share the
57 * same runtime code. So, we need to keep count in order not to terminate
58 * it prematurely. */
59static int32_t volatile g_crtR0Users = 0;
60
61
62/**
63 * Initalizes the ring-0 driver runtime library.
64 *
65 * @returns iprt status code.
66 * @param fReserved Flags reserved for the future.
67 */
68RTR0DECL(int) RTR0Init(unsigned fReserved)
69{
70 int rc;
71 Assert(fReserved == 0);
72 RT_ASSERT_PREEMPTIBLE();
73
74 /*
75 * The first user initializes it.
76 * We rely on the module loader to ensure that there are no
77 * initialization races should two modules share the IPRT.
78 */
79 if (ASMAtomicIncS32(&g_crtR0Users) != 1)
80 return VINF_SUCCESS;
81
82 rc = rtR0InitNative();
83 if (RT_SUCCESS(rc))
84 {
85#if !defined(RT_OS_LINUX) /** @todo implement thread2-r0drv-linux.c */
86 rc = rtThreadInit();
87#endif
88 if (RT_SUCCESS(rc))
89 {
90#ifndef IN_GUEST /* play safe for now */
91 rc = rtR0MpNotificationInit();
92 if (RT_SUCCESS(rc))
93 {
94 rc = rtR0PowerNotificationInit();
95 if (RT_SUCCESS(rc))
96 return rc;
97 rtR0MpNotificationTerm();
98 }
99#else
100 if (RT_SUCCESS(rc))
101 return rc;
102#endif
103#if !defined(RT_OS_LINUX) /** @todo implement thread2-r0drv-linux.c */
104 rtThreadTerm();
105#endif
106 }
107 rtR0TermNative();
108 }
109 return rc;
110}
111RT_EXPORT_SYMBOL(RTR0Init);
112
113
114static void rtR0Term(void)
115{
116#if !defined(RT_OS_LINUX) /** @todo implement thread2-r0drv-linux.c */
117 rtThreadTerm();
118#endif
119#ifndef IN_GUEST /* play safe for now */
120 rtR0PowerNotificationTerm();
121 rtR0MpNotificationTerm();
122#endif
123 rtR0TermNative();
124}
125
126
127/**
128 * Terminates the ring-0 driver runtime library.
129 */
130RTR0DECL(void) RTR0Term(void)
131{
132 int32_t cNewUsers;
133 RT_ASSERT_PREEMPTIBLE();
134
135 cNewUsers = ASMAtomicDecS32(&g_crtR0Users);
136 Assert(cNewUsers >= 0);
137 if (cNewUsers == 0)
138 rtR0Term();
139}
140RT_EXPORT_SYMBOL(RTR0Term);
141
142
143/* Note! Should *not* be exported since it's only for static linking. */
144RTR0DECL(void) RTR0TermForced(void)
145{
146 RT_ASSERT_PREEMPTIBLE();
147 AssertMsg(g_crtR0Users == 1, ("%d\n", g_crtR0Users));
148
149 rtR0Term();
150}
151
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