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 <libkern/libkern.h>
39 work_interval_ctl(__unused proc_t p
, struct work_interval_ctl_args
*uap
, __unused
int32_t *retval
)
41 uint32_t operation
= uap
->operation
;
43 kern_return_t kret
= KERN_SUCCESS
;
44 uint64_t work_interval_id
;
45 struct work_interval_notification notification
;
48 case WORK_INTERVAL_OPERATION_CREATE
:
49 if (uap
->arg
== USER_ADDR_NULL
|| uap
->work_interval_id
!= 0) {
52 if (uap
->len
< sizeof(work_interval_id
)) {
57 * Privilege check performed up-front, and then the work
58 * ID is allocated for use by the thread
60 error
= priv_check_cred(kauth_cred_get(), PRIV_WORK_INTERVAL
, 0);
65 kret
= thread_policy_create_work_interval(current_thread(),
67 if (kret
== KERN_SUCCESS
) {
68 error
= copyout(&work_interval_id
, uap
->arg
, sizeof(work_interval_id
));
74 case WORK_INTERVAL_OPERATION_DESTROY
:
75 if (uap
->arg
!= USER_ADDR_NULL
|| uap
->work_interval_id
== 0) {
80 * No privilege check, we assume a previous WORK_INTERVAL_OPERATION_CREATE
81 * operation would have allocated a work interval ID for the current
82 * thread, which the scheduler will validate.
84 kret
= thread_policy_destroy_work_interval(current_thread(),
85 uap
->work_interval_id
);
86 if (kret
!= KERN_SUCCESS
) {
91 case WORK_INTERVAL_OPERATION_NOTIFY
:
92 if (uap
->arg
== USER_ADDR_NULL
|| uap
->work_interval_id
== 0) {
95 if (uap
->len
< sizeof(notification
)) {
100 * No privilege check, we assume a previous WORK_INTERVAL_OPERATION_CREATE
101 * operation would have allocated a work interval ID for the current
102 * thread, which the scheduler will validate.
104 error
= copyin(uap
->arg
, ¬ification
, sizeof(notification
));
109 kret
= sched_work_interval_notify(current_thread(),
110 uap
->work_interval_id
,
113 notification
.deadline
,
114 notification
.next_start
,
116 if (kret
!= KERN_SUCCESS
) {