From e7c99d92bf4e4d1189c904195ed317951f9a35ad Mon Sep 17 00:00:00 2001 From: Apple Date: Sat, 9 Aug 2003 00:06:40 +0000 Subject: [PATCH] xnu-124.7.tar.gz --- bsd/conf/version.variant | 1 + bsd/hfs/hfs_vfsutils.c | 5 +- bsd/hfs/hfs_vnodeops.c | 2 +- bsd/hfs/hfscommon/Catalog/Catalog.c | 3 +- bsd/kern/kern_sysctl.c | 7 ++ bsd/kern/sys_generic.c | 5 +- .../drvAppleADBDevices/AppleADBButtons.cpp | 19 ++++++ .../drvAppleADBDevices/AppleADBKeyboard.cpp | 13 ++-- .../drvAppleADBDevices/AppleADBKeyboard.h | 5 +- .../IONDRVSupport/IONDRVFramebuffer.cpp | 27 ++++++++ .../IONDRVSupport/IONDRVLibraries.cpp | 7 +- .../IOStorage/IOBlockStorageDriver.cpp | 4 +- iokit/IOKit/IOServicePM.h | 3 + iokit/IOKit/adb/IOADBDevice.h | 6 ++ iokit/IOKit/ndrvsupport/IONDRVFramebuffer.h | 2 + iokit/Kernel/IOServicePM.cpp | 40 ++++++++++- iokit/KernelConfigTables.cpp | 30 ++++---- iokit/conf/version.variant | 1 + libkern/conf/version.variant | 1 + libsa/conf/version.variant | 1 + osfmk/conf/kernelversion.variant | 2 +- osfmk/conf/version.variant | 2 +- osfmk/kern/bsd_kern.c | 3 +- osfmk/kern/sched_prim.c | 18 ++--- osfmk/kern/task.c | 68 ++++++++++++------- osfmk/kern/thread_act.c | 41 +++-------- pexpert/conf/version.variant | 1 + 27 files changed, 214 insertions(+), 103 deletions(-) diff --git a/bsd/conf/version.variant b/bsd/conf/version.variant index e69de29bb..0cfbf0888 100644 --- a/bsd/conf/version.variant +++ b/bsd/conf/version.variant @@ -0,0 +1 @@ +2 diff --git a/bsd/hfs/hfs_vfsutils.c b/bsd/hfs/hfs_vfsutils.c index 93062300d..36c3e550e 100644 --- a/bsd/hfs/hfs_vfsutils.c +++ b/bsd/hfs/hfs_vfsutils.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -2866,6 +2866,7 @@ void UnpackCommonAttributeBlock(struct attrlist *alist, catInfo->nodeData.cnd_contentModDate = to_hfs_time((UInt32)((struct timespec *)attrbufptr)->tv_sec); VTOH(vp)->h_meta->h_mtime = (UInt32)((struct timespec *)attrbufptr)->tv_sec; ++((struct timespec *)attrbufptr); + hp->h_nodeflags &= ~IN_UPDATE; #if HFS_DIAGNOSTIC a &= ~ATTR_CMN_MODTIME; #endif @@ -2874,6 +2875,7 @@ void UnpackCommonAttributeBlock(struct attrlist *alist, catInfo->nodeData.cnd_attributeModDate = to_hfs_time((UInt32)((struct timespec *)attrbufptr)->tv_sec); VTOH(vp)->h_meta->h_ctime = (UInt32)((struct timespec *)attrbufptr)->tv_sec; ++((struct timespec *)attrbufptr); + hp->h_nodeflags &= ~IN_CHANGE; #if HFS_DIAGNOSTIC a &= ~ATTR_CMN_CHGTIME; #endif @@ -2882,6 +2884,7 @@ void UnpackCommonAttributeBlock(struct attrlist *alist, catInfo->nodeData.cnd_accessDate = to_hfs_time((UInt32)((struct timespec *)attrbufptr)->tv_sec); VTOH(vp)->h_meta->h_atime = (UInt32)((struct timespec *)attrbufptr)->tv_sec; ++((struct timespec *)attrbufptr); + hp->h_nodeflags &= ~IN_ACCESS; #if HFS_DIAGNOSTIC a &= ~ATTR_CMN_ACCTIME; #endif diff --git a/bsd/hfs/hfs_vnodeops.c b/bsd/hfs/hfs_vnodeops.c index 14a784ee9..f922b4471 100644 --- a/bsd/hfs/hfs_vnodeops.c +++ b/bsd/hfs/hfs_vnodeops.c @@ -3227,7 +3227,7 @@ struct vop_readdir_args /* { goto Exit; } - diroffset = uio->uio_offset; + diroffset = uio->uio_offset - sizeof(rootdots); /* lock catalog b-tree */ retval = hfs_metafilelocking(VTOHFS(ap->a_vp), kHFSCatalogFileID, LK_SHARED, p); diff --git a/bsd/hfs/hfscommon/Catalog/Catalog.c b/bsd/hfs/hfscommon/Catalog/Catalog.c index c71d5c7f9..d200f63ec 100644 --- a/bsd/hfs/hfscommon/Catalog/Catalog.c +++ b/bsd/hfs/hfscommon/Catalog/Catalog.c @@ -797,7 +797,6 @@ GetDirEntrySize(BTreeIterator *bip, ExtendedVCB * vol) cnp->ustr.length * sizeof(UniChar), ':', 0); if (utf8chars > kdirentMaxNameBytes) utf8chars = kdirentMaxNameBytes; - utf8chars++; /* account for NULL termination */ } else { /* hfs */ cnp = (CatalogName*) ckp->hfs.nodeName; result = hfs_to_utf8(vol, cnp->pstr, kdirentMaxNameBytes + 1, @@ -817,7 +816,7 @@ GetDirEntrySize(BTreeIterator *bip, ExtendedVCB * vol) OSErr PositionIterator(CatalogIterator *cip, UInt32 offset, BTreeIterator *bip, UInt16 *op) { -#define CAT_START_OFFSET (2 * sizeof(struct hfsdotentry)) +#define CAT_START_OFFSET 0 ExtendedVCB * vol; FCB * fcb; OSErr result = 0; diff --git a/bsd/kern/kern_sysctl.c b/bsd/kern/kern_sysctl.c index c7332ad05..047eb70b1 100644 --- a/bsd/kern/kern_sysctl.c +++ b/bsd/kern/kern_sysctl.c @@ -837,6 +837,7 @@ again: break; } if (buflen >= sizeof(struct kinfo_proc)) { + bzero(&kproc, sizeof(struct kinfo_proc)); fill_proc(p, &kproc, doingzomb); if (error = copyout((caddr_t)&kproc, &dp->kp_proc, sizeof(struct kinfo_proc))) @@ -882,6 +883,12 @@ fill_eproc(p, ep) { register struct tty *tp; + /* + * Skip zombie processes. + */ + if (p->p_stat == SZOMB) + return; + ep->e_paddr = p; ep->e_sess = p->p_pgrp->pg_session; ep->e_pcred = *p->p_cred; diff --git a/bsd/kern/sys_generic.c b/bsd/kern/sys_generic.c index b8c6e975e..cf5878004 100644 --- a/bsd/kern/sys_generic.c +++ b/bsd/kern/sys_generic.c @@ -720,13 +720,10 @@ selrecord(selector, sip) } else { sip->si_thread = my_thread; splx(oldpri); + act_reference(current_act()); if (selthread) { - /* thread_deallocate(selthread); */ act_deallocate(getact_thread(selthread)); } - /* do I need act reference ??? */ - /* thread_reference(sip->si_thread); */ - act_reference(getact_thread(sip->si_thread)); } return; diff --git a/iokit/Drivers/hidsystem/drvAppleADBDevices/AppleADBButtons.cpp b/iokit/Drivers/hidsystem/drvAppleADBDevices/AppleADBButtons.cpp index 1810d1854..b0c7168f7 100644 --- a/iokit/Drivers/hidsystem/drvAppleADBDevices/AppleADBButtons.cpp +++ b/iokit/Drivers/hidsystem/drvAppleADBDevices/AppleADBButtons.cpp @@ -20,6 +20,7 @@ * @APPLE_LICENSE_HEADER_END@ */ #include "AppleADBButtons.h" +#include "AppleADBKeyboard.h" #include #include #include @@ -88,6 +89,24 @@ UInt32 AppleADBButtons::interfaceID() UInt32 AppleADBButtons::deviceType() { + //if initial id is 31 then this is a post-WallStreet PowerBook, so + //look for a AppleADBKeyboard driver and return the handler ID from it. + //Note though that the ADB keyboard driver may not exist. + if (_initial_handler_id == 31) + { + mach_timespec_t t; + AppleADBKeyboard *adbkeyboard; + + t.tv_sec = 2; + t.tv_nsec = 0; + adbkeyboard = (AppleADBKeyboard *)waitForService(serviceMatching("AppleADBKeyboard"), &t); + if (adbkeyboard) + { + return adbkeyboard->deviceType(); + } + + } + return adbDevice->handlerID(); } diff --git a/iokit/Drivers/hidsystem/drvAppleADBDevices/AppleADBKeyboard.cpp b/iokit/Drivers/hidsystem/drvAppleADBDevices/AppleADBKeyboard.cpp index 42657151c..6d8d7cd32 100644 --- a/iokit/Drivers/hidsystem/drvAppleADBDevices/AppleADBKeyboard.cpp +++ b/iokit/Drivers/hidsystem/drvAppleADBDevices/AppleADBKeyboard.cpp @@ -93,23 +93,18 @@ return NX_EVS_DEVICE_INTERFACE_ADB; UInt32 AppleADBKeyboard::deviceType ( void ) { UInt32 id; //We need handler ID to remap adjustable JIS keyboard - - id = adbDevice->handlerID(); - if (id == 18) //Adjustable JIS - { - kmapConvert[0x32] = 0x35; //tilde to ESC - } IORegistryEntry *regEntry; OSData * data = 0; UInt32 *dataptr; - + id = adbDevice->handlerID(); if (id == 18) //Adjustable JIS { kmapConvert[0x32] = 0x35; //tilde to ESC } - if ((id == kgestaltPwrBkEKDomKbd) || (id == kgestaltPwrBkEKISOKbd) || (id == kgestaltPwrBkEKJISKbd)) + if ((id == kgestaltPwrBkEKDomKbd) || (id == kgestaltPwrBkEKISOKbd) || + (id == kgestaltPwrBkEKJISKbd) || (id == kgestaltPwrBk99JISKbd)) { if( (regEntry = IORegistryEntry::fromPath( "/pci@f2000000/mac-io/via-pmu/adb/keyboard", gIODTPlane ))) { @@ -122,7 +117,7 @@ UInt32 AppleADBKeyboard::deviceType ( void ) regEntry->release(); } } - + return id; } diff --git a/iokit/Drivers/hidsystem/drvAppleADBDevices/AppleADBKeyboard.h b/iokit/Drivers/hidsystem/drvAppleADBDevices/AppleADBKeyboard.h index 6ab4ee976..038d15c0b 100644 --- a/iokit/Drivers/hidsystem/drvAppleADBDevices/AppleADBKeyboard.h +++ b/iokit/Drivers/hidsystem/drvAppleADBDevices/AppleADBKeyboard.h @@ -25,7 +25,8 @@ enum { kgestaltPwrBkEKDomKbd = 0xc3, kgestaltPwrBkEKISOKbd = 0xc4, - kgestaltPwrBkEKJISKbd = 0xc5 + kgestaltPwrBkEKJISKbd = 0xc5, + kgestaltPwrBk99JISKbd = 0xc9 }; class AppleADBKeyboard : public IOHIKeyboard @@ -39,7 +40,6 @@ void setNumLockFeedback ( bool to ); UInt32 maxKeyCodes ( void ); const unsigned char * defaultKeymapOfLength (UInt32 * length ); UInt32 interfaceID ( void ); -UInt32 deviceType ( void ); bool doesKeyLock ( unsigned key); unsigned getLEDStatus (void ); bool programmerKey; @@ -49,6 +49,7 @@ AbsoluteTime debuggerTime; public: +UInt32 deviceType ( void ); IOADBDevice * adbDevice; UInt16 turnLEDon; // used by setAlphaLockFeedback mechanism UInt16 LEDStatus; //For ADB device TALK commands diff --git a/iokit/Families/IONDRVSupport/IONDRVFramebuffer.cpp b/iokit/Families/IONDRVSupport/IONDRVFramebuffer.cpp index 472e54d9e..18119f96d 100644 --- a/iokit/Families/IONDRVSupport/IONDRVFramebuffer.cpp +++ b/iokit/Families/IONDRVSupport/IONDRVFramebuffer.cpp @@ -46,6 +46,8 @@ #include +#define kAppleAudioVideoJackStateKey "AppleAudioVideoJackState" + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ class IOATINDRV : public IONDRVFramebuffer @@ -242,6 +244,12 @@ IOReturn IONDRVFramebuffer::enableController( void ) if( kIOReturnSuccess == err) do { + // find out about onboard audio/video jack state + // OSObject * notify = + addNotification( gIOPublishNotification, + resourceMatching(kAppleAudioVideoJackStateKey), + _videoJackStateChangeHandler, this, 0 ); + ignore_zero_fault( true ); err = checkDriver(); ignore_zero_fault( false ); @@ -273,6 +281,25 @@ IOReturn IONDRVFramebuffer::enableController( void ) return( err); } +bool IONDRVFramebuffer::_videoJackStateChangeHandler( void * target, void * ref, + IOService * resourceService ) +{ + IONDRVFramebuffer * self = (IONDRVFramebuffer *) target; + IOReturn err; + UInt32 jackData; + + OSObject * jackValue = resourceService->getProperty(kAppleAudioVideoJackStateKey); + if( !jackValue) + return( true ); + + jackData = (jackValue == kOSBooleanTrue); + + self->nub->setProperty( kAppleAudioVideoJackStateKey, &jackData, sizeof(jackData) ); + resourceService->removeProperty(kAppleAudioVideoJackStateKey); + + return( true ); +} + IODeviceMemory * IONDRVFramebuffer::getVRAMRange( void ) { if( vramMemory) diff --git a/iokit/Families/IONDRVSupport/IONDRVLibraries.cpp b/iokit/Families/IONDRVSupport/IONDRVLibraries.cpp index 565126fef..24ab2ee5c 100644 --- a/iokit/Families/IONDRVSupport/IONDRVLibraries.cpp +++ b/iokit/Families/IONDRVSupport/IONDRVLibraries.cpp @@ -655,7 +655,8 @@ _eRegistryCStrEntryLookup( const RegEntryID * parentEntry, char * buf; char * cvtPath; char c; -#define kDTRoot "Devices:device-tree:" +#define kDTRoot "Devices:device-tree:" +#define kMacIORoot "Devices:device-tree:pci:mac-io:" if( parentEntry) { REG_ENTRY_TO_OBJ( parentEntry, regEntry) @@ -669,6 +670,10 @@ _eRegistryCStrEntryLookup( const RegEntryID * parentEntry, cvtPath = buf; if( ':' == path[0]) path++; + else if( 0 == strncmp( path, kMacIORoot, strlen( kMacIORoot ))) { + path += strlen( kMacIORoot ) - 7; + regEntry = 0; + } else if( 0 == strncmp( path, kDTRoot, strlen( kDTRoot ))) { path += strlen( kDTRoot ) - 1; regEntry = 0; diff --git a/iokit/Families/IOStorage/IOBlockStorageDriver.cpp b/iokit/Families/IOStorage/IOBlockStorageDriver.cpp index 8e843b49a..345e55b56 100644 --- a/iokit/Families/IOStorage/IOBlockStorageDriver.cpp +++ b/iokit/Families/IOStorage/IOBlockStorageDriver.cpp @@ -1759,7 +1759,7 @@ IOByteCount IODeblocker::readBytes( IOByteCount offset, for ( ; index < _chunksCount && withLength; index++) { - IOByteCount copy = min(_chunks[index].length, withLength); + IOByteCount copy = min(_chunks[index].length - offset, withLength); IOByteCount copied = _chunks[index].buffer->readBytes( /* offset */ offset + _chunks[index].offset, /* bytes */ bytes, @@ -1798,7 +1798,7 @@ IOByteCount IODeblocker::writeBytes( IOByteCount offset, for ( ; index < _chunksCount && withLength; index++) { - IOByteCount copy = min(_chunks[index].length, withLength); + IOByteCount copy = min(_chunks[index].length - offset, withLength); IOByteCount copied = _chunks[index].buffer->writeBytes( /* offset */ offset + _chunks[index].offset, /* bytes */ bytes, diff --git a/iokit/IOKit/IOServicePM.h b/iokit/IOKit/IOServicePM.h index 7f958c7c9..2b48bb337 100644 --- a/iokit/IOKit/IOServicePM.h +++ b/iokit/IOKit/IOServicePM.h @@ -148,6 +148,9 @@ class IOPMpriv : public OSObject /*! @field device_active true: there has been device activity since last idle timer expiration */ bool device_active; + /*! @field device_active_timestamp time in ticks of last activity */ + AbsoluteTime device_active_timestamp; + /*! @field driverDesire This is the power state desired by our controlling driver. It is initialized to myCurrentState and is changed when the controlling driver calls changePowerStateTo. A change in driverDesire may cause a change in ourDesiredPowerState. diff --git a/iokit/IOKit/adb/IOADBDevice.h b/iokit/IOKit/adb/IOADBDevice.h index 882963ad0..c8c1d7c13 100644 --- a/iokit/IOKit/adb/IOADBDevice.h +++ b/iokit/IOKit/adb/IOADBDevice.h @@ -19,6 +19,9 @@ * * @APPLE_LICENSE_HEADER_END@ */ +#ifndef IOADBDEVICE_H +#define IOADBDEVICE_H + #include #include #include @@ -53,3 +56,6 @@ IOReturn setHandlerID ( UInt8 handlerID ); void * busRef ( void ); }; + +#endif + diff --git a/iokit/IOKit/ndrvsupport/IONDRVFramebuffer.h b/iokit/IOKit/ndrvsupport/IONDRVFramebuffer.h index d81e8f29a..f285d98be 100644 --- a/iokit/IOKit/ndrvsupport/IONDRVFramebuffer.h +++ b/iokit/IOKit/ndrvsupport/IONDRVFramebuffer.h @@ -154,6 +154,8 @@ private: static const IOTVector * _undefinedSymbolHandler( void * self, const char * libraryName, const char * symbolName ); void displayI2CPower( bool enable ); + static bool _videoJackStateChangeHandler( void * target, void * ref, + IOService * resourceService ); public: virtual IOReturn doControl( UInt32 code, void * params ); diff --git a/iokit/Kernel/IOServicePM.cpp b/iokit/Kernel/IOServicePM.cpp index 424f3f79c..4c72153e3 100644 --- a/iokit/Kernel/IOServicePM.cpp +++ b/iokit/Kernel/IOServicePM.cpp @@ -34,6 +34,7 @@ #include "IOKit/pwr_mgt/IOPMchangeNoteList.h" #include "IOKit/pwr_mgt/IOPMlog.h" #include "IOKit/pwr_mgt/IOPowerConnection.h" +#include static void ack_timer_expired(thread_call_param_t); static void settle_timer_expired(thread_call_param_t); @@ -1188,6 +1189,8 @@ unsigned long IOService::currentPowerConsumption ( void ) bool IOService::activityTickle ( unsigned long type, unsigned long stateNumber=0 ) { + AbsoluteTime uptime; + if ( type == kIOPMSuperclassPolicy1 ) { if ( (priv->activityLock == NULL) || (pm_vars->theControllingDriver == NULL) || @@ -1196,6 +1199,10 @@ bool IOService::activityTickle ( unsigned long type, unsigned long stateNumber=0 } IOTakeLock(priv->activityLock); priv->device_active = true; + + clock_get_uptime(&uptime); + priv->device_active_timestamp = uptime; + if ( pm_vars->myCurrentState >= stateNumber) { IOUnlock(priv->activityLock); return true; @@ -1285,7 +1292,38 @@ IOReturn IOService::setIdleTimerPeriod ( unsigned long period ) //********************************************************************************* void IOService::start_PM_idle_timer ( void ) { - priv->timerEventSrc->setTimeout(priv->idle_timer_period, NSEC_PER_SEC); + AbsoluteTime uptime; + AbsoluteTime delta; + UInt64 delta_ns; + UInt64 delta_secs; + UInt64 delay_secs; + + IOLockLock(priv->activityLock); + + clock_get_uptime(&uptime); + + /* Calculate time difference using funky macro from clock.h. + */ + delta = uptime; + SUB_ABSOLUTETIME(&delta, &(priv->device_active_timestamp)); + + /* Figure it in seconds. + */ + absolutetime_to_nanoseconds(delta, &delta_ns); + delta_secs = delta_ns / NSEC_PER_SEC; + + /* Be paranoid about delta somehow exceeding timer period. + */ + if (delta_secs < priv->idle_timer_period ) { + delay_secs = priv->idle_timer_period - delta_secs; + } else { + delay_secs = priv->idle_timer_period; + } + + priv->timerEventSrc->setTimeout(delay_secs, NSEC_PER_SEC); + + IOLockUnlock(priv->activityLock); + return; } diff --git a/iokit/KernelConfigTables.cpp b/iokit/KernelConfigTables.cpp index 8070a2eaf..f7f4e6ec4 100644 --- a/iokit/KernelConfigTables.cpp +++ b/iokit/KernelConfigTables.cpp @@ -28,21 +28,21 @@ */ const char * gIOKernelKmods = "{ - 'com.apple.kernel' = '1.0.0b1'; - 'com.apple.kernel.bsd' = '1.0.0b1'; - 'com.apple.kernel.iokit' = '1.0.0b1'; - 'com.apple.kernel.libkern' = '1.0.0b1'; - 'com.apple.kernel.mach' = '1.0.0b1'; - 'com.apple.iokit.IOADBFamily' = '1.0.0b1'; - 'com.apple.iokit.IOCDStorageFamily' = '1.0.0b1'; - 'com.apple.iokit.IODVDStorageFamily' = '1.0.0b1'; - 'com.apple.iokit.IOGraphicsFamily' = '1.0.0b1'; - 'com.apple.iokit.IOHIDSystem' = '1.0.0b1'; - 'com.apple.iokit.IONDRVSupport' = '1.0.0b1'; - 'com.apple.iokit.IONetworkingFamily' = '1.0.0b1'; - 'com.apple.iokit.IOPCIFamily' = '1.0.0b1'; - 'com.apple.iokit.IOStorageFamily' = '1.0.0b1'; - 'com.apple.iokit.IOSystemManagementFamily' = '1.0.0b1'; + 'com.apple.kernel' = '1.3.2'; + 'com.apple.kernel.bsd' = '1.0.2'; + 'com.apple.kernel.iokit' = '1.0.2'; + 'com.apple.kernel.libkern' = '1.0.2'; + 'com.apple.kernel.mach' = '1.0.2'; + 'com.apple.iokit.IOADBFamily' = '1.0.2'; + 'com.apple.iokit.IOCDStorageFamily' = '1.0.2'; + 'com.apple.iokit.IODVDStorageFamily' = '1.0.2'; + 'com.apple.iokit.IOGraphicsFamily' = '1.0.2'; + 'com.apple.iokit.IOHIDSystem' = '1.0.2'; + 'com.apple.iokit.IONDRVSupport' = '1.0.2'; + 'com.apple.iokit.IONetworkingFamily' = '1.0.2'; + 'com.apple.iokit.IOPCIFamily' = '1.0.2'; + 'com.apple.iokit.IOStorageFamily' = '1.0.2'; + 'com.apple.iokit.IOSystemManagementFamily' = '1.0.2'; }"; diff --git a/iokit/conf/version.variant b/iokit/conf/version.variant index e69de29bb..0cfbf0888 100644 --- a/iokit/conf/version.variant +++ b/iokit/conf/version.variant @@ -0,0 +1 @@ +2 diff --git a/libkern/conf/version.variant b/libkern/conf/version.variant index e69de29bb..0cfbf0888 100644 --- a/libkern/conf/version.variant +++ b/libkern/conf/version.variant @@ -0,0 +1 @@ +2 diff --git a/libsa/conf/version.variant b/libsa/conf/version.variant index e69de29bb..0cfbf0888 100644 --- a/libsa/conf/version.variant +++ b/libsa/conf/version.variant @@ -0,0 +1 @@ +2 diff --git a/osfmk/conf/kernelversion.variant b/osfmk/conf/kernelversion.variant index 8b1378917..0cfbf0888 100644 --- a/osfmk/conf/kernelversion.variant +++ b/osfmk/conf/kernelversion.variant @@ -1 +1 @@ - +2 diff --git a/osfmk/conf/version.variant b/osfmk/conf/version.variant index 8b1378917..0cfbf0888 100644 --- a/osfmk/conf/version.variant +++ b/osfmk/conf/version.variant @@ -1 +1 @@ - +2 diff --git a/osfmk/kern/bsd_kern.c b/osfmk/kern/bsd_kern.c index 24017dd53..0c03a9193 100644 --- a/osfmk/kern/bsd_kern.c +++ b/osfmk/kern/bsd_kern.c @@ -427,7 +427,8 @@ current_thread_aborted ( { thread_t th = current_thread(); - return(!th->top_act || (th->state & TH_ABORT)); + return(!th->top_act || + ((th->state & TH_ABORT) && (th->interruptible))); } /* diff --git a/osfmk/kern/sched_prim.c b/osfmk/kern/sched_prim.c index ae49e69ca..e2da65ad1 100644 --- a/osfmk/kern/sched_prim.c +++ b/osfmk/kern/sched_prim.c @@ -610,13 +610,15 @@ thread_stop( wake_lock(thread); while (thread->state & TH_SUSP) { + int wait_result; + thread->wake_active = TRUE; assert_wait((event_t)&thread->wake_active, THREAD_ABORTSAFE); wake_unlock(thread); splx(s); - thread_block((void (*)(void)) 0); - if (current_thread()->wait_result != THREAD_AWAKENED) + wait_result = thread_block((void (*)(void)) 0); + if (wait_result != THREAD_AWAKENED) return (FALSE); s = splsched(); @@ -694,6 +696,8 @@ thread_wait( wake_lock(thread); while (thread->state & (TH_RUN/*|TH_UNINT*/)) { + int wait_result; + if (thread->last_processor != PROCESSOR_NULL) cause_ast_check(thread->last_processor); @@ -702,18 +706,16 @@ thread_wait( wake_unlock(thread); splx(s); - thread_block((void (*)(void))0); - if (current_thread()->wait_result != THREAD_AWAKENED) - return (FALSE); + wait_result = thread_block((void (*)(void))0); + if (wait_result != THREAD_AWAKENED) + return FALSE; s = splsched(); wake_lock(thread); } - wake_unlock(thread); splx(s); - - return (TRUE); + return TRUE; } diff --git a/osfmk/kern/task.c b/osfmk/kern/task.c index 0eaf47eaa..bea0f27d0 100644 --- a/osfmk/kern/task.c +++ b/osfmk/kern/task.c @@ -623,6 +623,8 @@ task_terminate_internal( { thread_act_t thr_act, cur_thr_act; task_t cur_task; + thread_t cur_thread; + boolean_t interrupt_save; assert(task != kernel_task); @@ -676,6 +678,14 @@ task_terminate_internal( if (cur_task != task) task_unlock(cur_task); + /* + * Make sure the current thread does not get aborted out of + * the waits inside these operations. + */ + cur_thread = current_thread(); + interrupt_save = cur_thread->interruptible; + cur_thread->interruptible = FALSE; + /* * Indicate that we want all the threads to stop executing * at user space by holding the task (we would have held @@ -696,22 +706,20 @@ task_terminate_internal( * clean up most of the thread resources. Then it will be * handed over to the reaper, who will finally remove the * thread from the task list and free the structures. - * - * We can't terminate the current activation yet, because - * it has to wait for the others in an interruptible state. - * We may also block interruptibly during the rest of the - * cleanup. Wait until the very last to terminate ourself. - * - * But if we have virtual machine state, we need to clean - * that up now, because it may be holding wirings the task's - * map that would get stuck in the vm_map_remove() below. */ queue_iterate(&task->thr_acts, thr_act, thread_act_t, thr_acts) { - if (thr_act != cur_thr_act) thread_terminate_internal(thr_act); - else - act_virtual_machine_destroy(thr_act); } + + /* + * Clean up any virtual machine state/resources associated + * with the current activation because it may hold wiring + * and other references on resources we will be trying to + * release below. + */ + if (cur_thr_act->task == task) + act_virtual_machine_destroy(cur_thr_act); + task_unlock(task); /* @@ -743,11 +751,14 @@ task_terminate_internal( task->map->max_offset, VM_MAP_NO_FLAGS); /* - * Finally, mark ourself for termination and then - * deallocate the task's reference to itself. + * We no longer need to guard against being aborted, so restore + * the previous interruptible state. + */ + cur_thread->interruptible = interrupt_save; + + /* + * Get rid of the task active reference on itself. */ - if (task == cur_task) - thread_terminate(cur_thr_act); task_deallocate(task); return(KERN_SUCCESS); @@ -815,19 +826,22 @@ task_halt( * clean up most of the thread resources. Then it will be * handed over to the reaper, who will finally remove the * thread from the task list and free the structures. - * - * If the current thread has any virtual machine state - * associated with it, clean that up now before we try - * to clean up the task VM and port spaces. */ queue_iterate(&task->thr_acts, thr_act, thread_act_t,thr_acts) { if (thr_act != cur_thr_act) thread_terminate_internal(thr_act); - else - act_virtual_machine_destroy(thr_act); } task_release_locked(task); } + + /* + * If the current thread has any virtual machine state + * associated with it, we need to explicitly clean that + * up now (because we did not terminate the current act) + * before we try to clean up the task VM and port spaces. + */ + act_virtual_machine_destroy(cur_thr_act); + task_unlock(task); /* @@ -840,10 +854,18 @@ task_halt( */ task_subsystem_destroy_all(task); +#if 0 /* * Destroy the IPC space, leaving just a reference for it. */ -#if 0 + /* + * Lookupd will break if we enable this cleaning, because it + * uses a slimey trick that depends upon the portspace not + * being cleaned up across exec (it passes the lookupd server + * port to the child after a restart using knowledge of this + * bug in past implementations). We need to fix lookupd to + * keep from leaking ports across exec. + */ if (!task->kernel_loaded) ipc_space_clean(task->itk_space); #endif diff --git a/osfmk/kern/thread_act.c b/osfmk/kern/thread_act.c index 459cf608a..9a97f50a6 100644 --- a/osfmk/kern/thread_act.c +++ b/osfmk/kern/thread_act.c @@ -124,9 +124,6 @@ thread_terminate_internal( task_t task; struct ipc_port *iplock; kern_return_t ret; -#if NCPUS > 1 - boolean_t held; -#endif /* NCPUS > 1 */ #if THREAD_SWAPPER thread_swap_disable(thr_act); @@ -138,6 +135,9 @@ thread_terminate_internal( return(KERN_TERMINATED); } + act_disable_task_locked(thr_act); + ret = act_abort(thr_act,FALSE); + #if NCPUS > 1 /* * Make sure this thread enters the kernel @@ -146,34 +146,17 @@ thread_terminate_internal( thread_hold(thr_act); act_unlock_thread(thr_act); - if (!thread_stop_wait(thread)) { + if (thread_stop_wait(thread)) + thread_unstop(thread); + else ret = KERN_ABORTED; - (void)act_lock_thread(thr_act); - thread_release(thr_act); - act_unlock_thread(thr_act); - return (ret); - } - held = TRUE; (void)act_lock_thread(thr_act); - } else { - held = FALSE; + thread_release(thr_act); } #endif /* NCPUS > 1 */ - assert(thr_act->active); - act_disable_task_locked(thr_act); - ret = act_abort(thr_act,FALSE); act_unlock_thread(thr_act); - -#if NCPUS > 1 - if (held) { - thread_unstop(thread); - (void)act_lock_thread(thr_act); - thread_release(thr_act); - act_unlock_thread(thr_act); - } -#endif /* NCPUS > 1 */ return(ret); } @@ -509,8 +492,7 @@ act_abort( thread_act_t thr_act, int chain_break ) thread_lock(thr_act->thread); if (thr_act->thread->top_act == thr_act) { thr_act->thread->state |= TH_ABORT; - if (thr_act->thread->state & TH_ABORT) - clear_wait_internal(thr_act->thread, THREAD_INTERRUPTED); + clear_wait_internal(thr_act->thread, THREAD_INTERRUPTED); thread_unlock(thr_act->thread); splx(spl); install_special_handler(thr_act); @@ -1459,12 +1441,9 @@ install_special_handler( #endif /* MACH_ASSERT */ spl = splsched(); - if (thread) - thread_lock(thread); + thread_lock(thread); install_special_handler_locked(thr_act); - act_set_apc(thr_act); - if (thread) - thread_unlock(thread); + thread_unlock(thread); splx(spl); } diff --git a/pexpert/conf/version.variant b/pexpert/conf/version.variant index e69de29bb..0cfbf0888 100644 --- a/pexpert/conf/version.variant +++ b/pexpert/conf/version.variant @@ -0,0 +1 @@ +2 -- 2.45.2