VirtualBox

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

最後變更 在這個檔案從57228是 57228,由 vboxsync 提交於 10 年 前

IPRT/r0drv/darwin: More EFLAGS.AC paranoia.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 6.6 KB
 
1/* $Id: the-darwin-kernel.h 57228 2015-08-06 23:27:10Z vboxsync $ */
2/** @file
3 * IPRT - Include all necessary headers for the Darwing kernel.
4 */
5
6/*
7 * Copyright (C) 2006-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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 <libkern/version.h>
63#include <mach/thread_act.h>
64#include <mach/vm_map.h>
65#include <mach/vm_region.h>
66#include <pexpert/pexpert.h>
67#include <sys/conf.h>
68#include <sys/errno.h>
69#include <sys/ioccom.h>
70#include <sys/malloc.h>
71#include <sys/proc.h>
72#include <sys/vnode.h>
73#include <sys/fcntl.h>
74#include <IOKit/IOTypes.h>
75#include <IOKit/IOLib.h>
76#include <IOKit/IOMemoryDescriptor.h>
77#include <IOKit/IOBufferMemoryDescriptor.h>
78#include <IOKit/IOMapper.h>
79
80
81/* See osfmk/kern/ast.h. */
82#ifndef AST_PREEMPT
83# define AST_PREEMPT UINT32_C(1)
84# define AST_QUANTUM UINT32_C(2)
85# define AST_URGENT UINT32_C(4)
86#endif
87
88/* This flag was added in 10.6, it seems. Should be harmless in earlier
89 releases... */
90#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
91# define kIOMemoryMapperNone UINT32_C(0x800)
92#endif
93
94/** @name Macros for preserving EFLAGS.AC (despair / paranoid)
95 * @remarks Unlike linux, we have to restore it unconditionally on darwin.
96 * @{ */
97#include <iprt/asm-amd64-x86.h>
98#include <iprt/x86.h>
99#define IPRT_DARWIN_SAVE_EFL_AC() RTCCUINTREG const fSavedEfl = ASMGetFlags();
100#define IPRT_DARWIN_RESTORE_EFL_AC() ASMSetFlags(fSavedEfl)
101#define IPRT_DARWIN_RESTORE_EFL_ONLY_AC() ASMChangeFlags(~X86_EFL_AC, fSavedEfl & X86_EFL_AC)
102#define IPRT_DARWIN_RESTORE_EFL_ONLY_AC_EX(a_fSavedEfl) ASMChangeFlags(~X86_EFL_AC, (a_fSavedEfl) & X86_EFL_AC)
103/** @} */
104
105
106RT_C_DECLS_BEGIN
107
108/* mach/vm_types.h */
109typedef struct pmap *pmap_t;
110
111/* vm/vm_kern.h */
112extern vm_map_t kernel_map;
113
114/* vm/pmap.h */
115extern pmap_t kernel_pmap;
116
117/* kern/task.h */
118extern vm_map_t get_task_map(task_t);
119
120/* osfmk/i386/pmap.h */
121extern ppnum_t pmap_find_phys(pmap_t, addr64_t);
122
123/* vm/vm_map.h */
124extern kern_return_t vm_map_wire(vm_map_t, vm_map_offset_t, vm_map_offset_t, vm_prot_t, boolean_t);
125extern kern_return_t vm_map_unwire(vm_map_t, vm_map_offset_t, vm_map_offset_t, boolean_t);
126
127/* mach/i386/thread_act.h */
128extern kern_return_t thread_terminate(thread_t);
129
130/* osfmk/i386/mp.h */
131extern void mp_rendezvous(void (*)(void *), void (*)(void *), void (*)(void *), void *);
132extern void mp_rendezvous_no_intrs(void (*)(void *), void *);
133
134/* osfmk/i386/cpu_data.h */
135struct my_cpu_data_x86
136{
137 struct my_cpu_data_x86 *cpu_this;
138 thread_t cpu_active_thread;
139 void *cpu_int_state;
140 vm_offset_t cpu_active_stack;
141 vm_offset_t cpu_kernel_stack;
142 vm_offset_t cpu_int_stack_top;
143 int cpu_preemption_level;
144 int cpu_simple_lock_count;
145 int cpu_interrupt_level;
146 int cpu_number;
147 int cpu_phys_number;
148 cpu_id_t cpu_id;
149 int cpu_signals;
150 int cpu_mcount_off;
151 /*ast_t*/uint32_t cpu_pending_ast;
152 int cpu_type;
153 int cpu_subtype;
154 int cpu_threadtype;
155 int cpu_running;
156};
157
158/* osfmk/i386/cpu_number.h */
159extern int cpu_number(void);
160
161/* osfmk/vm/vm_user.c */
162extern kern_return_t vm_protect(vm_map_t, vm_offset_t, vm_size_t, boolean_t, vm_prot_t);
163/*extern kern_return_t vm_region(vm_map_t, vm_address_t *, vm_size_t *, vm_region_flavor_t, vm_region_info_t,
164 mach_msg_type_number_t *, mach_port_t *);*/
165
166/* i386/machine_routines.h */
167extern int ml_get_max_cpus(void);
168
169RT_C_DECLS_END
170
171
172/*
173 * Internals of the Darwin Ring-0 IPRT.
174 */
175RT_C_DECLS_BEGIN
176
177/* initterm-r0drv-darwin.cpp. */
178typedef uint32_t * (*PFNR0DARWINASTPENDING)(void);
179typedef void (*PFNR0DARWINCPUINTERRUPT)(int);
180extern lck_grp_t *g_pDarwinLockGroup;
181extern PFNR0DARWINASTPENDING g_pfnR0DarwinAstPending;
182extern PFNR0DARWINCPUINTERRUPT g_pfnR0DarwinCpuInterrupt;
183
184/* threadpreempt-r0drv-darwin.cpp */
185int rtThreadPreemptDarwinInit(void);
186void rtThreadPreemptDarwinTerm(void);
187
188RT_C_DECLS_END
189
190
191/**
192 * Converts from nanoseconds to Darwin absolute time units.
193 * @returns Darwin absolute time.
194 * @param u64Nano Time interval in nanoseconds
195 */
196DECLINLINE(uint64_t) rtDarwinAbsTimeFromNano(const uint64_t u64Nano)
197{
198 uint64_t u64AbsTime;
199 nanoseconds_to_absolutetime(u64Nano, &u64AbsTime);
200 return u64AbsTime;
201}
202
203
204#include <iprt/err.h>
205
206/**
207 * Convert from mach kernel return code to IPRT status code.
208 * @todo put this where it belongs! (i.e. in a separate file and prototype in iprt/err.h)
209 */
210DECLINLINE(int) RTErrConvertFromMachKernReturn(kern_return_t rc)
211{
212 switch (rc)
213 {
214 case KERN_SUCCESS: return VINF_SUCCESS;
215 default: return VERR_GENERAL_FAILURE;
216 }
217}
218
219#endif
220
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette