]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/task_policy.c
xnu-124.13.tar.gz
[apple/xnu.git] / osfmk / kern / task_policy.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
24 *
25 * HISTORY
26 *
27 * 15 October 2000 (debo)
28 * Created.
29 */
30
31 #include <mach/mach_types.h>
32
33 kern_return_t
34 task_policy_set(
35 task_t task,
36 task_policy_flavor_t flavor,
37 task_policy_t policy_info,
38 mach_msg_type_number_t count)
39 {
40 if (task == TASK_NULL)
41 return (KERN_INVALID_ARGUMENT);
42
43 switch (flavor) {
44
45 case TASK_CATEGORY_POLICY:
46 {
47 task_category_policy_t info = (task_category_policy_t)policy_info;
48
49 if (count < TASK_CATEGORY_POLICY_COUNT)
50 return (KERN_INVALID_ARGUMENT);
51
52 switch (info->role) {
53
54 case TASK_UNSPECIFIED:
55 case TASK_FOREGROUND_APPLICATION:
56 case TASK_BACKGROUND_APPLICATION:
57 case TASK_CONTROL_APPLICATION:
58 case TASK_GRAPHICS_SERVER:
59 return (KERN_SUCCESS);
60
61 default:
62 return (KERN_INVALID_ARGUMENT);
63 }
64
65 break;
66 }
67
68 default:
69 return (KERN_INVALID_ARGUMENT);
70 }
71
72 return (KERN_SUCCESS);
73 }
74
75 kern_return_t
76 task_policy_get(
77 task_t task,
78 task_policy_flavor_t flavor,
79 task_policy_t policy_info,
80 mach_msg_type_number_t *count,
81 boolean_t *get_default)
82 {
83 if (task == TASK_NULL)
84 return (KERN_INVALID_ARGUMENT);
85
86 switch (flavor) {
87
88 case TASK_CATEGORY_POLICY:
89 {
90 task_category_policy_t info = (task_category_policy_t)policy_info;
91
92 if (*count < TASK_CATEGORY_POLICY_COUNT)
93 return (KERN_INVALID_ARGUMENT);
94
95 info->role = TASK_UNSPECIFIED;
96 break;
97 }
98
99 default:
100 return (KERN_INVALID_ARGUMENT);
101 }
102
103 return (KERN_SUCCESS);
104 }