user/lib/libsystem/src/sys/vm.c
/**
 * Searches for a free space of virtual memory big enough to fit a view of the specified length,
 * which maps the given VM region in a remote task.
 *
 * @param taskHandle Task into which the object is mapped
 * @param range An array containing the starting and ending addresses of the range, in the remote
 *        task's address space
 * @param outBase If non-null, a location into which the base address of the mapping is written
 */
Searches for a free space of virtual memory big enough to fit a view of the specified length,
which maps the given VM region in a remote task.

@param taskHandle Task into which the object is mapped
@param range An array containing the starting and ending addresses of the range, in the remote
task's address space
@param outBase If non-null, a location into which the base address of the mapping is written
Searches for a free space of virtual memory big enough to fit a view of the specified length which maps the given VM region in a remote task . @param taskHandle Task into which the object is mapped @param range An array containing the starting and ending addresses of the range in the remote task ' s address space @param outBase If non - null a location into which the base address of the mapping is written
int MapVirtualRegionRangeRemote(const uintptr_t taskHandle, const uintptr_t regionHandle,
        const uintptr_t range[2], const size_t length, const uintptr_t inFlags,
        uintptr_t *outBase) {
    int err;
    if(!taskHandle || !regionHandle || !range || !length) return -1;
    else if(!range[0]) return -1;
    struct VmMapRequest req = {
        .start  = range[0],
        .end    = range[1],
        .length = length,
        .flags  = BuildSyscallMapFlags(inFlags, true)
    };
    err = __do_syscall4(regionHandle, taskHandle, (const uintptr_t) &req, sizeof(req),
            SYS_VM_MAP_EX);
    if(!err) {
        if(outBase) *outBase = req.start;
    } else {
        if(outBase) *outBase = 0;
    }
    return err;
}
int MapVirtualRegionRangeRemote ( const uintptr_t taskHandle , const uintptr_t regionHandle , const uintptr_t range [ 2 ] , const size_t length , const uintptr_t inFlags , uintptr_t * outBase ) { int err ; if ( ! taskHandle || ! regionHandle || ! range || ! length ) return -1 ; else if ( ! range [ 0 ] ) return -1 ; struct VmMapRequest req = { . start = range [ 0 ] , . end = range [ 1 ] , . length = length , . flags = BuildSyscallMapFlags ( inFlags , true ) } ; err = __do_syscall4 ( regionHandle , taskHandle , ( const uintptr_t ) & req , sizeof ( req ) , SYS_VM_MAP_EX ) ; if ( ! err ) { if ( outBase ) * outBase = req . start ; } else { if ( outBase ) * outBase = 0 ; } return err ; }
Searches for a free space of virtual memory big enough to fit a view of the specified length,
 which maps the given VM region in a remote task.
Searches for a free space of virtual memory big enough to fit a view of the specified length which maps the given VM region in a remote task .
// validate args // build the request // invoke method // the kernel will write the actual base address into `start` // clear the address, as we can't have a mapping at address 0