VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/darwin/the-darwin-kernel.h@ 37575

Last change on this file since 37575 was 37575, checked in by vboxsync, 13 years ago

IPRT/darwin-r0drv: Implemented RTMpPokeCpu and RTThreadPreemptIsPending/Trusty using the right kernel APIs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1/* $Id: the-darwin-kernel.h 37575 2011-06-21 12:40:01Z vboxsync $ */
2/** @file
3 * IPRT - Include all necessary headers for the Darwing kernel.
4 */
5
6/*
7 * Copyright (C) 2006-2011 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#ifndef ___the_darwin_kernel_h
28#define ___the_darwin_kernel_h
29
30/* Problematic header(s) containing conflicts with IPRT first. */
31#define __STDC_CONSTANT_MACROS
32#define __STDC_LIMIT_MACROS
33#include <sys/param.h>
34#include <mach/vm_param.h>
35#undef ALIGN
36#undef MIN
37#undef MAX
38#undef PAGE_SIZE
39#undef PAGE_SHIFT
40
41/* Include the IPRT definitions of the conflicting #defines & typedefs. */
42#include <iprt/cdefs.h>
43#include <iprt/types.h>
44#include <iprt/param.h>
45
46
47/* After including cdefs, we can check that this really is Darwin. */
48#ifndef RT_OS_DARWIN
49# error "RT_OS_DARWIN must be defined!"
50#endif
51
52/* now we're ready for including the rest of the Darwin headers. */
53#include <kern/thread.h>
54#include <kern/clock.h>
55#include <kern/sched_prim.h>
56#include <kern/locks.h>
57#if defined(RT_ARCH_X86) && MAC_OS_X_VERSION_MIN_REQUIRED < 1060
58# include <i386/mp_events.h>
59#endif
60#include <libkern/libkern.h>
61#include <libkern/sysctl.h>
62#include <mach/thread_act.h>
63#include <mach/vm_map.h>
64#include <pexpert/pexpert.h>
65#include <sys/conf.h>
66#include <sys/errno.h>
67#include <sys/ioccom.h>
68#include <sys/malloc.h>
69#include <sys/proc.h>
70#include <sys/vnode.h>
71#include <sys/fcntl.h>
72#include <IOKit/IOTypes.h>
73#include <IOKit/IOLib.h>
74#include <IOKit/IOMemoryDescriptor.h>
75#include <IOKit/IOBufferMemoryDescriptor.h>
76#include <IOKit/IOMapper.h>
77
78
79/* See osfmk/kern/ast.h. */
80#ifndef AST_PREEMPT
81# define AST_PREEMPT UINT32_C(1)
82# define AST_QUANTUM UINT32_C(2)
83# define AST_URGENT UINT32_C(4)
84#endif
85
86
87RT_C_DECLS_BEGIN
88
89/* mach/vm_types.h */
90typedef struct pmap *pmap_t;
91
92/* vm/vm_kern.h */
93extern vm_map_t kernel_map;
94
95/* vm/pmap.h */
96extern pmap_t kernel_pmap;
97
98/* kern/task.h */
99extern vm_map_t get_task_map(task_t);
100
101/* osfmk/i386/pmap.h */
102extern ppnum_t pmap_find_phys(pmap_t, addr64_t);
103
104/* vm/vm_map.h */
105extern kern_return_t vm_map_wire(vm_map_t, vm_map_offset_t, vm_map_offset_t, vm_prot_t, boolean_t);
106extern kern_return_t vm_map_unwire(vm_map_t, vm_map_offset_t, vm_map_offset_t, boolean_t);
107
108/* mach/i386/thread_act.h */
109extern kern_return_t thread_terminate(thread_t);
110
111/* osfmk/i386/mp.h */
112extern void mp_rendezvous(void (*)(void *), void (*)(void *), void (*)(void *), void *);
113extern void mp_rendezvous_no_intrs(void (*)(void *), void *);
114
115/* osfmk/i386/cpu_data.h */
116struct my_cpu_data_x86
117{
118 struct my_cpu_data_x86 *cpu_this;
119 thread_t cpu_active_thread;
120 void *cpu_int_state;
121 vm_offset_t cpu_active_stack;
122 vm_offset_t cpu_kernel_stack;
123 vm_offset_t cpu_int_stack_top;
124 int cpu_preemption_level;
125 int cpu_simple_lock_count;
126 int cpu_interrupt_level;
127 int cpu_number;
128 int cpu_phys_number;
129 cpu_id_t cpu_id;
130 int cpu_signals;
131 int cpu_mcount_off;
132 /*ast_t*/uint32_t cpu_pending_ast;
133 int cpu_type;
134 int cpu_subtype;
135 int cpu_threadtype;
136 int cpu_running;
137};
138
139/* osfmk/i386/cpu_number.h */
140extern int cpu_number(void);
141
142/* osfmk/vm/vm_user.c */
143extern kern_return_t vm_protect(vm_map_t, vm_offset_t, vm_size_t, boolean_t, vm_prot_t);
144
145/* i386/machine_routines.h */
146extern int ml_get_max_cpus(void);
147
148RT_C_DECLS_END
149
150
151/*
152 * Internals of the Darwin Ring-0 IPRT.
153 */
154RT_C_DECLS_BEGIN
155
156/* initterm-r0drv-darwin.cpp. */
157typedef uint32_t * (*PFNR0DARWINASTPENDING)(void);
158typedef void (*PFNR0DARWINCPUINTERRUPT)(int);
159extern lck_grp_t *g_pDarwinLockGroup;
160extern PFNR0DARWINASTPENDING g_pfnR0DarwinAstPending;
161extern PFNR0DARWINCPUINTERRUPT g_pfnR0DarwinCpuInterrupt;
162
163/* threadpreempt-r0drv-darwin.cpp */
164int rtThreadPreemptDarwinInit(void);
165void rtThreadPreemptDarwinTerm(void);
166
167RT_C_DECLS_END
168
169
170/**
171 * Converts from nanoseconds to Darwin absolute time units.
172 * @returns Darwin absolute time.
173 * @param u64Nano Time interval in nanoseconds
174 */
175DECLINLINE(uint64_t) rtDarwinAbsTimeFromNano(const uint64_t u64Nano)
176{
177 uint64_t u64AbsTime;
178 nanoseconds_to_absolutetime(u64Nano, &u64AbsTime);
179 return u64AbsTime;
180}
181
182
183#include <iprt/err.h>
184
185/**
186 * Convert from mach kernel return code to IPRT status code.
187 * @todo put this where it belongs! (i.e. in a separate file and prototype in iprt/err.h)
188 */
189DECLINLINE(int) RTErrConvertFromMachKernReturn(kern_return_t rc)
190{
191 switch (rc)
192 {
193 case KERN_SUCCESS: return VINF_SUCCESS;
194 default: return VERR_GENERAL_FAILURE;
195 }
196}
197
198#endif
199
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