@@ -84,9 +84,96 @@ int sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
84
84
LINUX_PORT_ERROR ();
85
85
}
86
86
87
- int kevent64 (int kq , const struct kevent * changelist , int nchanges , struct kevent * eventlist , int nevents ,unsigned int flags , const struct timespec * timeout )
87
+
88
+ DISPATCH_NOINLINE
89
+ static const char *
90
+ _evfiltstr (short filt )
91
+ {
92
+ switch (filt ) {
93
+ #define _evfilt2 (f ) case (f): return #f
94
+ _evfilt2 (EVFILT_READ );
95
+ _evfilt2 (EVFILT_WRITE );
96
+ _evfilt2 (EVFILT_AIO );
97
+ _evfilt2 (EVFILT_VNODE );
98
+ _evfilt2 (EVFILT_PROC );
99
+ _evfilt2 (EVFILT_SIGNAL );
100
+ _evfilt2 (EVFILT_TIMER );
101
+ #if HAVE_MACH
102
+ _evfilt2 (EVFILT_MACHPORT );
103
+ _evfilt2 (DISPATCH_EVFILT_MACH_NOTIFICATION );
104
+ #endif
105
+ _evfilt2 (EVFILT_FS );
106
+ _evfilt2 (EVFILT_USER );
107
+ #ifdef EVFILT_VM
108
+ _evfilt2 (EVFILT_VM );
109
+ #endif
110
+ #ifdef EVFILT_SOCK
111
+ _evfilt2 (EVFILT_SOCK );
112
+ #endif
113
+ #ifdef EVFILT_MEMORYSTATUS
114
+ _evfilt2 (EVFILT_MEMORYSTATUS );
115
+ #endif
116
+
117
+ _evfilt2 (DISPATCH_EVFILT_TIMER );
118
+ _evfilt2 (DISPATCH_EVFILT_CUSTOM_ADD );
119
+ _evfilt2 (DISPATCH_EVFILT_CUSTOM_OR );
120
+ default :
121
+ return "EVFILT_missing" ;
122
+ }
123
+ }
124
+
125
+ #if 0
126
+ #define dbg_kevent64 (fmt ...) do { printf(fmt); } while(0)
127
+ #define dbg_cond_kevent64 (cond ,fmt ...) do { if (cond) printf(fmt); } while(0)
128
+ #else
129
+ #define dbg_kevent64 (fmt ...) do { } while(0)
130
+ #define dbg_cond_kevent64 (cond ,fmt ...) do { } while(0)
131
+ #endif
132
+
133
+ #include <time.h>
134
+
135
+ int kevent64 (int kq , /*const*/ struct kevent64_s * changelist , int nchanges , struct kevent64_s * eventlist ,
136
+ int nevents , unsigned int flags , const struct timespec * timeout )
88
137
{
89
- return kevent (kq ,changelist ,nchanges ,eventlist ,nevents ,timeout );
138
+ // Documentation is not really clear. Instrument the code to make sure
139
+ // we can do type conversions right now between kevent64 <-> kevent, where as
140
+ // kevent64 uses the ext[2] extension. So far we only see these used in the EVFILT_TIMER.
141
+ // right now we do this in the way into kevent, we also have to assert that
142
+ // no more than 1 change or one event is passed until we get a better handle of the
143
+ // usage pattern of this. (Hubertus Franke)
144
+
145
+ #if 1
146
+ // lets put some checks in here to make sure we do it all correct
147
+ // we can only convert kevent64_s -> kevent for a single entry since kevent64_s has ext[0:1] extension
148
+ if ((nchanges > 1 ) || (nevents > 1 ))
149
+ LINUX_PORT_ERROR ();
150
+ if (nchanges ) {
151
+ dbg_kevent64 ("kevent64(%s,%x,%x): cl.ext[0,1]=%lx:%ld %lx:%ld cl.data=%lx:%ld\n" ,
152
+ _evfiltstr (changelist -> filter ), changelist -> flags , changelist -> fflags ,
153
+ changelist -> ext [0 ], changelist -> ext [0 ],
154
+ changelist -> ext [1 ], changelist -> ext [1 ],
155
+ changelist -> data , changelist -> data );
156
+ if ((changelist -> filter == EVFILT_TIMER ) && (changelist -> fflags & NOTE_ABSOLUTE )) {
157
+ // NOTE_ABSOLUTE is not recognized by the current kevent we need to convert this
158
+ // into a relative. Consider fiddling with creating relative events instead (didn't work
159
+ // on first attempt). We also ignore the LEEWAY. Finally we must convert from
160
+ // NSECS to MSECS (might have to expand to deal with OTHER NOTE_xSECS flags
161
+
162
+ changelist -> data -= _dispatch_get_nanoseconds ();
163
+ //changelist->data -= time(NULL) * NSEC_PER_SEC;
164
+ dbg_kevent64 ("kevent64(%s,%x) data=%lx:%ld\n" ,
165
+ _evfiltstr (changelist -> filter ),changelist -> fflags ,
166
+ changelist -> data ,changelist -> data );
167
+ changelist -> data /= 1000000UL ;
168
+ if ((int64_t )(changelist -> data ) <= 0 ) changelist -> data = 1 ; // for some reason time turns negative
169
+ }
170
+ }
171
+ #endif
172
+ // eventlist can not return more than 1 event type coersion doesn't work
173
+ int rc = kevent (kq ,(struct kevent * ) changelist ,nchanges ,(struct kevent * ) eventlist ,nevents ,timeout );
174
+ if (rc > 1 )
175
+ LINUX_PORT_ERROR ();
176
+ return rc ;
90
177
}
91
178
92
179
/*
0 commit comments