xref: /xnu-8796.121.2/iokit/Tests/TestServices/TestIOUserClient2022Entitlements.cpp (revision c54f35ca767986246321eb901baf8f5ff7923f6a)
1*c54f35caSApple OSS Distributions #include "TestIOUserClient2022Entitlements.h"
2*c54f35caSApple OSS Distributions #include <IOKit/IOService.h>
3*c54f35caSApple OSS Distributions #include <IOKit/IOUserClient.h>
4*c54f35caSApple OSS Distributions #include <IOKit/IOKitServer.h>
5*c54f35caSApple OSS Distributions #include <kern/ipc_kobject.h>
6*c54f35caSApple OSS Distributions 
7*c54f35caSApple OSS Distributions #if (DEVELOPMENT || DEBUG)
8*c54f35caSApple OSS Distributions 
9*c54f35caSApple OSS Distributions OSDefineMetaClassAndStructors(TestIOUserClient2022Entitlements, IOService);
10*c54f35caSApple OSS Distributions 
11*c54f35caSApple OSS Distributions OSDefineMetaClassAndStructors(TestIOUserClient2022EntitlementsUserClient, IOUserClient2022);
12*c54f35caSApple OSS Distributions 
13*c54f35caSApple OSS Distributions bool
start(IOService * provider)14*c54f35caSApple OSS Distributions TestIOUserClient2022Entitlements::start(IOService * provider)
15*c54f35caSApple OSS Distributions {
16*c54f35caSApple OSS Distributions 	OSString * str = OSString::withCStringNoCopy("TestIOUserClient2022EntitlementsUserClient");
17*c54f35caSApple OSS Distributions 	bool ret = IOService::start(provider);
18*c54f35caSApple OSS Distributions 	if (ret && str != NULL) {
19*c54f35caSApple OSS Distributions 		setProperty(gIOUserClientClassKey, str);
20*c54f35caSApple OSS Distributions 		registerService();
21*c54f35caSApple OSS Distributions 	}
22*c54f35caSApple OSS Distributions 	OSSafeReleaseNULL(str);
23*c54f35caSApple OSS Distributions 	return ret;
24*c54f35caSApple OSS Distributions }
25*c54f35caSApple OSS Distributions 
26*c54f35caSApple OSS Distributions bool
start(IOService * provider)27*c54f35caSApple OSS Distributions TestIOUserClient2022EntitlementsUserClient::start(IOService * provider)
28*c54f35caSApple OSS Distributions {
29*c54f35caSApple OSS Distributions 	if (!IOUserClient2022::start(provider)) {
30*c54f35caSApple OSS Distributions 		return false;
31*c54f35caSApple OSS Distributions 	}
32*c54f35caSApple OSS Distributions 	setProperty(kIOUserClientDefaultLockingKey, kOSBooleanTrue);
33*c54f35caSApple OSS Distributions 	setProperty(kIOUserClientDefaultLockingSetPropertiesKey, kOSBooleanTrue);
34*c54f35caSApple OSS Distributions 	setProperty(kIOUserClientDefaultLockingSingleThreadExternalMethodKey, kOSBooleanTrue);
35*c54f35caSApple OSS Distributions 
36*c54f35caSApple OSS Distributions 	setProperty(kIOUserClientEntitlementsKey, "com.apple.iokit.test-check-entitlement-open");
37*c54f35caSApple OSS Distributions 
38*c54f35caSApple OSS Distributions 	return true;
39*c54f35caSApple OSS Distributions }
40*c54f35caSApple OSS Distributions 
41*c54f35caSApple OSS Distributions IOReturn
clientClose()42*c54f35caSApple OSS Distributions TestIOUserClient2022EntitlementsUserClient::clientClose()
43*c54f35caSApple OSS Distributions {
44*c54f35caSApple OSS Distributions 	terminate();
45*c54f35caSApple OSS Distributions 	return kIOReturnSuccess;
46*c54f35caSApple OSS Distributions }
47*c54f35caSApple OSS Distributions 
48*c54f35caSApple OSS Distributions IOReturn
extBasicMethod(OSObject * target,void * reference,IOExternalMethodArguments * arguments)49*c54f35caSApple OSS Distributions TestIOUserClient2022EntitlementsUserClient::extBasicMethod(OSObject * target, void * reference, IOExternalMethodArguments * arguments)
50*c54f35caSApple OSS Distributions {
51*c54f35caSApple OSS Distributions 	return kIOReturnSuccess;
52*c54f35caSApple OSS Distributions }
53*c54f35caSApple OSS Distributions 
54*c54f35caSApple OSS Distributions IOReturn
extPerSelectorCheck(OSObject * target,void * reference,IOExternalMethodArguments * arguments)55*c54f35caSApple OSS Distributions TestIOUserClient2022EntitlementsUserClient::extPerSelectorCheck(OSObject * target, void * reference, IOExternalMethodArguments * arguments)
56*c54f35caSApple OSS Distributions {
57*c54f35caSApple OSS Distributions 	return kIOReturnSuccess;
58*c54f35caSApple OSS Distributions }
59*c54f35caSApple OSS Distributions 
60*c54f35caSApple OSS Distributions IOReturn
externalMethod(uint32_t selector,IOExternalMethodArgumentsOpaque * args)61*c54f35caSApple OSS Distributions TestIOUserClient2022EntitlementsUserClient::externalMethod(uint32_t selector, IOExternalMethodArgumentsOpaque * args)
62*c54f35caSApple OSS Distributions {
63*c54f35caSApple OSS Distributions 	static const IOExternalMethodDispatch2022 dispatchArray[] = {
64*c54f35caSApple OSS Distributions 		[0] {
65*c54f35caSApple OSS Distributions 			.function                 = &TestIOUserClient2022EntitlementsUserClient::extBasicMethod,
66*c54f35caSApple OSS Distributions 			.checkScalarInputCount    = 0,
67*c54f35caSApple OSS Distributions 			.checkStructureInputSize  = 0,
68*c54f35caSApple OSS Distributions 			.checkScalarOutputCount   = 0,
69*c54f35caSApple OSS Distributions 			.checkStructureOutputSize = 0,
70*c54f35caSApple OSS Distributions 			.allowAsync               = false,
71*c54f35caSApple OSS Distributions 			.checkEntitlement         = NULL,
72*c54f35caSApple OSS Distributions 		},
73*c54f35caSApple OSS Distributions 		[1] {
74*c54f35caSApple OSS Distributions 			.function                 = &TestIOUserClient2022EntitlementsUserClient::extPerSelectorCheck,
75*c54f35caSApple OSS Distributions 			.checkScalarInputCount    = 0,
76*c54f35caSApple OSS Distributions 			.checkStructureInputSize  = 0,
77*c54f35caSApple OSS Distributions 			.checkScalarOutputCount   = 0,
78*c54f35caSApple OSS Distributions 			.checkStructureOutputSize = 0,
79*c54f35caSApple OSS Distributions 			.allowAsync               = false,
80*c54f35caSApple OSS Distributions 			.checkEntitlement         = "com.apple.iokit.test-check-entitlement-per-selector",
81*c54f35caSApple OSS Distributions 		},
82*c54f35caSApple OSS Distributions 	};
83*c54f35caSApple OSS Distributions 
84*c54f35caSApple OSS Distributions 	return dispatchExternalMethod(selector, args, dispatchArray, sizeof(dispatchArray) / sizeof(dispatchArray[0]), this, NULL);
85*c54f35caSApple OSS Distributions }
86*c54f35caSApple OSS Distributions 
87*c54f35caSApple OSS Distributions #endif /* (DEVELOPMENT || DEBUG) */
88