Set job security and resource policies.
#include <zircon/syscalls.h> zx_status_t zx_job_set_policy(zx_handle_t handle, uint32_t options, uint32_t topic, const void* policy, uint32_t policy_size);
Sets one or more security and/or resource policies to an empty job. The job‘s effective policies is the combination of the parent’s effective policies and the policies specified in policy. The effect in the case of conflict between the existing policies and the new policies is controlled by options values:
After this call succeeds any new child process or child job will have the new effective policy applied to it.
topic indicates the policy format. Supported values are ZX_JOB_POL_BASIC_V1, ZX_JOB_POL_BASIC_V2 and ZX_JOB_POL_TIMER_SLACK.
A topic of ZX_JOB_POL_BASIC_V2 indicates that policy is an array of count entries of:
typedef struct zx_policy_basic { uint32_t condition; uint32_t action; uint32_t flags; } zx_policy_basic_v2_t;
A topic of ZX_JOB_POL_BASIC_V1 indicates that policy is an array of count entries of:
// Deprecated. Use zx_policy_basic_v2_t. typedef struct zx_policy_basic { uint32_t condition; uint32_t policy; } zx_policy_basic_v1_t;
Where condition is one of
zx_vmo_replace_as_executable()
with a ZX_HANDLE_INVALID as the second argument rather than a valid ZX_RSRC_KIND_VMEX.Where policy for ZX_JOB_POL_BASIC_V1 or action for ZX_JOB_POL_BASIC_V2 is one of
Where flags is one of
Regardless of the override mode, as long a Job has any children its policy cannot be mutated.
A topic of ZX_JOB_POL_TIMER_SLACK indicates that policy is:
typedef struct zx_policy_timer_slack { zx_duration_t min_slack; uint32_t default_mode; } zx_policy_timer_slack_t;
min_slack specifies the minimum amount of slack applied to timers and deadline-based events created by the job.
If the parent job‘s min_slack is greater than the specified min_slack then the parent job’s value is used instead. In other words, a job‘s min_slack is the maximum of the specified value and its parent job’s min_slack.
default_mode specifies how slack will be applied when not otherwise indicated by the syscall arguments. A job‘s default_mode may be set regardless of its parent job’s default_mode. The possible values for default_mode are:
See timer slack for more information.
When setting timer slack policy, options must be ZX_JOB_POL_RELATIVE and count must be 1.
handle must be of type ZX_OBJ_TYPE_JOB and have ZX_RIGHT_SET_POLICY.
zx_job_set_policy()
returns ZX_OK on success. In the event of failure, a negative error value is returned.
The ZX_POL_BAD_HANDLE policy never applies when calling zx_object_get_info()
with the topic ZX_INFO_HANDLE_VALID. All other topics and all other syscalls that take handles are subject to the policy if active.
ZX_ERR_INVALID_ARGS policy was not a valid pointer, or count was 0, or policy was not ZX_JOB_POL_RELATIVE or ZX_JOB_POL_ABSOLUTE, or topic was not ZX_JOB_POL_BASIC.
ZX_ERR_BAD_HANDLE handle is not valid handle.
ZX_ERR_WRONG_TYPE handle is not a job handle.
ZX_ERR_ACCESS_DENIED handle does not have ZX_POL_RIGHT_SET right.
ZX_ERR_BAD_STATE the job has existing jobs or processes alive.
ZX_ERR_OUT_OF_RANGE count is bigger than ZX_POL_MAX or condition is bigger than ZX_POL_MAX.
ZX_ERR_ALREADY_EXISTS existing policy conflicts with the new policy.
ZX_ERR_NOT_SUPPORTED an entry in policy has an invalid value.
ZX_ERR_NO_MEMORY Failure due to lack of memory. There is no good way for userspace to handle this (unlikely) error. In a future build this error will no longer occur.