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