Skip to main content

kqueue_sys/constants/
darwin.rs

1use bitflags::bitflags;
2use libc::{c_uint, c_ushort};
3
4#[allow(non_camel_case_types)]
5#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
6#[repr(i16)]
7pub enum EventFilter {
8    EVFILT_READ = -1,
9    EVFILT_WRITE = -2,
10    EVFILT_AIO = -3,      /* attached to aio requests */
11    EVFILT_VNODE = -4,    /* attached to vnodes */
12    EVFILT_PROC = -5,     /* attached to struct proc */
13    EVFILT_SIGNAL = -6,   /* attached to struct proc */
14    EVFILT_TIMER = -7,    /* timers */
15    EVFILT_MACHPORT = -8, /* Mach portsets */
16    EVFILT_FS = -9,       /* Filesystem events */
17    EVFILT_USER = -10,    /* User events */
18    EVFILT_VM = -12,      /* Virtual memory events */
19    EVFILT_SYSCOUNT = 14,
20}
21
22bitflags! {
23    #[repr(transparent)]
24    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Ord, PartialOrd)]
25    pub struct EventFlag: c_ushort {
26        const EV_ADD            = 0x0001;   /* add event to kq (implies enable) */
27        const EV_DELETE         = 0x0002;   /* delete event from kq */
28        const EV_ENABLE         = 0x0004;   /* enable event */
29        const EV_DISABLE        = 0x0008;   /* disable event (not reported) */
30        const EV_UDATA_SPECIFIC = 0x0100;   /* unique kevent per udata value */
31                                            /* ... in combination with EV_DELETE */
32                                            /* will defer delete until udata-specific */
33                                            /* event enabled. EINPROGRESS will be */
34                                            /* returned to indicate the deferral */
35
36        const EV_ONESHOT        = 0x0010;   /* only report one occurrence */
37        const EV_CLEAR          = 0x0020;   /* clear event state after reporting */
38        const EV_RECEIPT        = 0x0040;   /* force EV_ERROR on success, data == 0 */
39        const EV_DISPATCH       = 0x0080;   /* disable event after reporting */
40
41        const EV_SYSFLAGS       = 0xF000;   /* reserved by system */
42        const EV_FLAG0          = 0x1000;   /* filter-specific flag */
43        const EV_FLAG1          = 0x2000;   /* filter-specific flag */
44        const EV_EOF            = 0x8000;   /* EOF detected */
45        const EV_ERROR          = 0x4000;   /* error, data contains errno */
46    }
47}
48
49impl EventFlag {
50    /// Convert from underlying bit representation, preserving all
51    /// bits (even those not corresponding to a defined flag).
52    ///
53    /// # Safety
54    ///
55    /// The caller of the `bitflags!` macro can chose to allow or
56    /// disallow extra bits for their bitflags type.
57    ///
58    /// The caller of `from_bits_unchecked()` has to ensure that
59    /// all bits correspond to a defined flag or that extra bits
60    /// are valid for this bitflags type.
61    #[deprecated = "use the safe `from_bits_retain` method instead"]
62    pub const unsafe fn from_bits_unchecked(bits: c_ushort) -> Self {
63        Self::from_bits_retain(bits)
64    }
65}
66
67bitflags! {
68    #[repr(transparent)]
69    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Ord, PartialOrd)]
70    pub struct FilterFlag: c_uint {
71        const NOTE_FFNOP                        = 0x00000000;   /* ignore input fflags */
72        const NOTE_FFAND                        = 0x40000000;   /* and fflags */
73        const NOTE_FFOR                         = 0x80000000;   /* or fflags */
74        const NOTE_FFCOPY                       = 0xc0000000;   /* copy fflags */
75        const NOTE_FFCTRLMASK                   = 0xc0000000;   /* mask for operations */
76        const NOTE_FFLAGSMASK                   = 0x00ffffff;
77        const NOTE_LOWAT                        = 0x00000001;   /* low water mark */
78        const NOTE_DELETE                       = 0x00000001;   /* vnode was removed */
79        const NOTE_WRITE                        = 0x00000002;   /* data contents changed */
80        const NOTE_EXTEND                       = 0x00000004;   /* size increased */
81        const NOTE_ATTRIB                       = 0x00000008;   /* attributes changed */
82        const NOTE_LINK                         = 0x00000010;   /* link count changed */
83        const NOTE_RENAME                       = 0x00000020;   /* vnode was renamed */
84        const NOTE_REVOKE                       = 0x00000040;   /* vnode access was revoked */
85        const NOTE_NONE                         = 0x00000080;   /* No specific vnode event: to test for EVFILT_READ activation*/
86        const NOTE_EXIT                         = 0x80000000;   /* process exited */
87        const NOTE_FORK                         = 0x40000000;   /* process forked */
88        const NOTE_EXEC                         = 0x20000000;   /* process exec'd */
89        const NOTE_SIGNAL                       = 0x08000000;   /* shared with EVFILT_SIGNAL */
90        const NOTE_EXITSTATUS                   = 0x04000000;   /* exit status to be returned, valid for child process only */
91        const NOTE_EXIT_DETAIL                  = 0x02000000;   /* provide details on reasons for exit */
92        const NOTE_PDATAMASK                    = 0x000fffff;   /* mask for signal & exit status */
93        const NOTE_PCTRLMASK                    = 0xf0000000;
94        const NOTE_SECONDS                      = 0x00000001;   /* data is seconds         */
95        const NOTE_USECONDS                     = 0x00000002;   /* data is microseconds    */
96        const NOTE_NSECONDS                     = 0x00000004;   /* data is nanoseconds     */
97        const NOTE_ABSOLUTE                     = 0x00000008;   /* absolute timeout        */
98                                                                /* ... implicit EV_ONESHOT */
99        const NOTE_LEEWAY                       = 0x00000010;   /* ext[1] holds leeway for power aware timers */
100        const NOTE_CRITICAL                     = 0x00000020;   /* system does minimal timer coalescing */
101        const NOTE_BACKGROUND                   = 0x00000040;   /* system does maximum timer coalescing */
102        const NOTE_VM_PRESSURE                  = 0x80000000;   /* will react on memory pressure */
103        const NOTE_VM_PRESSURE_TERMINATE        = 0x40000000;   /* will quit on memory pressure, possibly after cleaning up dirty state */
104        const NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000;   /* will quit immediately on memory pressure */
105        const NOTE_VM_ERROR                     = 0x10000000;   /* there was an error */
106        const NOTE_TRACK                        = 0x00000001;   /* follow across forks */
107        const NOTE_TRACKERR                     = 0x00000002;   /* could not track child */
108        const NOTE_CHILD                        = 0x00000004;   /* am a child process */
109    }
110}
111
112impl FilterFlag {
113    /// Convert from underlying bit representation, preserving all
114    /// bits (even those not corresponding to a defined flag).
115    ///
116    /// # Safety
117    ///
118    /// The caller of the `bitflags!` macro can chose to allow or
119    /// disallow extra bits for their bitflags type.
120    ///
121    /// The caller of `from_bits_unchecked()` has to ensure that
122    /// all bits correspond to a defined flag or that extra bits
123    /// are valid for this bitflags type.
124    #[deprecated = "use the safe `from_bits_retain` method instead"]
125    pub const unsafe fn from_bits_unchecked(bits: c_uint) -> Self {
126        Self::from_bits_retain(bits)
127    }
128}