VirtualBox

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

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

IPRT,HostDrv,AddDrv: Export public IPRT symbols for the linux kernel (pain).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1/* $Id: initterm-r0drv.cpp 21337 2009-07-07 14:58:27Z 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#ifndef IN_GUEST /* play safe for now */
42# include "r0drv/mp-r0drv.h"
43# include "r0drv/power-r0drv.h"
44#endif
45
46#include "internal/initterm.h"
47#include "internal/thread.h"
48
49
50/*******************************************************************************
51* Global Variables *
52*******************************************************************************/
53/** Count of current IPRT users.
54 * In ring-0 several drivers / kmods / kexts / wossnames may share the
55 * same runtime code. So, we need to keep count in order not to terminate
56 * it prematurely. */
57static int32_t volatile g_crtR0Users = 0;
58
59
60/**
61 * Initalizes the ring-0 driver runtime library.
62 *
63 * @returns iprt status code.
64 * @param fReserved Flags reserved for the future.
65 */
66RTR0DECL(int) RTR0Init(unsigned fReserved)
67{
68 int rc;
69 Assert(fReserved == 0);
70
71 /*
72 * The first user initializes it.
73 * We rely on the module loader to ensure that there are no
74 * initialization races should two modules share the IPRT.
75 */
76 if (ASMAtomicIncS32(&g_crtR0Users) != 1)
77 return VINF_SUCCESS;
78
79 rc = rtR0InitNative();
80 if (RT_SUCCESS(rc))
81 {
82#if !defined(RT_OS_LINUX)
83 rc = rtThreadInit();
84#endif
85 if (RT_SUCCESS(rc))
86 {
87#ifndef IN_GUEST /* play safe for now */
88 rc = rtR0MpNotificationInit();
89 if (RT_SUCCESS(rc))
90 rc = rtR0PowerNotificationInit();
91#endif
92 if (RT_SUCCESS(rc))
93 return rc;
94 }
95
96 rtR0TermNative();
97 }
98 return rc;
99}
100RT_EXPORT_SYMBOL(RTR0Init);
101
102
103/**
104 * Terminates the ring-0 driver runtime library.
105 */
106RTR0DECL(void) RTR0Term(void)
107{
108 /*
109 * Last user does the cleanup.
110 */
111 int32_t cNewUsers = ASMAtomicDecS32(&g_crtR0Users);
112 Assert(cNewUsers >= 0);
113 if (cNewUsers != 0)
114 return;
115
116#if !defined(RT_OS_LINUX)
117 rtThreadTerm();
118#endif
119#ifndef IN_GUEST /* play safe for now */
120 rtR0PowerNotificationTerm();
121 rtR0MpNotificationTerm();
122#endif
123 rtR0TermNative();
124}
125RT_EXPORT_SYMBOL(RTR0Term);
126
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