2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 #include <mach/mach_types.h>
32 #include <mach/task_server.h>
34 #include <kern/sched.h>
35 #include <kern/task.h>
41 integer_t max_priority
);
46 task_policy_flavor_t flavor
,
47 task_policy_t policy_info
,
48 mach_msg_type_number_t count
)
50 kern_return_t result
= KERN_SUCCESS
;
52 if (task
== TASK_NULL
|| task
== kernel_task
)
53 return (KERN_INVALID_ARGUMENT
);
57 case TASK_CATEGORY_POLICY
:
59 task_category_policy_t info
= (task_category_policy_t
)policy_info
;
61 if (count
< TASK_CATEGORY_POLICY_COUNT
)
62 return (KERN_INVALID_ARGUMENT
);
66 if ( info
->role
== TASK_FOREGROUND_APPLICATION
||
67 info
->role
== TASK_BACKGROUND_APPLICATION
) {
70 case TASK_FOREGROUND_APPLICATION
:
71 case TASK_BACKGROUND_APPLICATION
:
72 case TASK_UNSPECIFIED
:
74 ((info
->role
== TASK_FOREGROUND_APPLICATION
)?
75 BASEPRI_FOREGROUND
: BASEPRI_BACKGROUND
),
77 task
->role
= info
->role
;
80 case TASK_CONTROL_APPLICATION
:
86 result
= KERN_INVALID_ARGUMENT
;
91 if (info
->role
== TASK_CONTROL_APPLICATION
) {
92 if ( task
!= current_task() ||
93 task
->sec_token
.val
[0] != 0 )
94 result
= KERN_INVALID_ARGUMENT
;
96 task_priority(task
, BASEPRI_CONTROL
, task
->max_priority
);
97 task
->role
= info
->role
;
101 if (info
->role
== TASK_GRAPHICS_SERVER
) {
102 if ( task
!= current_task() ||
103 task
->sec_token
.val
[0] != 0 )
104 result
= KERN_INVALID_ARGUMENT
;
106 task_priority(task
, MAXPRI_RESERVED
- 3, MAXPRI_RESERVED
);
107 task
->role
= info
->role
;
111 result
= KERN_INVALID_ARGUMENT
;
119 result
= KERN_INVALID_ARGUMENT
;
130 integer_t max_priority
)
134 task
->max_priority
= max_priority
;
136 if (priority
> task
->max_priority
)
137 priority
= task
->max_priority
;
139 if (priority
< MINPRI
)
142 task
->priority
= priority
;
144 queue_iterate(&task
->threads
, thread
, thread_t
, task_threads
) {
145 thread_mtx_lock(thread
);
148 thread_task_priority(thread
, priority
, max_priority
);
150 thread_mtx_unlock(thread
);
157 integer_t importance
)
159 if (task
== TASK_NULL
|| task
== kernel_task
)
160 return (KERN_INVALID_ARGUMENT
);
167 return (KERN_TERMINATED
);
170 if (task
->role
>= TASK_CONTROL_APPLICATION
) {
173 return (KERN_INVALID_ARGUMENT
);
176 task_priority(task
, importance
+ BASEPRI_DEFAULT
, task
->max_priority
);
177 task
->role
= TASK_RENICED
;
181 return (KERN_SUCCESS
);
187 task_policy_flavor_t flavor
,
188 task_policy_t policy_info
,
189 mach_msg_type_number_t
*count
,
190 boolean_t
*get_default
)
192 if (task
== TASK_NULL
|| task
== kernel_task
)
193 return (KERN_INVALID_ARGUMENT
);
197 case TASK_CATEGORY_POLICY
:
199 task_category_policy_t info
= (task_category_policy_t
)policy_info
;
201 if (*count
< TASK_CATEGORY_POLICY_COUNT
)
202 return (KERN_INVALID_ARGUMENT
);
205 info
->role
= TASK_UNSPECIFIED
;
208 info
->role
= task
->role
;
215 return (KERN_INVALID_ARGUMENT
);
218 return (KERN_SUCCESS
);