24 #if TARGET_OS_IPHONE || MAC_OS_X_VERSION_MAX_ALLOWED < 1070
51 static const int kFSEventsModified =
58 static const int kFSEventsRenamed =
63 static const int kFSEventsSystem =
72 typedef struct uv__fsevents_event_s uv__fsevents_event_t;
73 typedef struct uv__cf_loop_signal_s uv__cf_loop_signal_t;
74 typedef struct uv__cf_loop_state_s uv__cf_loop_state_t;
76 enum uv__cf_loop_signal_type_e {
77 kUVCFLoopSignalRegular,
78 kUVCFLoopSignalClosing
80 typedef enum uv__cf_loop_signal_type_e uv__cf_loop_signal_type_t;
82 struct uv__cf_loop_signal_s {
85 uv__cf_loop_signal_type_t
type;
88 struct uv__fsevents_event_s {
94 struct uv__cf_loop_state_s {
97 int fsevent_need_reschedule;
101 void* fsevent_handles[2];
102 unsigned int fsevent_handle_count;
106 static void uv__cf_loop_cb(
void*
arg);
107 static void* uv__cf_loop_runner(
void*
arg);
110 uv__cf_loop_signal_type_t
type);
125 static void (*pCFRunLoopRun)(void);
132 static CFStringRef (*pCFStringCreateWithFileSystemRepresentation)(
153 #define UV__FSEVENTS_PROCESS(handle, block) \
157 uv__fsevents_event_t* event; \
159 uv_mutex_lock(&(handle)->cf_mutex); \
161 QUEUE_MOVE(&(handle)->cf_events, &events); \
163 err = (handle)->cf_error; \
164 (handle)->cf_error = 0; \
165 uv_mutex_unlock(&(handle)->cf_mutex); \
167 while (!QUEUE_EMPTY(&events)) { \
168 q = QUEUE_HEAD(&events); \
169 event = QUEUE_DATA(q, uv__fsevents_event_t, member); \
174 if (!uv__is_closing((handle)) && uv__is_active((handle))) \
179 if (err != 0 && !uv__is_closing((handle)) && uv__is_active((handle))) \
180 (handle)->cb((handle), NULL, 0, err); \
190 UV__FSEVENTS_PROCESS(
handle, {
231 uv__cf_loop_state_t*
state;
232 uv__fsevents_event_t* event;
248 for (
i = 0;
i < numEvents;
i++) {
252 if (
flags & kFSEventsSystem)
258 if (
handle->realpath_len == 0)
262 if (len < handle->realpath_len)
269 handle->realpath_len > 1 &&
276 if (!(
handle->realpath_len == 1 &&
handle->realpath[0] ==
'/')) {
289 while (len < handle->realpath_len &&
path[-1] !=
'/') {
294 flags &= ~kFSEventsRenamed;
313 memset(event, 0,
sizeof(*event));
317 if (0 == (
flags & kFSEventsRenamed)) {
318 if (0 != (
flags & kFSEventsModified) ||
335 uv__cf_loop_state_t*
state;
367 ref = pFSEventStreamCreate(
NULL,
368 &uv__fsevents_event_cb,
377 pFSEventStreamScheduleWithRunLoop(ref,
379 *pkCFRunLoopDefaultMode);
380 if (!pFSEventStreamStart(ref)) {
381 pFSEventStreamInvalidate(ref);
382 pFSEventStreamRelease(ref);
386 state->fsevent_stream = ref;
393 uv__cf_loop_state_t*
state;
401 pFSEventStreamStop(
state->fsevent_stream);
404 pFSEventStreamInvalidate(
state->fsevent_stream);
405 pFSEventStreamRelease(
state->fsevent_stream);
412 uv__cf_loop_signal_type_t
type) {
413 uv__cf_loop_state_t*
state;
420 unsigned int path_count;
433 if (
state->fsevent_need_reschedule == 0) {
437 state->fsevent_need_reschedule = 0;
441 uv__fsevents_destroy_stream(
handle->loop);
448 path_count =
state->fsevent_handle_count;
449 if (path_count != 0) {
450 paths =
uv__malloc(
sizeof(*paths) * path_count);
456 q = &
state->fsevent_handles;
457 for (;
i < path_count;
i++) {
464 pCFStringCreateWithFileSystemRepresentation(
NULL, curr->realpath);
465 if (paths[
i] ==
NULL) {
474 if (path_count != 0) {
476 cf_paths = pCFArrayCreate(
NULL, (
const void**) paths, path_count,
NULL);
477 if (cf_paths ==
NULL) {
481 err = uv__fsevents_create_stream(
handle->loop, cf_paths);
487 if (cf_paths ==
NULL) {
489 pCFRelease(paths[--
i]);
493 pCFRelease(cf_paths);
500 uv__fsevents_push_event(curr,
NULL,
err);
511 if (
type == kUVCFLoopSignalClosing)
516 static int uv__fsevents_global_init(
void) {
517 static pthread_mutex_t global_init_mutex = PTHREAD_MUTEX_INITIALIZER;
518 static void* core_foundation_handle;
519 static void* core_services_handle;
523 pthread_mutex_lock(&global_init_mutex);
524 if (core_foundation_handle !=
NULL)
533 core_foundation_handle = dlopen(
"/System/Library/Frameworks/"
534 "CoreFoundation.framework/"
535 "Versions/A/CoreFoundation",
536 RTLD_LAZY | RTLD_LOCAL);
537 if (core_foundation_handle ==
NULL)
540 core_services_handle = dlopen(
"/System/Library/Frameworks/"
541 "CoreServices.framework/"
542 "Versions/A/CoreServices",
543 RTLD_LAZY | RTLD_LOCAL);
544 if (core_services_handle ==
NULL)
548 #define V(handle, symbol) \
550 *(void **)(&p ## symbol) = dlsym((handle), #symbol); \
551 if (p ## symbol == NULL) \
555 V(core_foundation_handle, CFArrayCreate);
556 V(core_foundation_handle, CFRelease);
557 V(core_foundation_handle, CFRunLoopAddSource);
558 V(core_foundation_handle, CFRunLoopGetCurrent);
559 V(core_foundation_handle, CFRunLoopRemoveSource);
560 V(core_foundation_handle, CFRunLoopRun);
561 V(core_foundation_handle, CFRunLoopSourceCreate);
562 V(core_foundation_handle, CFRunLoopSourceSignal);
563 V(core_foundation_handle, CFRunLoopStop);
564 V(core_foundation_handle, CFRunLoopWakeUp);
565 V(core_foundation_handle, CFStringCreateWithFileSystemRepresentation);
566 V(core_foundation_handle, CFStringGetSystemEncoding);
567 V(core_foundation_handle, kCFRunLoopDefaultMode);
568 V(core_services_handle, FSEventStreamCreate);
569 V(core_services_handle, FSEventStreamFlushSync);
570 V(core_services_handle, FSEventStreamInvalidate);
571 V(core_services_handle, FSEventStreamRelease);
572 V(core_services_handle, FSEventStreamScheduleWithRunLoop);
573 V(core_services_handle, FSEventStreamStart);
574 V(core_services_handle, FSEventStreamStop);
579 if (
err && core_services_handle !=
NULL) {
580 dlclose(core_services_handle);
581 core_services_handle =
NULL;
584 if (
err && core_foundation_handle !=
NULL) {
585 dlclose(core_foundation_handle);
586 core_foundation_handle =
NULL;
589 pthread_mutex_unlock(&global_init_mutex);
597 uv__cf_loop_state_t*
state;
598 pthread_attr_t attr_storage;
599 pthread_attr_t* attr;
605 err = uv__fsevents_global_init();
615 goto fail_mutex_init;
625 goto fail_fsevent_sem_init;
629 goto fail_fsevent_mutex_init;
632 state->fsevent_need_reschedule = 0;
633 state->fsevent_handle_count = 0;
637 ctx.perform = uv__cf_loop_cb;
638 state->signal_source = pCFRunLoopSourceCreate(
NULL, 0, &
ctx);
641 goto fail_signal_source_create;
648 attr = &attr_storage;
649 if (pthread_attr_init(attr))
653 if (pthread_attr_setstacksize(attr, 4 * PTHREAD_STACK_MIN))
662 pthread_attr_destroy(attr);
665 goto fail_thread_create;
674 fail_signal_source_create:
677 fail_fsevent_mutex_init:
680 fail_fsevent_sem_init:
694 uv__cf_loop_signal_t*
s;
695 uv__cf_loop_state_t*
state;
701 if (uv__cf_loop_signal(
loop,
NULL, kUVCFLoopSignalRegular) != 0)
720 pCFRelease(
state->signal_source);
727 static void* uv__cf_loop_runner(
void*
arg) {
729 uv__cf_loop_state_t*
state;
733 state->loop = pCFRunLoopGetCurrent();
735 pCFRunLoopAddSource(
state->loop,
736 state->signal_source,
737 *pkCFRunLoopDefaultMode);
742 pCFRunLoopRemoveSource(
state->loop,
743 state->signal_source,
744 *pkCFRunLoopDefaultMode);
753 static void uv__cf_loop_cb(
void*
arg) {
755 uv__cf_loop_state_t*
state;
758 uv__cf_loop_signal_t*
s;
771 s =
QUEUE_DATA(item, uv__cf_loop_signal_t, member);
774 if (
s->handle ==
NULL)
775 pCFRunLoopStop(
state->loop);
777 uv__fsevents_reschedule(
s->handle,
s->type);
787 uv__cf_loop_signal_type_t
type) {
788 uv__cf_loop_signal_t* item;
789 uv__cf_loop_state_t*
state;
803 pCFRunLoopSourceSignal(
state->signal_source);
804 pCFRunLoopWakeUp(
state->loop);
815 uv__cf_loop_state_t*
state;
817 err = uv__fsevents_loop_init(
handle->loop);
838 goto fail_cf_cb_malloc;
848 goto fail_cf_mutex_init;
854 state->fsevent_handle_count++;
855 state->fsevent_need_reschedule = 1;
860 err = uv__cf_loop_signal(
handle->loop,
handle, kUVCFLoopSignalRegular);
862 goto fail_loop_signal;
885 uv__cf_loop_state_t*
state;
894 state->fsevent_handle_count--;
895 state->fsevent_need_reschedule = 1;
900 err = uv__cf_loop_signal(
handle->loop,
handle, kUVCFLoopSignalClosing);
911 UV__FSEVENTS_PROCESS(
handle, {
static const char * arg(RzAnalysis *a, csh *handle, cs_insn *insn, char *buf, int n)
static mcore_handle handle
RzBinInfo * info(RzBinFile *bf)
const lzma_allocator const uint8_t size_t uint8_t * out
static static fork const void static count static fd const char const char static newpath const char static path const char path
static const int kFSEventStreamEventFlagItemCreated
uint64_t FSEventStreamEventId
static const int kFSEventStreamEventFlagUnmount
uint32_t FSEventStreamCreateFlags
static const int kFSEventStreamCreateFlagNoDefer
static const int kFSEventStreamEventFlagEventIdsWrapped
static const int kFSEventStreamEventFlagKernelDropped
void(* FSEventStreamCallback)(const FSEventStreamRef, void *, size_t, void *, const FSEventStreamEventFlags *, const FSEventStreamEventId *)
static const int kFSEventStreamEventFlagHistoryDone
static const int kFSEventStreamEventFlagItemChangeOwner
static const int kFSEventStreamEventFlagItemIsDir
static const int kFSEventStreamEventFlagItemFinderInfoMod
static const int kFSEventStreamEventFlagUserDropped
static const int kFSEventStreamCreateFlagFileEvents
static const int kFSEventStreamEventFlagItemRenamed
static const int kFSEventStreamEventFlagItemRemoved
struct CFArrayCallBacks CFArrayCallBacks
static const int kFSEventStreamEventFlagMount
static const FSEventStreamEventId kFSEventStreamEventIdSinceNow
void * CFRunLoopSourceRef
static const int kFSEventStreamEventFlagItemXattrMod
static const int kFSEventStreamEventFlagRootChanged
unsigned CFStringEncoding
static const int kFSEventStreamEventFlagItemInodeMetaMod
int FSEventStreamEventFlags
static const int kFSEventStreamEventFlagItemModified
int uv__fsevents_init(uv_fs_event_t *handle)
int uv__fsevents_close(uv_fs_event_t *handle)
void uv__fsevents_loop_delete(uv_loop_t *loop)
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
assert(limit<=UINT32_MAX/2)
#define QUEUE_FOREACH(q, h)
#define QUEUE_DATA(ptr, type, field)
#define QUEUE_INSERT_TAIL(h, q)
static struct sockaddr static addrlen static backlog const void static flags void flags
#define V(handle, symbol)
UV_PLATFORM_SEM_T uv_sem_t
pthread_mutex_t uv_mutex_t
void * uv__malloc(size_t size)
void * uv__calloc(size_t count, size_t size)
UV_EXTERN void uv_mutex_lock(uv_mutex_t *handle)
UV_EXTERN int uv_thread_join(uv_thread_t *tid)
UV_EXTERN void uv_sem_destroy(uv_sem_t *sem)
UV_EXTERN void uv_sem_post(uv_sem_t *sem)
UV_EXTERN void uv_mutex_destroy(uv_mutex_t *handle)
UV_EXTERN void uv_mutex_unlock(uv_mutex_t *handle)
UV_EXTERN void uv_unref(uv_handle_t *)
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
UV_EXTERN int uv_async_init(uv_loop_t *, uv_async_t *async, uv_async_cb async_cb)
UV_EXTERN int uv_async_send(uv_async_t *async)
UV_EXTERN void uv_sem_wait(uv_sem_t *sem)
UV_EXTERN int uv_sem_init(uv_sem_t *sem, unsigned int value)
void(* uv_close_cb)(uv_handle_t *handle)
UV_EXTERN int uv_mutex_init(uv_mutex_t *handle)