1*699cd480SApple OSS Distributions/* 2*699cd480SApple OSS Distributions * Copyright (c) 2019-2019 Apple Inc. All rights reserved. 3*699cd480SApple OSS Distributions * 4*699cd480SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*699cd480SApple OSS Distributions * 6*699cd480SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*699cd480SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*699cd480SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*699cd480SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*699cd480SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*699cd480SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*699cd480SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*699cd480SApple OSS Distributions * terms of an Apple operating system software license agreement. 14*699cd480SApple OSS Distributions * 15*699cd480SApple OSS Distributions * Please obtain a copy of the License at 16*699cd480SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*699cd480SApple OSS Distributions * 18*699cd480SApple OSS Distributions * The Original Code and all software distributed under the License are 19*699cd480SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*699cd480SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*699cd480SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*699cd480SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*699cd480SApple OSS Distributions * Please see the License for the specific language governing rights and 24*699cd480SApple OSS Distributions * limitations under the License. 25*699cd480SApple OSS Distributions * 26*699cd480SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*699cd480SApple OSS Distributions */ 28*699cd480SApple OSS Distributions 29*699cd480SApple OSS Distributions#ifndef _IOKIT_OSACTION_H 30*699cd480SApple OSS Distributions#define _IOKIT_OSACTION_H 31*699cd480SApple OSS Distributions 32*699cd480SApple OSS Distributions#include <DriverKit/OSObject.iig> 33*699cd480SApple OSS Distributions 34*699cd480SApple OSS Distributionstypedef void (^OSActionCancelHandler)(void); 35*699cd480SApple OSS Distributionstypedef void (^OSActionAbortedHandler)(void); 36*699cd480SApple OSS Distributionsstruct OSActionWaitToken; 37*699cd480SApple OSS Distributionsclass OSString; 38*699cd480SApple OSS Distributions 39*699cd480SApple OSS Distributions/*! 40*699cd480SApple OSS Distributions * @class OSAction 41*699cd480SApple OSS Distributions * 42*699cd480SApple OSS Distributions * @abstract 43*699cd480SApple OSS Distributions * OSAction is an object that represents a callback to be be invoked. 44*699cd480SApple OSS Distributions * 45*699cd480SApple OSS Distributions * @discussion 46*699cd480SApple OSS Distributions * The callback is specified as a method and object pair. 47*699cd480SApple OSS Distributions * State associated with the callback may be allocated and stored for the creator of the object. 48*699cd480SApple OSS Distributions * Methods to allocate an OSAction instance are generated for each method defined in a class with 49*699cd480SApple OSS Distributions * a TYPE attribute. The generated methods are named CreateAction{name of method with type attribute} 50*699cd480SApple OSS Distributions * and have the following declaration: 51*699cd480SApple OSS Distributions * 52*699cd480SApple OSS Distributions * kern_return_t CreateActionNameOfMethod(size_t referenceSize, OSAction **action); 53*699cd480SApple OSS Distributions * 54*699cd480SApple OSS Distributions * referenceSize refers to the size of additional state structure available to the creator of the OSAction 55*699cd480SApple OSS Distributions * with GetReference. If successful, the generated method returns kIOReturnSuccess and a created OSAction 56*699cd480SApple OSS Distributions * through the 'action' parameter with a +1 retain count to be released by the caller. See IOReturn.h for 57*699cd480SApple OSS Distributions * error codes. 58*699cd480SApple OSS Distributions */ 59*699cd480SApple OSS Distributions 60*699cd480SApple OSS Distributionsclass NATIVE KERNEL OSAction : public OSObject 61*699cd480SApple OSS Distributions{ 62*699cd480SApple OSS Distributionspublic: 63*699cd480SApple OSS Distributions 64*699cd480SApple OSS Distributions#if DRIVERKIT_PRIVATE 65*699cd480SApple OSS Distributions /*! 66*699cd480SApple OSS Distributions * @brief Create an instance of OSAction. 67*699cd480SApple OSS Distributions * @discussion Methods to allocate an OSAction instance are generated for each method defined in a class with 68*699cd480SApple OSS Distributions * a TYPE attribute, so there should not be any need to directly call OSAction::Create(). 69*699cd480SApple OSS Distributions * @param target OSObject to receive the callback. This object will be retained until the OSAction is 70*699cd480SApple OSS Distributions * canceled or freed. 71*699cd480SApple OSS Distributions * @param targetmsgid Generated message ID for the target method. 72*699cd480SApple OSS Distributions * @param msgid Generated message ID for the method invoked by the receiver of the OSAction 73*699cd480SApple OSS Distributions * to generate the callback. 74*699cd480SApple OSS Distributions * @param referenceSize Size of additional state structure available to the creator of the OSAction 75*699cd480SApple OSS Distributions * with GetReference. 76*699cd480SApple OSS Distributions * @param action Created OSAction with +1 retain count to be released by the caller. 77*699cd480SApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 78*699cd480SApple OSS Distributions */ 79*699cd480SApple OSS Distributions static kern_return_t 80*699cd480SApple OSS Distributions Create( 81*699cd480SApple OSS Distributions OSObject * target, 82*699cd480SApple OSS Distributions uint64_t targetmsgid, 83*699cd480SApple OSS Distributions uint64_t msgid, 84*699cd480SApple OSS Distributions size_t referenceSize, 85*699cd480SApple OSS Distributions OSAction ** action) LOCAL; 86*699cd480SApple OSS Distributions 87*699cd480SApple OSS Distributions static kern_return_t 88*699cd480SApple OSS Distributions CreateWithTypeName( 89*699cd480SApple OSS Distributions OSObject * target, 90*699cd480SApple OSS Distributions uint64_t targetmsgid, 91*699cd480SApple OSS Distributions uint64_t msgid, 92*699cd480SApple OSS Distributions size_t referenceSize, 93*699cd480SApple OSS Distributions OSString * typeName, 94*699cd480SApple OSS Distributions OSAction ** action) LOCAL; 95*699cd480SApple OSS Distributions#endif 96*699cd480SApple OSS Distributions 97*699cd480SApple OSS Distributions virtual void 98*699cd480SApple OSS Distributions free() override; 99*699cd480SApple OSS Distributions 100*699cd480SApple OSS Distributions /*! 101*699cd480SApple OSS Distributions * @brief Return a pointer to any state allocated by the OSAction creator. 102*699cd480SApple OSS Distributions * @discussion Reference data is allocated with zero initialized content. It may be set and retrieved later 103*699cd480SApple OSS Distributions * with this method. 104*699cd480SApple OSS Distributions * @return A pointer to storage for the owner. It will be NULL if referenceSize was zero, and NULL 105*699cd480SApple OSS Distributions * when called in a process other than the owner that is receiving the OSAction as a parameter. 106*699cd480SApple OSS Distributions */ 107*699cd480SApple OSS Distributions void * 108*699cd480SApple OSS Distributions GetReference() LOCALONLY; 109*699cd480SApple OSS Distributions 110*699cd480SApple OSS Distributions /*! 111*699cd480SApple OSS Distributions * @brief Cancel all callbacks from the action. 112*699cd480SApple OSS Distributions * @discussion After cancellation, the action can only be freed. It cannot be reactivated. 113*699cd480SApple OSS Distributions * @param handler Handler block to be invoked after any callbacks have completed. 114*699cd480SApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 115*699cd480SApple OSS Distributions */ 116*699cd480SApple OSS Distributions kern_return_t 117*699cd480SApple OSS Distributions Cancel(OSActionCancelHandler handler) LOCALONLY; 118*699cd480SApple OSS Distributions 119*699cd480SApple OSS Distributions /*! 120*699cd480SApple OSS Distributions * @brief Install a handler to be invoked when no other processes reference the action. 121*699cd480SApple OSS Distributions * @discussion When all tasks other than the creator release their references to the action, 122*699cd480SApple OSS Distributions * invoke the handler in the owner. A task exiting will always remove its references. 123*699cd480SApple OSS Distributions * @param handler Handler block to be invoked on no more references. 124*699cd480SApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 125*699cd480SApple OSS Distributions */ 126*699cd480SApple OSS Distributions kern_return_t 127*699cd480SApple OSS Distributions SetAbortedHandler(OSActionAbortedHandler handler) LOCALONLY; 128*699cd480SApple OSS Distributions 129*699cd480SApple OSS Distributions /*! 130*699cd480SApple OSS Distributions * @brief Mark this OSAction to be waited for later with Wait(). 131*699cd480SApple OSS Distributions * @discussion This call should be made before any possible invocation of the action. 132*699cd480SApple OSS Distributions * An OSAction instance only supports one waiter and WillWait() will return an error if already called. 133*699cd480SApple OSS Distributions * @param token Opaque value to be passed to a later call to Wait() and EndWait(). 134*699cd480SApple OSS Distributions * @return kIOReturnSuccess on success. See IOReturn.h for error codes. 135*699cd480SApple OSS Distributions */ 136*699cd480SApple OSS Distributions kern_return_t 137*699cd480SApple OSS Distributions WillWait(OSActionWaitToken ** token) LOCALONLY; 138*699cd480SApple OSS Distributions 139*699cd480SApple OSS Distributions /*! 140*699cd480SApple OSS Distributions * @brief Discard the OSActionWaitToken for the action. 141*699cd480SApple OSS Distributions * @discussion Free any resources needed to wait for the action allocated by WillWait(). 142*699cd480SApple OSS Distributions * There should be no outstanding invocations of the action when EndWait is called, 143*699cd480SApple OSS Distributions * if necessary the action should be canceled before calling EndWait(). 144*699cd480SApple OSS Distributions * @param token Opaque value to be passed from an earlier call to WillWait(). 145*699cd480SApple OSS Distributions * @return kIOReturnSuccess on success. kIOReturnAborted if aborted or canceled. 146*699cd480SApple OSS Distributions kIOReturnTimeout if the deadline was passed. See IOReturn.h for error codes. 147*699cd480SApple OSS Distributions */ 148*699cd480SApple OSS Distributions kern_return_t 149*699cd480SApple OSS Distributions EndWait( 150*699cd480SApple OSS Distributions OSActionWaitToken * token) LOCALONLY; 151*699cd480SApple OSS Distributions 152*699cd480SApple OSS Distributions /*! 153*699cd480SApple OSS Distributions * @brief Wait for the action to be invoked. 154*699cd480SApple OSS Distributions * @discussion The current thread is blocked until the action invocation has completed, the action canceled 155*699cd480SApple OSS Distributions or aborted, or the deadline passed. 156*699cd480SApple OSS Distributions * @param token Opaque value to be passed from an earlier call to WillWait(). 157*699cd480SApple OSS Distributions * @param options Pass one of the kIOTimerClock* options to specify the timebase for the 158*699cd480SApple OSS Distributions * deadline, or zero for no timeout. 159*699cd480SApple OSS Distributions * @param deadline Pass the time the wait should timeout, or zero for no timeout. 160*699cd480SApple OSS Distributions * @return kIOReturnSuccess on success. kIOReturnAborted if aborted or canceled. 161*699cd480SApple OSS Distributions kIOReturnTimeout if the deadline was passed. See IOReturn.h for error codes. 162*699cd480SApple OSS Distributions */ 163*699cd480SApple OSS Distributions kern_return_t 164*699cd480SApple OSS Distributions Wait( 165*699cd480SApple OSS Distributions OSActionWaitToken * token, 166*699cd480SApple OSS Distributions uint64_t options, 167*699cd480SApple OSS Distributions uint64_t deadline) LOCALONLY; 168*699cd480SApple OSS Distributions 169*699cd480SApple OSS Distributions virtual void 170*699cd480SApple OSS Distributions Aborted(void) LOCALHOST; 171*699cd480SApple OSS Distributions}; 172*699cd480SApple OSS Distributions 173*699cd480SApple OSS Distributions#endif /* ! _IOKIT_OSACTION_H */ 174