1/* 2 * Copyright (c) 2016 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 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. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 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. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 29#include <mach/mach_types.defs> // mach_port_t 30#include <mach/clock_types.defs> // mach_timespec_t 31 32#if KERNEL_USER 33import <mach/resource_monitors.h>; 34import <mach/clock_types.h>; 35#else 36import <System/mach/resource_monitors.h>; 37import <System/mach/clock_types.h>; 38#endif 39 40// match struct proc.p_name / proc_name_t as of January 2016 41#define MAXCOMLEN 16 42type proc_name_t = array [2*MAXCOMLEN+1] of char; 43type posix_path_t = array [1024] of char; /* 1024 == PATH_MAX */ 44type resource_notify_flags_t = uint64_t; 45 46/* The kernel sends the message, so we compile with KernelUser when 47 building in the kernel. */ 48subsystem 49#if KERNEL_USER 50 KernelUser 51#endif 52 resource_notify 827800; /* 'R''N'00 */ 53 54UserPrefix send_; 55ServerPrefix receive_; 56 57 58SimpleRoutine cpu_usage_violation( 59 receiver : mach_port_t; 60 61 /* violator */ 62 procname : proc_name_t; 63 pid : int; 64 killed_proc_path : posix_path_t; /* filled in if fatal */ 65 66 /* violation */ 67 timestamp : mach_timespec_t; /* 32b time, see 25567702 */ 68 observed_cpu_nsecs : int64_t; 69 observation_nsecs : int64_t; /* time it took to hit limit */ 70 71 /* threshold crossed: calculated from proc_set_cpumon_params() */ 72 cpu_nsecs_allowed : int64_t; 73 limit_window_nsecs : int64_t; /* over this period */ 74 75 flags : resource_notify_flags_t 76); 77 78SimpleRoutine cpu_wakes_violation( 79 receiver : mach_port_t; 80 81 /* violator */ 82 procname : proc_name_t; 83 pid : int; 84 killed_proc_path : posix_path_t; /* filled in if fatal */ 85 86 /* violation */ 87 timestamp : mach_timespec_t; 88 observed_cpu_wakes : int64_t; 89 observation_nsecs : int64_t; /* time it took to hit limit */ 90 91 /* threshold crossed: calculated from proc_set_wakemon_params() */ 92 cpu_wakes_allowed : int64_t; 93 limit_window_nsecs : int64_t; /* over this period */ 94 95 flags : resource_notify_flags_t 96); 97 98SimpleRoutine disk_writes_violation( 99 receiver : mach_port_t; 100 101 /* violator */ 102 procname : proc_name_t; 103 pid : int; 104 killed_proc_path : posix_path_t; /* filled in if fatal */ 105 106 /* violation */ 107 timestamp : mach_timespec_t; 108 observed_bytes_dirtied : int64_t; 109 observation_nsecs : int64_t; /* time it took to hit limit */ 110 111 /* threshold */ 112 bytes_dirtied_allowed : int64_t; 113 limit_window_nsecs : int64_t; /* over this period */ 114 115 flags : resource_notify_flags_t 116); 117 118SimpleRoutine port_space_violation( 119 receiver : mach_port_t; 120 121 /* violator */ 122 procname : proc_name_t; 123 pid : int; 124 125 /* violation */ 126 timestamp : mach_timespec_t; 127 observed_ports : int64_t; 128 129 /* threshold */ 130 ports_allowed : int64_t; 131 132 /* kill port */ 133 fatal_port : mach_port_copy_send_t; 134 135 flags : resource_notify_flags_t 136); 137 138SimpleRoutine file_descriptors_violation( 139 receiver : mach_port_t; 140 141 /* violator */ 142 procname : proc_name_t; 143 pid : int; 144 145 /* violation */ 146 timestamp : mach_timespec_t; 147 observed_filedesc : int64_t; 148 149 /* threshold */ 150 filedesc_allowed : int64_t; 151 152 /* kill port */ 153 fatal_port : mach_port_copy_send_t; 154 155 flags : resource_notify_flags_t 156); 157 158#if (KERNEL_USER || KQWORKLOOPS_VIOLATION_SUPPORTED) 159SimpleRoutine kqworkloops_violation( 160 receiver : mach_port_t; 161 162 /* violator */ 163 procname : proc_name_t; 164 pid : int; 165 166 /* violation */ 167 timestamp : mach_timespec_t; 168 observed_kqworkloops : int64_t; 169 170 /* threshold */ 171 kqworkloops_allowed : int64_t; 172 173 /* kill port */ 174 fatal_port : mach_port_copy_send_t; 175 176 flags : resource_notify_flags_t 177); 178#else 179skip; 180#endif 181/* vim: set ft=c : */ 182