user/lib/libsystem/src/sys/vm.c
int MapVirtualRegionRange(const uintptr_t regionHandle, const uintptr_t range[2],
        const size_t length, const uintptr_t inFlags, uintptr_t *outBase) {
    int err;

    // validate args
    if(!regionHandle || !range || !length) return -1;
    else if(!range[0]) return -1;

    // build the request
    struct VmMapRequest req = {
        .start  = range[0],
        .end    = range[1],
        .length = length,
        .flags  = BuildSyscallMapFlags(inFlags, false)
    };

    // invoke method
    err = __do_syscall4(regionHandle, 0, (const uintptr_t) &req, sizeof(req), SYS_VM_MAP_EX);

    if(!err) {
        // the kernel will write the actual base address into `start`
        if(outBase) *outBase = req.start;
    } else {
        // clear the address, as we can't have a mapping at address 0
        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.
 *
 * @param range An array containing the starting and ending addresses of the range
 * @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.

@param range An array containing the starting and ending addresses of the range
@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 . @param range An array containing the starting and ending addresses of the range @param outBase If non - null a location into which the base address of the mapping is written
int MapVirtualRegionRange(const uintptr_t regionHandle, const uintptr_t range[2],
        const size_t length, const uintptr_t inFlags, uintptr_t *outBase) {
    int err;
    if(!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, false)
    };
    err = __do_syscall4(regionHandle, 0, (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 MapVirtualRegionRange ( const uintptr_t regionHandle , const uintptr_t range [ 2 ] , const size_t length , const uintptr_t inFlags , uintptr_t * outBase ) { int err ; if ( ! 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 , false ) } ; err = __do_syscall4 ( regionHandle , 0 , ( 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.
Searches for a free space of virtual memory big enough to fit a view of the specified length which maps the given VM region .
// 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