VirtualBox

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

Last change on this file since 78120 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

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