]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/dev/dtrace/dtrace_ptss.c
xnu-3789.60.24.tar.gz
[apple/xnu.git] / bsd / dev / dtrace / dtrace_ptss.c
index 9c75c3f1fc644d7e1156099c72ff652d2e0e3a9a..c09b8f32e68b9540f50e8182aa12cc8b05287da2 100644 (file)
@@ -33,6 +33,7 @@
 #include <sys/user.h>
 #include <sys/dtrace_ptss.h>
 
+#include <mach/vm_map.h>
 #include <mach/vm_param.h>
 #include <mach/mach_vm.h>
 
@@ -127,10 +128,14 @@ dtrace_ptss_claim_entry(struct proc* p) {
 
 /*
  * This function does not require any locks to be held on entry.
+ *
+ * (PR-11138709) A NULL p->p_dtrace_ptss_pages means the entry can
+ * no longer be referenced safely. When found in this state, the chore
+ * of releasing an entry to the free list is ignored.
  */
 void
 dtrace_ptss_release_entry(struct proc* p, struct dtrace_ptss_page_entry* e) {
-       if (p && e) {
+       if (p && p->p_dtrace_ptss_pages && e) {
                do {
                        e->next = p->p_dtrace_ptss_free_list;
                } while (!OSCompareAndSwapPtr((void *)e->next, (void *)e, (void * volatile *)&p->p_dtrace_ptss_free_list));
@@ -157,32 +162,18 @@ dtrace_ptss_allocate_page(struct proc* p)
        // Now allocate a page in user space and set its protections to allow execute.
        task_t task = p->task;
        vm_map_t map = get_task_map_reference(task);
+       if (map == NULL)
+         goto err;
 
-       mach_vm_address_t addr = 0LL;
-       mach_vm_size_t size = PAGE_SIZE; // We need some way to assert that this matches vm_map_round_page() !!!
+       mach_vm_size_t size = PAGE_MAX_SIZE;
+       mach_vm_offset_t addr = 0;
+       vm_prot_t cur_protection = VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE;
+       vm_prot_t max_protection = VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE;
 
-#if CONFIG_EMBEDDED
-       /* The embedded OS has extra permissions for writable and executable pages. We can't pass in the flags
-        * we need for the correct permissions from mach_vm_allocate, so need to call mach_vm_map directly. */
-       vm_map_offset_t map_addr = 0;
-       kern_return_t kr = mach_vm_map(map, &map_addr, size, 0, VM_FLAGS_ANYWHERE, IPC_PORT_NULL, 0, FALSE, VM_PROT_READ|VM_PROT_EXECUTE, VM_PROT_READ|VM_PROT_EXECUTE, VM_INHERIT_DEFAULT);
-       if (kr != KERN_SUCCESS) {
-               goto err;
-       }
-       addr = map_addr;
-#else
-       kern_return_t kr = mach_vm_allocate(map, &addr, size, VM_FLAGS_ANYWHERE);
+       kern_return_t kr = mach_vm_map(map, &addr, size, 0, VM_FLAGS_ANYWHERE, IPC_PORT_NULL, 0, FALSE, cur_protection, max_protection, VM_INHERIT_DEFAULT);
        if (kr != KERN_SUCCESS) {
                goto err;
        }
-
-       kr = mach_vm_protect(map, addr, size, 0, VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
-       if (kr != KERN_SUCCESS) {
-               mach_vm_deallocate(map, addr, size);
-               goto err;
-       }       
-#endif
-
        // Chain the page entries.
        int i;
        for (i=0; i<DTRACE_PTSS_ENTRIES_PER_PAGE; i++) {
@@ -200,7 +191,8 @@ dtrace_ptss_allocate_page(struct proc* p)
 err:
        _FREE(ptss_page, M_TEMP);
 
-       vm_map_deallocate(map);
+       if (map)
+         vm_map_deallocate(map);
 
        return NULL;
 }
@@ -225,6 +217,7 @@ dtrace_ptss_free_page(struct proc* p, struct dtrace_ptss_page* ptss_page)
        // Silent failures, no point in checking return code.
        mach_vm_deallocate(map, addr, size);
 
+
        vm_map_deallocate(map);
 }