2 * Copyright (c) 2003-2010 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 * Here's what to do if you want to add a new routine to the comm page:
32 * 1. Add a definition for it's address in osfmk/i386/cpu_capabilities.h,
33 * being careful to reserve room for future expansion.
35 * 2. Write one or more versions of the routine, each with it's own
36 * commpage_descriptor. The tricky part is getting the "special",
37 * "musthave", and "canthave" fields right, so that exactly one
38 * version of the routine is selected for every machine.
39 * The source files should be in osfmk/i386/commpage/.
41 * 3. Add a ptr to your new commpage_descriptor(s) in the "routines"
42 * array in osfmk/i386/commpage/commpage_asm.s. There are two
43 * arrays, one for the 32-bit and one for the 64-bit commpage.
45 * 4. Write the code in Libc to use the new routine.
48 #include <mach/mach_types.h>
49 #include <mach/machine.h>
50 #include <mach/vm_map.h>
51 #include <mach/mach_vm.h>
52 #include <mach/machine.h>
53 #include <i386/cpuid.h>
55 #include <i386/rtclock_protos.h>
56 #include <i386/cpu_data.h>
57 #include <i386/machine_routines.h>
58 #include <i386/misc_protos.h>
59 #include <i386/cpuid.h>
60 #include <machine/cpu_capabilities.h>
61 #include <machine/commpage.h>
62 #include <machine/pmap.h>
63 #include <vm/vm_kern.h>
64 #include <vm/vm_map.h>
66 #include <ipc/ipc_port.h>
68 #include <kern/page_decrypt.h>
69 #include <kern/processor.h>
71 #include <sys/kdebug.h>
74 #include <atm/atm_internal.h>
77 /* the lists of commpage routines are in commpage_asm.s */
78 extern commpage_descriptor
* commpage_32_routines
[];
79 extern commpage_descriptor
* commpage_64_routines
[];
81 extern vm_map_t commpage32_map
; // the shared submap, set up in vm init
82 extern vm_map_t commpage64_map
; // the shared submap, set up in vm init
83 extern vm_map_t commpage_text32_map
; // the shared submap, set up in vm init
84 extern vm_map_t commpage_text64_map
; // the shared submap, set up in vm init
87 char *commPagePtr32
= NULL
; // virtual addr in kernel map of 32-bit commpage
88 char *commPagePtr64
= NULL
; // ...and of 64-bit commpage
89 char *commPageTextPtr32
= NULL
; // virtual addr in kernel map of 32-bit commpage
90 char *commPageTextPtr64
= NULL
; // ...and of 64-bit commpage
92 uint64_t _cpu_capabilities
= 0; // define the capability vector
94 typedef uint32_t commpage_address_t
;
96 static commpage_address_t next
; // next available address in comm page
98 static char *commPagePtr
; // virtual addr in kernel map of commpage we are working on
99 static commpage_address_t commPageBaseOffset
; // subtract from 32-bit runtime address to get offset in virtual commpage in kernel map
101 static commpage_time_data
*time_data32
= NULL
;
102 static commpage_time_data
*time_data64
= NULL
;
104 decl_simple_lock_data(static,commpage_active_cpus_lock
);
106 /* Allocate the commpage and add to the shared submap created by vm:
107 * 1. allocate a page in the kernel map (RW)
109 * 3. make a memory entry out of it
110 * 4. map that entry into the shared comm region map (R-only)
115 vm_map_t submap
, // commpage32_map or commpage_map64
116 size_t area_used
, // _COMM_PAGE32_AREA_USED or _COMM_PAGE64_AREA_USED
119 vm_offset_t kernel_addr
= 0; // address of commpage in kernel map
120 vm_offset_t zero
= 0;
121 vm_size_t size
= area_used
; // size actually populated
122 vm_map_entry_t entry
;
127 panic("commpage submap is null");
129 if ((kr
= vm_map(kernel_map
,
133 VM_FLAGS_ANYWHERE
| VM_MAKE_TAG(VM_KERN_MEMORY_OSFMK
),
140 panic("cannot allocate commpage %d", kr
);
142 if ((kr
= vm_map_wire(kernel_map
,
144 kernel_addr
+area_used
,
145 VM_PROT_DEFAULT
|VM_PROT_MEMORY_TAG_MAKE(VM_KERN_MEMORY_OSFMK
),
147 panic("cannot wire commpage: %d", kr
);
150 * Now that the object is created and wired into the kernel map, mark it so that no delay
151 * copy-on-write will ever be performed on it as a result of mapping it into user-space.
152 * If such a delayed copy ever occurred, we could remove the kernel's wired mapping - and
153 * that would be a real disaster.
155 * JMM - What we really need is a way to create it like this in the first place.
157 if (!(kr
= vm_map_lookup_entry( kernel_map
, vm_map_trunc_page(kernel_addr
, VM_MAP_PAGE_MASK(kernel_map
)), &entry
) || entry
->is_sub_map
))
158 panic("cannot find commpage entry %d", kr
);
159 VME_OBJECT(entry
)->copy_strategy
= MEMORY_OBJECT_COPY_NONE
;
161 if ((kr
= mach_make_memory_entry( kernel_map
, // target map
163 kernel_addr
, // offset (address in kernel map)
164 uperm
, // protections as specified
165 &handle
, // this is the object handle we get
166 NULL
))) // parent_entry (what is this?)
167 panic("cannot make entry for commpage %d", kr
);
169 if ((kr
= vm_map_64( submap
, // target map (shared submap)
170 &zero
, // address (map into 1st page in submap)
173 VM_FLAGS_FIXED
, // flags (it must be 1st page in submap)
174 handle
, // port is the memory entry we just made
175 0, // offset (map 1st page in memory entry)
177 uperm
, // cur_protection (R-only in user map)
178 uperm
, // max_protection
179 VM_INHERIT_SHARE
))) // inheritance
180 panic("cannot map commpage %d", kr
);
182 ipc_port_release(handle
);
183 /* Make the kernel mapping non-executable. This cannot be done
184 * at the time of map entry creation as mach_make_memory_entry
185 * cannot handle disjoint permissions at this time.
187 kr
= vm_protect(kernel_map
, kernel_addr
, area_used
, FALSE
, VM_PROT_READ
| VM_PROT_WRITE
);
188 assert (kr
== KERN_SUCCESS
);
190 return (void*)(intptr_t)kernel_addr
; // return address in kernel map
193 /* Get address (in kernel map) of a commpage field. */
197 commpage_address_t addr_at_runtime
)
199 return (void*) ((uintptr_t)commPagePtr
+ (addr_at_runtime
- commPageBaseOffset
));
202 /* Determine number of CPUs on this system. We cannot rely on
203 * machine_info.max_cpus this early in the boot.
206 commpage_cpus( void )
210 cpus
= ml_get_max_cpus(); // NB: this call can block
213 panic("commpage cpus==0");
220 /* Initialize kernel version of _cpu_capabilities vector (used by KEXTs.) */
223 commpage_init_cpu_capabilities( void )
227 ml_cpu_info_t cpu_info
;
230 ml_cpu_get_info(&cpu_info
);
232 switch (cpu_info
.vector_unit
) {
243 bits
|= kHasSupplementalSSE3
;
259 switch (cpu_info
.cache_line_size
) {
272 cpus
= commpage_cpus(); // how many CPUs do we have
274 bits
|= (cpus
<< kNumCPUsShift
);
276 bits
|= kFastThreadLocalStorage
; // we use %gs for TLS
278 #define setif(_bits, _bit, _condition) \
279 if (_condition) _bits |= _bit
281 setif(bits
, kUP
, cpus
== 1);
282 setif(bits
, k64Bit
, cpu_mode_is64bit());
283 setif(bits
, kSlow
, tscFreq
<= SLOW_TSC_THRESHOLD
);
285 setif(bits
, kHasAES
, cpuid_features() &
287 setif(bits
, kHasF16C
, cpuid_features() &
289 setif(bits
, kHasRDRAND
, cpuid_features() &
290 CPUID_FEATURE_RDRAND
);
291 setif(bits
, kHasFMA
, cpuid_features() &
294 setif(bits
, kHasBMI1
, cpuid_leaf7_features() &
295 CPUID_LEAF7_FEATURE_BMI1
);
296 setif(bits
, kHasBMI2
, cpuid_leaf7_features() &
297 CPUID_LEAF7_FEATURE_BMI2
);
298 setif(bits
, kHasRTM
, cpuid_leaf7_features() &
299 CPUID_LEAF7_FEATURE_RTM
);
300 setif(bits
, kHasHLE
, cpuid_leaf7_features() &
301 CPUID_LEAF7_FEATURE_HLE
);
302 setif(bits
, kHasAVX2_0
, cpuid_leaf7_features() &
303 CPUID_LEAF7_FEATURE_AVX2
);
304 setif(bits
, kHasRDSEED
, cpuid_features() &
305 CPUID_LEAF7_FEATURE_RDSEED
);
306 setif(bits
, kHasADX
, cpuid_features() &
307 CPUID_LEAF7_FEATURE_ADX
);
309 setif(bits
, kHasMPX
, cpuid_leaf7_features() &
310 CPUID_LEAF7_FEATURE_MPX
);
311 setif(bits
, kHasSGX
, cpuid_leaf7_features() &
312 CPUID_LEAF7_FEATURE_SGX
);
314 uint64_t misc_enable
= rdmsr64(MSR_IA32_MISC_ENABLE
);
315 setif(bits
, kHasENFSTRG
, (misc_enable
& 1ULL) &&
316 (cpuid_leaf7_features() &
317 CPUID_LEAF7_FEATURE_ERMS
));
319 _cpu_capabilities
= bits
; // set kernel version for use by drivers etc
322 /* initialize the approx_time_supported flag and set the approx time to 0.
323 * Called during initial commpage population.
326 commpage_mach_approximate_time_init(void)
328 char *cp
= commPagePtr32
;
331 #ifdef CONFIG_MACH_APPROXIMATE_TIME
337 cp
+= (_COMM_PAGE_APPROX_TIME_SUPPORTED
- _COMM_PAGE32_BASE_ADDRESS
);
338 *(boolean_t
*)cp
= supported
;
342 cp
+= (_COMM_PAGE_APPROX_TIME_SUPPORTED
- _COMM_PAGE32_START_ADDRESS
);
343 *(boolean_t
*)cp
= supported
;
345 commpage_update_mach_approximate_time(0);
350 _get_cpu_capabilities(void)
352 return _cpu_capabilities
;
355 /* Copy data into commpage. */
359 commpage_address_t address
,
363 void *dest
= commpage_addr_of(address
);
366 panic("commpage overlap at address 0x%p, 0x%x < 0x%x", dest
, address
, next
);
368 bcopy(source
,dest
,length
);
370 next
= address
+ length
;
373 /* Copy a routine into comm page if it matches running machine.
376 commpage_stuff_routine(
377 commpage_descriptor
*rd
)
379 commpage_stuff(rd
->commpage_address
,rd
->code_address
,rd
->code_length
);
382 /* Fill in the 32- or 64-bit commpage. Called once for each.
386 commpage_populate_one(
387 vm_map_t submap
, // commpage32_map or compage64_map
388 char ** kernAddressPtr
, // &commPagePtr32 or &commPagePtr64
389 size_t area_used
, // _COMM_PAGE32_AREA_USED or _COMM_PAGE64_AREA_USED
390 commpage_address_t base_offset
, // will become commPageBaseOffset
391 commpage_time_data
** time_data
, // &time_data32 or &time_data64
392 const char* signature
, // "commpage 32-bit" or "commpage 64-bit"
400 short version
= _COMM_PAGE_THIS_VERSION
;
403 commPagePtr
= (char *)commpage_allocate( submap
, (vm_size_t
) area_used
, uperm
);
404 *kernAddressPtr
= commPagePtr
; // save address either in commPagePtr32 or 64
405 commPageBaseOffset
= base_offset
;
407 *time_data
= commpage_addr_of( _COMM_PAGE_TIME_DATA_START
);
409 /* Stuff in the constants. We move things into the comm page in strictly
410 * ascending order, so we can check for overlap and panic if so.
411 * Note: the 32-bit cpu_capabilities vector is retained in addition to
412 * the expanded 64-bit vector.
414 commpage_stuff(_COMM_PAGE_SIGNATURE
,signature
,(int)MIN(_COMM_PAGE_SIGNATURELEN
, strlen(signature
)));
415 commpage_stuff(_COMM_PAGE_CPU_CAPABILITIES64
,&_cpu_capabilities
,sizeof(_cpu_capabilities
));
416 commpage_stuff(_COMM_PAGE_VERSION
,&version
,sizeof(short));
417 commpage_stuff(_COMM_PAGE_CPU_CAPABILITIES
,&_cpu_capabilities
,sizeof(uint32_t));
420 if (_cpu_capabilities
& kCache64
)
422 else if (_cpu_capabilities
& kCache128
)
424 commpage_stuff(_COMM_PAGE_CACHE_LINESIZE
,&c2
,2);
427 commpage_stuff(_COMM_PAGE_SPIN_COUNT
,&c4
,4);
429 /* machine_info valid after ml_get_max_cpus() */
430 c1
= machine_info
.physical_cpu_max
;
431 commpage_stuff(_COMM_PAGE_PHYSICAL_CPUS
,&c1
,1);
432 c1
= machine_info
.logical_cpu_max
;
433 commpage_stuff(_COMM_PAGE_LOGICAL_CPUS
,&c1
,1);
435 c8
= ml_cpu_cache_size(0);
436 commpage_stuff(_COMM_PAGE_MEMORY_SIZE
, &c8
, 8);
438 cfamily
= cpuid_info()->cpuid_cpufamily
;
439 commpage_stuff(_COMM_PAGE_CPUFAMILY
, &cfamily
, 4);
441 if (next
> _COMM_PAGE_END
)
442 panic("commpage overflow: next = 0x%08x, commPagePtr = 0x%p", next
, commPagePtr
);
447 /* Fill in commpages: called once, during kernel initialization, from the
448 * startup thread before user-mode code is running.
450 * See the top of this file for a list of what you have to do to add
451 * a new routine to the commpage.
455 commpage_populate( void )
457 commpage_init_cpu_capabilities();
459 commpage_populate_one( commpage32_map
,
461 _COMM_PAGE32_AREA_USED
,
462 _COMM_PAGE32_BASE_ADDRESS
,
467 pmap_commpage32_init((vm_offset_t
) commPagePtr32
, _COMM_PAGE32_BASE_ADDRESS
,
468 _COMM_PAGE32_AREA_USED
/INTEL_PGBYTES
);
470 time_data64
= time_data32
; /* if no 64-bit commpage, point to 32-bit */
472 if (_cpu_capabilities
& k64Bit
) {
473 commpage_populate_one( commpage64_map
,
475 _COMM_PAGE64_AREA_USED
,
476 _COMM_PAGE32_START_ADDRESS
, /* commpage address are relative to 32-bit commpage placement */
481 pmap_commpage64_init((vm_offset_t
) commPagePtr64
, _COMM_PAGE64_BASE_ADDRESS
,
482 _COMM_PAGE64_AREA_USED
/INTEL_PGBYTES
);
486 simple_lock_init(&commpage_active_cpus_lock
, 0);
488 commpage_update_active_cpus();
489 commpage_mach_approximate_time_init();
490 rtc_nanotime_init_commpage();
491 commpage_update_kdebug_enable();
493 commpage_update_atm_diagnostic_config(atm_get_diagnostic_config());
497 /* Fill in the common routines during kernel initialization.
498 * This is called before user-mode code is running.
500 void commpage_text_populate( void ){
501 commpage_descriptor
**rd
;
504 commPagePtr
= (char *) commpage_allocate(commpage_text32_map
, (vm_size_t
) _COMM_PAGE_TEXT_AREA_USED
, VM_PROT_READ
| VM_PROT_EXECUTE
);
505 commPageTextPtr32
= commPagePtr
;
507 char *cptr
= commPagePtr
;
509 for(; i
< _COMM_PAGE_TEXT_AREA_USED
; i
++){
513 commPageBaseOffset
= _COMM_PAGE_TEXT_START
;
514 for (rd
= commpage_32_routines
; *rd
!= NULL
; rd
++) {
515 commpage_stuff_routine(*rd
);
519 pmap_commpage32_init((vm_offset_t
) commPageTextPtr32
, _COMM_PAGE_TEXT_START
,
520 _COMM_PAGE_TEXT_AREA_USED
/INTEL_PGBYTES
);
523 if (_cpu_capabilities
& k64Bit
) {
525 commPagePtr
= (char *) commpage_allocate(commpage_text64_map
, (vm_size_t
) _COMM_PAGE_TEXT_AREA_USED
, VM_PROT_READ
| VM_PROT_EXECUTE
);
526 commPageTextPtr64
= commPagePtr
;
529 for(i
=0; i
<_COMM_PAGE_TEXT_AREA_USED
; i
++){
533 for (rd
= commpage_64_routines
; *rd
!=NULL
; rd
++) {
534 commpage_stuff_routine(*rd
);
538 pmap_commpage64_init((vm_offset_t
) commPageTextPtr64
, _COMM_PAGE_TEXT_START
,
539 _COMM_PAGE_TEXT_AREA_USED
/INTEL_PGBYTES
);
543 if (next
> _COMM_PAGE_TEXT_END
)
544 panic("commpage text overflow: next=0x%08x, commPagePtr=%p", next
, commPagePtr
);
548 /* Update commpage nanotime information.
550 * This routine must be serialized by some external means, ie a lock.
554 commpage_set_nanotime(
560 commpage_time_data
*p32
= time_data32
;
561 commpage_time_data
*p64
= time_data64
;
562 static uint32_t generation
= 0;
565 if (p32
== NULL
) /* have commpages been allocated yet? */
568 if ( generation
!= p32
->nt_generation
)
569 panic("nanotime trouble 1"); /* possibly not serialized */
570 if ( ns_base
< p32
->nt_ns_base
)
571 panic("nanotime trouble 2");
572 if ((shift
!= 0) && ((_cpu_capabilities
& kSlow
)==0) )
573 panic("nanotime trouble 3");
575 next_gen
= ++generation
;
577 next_gen
= ++generation
;
579 p32
->nt_generation
= 0; /* mark invalid, so commpage won't try to use it */
580 p64
->nt_generation
= 0;
582 p32
->nt_tsc_base
= tsc_base
;
583 p64
->nt_tsc_base
= tsc_base
;
585 p32
->nt_ns_base
= ns_base
;
586 p64
->nt_ns_base
= ns_base
;
588 p32
->nt_scale
= scale
;
589 p64
->nt_scale
= scale
;
591 p32
->nt_shift
= shift
;
592 p64
->nt_shift
= shift
;
594 p32
->nt_generation
= next_gen
; /* mark data as valid */
595 p64
->nt_generation
= next_gen
;
599 /* Disable commpage gettimeofday(), forcing commpage to call through to the kernel. */
602 commpage_disable_timestamp( void )
604 time_data32
->gtod_generation
= 0;
605 time_data64
->gtod_generation
= 0;
609 /* Update commpage gettimeofday() information. As with nanotime(), we interleave
610 * updates to the 32- and 64-bit commpage, in order to keep time more nearly in sync
611 * between the two environments.
613 * This routine must be serializeed by some external means, ie a lock.
617 commpage_set_timestamp(
621 commpage_time_data
*p32
= time_data32
;
622 commpage_time_data
*p64
= time_data64
;
623 static uint32_t generation
= 0;
626 next_gen
= ++generation
;
628 next_gen
= ++generation
;
630 p32
->gtod_generation
= 0; /* mark invalid, so commpage won't try to use it */
631 p64
->gtod_generation
= 0;
633 p32
->gtod_ns_base
= abstime
;
634 p64
->gtod_ns_base
= abstime
;
636 p32
->gtod_sec_base
= secs
;
637 p64
->gtod_sec_base
= secs
;
639 p32
->gtod_generation
= next_gen
; /* mark data as valid */
640 p64
->gtod_generation
= next_gen
;
644 /* Update _COMM_PAGE_MEMORY_PRESSURE. Called periodically from vm's compute_memory_pressure() */
647 commpage_set_memory_pressure(
648 unsigned int pressure
)
655 cp
+= (_COMM_PAGE_MEMORY_PRESSURE
- _COMM_PAGE32_BASE_ADDRESS
);
656 ip
= (uint32_t*) (void *) cp
;
657 *ip
= (uint32_t) pressure
;
662 cp
+= (_COMM_PAGE_MEMORY_PRESSURE
- _COMM_PAGE32_START_ADDRESS
);
663 ip
= (uint32_t*) (void *) cp
;
664 *ip
= (uint32_t) pressure
;
670 /* Update _COMM_PAGE_SPIN_COUNT. We might want to reduce when running on a battery, etc. */
673 commpage_set_spin_count(
679 if (count
== 0) /* we test for 0 after decrement, not before */
684 cp
+= (_COMM_PAGE_SPIN_COUNT
- _COMM_PAGE32_BASE_ADDRESS
);
685 ip
= (uint32_t*) (void *) cp
;
686 *ip
= (uint32_t) count
;
691 cp
+= (_COMM_PAGE_SPIN_COUNT
- _COMM_PAGE32_START_ADDRESS
);
692 ip
= (uint32_t*) (void *) cp
;
693 *ip
= (uint32_t) count
;
698 /* Updated every time a logical CPU goes offline/online */
700 commpage_update_active_cpus(void)
703 volatile uint8_t *ip
;
705 /* At least 32-bit commpage must be initialized */
709 simple_lock(&commpage_active_cpus_lock
);
712 cp
+= (_COMM_PAGE_ACTIVE_CPUS
- _COMM_PAGE32_BASE_ADDRESS
);
713 ip
= (volatile uint8_t*) cp
;
714 *ip
= (uint8_t) processor_avail_count
;
718 cp
+= (_COMM_PAGE_ACTIVE_CPUS
- _COMM_PAGE32_START_ADDRESS
);
719 ip
= (volatile uint8_t*) cp
;
720 *ip
= (uint8_t) processor_avail_count
;
723 simple_unlock(&commpage_active_cpus_lock
);
727 * Update the commpage data with the value of the "kdebug_enable"
728 * global so that userspace can avoid trapping into the kernel
729 * for kdebug_trace() calls. Serialization is handled
730 * by the caller in bsd/kern/kdebug.c.
733 commpage_update_kdebug_enable(void)
735 volatile uint32_t *saved_data_ptr
;
740 cp
+= (_COMM_PAGE_KDEBUG_ENABLE
- _COMM_PAGE32_BASE_ADDRESS
);
741 saved_data_ptr
= (volatile uint32_t *)cp
;
742 *saved_data_ptr
= kdebug_enable
;
747 cp
+= (_COMM_PAGE_KDEBUG_ENABLE
- _COMM_PAGE32_START_ADDRESS
);
748 saved_data_ptr
= (volatile uint32_t *)cp
;
749 *saved_data_ptr
= kdebug_enable
;
753 /* Ditto for atm_diagnostic_config */
755 commpage_update_atm_diagnostic_config(uint32_t diagnostic_config
)
757 volatile uint32_t *saved_data_ptr
;
762 cp
+= (_COMM_PAGE_ATM_DIAGNOSTIC_CONFIG
- _COMM_PAGE32_BASE_ADDRESS
);
763 saved_data_ptr
= (volatile uint32_t *)cp
;
764 *saved_data_ptr
= diagnostic_config
;
769 cp
+= (_COMM_PAGE_ATM_DIAGNOSTIC_CONFIG
- _COMM_PAGE32_START_ADDRESS
);
770 saved_data_ptr
= (volatile uint32_t *)cp
;
771 *saved_data_ptr
= diagnostic_config
;
776 * update the commpage data for last known value of mach_absolute_time()
780 commpage_update_mach_approximate_time(uint64_t abstime
)
782 #ifdef CONFIG_MACH_APPROXIMATE_TIME
788 cp
+= (_COMM_PAGE_APPROX_TIME
- _COMM_PAGE32_BASE_ADDRESS
);
789 saved_data
= *(uint64_t *)cp
;
790 if (saved_data
< abstime
) {
791 /* ignoring the success/fail return value assuming that
792 * if the value has been updated since we last read it,
793 * "someone" has a newer timestamp than us and ours is
795 OSCompareAndSwap64(saved_data
, abstime
, (uint64_t *)cp
);
800 cp
+= (_COMM_PAGE_APPROX_TIME
- _COMM_PAGE32_START_ADDRESS
);
801 saved_data
= *(uint64_t *)cp
;
802 if (saved_data
< abstime
) {
803 /* ignoring the success/fail return value assuming that
804 * if the value has been updated since we last read it,
805 * "someone" has a newer timestamp than us and ours is
807 OSCompareAndSwap64(saved_data
, abstime
, (uint64_t *)cp
);
811 #pragma unused (abstime)
816 extern user32_addr_t commpage_text32_location
;
817 extern user64_addr_t commpage_text64_location
;
819 /* Check to see if a given address is in the Preemption Free Zone (PFZ) */
822 commpage_is_in_pfz32(uint32_t addr32
)
824 if ( (addr32
>= (commpage_text32_location
+ _COMM_TEXT_PFZ_START_OFFSET
))
825 && (addr32
< (commpage_text32_location
+_COMM_TEXT_PFZ_END_OFFSET
))) {
833 commpage_is_in_pfz64(addr64_t addr64
)
835 if ( (addr64
>= (commpage_text64_location
+ _COMM_TEXT_PFZ_START_OFFSET
))
836 && (addr64
< (commpage_text64_location
+ _COMM_TEXT_PFZ_END_OFFSET
))) {