]> git.saurik.com Git - apple/xnu.git/blobdiff - libsyscall/wrappers/work_interval.c
xnu-7195.81.3.tar.gz
[apple/xnu.git] / libsyscall / wrappers / work_interval.c
index 96ca9ef8363cdddb845c36bf23e7dab273842cd8..89d2d0cce907c0321fbbfa3e21a4f00c597906f3 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <sys/errno.h>
 #include <stdlib.h>
+#include <strings.h>
 
 struct work_interval {
        uint64_t thread_id;
@@ -57,7 +58,7 @@ work_interval_create(work_interval_t *interval_handle, uint32_t create_flags)
        };
 
        ret = __work_interval_ctl(WORK_INTERVAL_OPERATION_CREATE2, 0,
-                                 &create_params, sizeof(create_params));
+           &create_params, sizeof(create_params));
        if (ret == -1) {
                return ret;
        }
@@ -77,10 +78,30 @@ work_interval_create(work_interval_t *interval_handle, uint32_t create_flags)
        return 0;
 }
 
+int
+work_interval_get_flags_from_port(mach_port_t port, uint32_t *flags)
+{
+       if (!MACH_PORT_VALID(port) || flags == NULL) {
+               errno = EINVAL;
+               return -1;
+       }
+
+       struct work_interval_create_params create_params = { 0 };
+
+       int ret = __work_interval_ctl(WORK_INTERVAL_OPERATION_GET_FLAGS, port,
+           &create_params, sizeof(create_params));
+       if (ret == -1) {
+               return ret;
+       }
+
+       *flags = create_params.wicp_create_flags;
+       return 0;
+}
+
 int
 work_interval_notify(work_interval_t interval_handle, uint64_t start,
-                     uint64_t finish, uint64_t deadline, uint64_t next_start,
-                     uint32_t notify_flags)
+    uint64_t finish, uint64_t deadline, uint64_t next_start,
+    uint32_t notify_flags)
 {
        int ret;
        uint64_t work_interval_id;
@@ -97,22 +118,27 @@ work_interval_notify(work_interval_t interval_handle, uint64_t start,
                return -1;
        }
 
+       if (interval_handle->create_flags & WORK_INTERVAL_FLAG_IGNORED) {
+               return 0;
+       }
+
        notification.create_flags = interval_handle->create_flags;
        work_interval_id = interval_handle->work_interval_id;
 
        ret = __work_interval_ctl(WORK_INTERVAL_OPERATION_NOTIFY, work_interval_id,
-                                 &notification, sizeof(notification));
+           &notification, sizeof(notification));
        return ret;
 }
 
 int
 work_interval_notify_simple(work_interval_t interval_handle, uint64_t start,
-                            uint64_t deadline, uint64_t next_start)
+    uint64_t deadline, uint64_t next_start)
 {
        return work_interval_notify(interval_handle, start, mach_absolute_time(),
-                                   deadline, next_start, 0);
+                  deadline, next_start, 0);
 }
 
+
 int
 work_interval_destroy(work_interval_t interval_handle)
 {
@@ -158,7 +184,7 @@ work_interval_destroy(work_interval_t interval_handle)
                uint64_t work_interval_id = interval_handle->work_interval_id;
 
                int ret = __work_interval_ctl(WORK_INTERVAL_OPERATION_DESTROY,
-                                             work_interval_id, NULL, 0);
+                   work_interval_id, NULL, 0);
 
                interval_handle->work_interval_id = 0;
 
@@ -201,14 +227,14 @@ work_interval_join_port(mach_port_t port)
        }
 
        return __work_interval_ctl(WORK_INTERVAL_OPERATION_JOIN,
-                                  (uint64_t)port, NULL, 0);
+                  (uint64_t)port, NULL, 0);
 }
 
 int
 work_interval_leave(void)
 {
        return __work_interval_ctl(WORK_INTERVAL_OPERATION_JOIN,
-                                  (uint64_t)MACH_PORT_NULL, NULL, 0);
+                  (uint64_t)MACH_PORT_NULL, NULL, 0);
 }
 
 int
@@ -234,7 +260,7 @@ work_interval_copy_port(work_interval_t interval_handle, mach_port_t *port)
        mach_port_t wi_port = interval_handle->wi_port;
 
        kern_return_t kr = mach_port_mod_refs(mach_task_self(), wi_port,
-                                             MACH_PORT_RIGHT_SEND, 1);
+           MACH_PORT_RIGHT_SEND, 1);
 
        if (kr != KERN_SUCCESS) {
                *port = MACH_PORT_NULL;
@@ -246,7 +272,3 @@ work_interval_copy_port(work_interval_t interval_handle, mach_port_t *port)
 
        return 0;
 }
-
-
-
-