VirtualBox

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

Last change on this file since 69111 was 69111, checked in by vboxsync, 7 years ago

(C) year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.2 KB
Line 
1/* $Id: the-darwin-kernel.h 69111 2017-10-17 14:26:02Z vboxsync $ */
2/** @file
3 * IPRT - Include all necessary headers for the Darwing kernel.
4 */
5
6/*
7 * Copyright (C) 2006-2017 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. (FreeBSD has fixed these ages ago.) */
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#undef PVM
41
42
43/* Include the IPRT definitions of the conflicting #defines & typedefs. */
44#include <iprt/cdefs.h>
45#include <iprt/types.h>
46#include <iprt/param.h>
47
48
49/* After including cdefs, we can check that this really is Darwin. */
50#ifndef RT_OS_DARWIN
51# error "RT_OS_DARWIN must be defined!"
52#endif
53
54#if defined(__clang__) || RT_GNUC_PREREQ(4, 4)
55# pragma GCC diagnostic push
56#endif
57#if defined(__clang__) || RT_GNUC_PREREQ(4, 2)
58# pragma GCC diagnostic ignored "-Wc++11-extensions"
59# pragma GCC diagnostic ignored "-Wc99-extensions"
60# pragma GCC diagnostic ignored "-Wextra-semi"
61# pragma GCC diagnostic ignored "-Wzero-length-array"
62# pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
63#endif
64
65/* now we're ready for including the rest of the Darwin headers. */
66#include <kern/thread.h>
67#include <kern/clock.h>
68#include <kern/sched_prim.h>
69#include <kern/locks.h>
70#if defined(RT_ARCH_X86) && MAC_OS_X_VERSION_MIN_REQUIRED < 1060
71# include <i386/mp_events.h>
72#endif
73#include <libkern/libkern.h>
74#include <libkern/sysctl.h>
75#include <libkern/version.h>
76#include <mach/thread_act.h>
77#include <mach/vm_map.h>
78#include <mach/vm_region.h>
79#include <pexpert/pexpert.h>
80#include <sys/conf.h>
81#include <sys/errno.h>
82#include <sys/ioccom.h>
83#include <sys/malloc.h>
84#include <sys/proc.h>
85#include <sys/vnode.h>
86#include <sys/fcntl.h>
87#include <IOKit/IOTypes.h>
88#include <IOKit/IOLib.h> /* Note! Has Assert down as a function. */
89#include <IOKit/IOMemoryDescriptor.h>
90#include <IOKit/IOBufferMemoryDescriptor.h>
91#include <IOKit/IOMapper.h>
92
93#if defined(__clang__) || RT_GNUC_PREREQ(4, 4)
94# pragma GCC diagnostic pop
95#endif
96
97
98/* See osfmk/kern/ast.h. */
99#ifndef AST_PREEMPT
100# define AST_PREEMPT UINT32_C(1)
101# define AST_QUANTUM UINT32_C(2)
102# define AST_URGENT UINT32_C(4)
103#endif
104
105/* This flag was added in 10.6, it seems. Should be harmless in earlier
106 releases... */
107#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
108# define kIOMemoryMapperNone UINT32_C(0x800)
109#endif
110
111/** @name Macros for preserving EFLAGS.AC (despair / paranoid)
112 * @remarks Unlike linux, we have to restore it unconditionally on darwin.
113 * @{ */
114#include <iprt/asm-amd64-x86.h>
115#include <iprt/x86.h>
116#define IPRT_DARWIN_SAVE_EFL_AC() RTCCUINTREG const fSavedEfl = ASMGetFlags();
117#define IPRT_DARWIN_RESTORE_EFL_AC() ASMSetFlags(fSavedEfl)
118#define IPRT_DARWIN_RESTORE_EFL_ONLY_AC() ASMChangeFlags(~X86_EFL_AC, fSavedEfl & X86_EFL_AC)
119#define IPRT_DARWIN_RESTORE_EFL_ONLY_AC_EX(a_fSavedEfl) ASMChangeFlags(~X86_EFL_AC, (a_fSavedEfl) & X86_EFL_AC)
120/** @} */
121
122
123RT_C_DECLS_BEGIN
124
125/* mach/vm_types.h */
126typedef struct pmap *pmap_t;
127
128/* vm/vm_kern.h */
129extern vm_map_t kernel_map;
130
131/* vm/pmap.h */
132extern pmap_t kernel_pmap;
133
134/* kern/task.h */
135extern vm_map_t get_task_map(task_t);
136
137/* osfmk/i386/pmap.h */
138extern ppnum_t pmap_find_phys(pmap_t, addr64_t);
139
140/* vm/vm_map.h */
141extern kern_return_t vm_map_wire(vm_map_t, vm_map_offset_t, vm_map_offset_t, vm_prot_t, boolean_t);
142extern kern_return_t vm_map_unwire(vm_map_t, vm_map_offset_t, vm_map_offset_t, boolean_t);
143
144/* mach/i386/thread_act.h */
145extern kern_return_t thread_terminate(thread_t);
146
147/* osfmk/i386/mp.h */
148extern void mp_rendezvous(void (*)(void *), void (*)(void *), void (*)(void *), void *);
149extern void mp_rendezvous_no_intrs(void (*)(void *), void *);
150
151/* osfmk/i386/cpu_data.h */
152struct my_cpu_data_x86
153{
154 struct my_cpu_data_x86 *cpu_this;
155 thread_t cpu_active_thread;
156 void *cpu_int_state;
157 vm_offset_t cpu_active_stack;
158 vm_offset_t cpu_kernel_stack;
159 vm_offset_t cpu_int_stack_top;
160 int cpu_preemption_level;
161 int cpu_simple_lock_count;
162 int cpu_interrupt_level;
163 int cpu_number;
164 int cpu_phys_number;
165 cpu_id_t cpu_id;
166 int cpu_signals;
167 int cpu_mcount_off;
168 /*ast_t*/uint32_t cpu_pending_ast;
169 int cpu_type;
170 int cpu_subtype;
171 int cpu_threadtype;
172 int cpu_running;
173};
174
175/* osfmk/i386/cpu_number.h */
176extern int cpu_number(void);
177
178/* osfmk/vm/vm_user.c */
179extern kern_return_t vm_protect(vm_map_t, vm_offset_t, vm_size_t, boolean_t, vm_prot_t);
180/*extern kern_return_t vm_region(vm_map_t, vm_address_t *, vm_size_t *, vm_region_flavor_t, vm_region_info_t,
181 mach_msg_type_number_t *, mach_port_t *);*/
182
183/* i386/machine_routines.h */
184extern int ml_get_max_cpus(void);
185
186RT_C_DECLS_END
187
188
189/*
190 * Internals of the Darwin Ring-0 IPRT.
191 */
192RT_C_DECLS_BEGIN
193
194/* initterm-r0drv-darwin.cpp. */
195typedef uint32_t * (*PFNR0DARWINASTPENDING)(void);
196typedef void (*PFNR0DARWINCPUINTERRUPT)(int);
197extern lck_grp_t *g_pDarwinLockGroup;
198extern PFNR0DARWINASTPENDING g_pfnR0DarwinAstPending;
199extern PFNR0DARWINCPUINTERRUPT g_pfnR0DarwinCpuInterrupt;
200
201/* threadpreempt-r0drv-darwin.cpp */
202int rtThreadPreemptDarwinInit(void);
203void rtThreadPreemptDarwinTerm(void);
204
205RT_C_DECLS_END
206
207
208/**
209 * Converts from nanoseconds to Darwin absolute time units.
210 * @returns Darwin absolute time.
211 * @param u64Nano Time interval in nanoseconds
212 */
213DECLINLINE(uint64_t) rtDarwinAbsTimeFromNano(const uint64_t u64Nano)
214{
215 uint64_t u64AbsTime;
216 nanoseconds_to_absolutetime(u64Nano, &u64AbsTime);
217 return u64AbsTime;
218}
219
220
221#include <iprt/err.h>
222
223/**
224 * Convert from mach kernel return code to IPRT status code.
225 * @todo put this where it belongs! (i.e. in a separate file and prototype in iprt/err.h)
226 */
227DECLINLINE(int) RTErrConvertFromMachKernReturn(kern_return_t rc)
228{
229 switch (rc)
230 {
231 case KERN_SUCCESS: return VINF_SUCCESS;
232 default: return VERR_GENERAL_FAILURE;
233 }
234}
235
236#endif
237
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