2 * Copyright (c) 2000-2004 Apple Computer, 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@
29 #include <mach/mach_types.h>
30 #include <mach/task_server.h>
32 #include <kern/sched.h>
33 #include <kern/task.h>
39 integer_t max_priority
);
44 task_policy_flavor_t flavor
,
45 task_policy_t policy_info
,
46 mach_msg_type_number_t count
)
48 kern_return_t result
= KERN_SUCCESS
;
50 if (task
== TASK_NULL
|| task
== kernel_task
)
51 return (KERN_INVALID_ARGUMENT
);
55 case TASK_CATEGORY_POLICY
:
57 task_category_policy_t info
= (task_category_policy_t
)policy_info
;
59 if (count
< TASK_CATEGORY_POLICY_COUNT
)
60 return (KERN_INVALID_ARGUMENT
);
64 if ( info
->role
== TASK_FOREGROUND_APPLICATION
||
65 info
->role
== TASK_BACKGROUND_APPLICATION
) {
68 case TASK_FOREGROUND_APPLICATION
:
69 case TASK_BACKGROUND_APPLICATION
:
70 case TASK_UNSPECIFIED
:
72 ((info
->role
== TASK_FOREGROUND_APPLICATION
)?
73 BASEPRI_FOREGROUND
: BASEPRI_BACKGROUND
),
75 task
->role
= info
->role
;
78 case TASK_CONTROL_APPLICATION
:
84 result
= KERN_INVALID_ARGUMENT
;
89 if (info
->role
== TASK_CONTROL_APPLICATION
) {
90 if ( task
!= current_task() ||
91 task
->sec_token
.val
[0] != 0 )
92 result
= KERN_INVALID_ARGUMENT
;
94 task_priority(task
, BASEPRI_CONTROL
, task
->max_priority
);
95 task
->role
= info
->role
;
99 if (info
->role
== TASK_GRAPHICS_SERVER
) {
100 if ( task
!= current_task() ||
101 task
->sec_token
.val
[0] != 0 )
102 result
= KERN_INVALID_ARGUMENT
;
104 task_priority(task
, MAXPRI_RESERVED
- 3, MAXPRI_RESERVED
);
105 task
->role
= info
->role
;
109 result
= KERN_INVALID_ARGUMENT
;
117 result
= KERN_INVALID_ARGUMENT
;
128 integer_t max_priority
)
132 task
->max_priority
= max_priority
;
134 if (priority
> task
->max_priority
)
135 priority
= task
->max_priority
;
137 if (priority
< MINPRI
)
140 task
->priority
= priority
;
142 queue_iterate(&task
->threads
, thread
, thread_t
, task_threads
) {
143 thread_mtx_lock(thread
);
146 thread_task_priority(thread
, priority
, max_priority
);
148 thread_mtx_unlock(thread
);
155 integer_t importance
)
157 if (task
== TASK_NULL
|| task
== kernel_task
)
158 return (KERN_INVALID_ARGUMENT
);
165 return (KERN_TERMINATED
);
168 if (task
->role
>= TASK_CONTROL_APPLICATION
) {
171 return (KERN_INVALID_ARGUMENT
);
174 task_priority(task
, importance
+ BASEPRI_DEFAULT
, task
->max_priority
);
175 task
->role
= TASK_RENICED
;
179 return (KERN_SUCCESS
);
185 task_policy_flavor_t flavor
,
186 task_policy_t policy_info
,
187 mach_msg_type_number_t
*count
,
188 boolean_t
*get_default
)
190 if (task
== TASK_NULL
|| task
== kernel_task
)
191 return (KERN_INVALID_ARGUMENT
);
195 case TASK_CATEGORY_POLICY
:
197 task_category_policy_t info
= (task_category_policy_t
)policy_info
;
199 if (*count
< TASK_CATEGORY_POLICY_COUNT
)
200 return (KERN_INVALID_ARGUMENT
);
203 info
->role
= TASK_UNSPECIFIED
;
206 info
->role
= task
->role
;
213 return (KERN_INVALID_ARGUMENT
);
216 return (KERN_SUCCESS
);