VirtualBox

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

Last change on this file since 29945 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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