| 1 |
// Licensed under the Apache License, Version 2.0 |
| 2 |
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 3 |
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. |
| 4 |
// All files in the project carrying such notice may not be copied, modified, or distributed |
| 5 |
// except according to those terms. |
| 6 |
use shared::basetsd::{SIZE_T, ULONG64}; |
| 7 |
use shared::guiddef::{LPCGUID, LPGUID}; |
| 8 |
use shared::minwindef::{UCHAR, ULONG, USHORT}; |
| 9 |
use um::winnt::{ANYSIZE_ARRAY, BOOLEAN, PCWSTR, PVOID, ULONGLONG, VOID}; |
| 10 |
pub const EVENT_MIN_LEVEL: UCHAR = 0; |
| 11 |
pub const EVENT_MAX_LEVEL: UCHAR = 0xff; |
| 12 |
pub const EVENT_ACTIVITY_CTRL_GET_ID: ULONG = 1; |
| 13 |
pub const EVENT_ACTIVITY_CTRL_SET_ID: ULONG = 2; |
| 14 |
pub const EVENT_ACTIVITY_CTRL_CREATE_ID: ULONG = 3; |
| 15 |
pub const EVENT_ACTIVITY_CTRL_GET_SET_ID: ULONG = 4; |
| 16 |
pub const EVENT_ACTIVITY_CTRL_CREATE_SET_ID: ULONG = 5; |
| 17 |
pub const MAX_EVENT_DATA_DESCRIPTORS: SIZE_T = 128; |
| 18 |
pub const MAX_EVENT_FILTER_DATA_SIZE: SIZE_T = 1024; |
| 19 |
pub const MAX_EVENT_FILTER_PAYLOAD_SIZE: SIZE_T = 4096; |
| 20 |
pub const MAX_EVENT_FILTER_EVENT_NAME_SIZE: SIZE_T = 4096; |
| 21 |
pub const MAX_EVENT_FILTERS_COUNT: SIZE_T = 8; |
| 22 |
pub const MAX_EVENT_FILTER_PID_COUNT: SIZE_T = 8; |
| 23 |
pub const MAX_EVENT_FILTER_EVENT_ID_COUNT: SIZE_T = 64; |
| 24 |
pub const EVENT_FILTER_TYPE_NONE: ULONG = 0x00000000; |
| 25 |
pub const EVENT_FILTER_TYPE_SCHEMATIZED: ULONG = 0x80000000; |
| 26 |
pub const EVENT_FILTER_TYPE_SYSTEM_FLAGS: ULONG = 0x80000001; |
| 27 |
pub const EVENT_FILTER_TYPE_TRACEHANDLE: ULONG = 0x80000002; |
| 28 |
pub const EVENT_FILTER_TYPE_PID: ULONG = 0x80000004; |
| 29 |
pub const EVENT_FILTER_TYPE_EXECUTABLE_NAME: ULONG = 0x80000008; |
| 30 |
pub const EVENT_FILTER_TYPE_PACKAGE_ID: ULONG = 0x80000010; |
| 31 |
pub const EVENT_FILTER_TYPE_PACKAGE_APP_ID: ULONG = 0x80000020; |
| 32 |
pub const EVENT_FILTER_TYPE_PAYLOAD: ULONG = 0x80000100; |
| 33 |
pub const EVENT_FILTER_TYPE_EVENT_ID: ULONG = 0x80000200; |
| 34 |
pub const EVENT_FILTER_TYPE_EVENT_NAME: ULONG = 0x80000400; |
| 35 |
pub const EVENT_FILTER_TYPE_STACKWALK: ULONG = 0x80001000; |
| 36 |
pub const EVENT_FILTER_TYPE_STACKWALK_NAME: ULONG = 0x80001000; |
| 37 |
pub const EVENT_FILTER_TYPE_STACKWALK_LEVEL_KW: ULONG = 0x80004000; |
| 38 |
pub const EVENT_DATA_DESCRIPTOR_TYPE_NONE: UCHAR = 0; |
| 39 |
pub const EVENT_DATA_DESCRIPTOR_TYPE_EVENT_METADATA: UCHAR = 1; |
| 40 |
pub const EVENT_DATA_DESCRIPTOR_TYPE_PROVIDER_METADATA: UCHAR = 2; |
| 41 |
pub const EVENT_DATA_DESCRIPTOR_TYPE_TIMESTAMP_OVERRIDE: UCHAR = 3; |
| 42 |
pub const EVENT_WRITE_FLAG_NO_FAULTING: ULONG = 0x00000001; |
| 43 |
pub const EVENT_WRITE_FLAG_INPRIVATE: ULONG = 0x00000002; |
| 44 |
pub type REGHANDLE = ULONGLONG; |
| 45 |
pub type PREGHANDLE = *mut REGHANDLE; |
| 46 |
STRUCT!{struct EVENT_DATA_DESCRIPTOR_u_s { |
| 47 |
Type: UCHAR, |
| 48 |
Reserved1: UCHAR, |
| 49 |
Reserved2: USHORT, |
| 50 |
}} |
| 51 |
UNION!{union EVENT_DATA_DESCRIPTOR_u { |
| 52 |
[u32; 1], |
| 53 |
Reserved Reserved_mut: ULONG, |
| 54 |
s s_mut: EVENT_DATA_DESCRIPTOR_u_s, |
| 55 |
}} |
| 56 |
STRUCT!{struct EVENT_DATA_DESCRIPTOR { |
| 57 |
Ptr: ULONGLONG, |
| 58 |
Size: ULONG, |
| 59 |
u: EVENT_DATA_DESCRIPTOR_u, |
| 60 |
}} |
| 61 |
pub type PEVENT_DATA_DESCRIPTOR = *mut EVENT_DATA_DESCRIPTOR; |
| 62 |
STRUCT!{struct EVENT_DESCRIPTOR { |
| 63 |
Id: USHORT, |
| 64 |
Version: UCHAR, |
| 65 |
Channel: UCHAR, |
| 66 |
Level: UCHAR, |
| 67 |
Opcode: UCHAR, |
| 68 |
Task: USHORT, |
| 69 |
Keyword: ULONGLONG, |
| 70 |
}} |
| 71 |
pub type PEVENT_DESCRIPTOR = *mut EVENT_DESCRIPTOR; |
| 72 |
pub type PCEVENT_DESCRIPTOR = *const EVENT_DESCRIPTOR; |
| 73 |
STRUCT!{struct EVENT_FILTER_DESCRIPTOR { |
| 74 |
Ptr: ULONGLONG, |
| 75 |
Size: ULONG, |
| 76 |
Type: ULONG, |
| 77 |
}} |
| 78 |
pub type PEVENT_FILTER_DESCRIPTOR = *mut EVENT_FILTER_DESCRIPTOR; |
| 79 |
STRUCT!{struct EVENT_FILTER_HEADER { |
| 80 |
Id: USHORT, |
| 81 |
Version: UCHAR, |
| 82 |
Reserved: [UCHAR; 5], |
| 83 |
InstanceId: ULONGLONG, |
| 84 |
Size: ULONG, |
| 85 |
NextOffset: ULONG, |
| 86 |
}} |
| 87 |
pub type PEVENT_FILTER_HEADER = *mut EVENT_FILTER_HEADER; |
| 88 |
STRUCT!{struct EVENT_FILTER_EVENT_ID { |
| 89 |
FilterIn: BOOLEAN, |
| 90 |
Reserved: UCHAR, |
| 91 |
Count: USHORT, |
| 92 |
Events: [USHORT; ANYSIZE_ARRAY], |
| 93 |
}} |
| 94 |
pub type PEVENT_FILTER_EVENT_ID = *mut EVENT_FILTER_EVENT_ID; |
| 95 |
STRUCT!{struct EVENT_FILTER_EVENT_NAME { |
| 96 |
MatchAnyKeyword: ULONGLONG, |
| 97 |
MatchAllKeyword: ULONGLONG, |
| 98 |
Level: UCHAR, |
| 99 |
FilterIn: BOOLEAN, |
| 100 |
NameCount: USHORT, |
| 101 |
Names: [UCHAR; ANYSIZE_ARRAY], |
| 102 |
}} |
| 103 |
pub type PEVENT_FILTER_EVENT_NAME = *mut EVENT_FILTER_EVENT_NAME; |
| 104 |
STRUCT!{struct EVENT_FILTER_LEVEL_KW { |
| 105 |
MatchAnyKeyword: ULONGLONG, |
| 106 |
MatchAllKeyword: ULONGLONG, |
| 107 |
Level: UCHAR, |
| 108 |
FilterIn: BOOLEAN, |
| 109 |
}} |
| 110 |
ENUM!{enum EVENT_INFO_CLASS { |
| 111 |
EventProviderBinaryTrackInfo, |
| 112 |
EventProviderSetReserved1, |
| 113 |
EventProviderSetTraits, |
| 114 |
EventProviderUseDescriptorType, |
| 115 |
MaxEventInfo, |
| 116 |
}} |
| 117 |
FN!{stdcall PENABLECALLBACK( |
| 118 |
SourceId: LPCGUID, |
| 119 |
IsEnabled: ULONG, |
| 120 |
Level: UCHAR, |
| 121 |
MatchAnyKeyword: ULONGLONG, |
| 122 |
MatchAllKeyword: ULONGLONG, |
| 123 |
FilterData: PEVENT_FILTER_DESCRIPTOR, |
| 124 |
CallbackContext: PVOID, |
| 125 |
) -> ()} |
| 126 |
extern "system" { |
| 127 |
pub fn EventRegister( |
| 128 |
ProviderId: LPCGUID, |
| 129 |
EnableCallback: PENABLECALLBACK, |
| 130 |
CallbackContext: PVOID, |
| 131 |
RegHandle: PREGHANDLE, |
| 132 |
) -> ULONG; |
| 133 |
pub fn EventUnregister( |
| 134 |
RegHandle: REGHANDLE, |
| 135 |
) -> ULONG; |
| 136 |
pub fn EventSetInformation( |
| 137 |
RegHandle: REGHANDLE, |
| 138 |
InformationClass: EVENT_INFO_CLASS, |
| 139 |
EventInformation: PVOID, |
| 140 |
InformationLength: ULONG, |
| 141 |
) -> ULONG; |
| 142 |
pub fn EventEnabled( |
| 143 |
RegHandle: REGHANDLE, |
| 144 |
EventDescriptor: PCEVENT_DESCRIPTOR, |
| 145 |
) -> BOOLEAN; |
| 146 |
pub fn EventProviderEnabled( |
| 147 |
RegHandle: REGHANDLE, |
| 148 |
Level: UCHAR, |
| 149 |
Keyword: ULONGLONG, |
| 150 |
) -> BOOLEAN; |
| 151 |
pub fn EventWrite( |
| 152 |
RegHandle: REGHANDLE, |
| 153 |
EventDescriptor: PCEVENT_DESCRIPTOR, |
| 154 |
UserDataCount: ULONG, |
| 155 |
UserData: PEVENT_DATA_DESCRIPTOR, |
| 156 |
) -> ULONG; |
| 157 |
pub fn EventWriteTransfer( |
| 158 |
RegHandle: REGHANDLE, |
| 159 |
EventDescriptor: PCEVENT_DESCRIPTOR, |
| 160 |
ActivityId: LPCGUID, |
| 161 |
RelatedActivityId: LPCGUID, |
| 162 |
UserDataCount: ULONG, |
| 163 |
UserData: PEVENT_DATA_DESCRIPTOR, |
| 164 |
) -> ULONG; |
| 165 |
pub fn EventWriteEx( |
| 166 |
RegHandle: REGHANDLE, |
| 167 |
EventDescriptor: PCEVENT_DESCRIPTOR, |
| 168 |
Filter: ULONG64, |
| 169 |
Flags: ULONG, |
| 170 |
ActivityId: LPCGUID, |
| 171 |
RelatedActivityId: LPCGUID, |
| 172 |
UserDataCount: ULONG, |
| 173 |
UserData: PEVENT_DATA_DESCRIPTOR, |
| 174 |
) -> ULONG; |
| 175 |
pub fn EventWriteString( |
| 176 |
RegHandle: REGHANDLE, |
| 177 |
Level: UCHAR, |
| 178 |
Keyword: ULONGLONG, |
| 179 |
EventString: PCWSTR, |
| 180 |
) -> ULONG; |
| 181 |
pub fn EventActivityIdControl( |
| 182 |
ControlCode: ULONG, |
| 183 |
ActivityId: LPGUID, |
| 184 |
) -> ULONG; |
| 185 |
} |
| 186 |
#[inline] |
| 187 |
pub unsafe fn EventDataDescCreate( |
| 188 |
EventDataDescriptor: PEVENT_DATA_DESCRIPTOR, |
| 189 |
DataPtr: *const VOID, |
| 190 |
DataSize: ULONG, |
| 191 |
) { |
| 192 |
(*EventDataDescriptor).Ptr = DataPtr as ULONGLONG; |
| 193 |
(*EventDataDescriptor).Size = DataSize; |
| 194 |
*(*EventDataDescriptor).u.Reserved_mut() = 0; |
| 195 |
} |
| 196 |
#[inline] |
| 197 |
pub unsafe fn EventDescCreate( |
| 198 |
EventDescriptor: PEVENT_DESCRIPTOR, |
| 199 |
Id: USHORT, |
| 200 |
Version: UCHAR, |
| 201 |
Channel: UCHAR, |
| 202 |
Level: UCHAR, |
| 203 |
Task: USHORT, |
| 204 |
Opcode: UCHAR, |
| 205 |
Keyword: ULONGLONG, |
| 206 |
) { |
| 207 |
(*EventDescriptor).Id = Id; |
| 208 |
(*EventDescriptor).Version = Version; |
| 209 |
(*EventDescriptor).Channel = Channel; |
| 210 |
(*EventDescriptor).Level = Level; |
| 211 |
(*EventDescriptor).Task = Task; |
| 212 |
(*EventDescriptor).Opcode = Opcode; |
| 213 |
(*EventDescriptor).Keyword = Keyword; |
| 214 |
} |
| 215 |
#[inline] |
| 216 |
pub unsafe fn EventDescZero(EventDescriptor: PEVENT_DESCRIPTOR) { |
| 217 |
use core::ptr::write_bytes; |
| 218 |
// FIXME: 16 = sizeof::<EVENT_DESCRIPTOR>() |
| 219 |
write_bytes(EventDescriptor, 0, 16); |
| 220 |
} |
| 221 |
#[inline] |
| 222 |
pub unsafe fn EventDescGetId(EventDescriptor: PCEVENT_DESCRIPTOR) -> USHORT { |
| 223 |
(*EventDescriptor).Id |
| 224 |
} |
| 225 |
#[inline] |
| 226 |
pub unsafe fn EventDescGetVersion(EventDescriptor: PCEVENT_DESCRIPTOR) -> UCHAR { |
| 227 |
(*EventDescriptor).Version |
| 228 |
} |
| 229 |
#[inline] |
| 230 |
pub unsafe fn EventDescGetTask(EventDescriptor: PCEVENT_DESCRIPTOR) -> USHORT { |
| 231 |
(*EventDescriptor).Task |
| 232 |
} |
| 233 |
#[inline] |
| 234 |
pub unsafe fn EventDescGetOpcode(EventDescriptor: PCEVENT_DESCRIPTOR) -> UCHAR { |
| 235 |
(*EventDescriptor).Opcode |
| 236 |
} |
| 237 |
#[inline] |
| 238 |
pub unsafe fn EventDescGetChannel(EventDescriptor: PCEVENT_DESCRIPTOR) -> UCHAR { |
| 239 |
(*EventDescriptor).Channel |
| 240 |
} |
| 241 |
#[inline] |
| 242 |
pub unsafe fn EventDescGetLevel(EventDescriptor: PCEVENT_DESCRIPTOR) -> UCHAR { |
| 243 |
(*EventDescriptor).Level |
| 244 |
} |
| 245 |
#[inline] |
| 246 |
pub unsafe fn EventDescGetKeyword(EventDescriptor: PCEVENT_DESCRIPTOR) -> ULONGLONG { |
| 247 |
(*EventDescriptor).Keyword |
| 248 |
} |
| 249 |
#[inline] |
| 250 |
pub unsafe fn EventDescSetId(EventDescriptor: PEVENT_DESCRIPTOR, Id: USHORT) -> PEVENT_DESCRIPTOR { |
| 251 |
(*EventDescriptor).Id = Id; |
| 252 |
EventDescriptor |
| 253 |
} |
| 254 |
#[inline] |
| 255 |
pub unsafe fn EventDescSetVersion( |
| 256 |
EventDescriptor: PEVENT_DESCRIPTOR, |
| 257 |
Version: UCHAR, |
| 258 |
) -> PEVENT_DESCRIPTOR { |
| 259 |
(*EventDescriptor).Version = Version; |
| 260 |
EventDescriptor |
| 261 |
} |
| 262 |
#[inline] |
| 263 |
pub unsafe fn EventDescSetTask( |
| 264 |
EventDescriptor: PEVENT_DESCRIPTOR, |
| 265 |
Task: USHORT, |
| 266 |
) -> PEVENT_DESCRIPTOR { |
| 267 |
(*EventDescriptor).Task = Task; |
| 268 |
EventDescriptor |
| 269 |
} |
| 270 |
#[inline] |
| 271 |
pub unsafe fn EventDescSetOpcode( |
| 272 |
EventDescriptor: PEVENT_DESCRIPTOR, |
| 273 |
Opcode: UCHAR, |
| 274 |
) -> PEVENT_DESCRIPTOR { |
| 275 |
(*EventDescriptor).Opcode = Opcode; |
| 276 |
EventDescriptor |
| 277 |
} |
| 278 |
#[inline] |
| 279 |
pub unsafe fn EventDescSetLevel( |
| 280 |
EventDescriptor: PEVENT_DESCRIPTOR, |
| 281 |
Level: UCHAR, |
| 282 |
) -> PEVENT_DESCRIPTOR { |
| 283 |
(*EventDescriptor).Level = Level; |
| 284 |
EventDescriptor |
| 285 |
} |
| 286 |
#[inline] |
| 287 |
pub unsafe fn EventDescSetChannel( |
| 288 |
EventDescriptor: PEVENT_DESCRIPTOR, |
| 289 |
Channel: UCHAR, |
| 290 |
) -> PEVENT_DESCRIPTOR { |
| 291 |
(*EventDescriptor).Channel = Channel; |
| 292 |
EventDescriptor |
| 293 |
} |
| 294 |
#[inline] |
| 295 |
pub unsafe fn EventDescSetKeyword( |
| 296 |
EventDescriptor: PEVENT_DESCRIPTOR, |
| 297 |
Keyword: ULONGLONG, |
| 298 |
) -> PEVENT_DESCRIPTOR { |
| 299 |
(*EventDescriptor).Keyword = Keyword; |
| 300 |
EventDescriptor |
| 301 |
} |
| 302 |
#[inline] |
| 303 |
pub unsafe fn EventDescOrKeyword( |
| 304 |
EventDescriptor: PEVENT_DESCRIPTOR, |
| 305 |
Keyword: ULONGLONG, |
| 306 |
) -> PEVENT_DESCRIPTOR { |
| 307 |
(*EventDescriptor).Keyword |= Keyword; |
| 308 |
EventDescriptor |
| 309 |
} |