2 * Copyright (c) 1998-2018 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@
28 #include <IOKit/IOBSD.h>
29 #include <IOKit/IOLib.h>
30 #include <IOKit/IOService.h>
31 #include <IOKit/IOCatalogue.h>
32 #include <IOKit/IODeviceTreeSupport.h>
33 #include <IOKit/IOKitKeys.h>
34 #include <IOKit/IOPlatformExpert.h>
35 #include <IOKit/IOUserClient.h>
39 #include <pexpert/pexpert.h>
40 #include <kern/clock.h>
41 #include <uuid/uuid.h>
42 #include <sys/vnode_internal.h>
43 #include <sys/mount.h>
45 // how long to wait for matching root device, secs
47 #define ROOTDEVICETIMEOUT 120
49 #define ROOTDEVICETIMEOUT 60
52 int panic_on_exception_triage
= 0;
54 extern dev_t
mdevadd(int devid
, uint64_t base
, unsigned int size
, int phys
);
55 extern dev_t
mdevlookup(int devid
);
56 extern void mdevremoveall(void);
57 extern int mdevgetrange(int devid
, uint64_t *base
, uint64_t *size
);
58 extern void di_root_ramfile(IORegistryEntry
* entry
);
62 #define IOPOLLED_COREFILE (CONFIG_KDP_INTERACTIVE_DEBUGGING)
64 #if defined(XNU_TARGET_OS_BRIDGE)
65 #define kIOCoreDumpSize 150ULL*1024ULL*1024ULL
66 // leave free space on volume:
67 #define kIOCoreDumpFreeSize 150ULL*1024ULL*1024ULL
68 #define kIOCoreDumpPath "/private/var/internal/kernelcore"
70 #define kIOCoreDumpSize 350ULL*1024ULL*1024ULL
71 // leave free space on volume:
72 #define kIOCoreDumpFreeSize 350ULL*1024ULL*1024ULL
73 #define kIOCoreDumpPath "/private/var/vm/kernelcore"
77 #define IOPOLLED_COREFILE 1
79 #define kIOCoreDumpSize 0ULL
80 #define kIOCoreDumpFreeSize 0ULL
82 #define IOPOLLED_COREFILE 0
88 NewKernelCoreMedia(void * target
, void * refCon
,
89 IOService
* newService
,
90 IONotifier
* notifier
);
91 #endif /* IOPOLLED_COREFILE */
93 #if CONFIG_KDP_INTERACTIVE_DEBUGGING
95 * Touched by IOFindBSDRoot() if a RAMDisk is used for the root device.
97 extern uint64_t kdp_core_ramdisk_addr
;
98 extern uint64_t kdp_core_ramdisk_size
;
104 IOService::publishResource("IOBSD");
106 return( kIOReturnSuccess
);
110 IOServicePublishResource( const char * property
, boolean_t value
)
113 IOService::publishResource( property
, kOSBooleanTrue
);
115 IOService::getResourceService()->removeProperty( property
);
119 IOServiceWaitForMatchingResource( const char * property
, uint64_t timeout
)
121 OSDictionary
* dict
= 0;
122 IOService
* match
= 0;
123 boolean_t found
= false;
127 dict
= IOService::resourceMatching( property
);
130 match
= IOService::waitForMatchingService( dict
, timeout
);
145 IOCatalogueMatchingDriversPresent( const char * property
)
147 OSDictionary
* dict
= 0;
148 OSOrderedSet
* set
= 0;
149 SInt32 generationCount
= 0;
150 boolean_t found
= false;
154 dict
= OSDictionary::withCapacity(1);
157 dict
->setObject( property
, kOSBooleanTrue
);
158 set
= gIOCatalogue
->findDrivers( dict
, &generationCount
);
159 if ( set
&& (set
->getCount() > 0))
172 OSDictionary
* IOBSDNameMatching( const char * name
)
175 const OSSymbol
* str
= 0;
179 dict
= IOService::serviceMatching( gIOServiceKey
);
182 str
= OSSymbol::withCString( name
);
185 dict
->setObject( kIOBSDNameKey
, (OSObject
*) str
);
200 OSDictionary
* IOUUIDMatching( void )
202 return IOService::resourceMatching( "boot-uuid-media" );
205 OSDictionary
* IONetworkNamePrefixMatching( const char * prefix
)
207 OSDictionary
* matching
;
208 OSDictionary
* propDict
= 0;
209 const OSSymbol
* str
= 0;
210 char networkType
[128];
213 matching
= IOService::serviceMatching( "IONetworkInterface" );
217 propDict
= OSDictionary::withCapacity(1);
221 str
= OSSymbol::withCString( prefix
);
225 propDict
->setObject( "IOInterfaceNamePrefix", (OSObject
*) str
);
229 // see if we're contrained to netroot off of specific network type
230 if(PE_parse_boot_argn( "network-type", networkType
, 128 ))
232 str
= OSSymbol::withCString( networkType
);
235 propDict
->setObject( "IONetworkRootType", str
);
241 if ( matching
->setObject( gIOPropertyMatchKey
,
242 (OSObject
*) propDict
) != true )
252 if ( matching
) matching
->release();
253 if ( propDict
) propDict
->release();
254 if ( str
) str
->release();
259 static bool IORegisterNetworkInterface( IOService
* netif
)
261 // A network interface is typically named and registered
262 // with BSD after receiving a request from a user space
263 // "namer". However, for cases when the system needs to
264 // root from the network, this registration task must be
265 // done inside the kernel and completed before the root
266 // device is handed to BSD.
271 OSDictionary
* dict
= 0;
274 enum { kMaxPathLen
= 512 };
277 stack
= IOService::waitForService(
278 IOService::serviceMatching("IONetworkStack") );
279 if ( stack
== 0 ) break;
281 dict
= OSDictionary::withCapacity(3);
282 if ( dict
== 0 ) break;
284 zero
= OSNumber::withNumber((UInt64
) 0, 32);
285 if ( zero
== 0 ) break;
287 pathBuf
= (char *) IOMalloc( kMaxPathLen
);
288 if ( pathBuf
== 0 ) break;
291 if ( netif
->getPath( pathBuf
, &len
, gIOServicePlane
)
294 path
= OSString::withCStringNoCopy( pathBuf
);
295 if ( path
== 0 ) break;
297 dict
->setObject( "IOInterfaceUnit", zero
);
298 dict
->setObject( kIOPathMatchKey
, path
);
300 stack
->setProperties( dict
);
304 if ( zero
) zero
->release();
305 if ( path
) path
->release();
306 if ( dict
) dict
->release();
307 if ( pathBuf
) IOFree(pathBuf
, kMaxPathLen
);
309 return ( netif
->getProperty( kIOBSDNameKey
) != 0 );
312 OSDictionary
* IOOFPathMatching( const char * path
, char * buf
, int maxLen
)
314 OSDictionary
* matching
= NULL
;
321 len
= strlen( kIODeviceTreePlane
":" );
326 strlcpy( buf
, kIODeviceTreePlane
":", len
+ 1 );
329 len
= strlen( path
);
333 strlcpy( comp
, path
, len
+ 1 );
335 matching
= OSDictionary::withCapacity( 1 );
339 str
= OSString::withCString( buf
);
342 matching
->setObject( kIOPathMatchKey
, str
);
355 static int didRam
= 0;
356 enum { kMaxPathBuf
= 512, kMaxBootVar
= 128 };
358 kern_return_t
IOFindBSDRoot( char * rootName
, unsigned int rootNameSize
,
359 dev_t
* root
, u_int32_t
* oflags
)
363 IORegistryEntry
* regEntry
;
364 OSDictionary
* matching
= 0;
371 const char * mediaProperty
= 0;
374 const char * look
= 0;
376 bool debugInfoPrintedOnce
= false;
377 const char * uuidStr
= NULL
;
379 static int mountAttempts
= 0;
383 // stall here for anyone matching on the IOBSD resource to finish (filesystems)
384 matching
= IOService::serviceMatching(gIOResourcesKey
);
386 matching
->setObject(gIOResourceMatchedKey
, gIOBSDKey
);
388 if ((service
= IOService::waitForMatchingService(matching
, 30ULL * kSecondScale
))) {
398 IOLog("mount(%d) failed\n", mountAttempts
);
402 str
= (char *) IOMalloc( kMaxPathBuf
+ kMaxBootVar
);
404 return( kIOReturnNoMemory
);
405 rdBootVar
= str
+ kMaxPathBuf
;
407 if (!PE_parse_boot_argn("rd", rdBootVar
, kMaxBootVar
)
408 && !PE_parse_boot_argn("rootdev", rdBootVar
, kMaxBootVar
))
412 if( (regEntry
= IORegistryEntry::fromPath( "/chosen", gIODTPlane
))) {
413 di_root_ramfile(regEntry
);
414 data
= OSDynamicCast(OSData
, regEntry
->getProperty( "root-matching" ));
416 matching
= OSDynamicCast(OSDictionary
, OSUnserializeXML((char *)data
->getBytesNoCopy()));
422 data
= (OSData
*) regEntry
->getProperty( "boot-uuid" );
424 uuidStr
= (const char*)data
->getBytesNoCopy();
425 OSString
*uuidString
= OSString::withCString( uuidStr
);
427 // match the boot-args boot-uuid processing below
429 IOLog("rooting via boot-uuid from /chosen: %s\n", uuidStr
);
430 IOService::publishResource( "boot-uuid", uuidString
);
431 uuidString
->release();
432 matching
= IOUUIDMatching();
433 mediaProperty
= "boot-uuid-media";
445 // See if we have a RAMDisk property in /chosen/memory-map. If so, make it into a device.
446 // It will become /dev/mdx, where x is 0-f.
449 if(!didRam
) { /* Have we already build this ram disk? */
450 didRam
= 1; /* Remember we did this */
451 if((regEntry
= IORegistryEntry::fromPath( "/chosen/memory-map", gIODTPlane
))) { /* Find the map node */
452 data
= (OSData
*)regEntry
->getProperty("RAMDisk"); /* Find the ram disk, if there */
453 if(data
) { /* We found one */
454 uintptr_t *ramdParms
;
455 ramdParms
= (uintptr_t *)data
->getBytesNoCopy(); /* Point to the ram disk base and size */
456 (void)mdevadd(-1, ml_static_ptovirt(ramdParms
[0]) >> 12, ramdParms
[1] >> 12, 0); /* Initialize it and pass back the device number */
458 regEntry
->release(); /* Toss the entry */
463 // Now check if we are trying to root on a memory device
466 if((rdBootVar
[0] == 'm') && (rdBootVar
[1] == 'd') && (rdBootVar
[3] == 0)) {
467 dchar
= xchar
= rdBootVar
[2]; /* Get the actual device */
468 if((xchar
>= '0') && (xchar
<= '9')) xchar
= xchar
- '0'; /* If digit, convert */
470 xchar
= xchar
& ~' '; /* Fold to upper case */
471 if((xchar
>= 'A') && (xchar
<= 'F')) { /* Is this a valid digit? */
472 xchar
= (xchar
& 0xF) + 9; /* Convert the hex digit */
473 dchar
= dchar
| ' '; /* Fold to lower case */
475 else xchar
= -1; /* Show bogus */
477 if(xchar
>= 0) { /* Do we have a valid memory device name? */
478 *root
= mdevlookup(xchar
); /* Find the device number */
479 if(*root
>= 0) { /* Did we find one? */
480 rootName
[0] = 'm'; /* Build root name */
481 rootName
[1] = 'd'; /* Build root name */
482 rootName
[2] = dchar
; /* Build root name */
483 rootName
[3] = 0; /* Build root name */
484 IOLog("BSD root: %s, major %d, minor %d\n", rootName
, major(*root
), minor(*root
));
485 *oflags
= 0; /* Show that this is not network */
487 #if CONFIG_KDP_INTERACTIVE_DEBUGGING
488 /* retrieve final ramdisk range and initialize KDP variables */
489 if (mdevgetrange(xchar
, &kdp_core_ramdisk_addr
, &kdp_core_ramdisk_size
) != 0) {
490 IOLog("Unable to retrieve range for root memory device %d\n", xchar
);
491 kdp_core_ramdisk_addr
= 0;
492 kdp_core_ramdisk_size
= 0;
496 goto iofrootx
; /* Join common exit... */
498 panic("IOFindBSDRoot: specified root memory device, %s, has not been configured\n", rdBootVar
); /* Not there */
502 if( (!matching
) && rdBootVar
[0] ) {
508 if ( strncmp( look
, "en", strlen( "en" )) == 0 ) {
509 matching
= IONetworkNamePrefixMatching( "en" );
510 } else if ( strncmp( look
, "uuid", strlen( "uuid" )) == 0 ) {
512 OSString
*uuidString
;
514 uuid
= (char *)IOMalloc( kMaxBootVar
);
517 if (!PE_parse_boot_argn( "boot-uuid", uuid
, kMaxBootVar
)) {
518 panic( "rd=uuid but no boot-uuid=<value> specified" );
520 uuidString
= OSString::withCString( uuid
);
522 IOService::publishResource( "boot-uuid", uuidString
);
523 uuidString
->release();
524 IOLog( "\nWaiting for boot volume with UUID %s\n", uuid
);
525 matching
= IOUUIDMatching();
526 mediaProperty
= "boot-uuid-media";
528 IOFree( uuid
, kMaxBootVar
);
531 matching
= IOBSDNameMatching( look
);
537 // Match any HFS media
539 matching
= IOService::serviceMatching( "IOMedia" );
540 astring
= OSString::withCStringNoCopy("Apple_HFS");
542 matching
->setObject("Content", astring
);
547 if( gIOKitDebug
& kIOWaitQuietBeforeRoot
) {
548 IOLog( "Waiting for matching to complete\n" );
549 IOService::getPlatform()->waitQuiet();
552 if( true && matching
) {
553 OSSerialize
* s
= OSSerialize::withCapacity( 5 );
555 if( matching
->serialize( s
)) {
556 IOLog( "Waiting on %s\n", s
->text() );
562 t
.tv_sec
= ROOTDEVICETIMEOUT
;
565 service
= IOService::waitForService( matching
, &t
);
566 if( (!service
) || (mountAttempts
== 10)) {
567 PE_display_icon( 0, "noroot");
568 IOLog( "Still waiting for root device\n" );
570 if( !debugInfoPrintedOnce
) {
571 debugInfoPrintedOnce
= true;
572 if( gIOKitDebug
& kIOLogDTree
) {
573 IOLog("\nDT plane:\n");
574 IOPrintPlane( gIODTPlane
);
576 if( gIOKitDebug
& kIOLogServiceTree
) {
577 IOLog("\nService plane:\n");
578 IOPrintPlane( gIOServicePlane
);
580 if( gIOKitDebug
& kIOLogMemory
)
587 if ( service
&& mediaProperty
) {
588 service
= (IOService
*)service
->getProperty(mediaProperty
);
594 // If the IOService we matched to is a subclass of IONetworkInterface,
595 // then make sure it has been registered with BSD and has a BSD name
599 && service
->metaCast( "IONetworkInterface" )
600 && !IORegisterNetworkInterface( service
) )
608 service
->getPath( str
, &len
, gIOServicePlane
);
609 IOLog( "Got boot device = %s\n", str
);
611 iostr
= (OSString
*) service
->getProperty( kIOBSDNameKey
);
613 strlcpy( rootName
, iostr
->getCStringNoCopy(), rootNameSize
);
614 off
= (OSNumber
*) service
->getProperty( kIOBSDMajorKey
);
616 mjr
= off
->unsigned32BitValue();
617 off
= (OSNumber
*) service
->getProperty( kIOBSDMinorKey
);
619 mnr
= off
->unsigned32BitValue();
621 if( service
->metaCast( "IONetworkInterface" ))
626 IOLog( "Wait for root failed\n" );
627 strlcpy( rootName
, "en0", rootNameSize
);
631 IOLog( "BSD root: %s", rootName
);
633 IOLog(", major %d, minor %d\n", mjr
, mnr
);
637 *root
= makedev( mjr
, mnr
);
640 IOFree( str
, kMaxPathBuf
+ kMaxBootVar
);
643 if( (gIOKitDebug
& (kIOLogDTree
| kIOLogServiceTree
| kIOLogMemory
)) && !debugInfoPrintedOnce
) {
645 IOService::getPlatform()->waitQuiet();
646 if( gIOKitDebug
& kIOLogDTree
) {
647 IOLog("\nDT plane:\n");
648 IOPrintPlane( gIODTPlane
);
650 if( gIOKitDebug
& kIOLogServiceTree
) {
651 IOLog("\nService plane:\n");
652 IOPrintPlane( gIOServicePlane
);
654 if( gIOKitDebug
& kIOLogMemory
)
658 return( kIOReturnSuccess
);
661 bool IORamDiskBSDRoot(void)
663 char rdBootVar
[kMaxBootVar
];
664 if (PE_parse_boot_argn("rd", rdBootVar
, kMaxBootVar
)
665 || PE_parse_boot_argn("rootdev", rdBootVar
, kMaxBootVar
)) {
666 if((rdBootVar
[0] == 'm') && (rdBootVar
[1] == 'd') && (rdBootVar
[3] == 0)) {
673 void IOSecureBSDRoot(const char * rootName
)
678 IOPlatformExpert
*pe
;
679 OSDictionary
*matching
;
680 const OSSymbol
*functionName
= OSSymbol::withCStringNoCopy("SecureRootName");
682 matching
= IOService::serviceMatching("IOPlatformExpert");
684 pe
= (IOPlatformExpert
*) IOService::waitForMatchingService(matching
, 30ULL * kSecondScale
);
687 // Returns kIOReturnNotPrivileged is the root device is not secure.
688 // Returns kIOReturnUnsupported if "SecureRootName" is not implemented.
689 result
= pe
->callPlatformFunction(functionName
, false, (void *)rootName
, (void *)0, (void *)0, (void *)0);
690 functionName
->release();
691 OSSafeReleaseNULL(pe
);
693 if (result
== kIOReturnNotPrivileged
) {
695 } else if (result
== kIOReturnSuccess
) {
696 // If we are booting with a secure root, and we have the right
697 // boot-arg, we will want to panic on exception triage. This
698 // behavior is intended as a debug aid (we can look at why an
699 // exception occured in the kernel debugger).
700 if (PE_parse_boot_argn("-panic_on_exception_triage", &tmpInt
, sizeof(tmpInt
))) {
701 panic_on_exception_triage
= 1;
705 #endif // CONFIG_EMBEDDED
709 IOBSDRegistryEntryForDeviceTree(char * path
)
711 return (IORegistryEntry::fromPath(path
, gIODTPlane
));
715 IOBSDRegistryEntryRelease(void * entry
)
717 IORegistryEntry
* regEntry
= (IORegistryEntry
*)entry
;
725 IOBSDRegistryEntryGetData(void * entry
, char * property_name
,
729 IORegistryEntry
* regEntry
= (IORegistryEntry
*)entry
;
731 data
= (OSData
*) regEntry
->getProperty(property_name
);
733 *packet_length
= data
->getLength();
734 return (data
->getBytesNoCopy());
739 kern_return_t
IOBSDGetPlatformUUID( uuid_t uuid
, mach_timespec_t timeout
)
741 IOService
* resources
;
744 resources
= IOService::waitForService( IOService::resourceMatching( kIOPlatformUUIDKey
), ( timeout
.tv_sec
|| timeout
.tv_nsec
) ? &timeout
: 0 );
745 if ( resources
== 0 ) return KERN_OPERATION_TIMED_OUT
;
747 string
= ( OSString
* ) IOService::getPlatform( )->getProvider( )->getProperty( kIOPlatformUUIDKey
);
748 if ( string
== 0 ) return KERN_NOT_SUPPORTED
;
750 uuid_parse( string
->getCStringNoCopy( ), uuid
);
757 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
759 #include <sys/conf.h>
760 #include <sys/vnode.h>
761 #include <sys/vnode_internal.h>
762 #include <sys/fcntl.h>
763 #include <IOKit/IOPolledInterface.h>
764 #include <IOKit/IOBufferMemoryDescriptor.h>
766 IOPolledFileIOVars
* gIOPolledCoreFileVars
;
768 #if IOPOLLED_COREFILE
771 IOOpenPolledCoreFile(const char * filename
)
776 if (gIOPolledCoreFileVars
) return (kIOReturnBusy
);
777 if (!IOPolledInterface::gMetaClass
.getInstanceCount()) return (kIOReturnUnsupported
);
780 PE_parse_boot_argn("debug", &debug
, sizeof (debug
));
781 if (DB_DISABLE_LOCAL_CORE
& debug
) return (kIOReturnUnsupported
);
783 err
= IOPolledFileOpen(filename
, kIOCoreDumpSize
, kIOCoreDumpFreeSize
,
785 &gIOPolledCoreFileVars
, NULL
, NULL
, 0);
786 if (kIOReturnSuccess
!= err
) return (err
);
788 err
= IOPolledFilePollersSetup(gIOPolledCoreFileVars
, kIOPolledPreflightCoreDumpState
);
789 if (kIOReturnSuccess
!= err
)
791 IOPolledFileClose(&gIOPolledCoreFileVars
, NULL
, NULL
, 0, 0, 0);
798 IOClosePolledCoreFile(void)
800 IOPolledFilePollersClose(gIOPolledCoreFileVars
, kIOPolledPostflightCoreDumpState
);
801 IOPolledFileClose(&gIOPolledCoreFileVars
, NULL
, NULL
, 0, 0, 0);
804 static thread_call_t gIOOpenPolledCoreFileTC
;
805 static IONotifier
* gIOPolledCoreFileNotifier
;
806 static IONotifier
* gIOPolledCoreFileInterestNotifier
;
809 KernelCoreMediaInterest(void * target
, void * refCon
,
810 UInt32 messageType
, IOService
* provider
,
811 void * messageArgument
, vm_size_t argSize
)
813 if (kIOMessageServiceIsTerminated
== messageType
)
815 gIOPolledCoreFileInterestNotifier
->remove();
816 gIOPolledCoreFileInterestNotifier
= 0;
817 IOClosePolledCoreFile();
820 return (kIOReturnSuccess
);
824 OpenKernelCoreMedia(thread_call_param_t p0
, thread_call_param_t p1
)
826 IOService
* newService
;
830 newService
= (IOService
*) p1
;
833 if (gIOPolledCoreFileVars
) break;
834 string
= OSDynamicCast(OSString
, newService
->getProperty(kIOBSDNameKey
));
836 snprintf(filename
, sizeof(filename
), "/dev/%s", string
->getCStringNoCopy());
837 if (kIOReturnSuccess
!= IOOpenPolledCoreFile(filename
)) break;
838 gIOPolledCoreFileInterestNotifier
= newService
->registerInterest(
839 gIOGeneralInterest
, &KernelCoreMediaInterest
, NULL
, 0);
843 newService
->release();
847 NewKernelCoreMedia(void * target
, void * refCon
,
848 IOService
* newService
,
849 IONotifier
* notifier
)
851 static volatile UInt32 onlyOneCorePartition
= 0;
854 if (!OSCompareAndSwap(0, 1, &onlyOneCorePartition
)) break;
855 if (gIOPolledCoreFileVars
) break;
856 if (!gIOOpenPolledCoreFileTC
) break;
857 newService
= newService
->getProvider();
858 if (!newService
) break;
859 newService
->retain();
860 thread_call_enter1(gIOOpenPolledCoreFileTC
, newService
);
867 #endif /* IOPOLLED_COREFILE */
870 IOBSDMountChange(struct mount
* mp
, uint32_t op
)
872 #if IOPOLLED_COREFILE
874 OSDictionary
* bsdMatching
;
875 OSDictionary
* mediaMatching
;
878 if (!gIOPolledCoreFileNotifier
) do
880 if (!gIOOpenPolledCoreFileTC
) gIOOpenPolledCoreFileTC
= thread_call_allocate(&OpenKernelCoreMedia
, NULL
);
881 bsdMatching
= IOService::serviceMatching("IOMediaBSDClient");
882 if (!bsdMatching
) break;
883 mediaMatching
= IOService::serviceMatching("IOMedia");
884 string
= OSString::withCStringNoCopy("5361644D-6163-11AA-AA11-00306543ECAC");
885 if (!string
|| !mediaMatching
) break;
886 mediaMatching
->setObject("Content", string
);
888 bsdMatching
->setObject(gIOParentMatchKey
, mediaMatching
);
889 mediaMatching
->release();
891 gIOPolledCoreFileNotifier
= IOService::addMatchingNotification(
892 gIOFirstMatchNotification
, bsdMatching
,
893 &NewKernelCoreMedia
, NULL
, NULL
, -1000);
906 case kIOMountChangeMount
:
907 case kIOMountChangeDidResize
:
909 if (gIOPolledCoreFileVars
) break;
910 flags
= vfs_flags(mp
);
911 if (MNT_RDONLY
& flags
) break;
912 if (!(MNT_LOCAL
& flags
)) break;
914 vn
= vfs_vnodecovered(mp
);
916 pathLen
= sizeof(path
);
917 result
= vn_getpath(vn
, &path
[0], &pathLen
);
919 if (0 != result
) break;
921 #if defined(XNU_TARGET_OS_BRIDGE)
922 // on bridgeOS systems we put the core in /private/var/internal. We don't
923 // want to match with /private/var because /private/var/internal is often mounted
925 if ((pathLen
- 1) < (int) strlen("/private/var/internal")) break;
927 if (0 != strncmp(path
, kIOCoreDumpPath
, pathLen
- 1)) break;
928 IOOpenPolledCoreFile(kIOCoreDumpPath
);
931 case kIOMountChangeUnmount
:
932 case kIOMountChangeWillResize
:
933 if (gIOPolledCoreFileVars
&& (mp
== kern_file_mount(gIOPolledCoreFileVars
->fileRef
)))
935 IOClosePolledCoreFile();
939 #endif /* CONFIG_EMBEDDED */
940 #endif /* IOPOLLED_COREFILE */
944 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
947 IOTaskHasEntitlement(task_t task
, const char * entitlement
)
950 obj
= IOUserClient::copyClientEntitlement(task
, entitlement
);
951 if (!obj
) return (false);
953 return (obj
!= kOSBooleanFalse
);