Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mheily/libkqueue
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: darlinghq/darling-libkqueue
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
Loading
50 changes: 43 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -14,11 +14,27 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.13)
INCLUDE (CheckIncludeFiles)

project(kqueue)

if (DARLING)
include_directories(
"${CMAKE_SOURCE_DIR}/src/external/xnu"
"${CMAKE_BINARY_DIR}/src/external/darlingserver/include"
"${CMAKE_SOURCE_DIR}/src/external/darlingserver/include"
)

# For epoll
include_directories("${CMAKE_SOURCE_DIR}/src/external/xnu/darling/src/libsystem_kernel/emulation/linux/ext")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -DHAVE_SYS_EVENTFD_H -DHAVE_SYS_SIGNALFD_H -DHAVE_SYS_TIMERFD_H -ggdb -O0")

#add_definitions(-DKERNEL_PRIVATE)
#add_definitions(-Dkqueue=kqueue_impl -Dkevent=kevent_impl -Dkevent64=kevent64_impl)
#add_definitions(-Dclose=__close_for_kqueue)
endif (DARLING)

#files
file(GLOB_RECURSE INCL include/*.h)
source_group(includes FILES ${INCL})
@@ -57,6 +73,9 @@ else()
src/linux/vnode.c
src/linux/write.c
src/linux/read.c
src/linux/proc.c
src/linux/machport.c
src/linux/fs.c
src/common/*.h
src/common/filter.c
src/common/knote.c
@@ -68,41 +87,58 @@ else()
src/common
)
add_definitions(
-Wall -Werror
-Wall
-fpic
-D_XOPEN_SOURCE=600
-std=c99
-fvisibility=hidden
-D__linux__
)
endif()
source_group(src FILES ${SRC})

if (DARLING)
file(GLOB SRC_DARLING
src/darling/*.h
src/darling/*.c
)
list (APPEND SRC ${SRC_DARLING})
add_definitions(
-DDARLING=1
)
endif (DARLING)

#includes
include_directories(
include
)

#library (static or shared)
option(STATIC_KQUEUE "Enable to build libkqueue as static lib" OFF)

if (DARLING)
set (STATIC_KQUEUE ON)
endif (DARLING)

if(STATIC_KQUEUE)
message("-- building libkqueue as static lib")
add_library(kqueue STATIC ${SRC} ${INCL})
add_darling_object_library(kqueue ${SRC} ${INCL})
make_fat(kqueue)
else()
add_library(kqueue SHARED ${SRC} ${INCL})
endif()

if(WIN32)
set(LIB ${LIB} Ws2_32)
endif()
if(NOT WIN32)
if(NOT WIN32 AND NOT DARLING)
set(LIB ${LIB} pthread)
endif()
target_link_libraries(kqueue ${LIB})
set_target_properties(kqueue PROPERTIES DEBUG_POSTFIX "D")

#tests
option(KQUEUE_TESTS "Enable to build tests for libkqueue" OFF)
if(KQUEUE_TESTS)
message("-- Adding tests for libkqueue")
add_subdirectory(test)
endif()

install(FILES kqueue.2 DESTINATION libexec/darling/usr/share/man/man2)
31 changes: 26 additions & 5 deletions include/sys/event.h
Original file line number Diff line number Diff line change
@@ -27,8 +27,25 @@
* $FreeBSD SVN Revision 197533$
*/

#ifndef _SYS_EVENT_H_
#define _SYS_EVENT_H_
#ifndef _SYS_EVENT_KQ_H_
#define _SYS_EVENT_KQ_H_

#ifdef DARLING
# include <sys/event.h>

struct kevent_internal_s {
uint64_t ident; /* identifier for this event */
int16_t filter; /* filter for event */
uint16_t flags; /* general flags */
int32_t qos; /* quality of service */
uint32_t fflags; /* filter-specific flags */
// uint32_t xflags; /* extra filter-specific flags */
int64_t data; /* filter-specific data */
uint64_t udata; /* opaque user data identifier */
uint64_t ext[4]; /* filter-specific extensions */
};

#else

#include <sys/types.h>

@@ -55,9 +72,9 @@ struct timespec;
#define EVFILT_TIMER (-7) /* timers */
#define EVFILT_NETDEV (-8) /* network devices */
#define EVFILT_FS (-9) /* filesystem events */
#define EVFILT_LIO (-10) /* attached to lio requests */
#define EVFILT_USER (-11) /* User events */
#define EVFILT_SYSCOUNT 11
//#define EVFILT_LIO (-10) /* attached to lio requests */
#define EVFILT_USER (-10) /* User events */
#define EVFILT_SYSCOUNT 10

#define EV_SET(kevp_, a, b, c, d, e, f) do { \
struct kevent *kevp = (kevp_); \
@@ -90,6 +107,9 @@ struct kevent {
#define EV_RECEIPT 0x0040 /* force EV_ERROR on success, data=0 */
#define EV_DISPATCH 0x0080 /* disable event after reporting */

#define EV_UDATA_SPECIFIC 0x0100 /* unique kevent per udata value */
#define EV_VANISHED 0x0200 /* report that source has vanished */

#define EV_SYSFLAGS 0xF000 /* reserved by system */
#define EV_FLAG1 0x2000 /* filter-specific flag */

@@ -209,4 +229,5 @@ int libkqueue_init();
#endif
#endif /* !__KERNEL__* */

#endif
#endif /* !_SYS_EVENT_H_ */
17 changes: 13 additions & 4 deletions src/common/debug.h
Original file line number Diff line number Diff line change
@@ -28,7 +28,10 @@
extern int DEBUG_KQUEUE;
extern char *KQUEUE_DEBUG_IDENT;

#if defined(__linux__)
#if defined(DARLING)
extern int __thread_selfid();
# define THREAD_ID (__thread_selfid())
#elif defined(__linux__)
# include <sys/syscall.h>
# define THREAD_ID ((pid_t) syscall(__NR_gettid))
#elif defined(__sun)
@@ -39,22 +42,28 @@ extern char *KQUEUE_DEBUG_IDENT;
# error Unsupported platform
#endif

#ifdef DARLING
#include <darling/emulation/simple.h>
#endif

FILE* debug_file();

#ifndef NDEBUG
#define dbg_puts(str) do { \
if (DEBUG_KQUEUE) \
fprintf(stderr, "%s [%d]: %s(): %s\n", \
__simple_kprintf("%s [%d]: %s(): %s\n", \
KQUEUE_DEBUG_IDENT, THREAD_ID, __func__, str); \
} while (0)

#define dbg_printf(fmt,...) do { \
if (DEBUG_KQUEUE) \
fprintf(stderr, "%s [%d]: %s(): "fmt"\n", \
__simple_kprintf("%s [%d]: %s(): "fmt"\n", \
KQUEUE_DEBUG_IDENT, THREAD_ID, __func__, __VA_ARGS__); \
} while (0)

#define dbg_perror(str) do { \
if (DEBUG_KQUEUE) \
fprintf(stderr, "%s [%d]: %s(): %s: %s (errno=%d)\n", \
__simple_kprintf("%s [%d]: %s(): %s: %s (errno=%d)\n", \
KQUEUE_DEBUG_IDENT, THREAD_ID, __func__, str, \
strerror(errno), errno); \
} while (0)
15 changes: 11 additions & 4 deletions src/common/filter.c
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@ extern const struct filter evfilt_vnode;
extern const struct filter evfilt_proc;
extern const struct filter evfilt_timer;
extern const struct filter evfilt_user;
extern const struct filter evfilt_machport;
extern const struct filter evfilt_fs;

static int
filter_register(struct kqueue *kq, short filter, const struct filter *src)
@@ -102,6 +104,8 @@ filter_register_all(struct kqueue *kq)
rv += filter_register(kq, EVFILT_PROC, &evfilt_proc);
rv += filter_register(kq, EVFILT_TIMER, &evfilt_timer);
rv += filter_register(kq, EVFILT_USER, &evfilt_user);
rv += filter_register(kq, EVFILT_MACHPORT, &evfilt_machport);
rv += filter_register(kq, EVFILT_FS, &evfilt_fs);
kq->kq_nfds++;
if (rv != 0) {
filter_unregister_all(kq);
@@ -165,10 +169,13 @@ filter_name(short filt)
"EVFILT_PROC",
"EVFILT_SIGNAL",
"EVFILT_TIMER",
"EVFILT_NETDEV",
"EVFILT_FS",
"EVFILT_LIO",
"EVFILT_USER"
"EVFILT_MACHPORT",
"EVFILT_FS",
"EVFILT_USER",
"EVFILT_VM",
"EVFILT_SOCK",
"EVFILT_MEMORYSTATUS",
"EVFILT_EXCEPT",
};

id = ~filt;
Loading