I committed the following patch [1] to NetBSD, it's a valid issue for
OpenBSD as well [2]:
Convert EV_SET from macro to static __inline function
LLDB introduced support for kevent(2) and it contains the following
function:
Status MainLoop::RunImpl::Poll() {
in_events.resize(loop.m_read_fds.size());
unsigned i = 0;
for (auto &fd : loop.m_read_fds)
EV_SET(&in_events[i++], fd.first, EVFILT_READ, EV_ADD, 0, 0, 0);
num_events = kevent(loop.m_kqueue, in_events.data(), in_events.size(),
out_events, llvm::array_lengthof(out_events),
nullptr);
if (num_events < 0)
return Status("kevent() failed with error %d\n", num_events);
return Status();
}
It works on FreeBSD and MacOSX, however it broke on NetBSD.
Culrpit line:
EV_SET(&in_events[i++], fd.first, EVFILT_READ, EV_ADD, 0, 0, 0);
FreeBSD defined EV_SET() as a macro this way:
#define EV_SET(kevp_, a, b, c, d, e, f) do {\
struct kevent *kevp = (kevp_); \
(kevp)->ident = (a);\
(kevp)->filter = (b); \
(kevp)->flags = (c);\
(kevp)->fflags = (d); \
(kevp)->data = (e); \
(kevp)->udata = (f);\
} while(0)
NetBSD version was different:
#define EV_SET(kevp, a, b, c, d, e, f) \
do {\
(kevp)->ident = (a);\
(kevp)->filter = (b); \
(kevp)->flags = (c);\
(kevp)->fflags = (d); \
(kevp)->data = (e); \
(kevp)->udata = (f);\
} while (/* CONSTCOND */ 0)
This resulted in heap damage, as keyp was incremented every time value was
assigned to (keyp)->.
[...]
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/sys/event.h.diff?r1=1.26&r2=1.27&only_with_tag=MAIN&f=h
[2]
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/sys/event.h?annotate=1.23
signature.asc
Description: OpenPGP digital signature