Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is a <a href="http://osxbook.com/book/bonus/chapter11/procfs/" rel="noreferrer">MacFUSE implementation of procfs</a>. With it, you can get the memory map as follows:</p> <pre><code>cat /proc/PID/task/vmmap </code></pre> <p>Looking at the <a href="http://macfuse.googlecode.com/svn/trunk/filesystems/procfs/" rel="noreferrer">source code</a>, it looks like it's using the <a href="http://www.gnu.org/software/hurd/gnumach-doc/Virtual-Memory-Interface.html#Virtual-Memory-Interface" rel="noreferrer">Mach virtual memory interface</a> to get the memory map from the kernel.</p> <p>Here's the implementation for the <code>vmmap</code> pseudofile:</p> <pre><code>/* * procfs as a MacFUSE file system for Mac OS X * * Copyright Amit Singh. All Rights Reserved. * http://osxbook.com * * http://code.google.com/p/macfuse/ * * Source License: GNU GENERAL PUBLIC LICENSE (GPL) */ READ_HANDLER(proc__task__vmmap) { int len = -1; kern_return_t kr; #define MAX_VMMAP_SIZE 65536 /* XXX */ char tmpbuf[MAX_VMMAP_SIZE]; task_t the_task; pid_t pid = strtol(argv[0], NULL, 10); kr = task_for_pid(mach_task_self(), pid, &amp;the_task); if (kr != KERN_SUCCESS) { return -EIO; } vm_size_t vmsize; vm_address_t address; vm_region_basic_info_data_t info; mach_msg_type_number_t info_count; vm_region_flavor_t flavor; memory_object_name_t object; kr = KERN_SUCCESS; address = 0; len = 0; do { flavor = VM_REGION_BASIC_INFO; info_count = VM_REGION_BASIC_INFO_COUNT; kr = vm_region(the_task, &amp;address, &amp;vmsize, flavor, (vm_region_info_t)&amp;info, &amp;info_count, &amp;object); if (kr == KERN_SUCCESS) { if (len &gt;= MAX_VMMAP_SIZE) { goto gotdata; } len += snprintf(tmpbuf + len, MAX_VMMAP_SIZE - len, "%08x-%08x %8uK %c%c%c/%c%c%c %11s %6s %10s uwir=%hu sub=%u\n", address, (address + vmsize), (vmsize &gt;&gt; 10), (info.protection &amp; VM_PROT_READ) ? 'r' : '-', (info.protection &amp; VM_PROT_WRITE) ? 'w' : '-', (info.protection &amp; VM_PROT_EXECUTE) ? 'x' : '-', (info.max_protection &amp; VM_PROT_READ) ? 'r' : '-', (info.max_protection &amp; VM_PROT_WRITE) ? 'w' : '-', (info.max_protection &amp; VM_PROT_EXECUTE) ? 'x' : '-', inheritance_strings[info.inheritance], (info.shared) ? "shared" : "-", behavior_strings[info.behavior], info.user_wired_count, info.reserved); address += vmsize; } else if (kr != KERN_INVALID_ADDRESS) { if (the_task != MACH_PORT_NULL) { mach_port_deallocate(mach_task_self(), the_task); } return -EIO; } } while (kr != KERN_INVALID_ADDRESS); gotdata: if (the_task != MACH_PORT_NULL) { mach_port_deallocate(mach_task_self(), the_task); } READ_PROC_TASK_EPILOGUE(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload