]>
git.saurik.com Git - apple/xnu.git/blob - tests/perf_exit_proc.c
7 #include <mach/mach_vm.h>
9 static void* loop(__attribute__ ((unused
)) void *arg
) {
16 static int run_additional_threads(int nthreads
) {
17 for (int i
= 0; i
< nthreads
; i
++) {
21 err
= pthread_create(&pthread
, NULL
, loop
, NULL
);
30 static int allocate_and_wire_memory(mach_vm_size_t size
) {
32 task_t task
= mach_task_self();
33 mach_vm_address_t addr
;
38 err
= mach_vm_allocate(task
, &addr
, size
, VM_FLAGS_ANYWHERE
);
39 if (err
!= KERN_SUCCESS
) {
40 printf("mach_vm_allocate returned non-zero: %s\n", mach_error_string(err
));
43 err
= mach_vm_protect(task
, addr
, size
, 0, VM_PROT_READ
| VM_PROT_WRITE
);;
44 if (err
!= KERN_SUCCESS
) {
45 printf("mach_vm_protect returned non-zero: %s\n", mach_error_string(err
));
48 host_t host_priv_port
;
49 err
= host_get_host_priv_port(mach_host_self(), &host_priv_port
);
50 if (err
!= KERN_SUCCESS
) {
51 printf("host_get_host_priv_port retruned non-zero: %s\n", mach_error_string(err
));
54 err
= mach_vm_wire(host_priv_port
, task
, addr
, size
, VM_PROT_READ
| VM_PROT_WRITE
);
55 if (err
!= KERN_SUCCESS
) {
56 printf("mach_vm_wire returned non-zero: %s\n", mach_error_string(err
));
63 int main(int argc
, char *argv
[]) {
66 mach_vm_size_t wired_mem
= 0;
69 nthreads
= (int)strtoul(argv
[1], NULL
, 10);
72 wired_mem
= (mach_vm_size_t
)strtoul(argv
[2], NULL
, 10);
75 err
= allocate_and_wire_memory(wired_mem
);
80 err
= run_additional_threads(nthreads
);