/** * Initializes the ring-0 driver runtime library. * * @returns iprt status code. * @param fReserved Flags reserved for the future. */ RTR0DECL(int) RTR0Init(unsigned fReserved) { int rc; uint32_t cNewUsers; Assert(fReserved == 0); #ifndef RT_OS_SOLARIS /* On Solaris our thread preemption information is only obtained in rtR0InitNative().*/ RT_ASSERT_PREEMPTIBLE(); #endif /* * The first user initializes it. * We rely on the module loader to ensure that there are no * initialization races should two modules share the IPRT. */ cNewUsers = ASMAtomicIncS32(&g_crtR0Users); if (cNewUsers != 1) { if (cNewUsers > 1) return VINF_SUCCESS; ASMAtomicDecS32(&g_crtR0Users); return VERR_INTERNAL_ERROR_3; } rc = rtR0InitNative(); if (RT_SUCCESS(rc)) { #ifdef RTR0MEM_WITH_EF_APIS rtR0MemEfInit(); #endif rc = rtThreadInit(); if (RT_SUCCESS(rc)) { #ifndef IN_GUEST /* play safe for now */ rc = rtR0MpNotificationInit(); if (RT_SUCCESS(rc)) { rc = rtR0PowerNotificationInit(); if (RT_SUCCESS(rc)) return rc; rtR0MpNotificationTerm(); } #else if (RT_SUCCESS(rc)) return rc; #endif rtThreadTerm(); } #ifdef RTR0MEM_WITH_EF_APIS rtR0MemEfTerm(); #endif rtR0TermNative(); } return rc; }
static void rtR0Term(void) { rtThreadTerm(); #ifndef IN_GUEST /* play safe for now */ rtR0PowerNotificationTerm(); rtR0MpNotificationTerm(); #endif #ifdef RTR0MEM_WITH_EF_APIS rtR0MemEfTerm(); #endif rtR0TermNative(); }
DECLHIDDEN(int) rtR0InitNative(void) { /* * Create the lock group. */ g_pDarwinLockGroup = lck_grp_alloc_init("IPRT", LCK_GRP_ATTR_NULL); AssertReturn(g_pDarwinLockGroup, VERR_NO_MEMORY); /* * Initialize the preemption hacks. */ int rc = rtThreadPreemptDarwinInit(); if (RT_SUCCESS(rc)) { /* * Try resolve kernel symbols we need but apple don't wish to give us. */ RTDBGKRNLINFO hKrnlInfo; rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0 /*fFlags*/); if (RT_SUCCESS(rc)) { RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "ast_pending", (void **)&g_pfnR0DarwinAstPending); printf("ast_pending=%p\n", g_pfnR0DarwinAstPending); RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "cpu_interrupt", (void **)&g_pfnR0DarwinCpuInterrupt); printf("cpu_interrupt=%p\n", g_pfnR0DarwinCpuInterrupt); RTR0DbgKrnlInfoRelease(hKrnlInfo); } if (RT_FAILURE(rc)) { printf("rtR0InitNative: warning! failed to resolve special kernel symbols\n"); rc = VINF_SUCCESS; } } if (RT_FAILURE(rc)) rtR0TermNative(); return rc; }
DECLHIDDEN(int) rtR0InitNative(void) { /* * Create the lock group. */ g_pDarwinLockGroup = lck_grp_alloc_init("IPRT", LCK_GRP_ATTR_NULL); AssertReturn(g_pDarwinLockGroup, VERR_NO_MEMORY); /* * Initialize the preemption hacks. */ int rc = rtThreadPreemptDarwinInit(); if (RT_SUCCESS(rc)) { /* * Try resolve kernel symbols we need but apple don't wish to give us. */ RTR0MACHKERNEL hKernel; rc = RTR0MachKernelOpen("/mach_kernel", &hKernel); if (RT_SUCCESS(rc)) { RTR0MachKernelGetSymbol(hKernel, "ast_pending", (void **)&g_pfnR0DarwinAstPending); printf("ast_pending=%p\n", g_pfnR0DarwinAstPending); RTR0MachKernelGetSymbol(hKernel, "cpu_interrupt", (void **)&g_pfnR0DarwinCpuInterrupt); printf("cpu_interrupt=%p\n", g_pfnR0DarwinCpuInterrupt); RTR0MachKernelClose(hKernel); } if (RT_FAILURE(rc)) { printf("rtR0InitNative: warning! failed to resolve special kernel symbols\n"); rc = VINF_SUCCESS; } } if (RT_FAILURE(rc)) rtR0TermNative(); return rc; }