+#include <mach/mach_types.h>
+#include <mach/vm_prot.h>
+#include <mach/semaphore.h>
+#include <mach/sync_policy.h>
+#include <kern/clock.h>
+#include <mach/kern_return.h>
+
+extern semaphore_t execve_semaphore;
+
+static int
+execargs_alloc(addrp)
+ vm_offset_t *addrp;
+{
+ kern_return_t kret;
+
+ kret = semaphore_wait(execve_semaphore);
+ if (kret != KERN_SUCCESS)
+ switch (kret) {
+ default:
+ return (EINVAL);
+ case KERN_INVALID_ADDRESS:
+ case KERN_PROTECTION_FAILURE:
+ return (EACCES);
+ case KERN_ABORTED:
+ case KERN_OPERATION_TIMED_OUT:
+ return (EINTR);
+ }
+
+ kret = kmem_alloc_pageable(bsd_pageable_map, addrp, NCARGS);
+ if (kret != KERN_SUCCESS)
+ return (ENOMEM);
+
+ return (0);
+}
+
+static int
+execargs_free(addr)
+ vm_offset_t addr;
+{
+ kern_return_t kret;
+
+ kmem_free(bsd_pageable_map, addr, NCARGS);
+
+ kret = semaphore_signal(execve_semaphore);
+ switch (kret) {
+ case KERN_INVALID_ADDRESS:
+ case KERN_PROTECTION_FAILURE:
+ return (EINVAL);
+ case KERN_ABORTED:
+ case KERN_OPERATION_TIMED_OUT:
+ return (EINTR);
+ case KERN_SUCCESS:
+ return(0);
+ default:
+ return (EINVAL);
+ }
+}
+