2 * Copyright (c) 2015 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 <sys/param.h>
29 #include <sys/kernel.h>
30 #include <sys/kernel_types.h>
31 #include <sys/sysproto.h>
33 #include <sys/work_interval.h>
34 #include <kern/sched_prim.h>
35 #include <kern/thread.h>
36 #include <kern/policy_internal.h>
38 #include <libkern/libkern.h>
41 work_interval_ctl(__unused proc_t p
, struct work_interval_ctl_args
*uap
, __unused
int32_t *retval
)
43 uint32_t operation
= uap
->operation
;
45 kern_return_t kret
= KERN_SUCCESS
;
46 uint64_t work_interval_id
;
47 struct work_interval_notification notification
;
50 case WORK_INTERVAL_OPERATION_CREATE
:
51 if (uap
->arg
== USER_ADDR_NULL
|| uap
->work_interval_id
!= 0) {
54 if (uap
->len
< sizeof(work_interval_id
)) {
59 * Privilege check performed up-front, and then the work
60 * ID is allocated for use by the thread
62 error
= priv_check_cred(kauth_cred_get(), PRIV_WORK_INTERVAL
, 0);
67 kret
= thread_policy_create_work_interval(current_thread(),
69 if (kret
== KERN_SUCCESS
) {
70 error
= copyout(&work_interval_id
, uap
->arg
, sizeof(work_interval_id
));
76 case WORK_INTERVAL_OPERATION_DESTROY
:
77 if (uap
->arg
!= USER_ADDR_NULL
|| uap
->work_interval_id
== 0) {
82 * No privilege check, we assume a previous WORK_INTERVAL_OPERATION_CREATE
83 * operation would have allocated a work interval ID for the current
84 * thread, which the scheduler will validate.
86 kret
= thread_policy_destroy_work_interval(current_thread(),
87 uap
->work_interval_id
);
88 if (kret
!= KERN_SUCCESS
) {
93 case WORK_INTERVAL_OPERATION_NOTIFY
:
94 if (uap
->arg
== USER_ADDR_NULL
|| uap
->work_interval_id
== 0) {
97 if (uap
->len
< sizeof(notification
)) {
102 * No privilege check, we assume a previous WORK_INTERVAL_OPERATION_CREATE
103 * operation would have allocated a work interval ID for the current
104 * thread, which the scheduler will validate.
106 error
= copyin(uap
->arg
, ¬ification
, sizeof(notification
));
111 kret
= sched_work_interval_notify(current_thread(),
112 uap
->work_interval_id
,
115 notification
.deadline
,
116 notification
.next_start
,
118 if (kret
!= KERN_SUCCESS
) {