#ifndef _COMPAT_SYS_EVENT_H_
#define _COMPAT_SYS_EVENT_H_
#include <sys/cdefs.h>
struct timespec;
struct timespec50;
#ifdef _KERNEL
#include <lib/libkern/libkern.h>
#else
#include <string.h>
#endif
struct kevent100 {
uintptr_t ident;
uint32_t filter;
uint32_t flags;
uint32_t fflags;
int64_t data;
void *udata;
};
static __inline void
kevent100_to_kevent(const struct kevent100 *kev100, struct kevent *kev)
{
memset(kev, 0, sizeof(*kev));
memcpy(kev, kev100, sizeof(*kev100));
}
static __inline void
kevent_to_kevent100(const struct kevent *kev, struct kevent100 *kev100)
{
memcpy(kev100, kev, sizeof(*kev100));
}
#ifdef _KERNEL
static __inline int
compat_100___kevent50_fetch_changes(void *ctx, const struct kevent *changelist,
struct kevent *changes, size_t index, int n)
{
int error, i;
struct kevent100 *buf;
const size_t buf_size = sizeof(*buf) * n;
const struct kevent100 *changelist100 = (const struct kevent100 *)changelist;
KASSERT(n >= 0);
buf = kmem_alloc(buf_size, KM_SLEEP);
error = copyin(changelist100 + index, buf, buf_size);
if (error != 0)
goto leave;
for (i = 0; i < n; i++)
kevent100_to_kevent(buf + i, changes + i);
leave:
kmem_free(buf, buf_size);
return error;
}
static __inline int
compat_100___kevent50_put_events(void *ctx, struct kevent *events,
struct kevent *eventlist, size_t index, int n)
{
int error, i;
struct kevent100 *buf;
const size_t buf_size = sizeof(*buf) * n;
struct kevent100 *eventlist100 = (struct kevent100 *)eventlist;
KASSERT(n >= 0);
buf = kmem_alloc(buf_size, KM_SLEEP);
for (i = 0; i < n; i++)
kevent_to_kevent100(events + i, buf + i);
error = copyout(buf, eventlist100 + index, buf_size);
kmem_free(buf, buf_size);
return error;
}
#endif
__BEGIN_DECLS
int kevent(int, const struct kevent100 *, size_t, struct kevent100 *,
size_t, const struct timespec50 *);
int __kevent50(int, const struct kevent100 *, size_t, struct kevent100 *,
size_t, const struct timespec *);
int __kevent100(int, const struct kevent *, size_t, struct kevent *,
size_t, const struct timespec *);
__END_DECLS
#endif