user/lib/libsystem/src/sys/vm.c
/**
 * Translates the given virtual address, from the view of the given task, into a handle to the
 * region that contains that address.
 *
 * A successful return code does not indicate that the pages actually exist; just that there is a
 * mapping that is prepared to handle faults for nonexistent pages. Perform an info request for
 * this region for more information.
 *
 * @return Negative error code, 0 if there is no VM mapping at the given address, or 1 if there is
 * a region and its handle was written out.
 */
Translates the given virtual address, from the view of the given task, into a handle to the
region that contains that address.

A successful return code does not indicate that the pages actually exist; just that there is a
mapping that is prepared to handle faults for nonexistent pages. Perform an info request for
this region for more information.

@return Negative error code, 0 if there is no VM mapping at the given address, or 1 if there is
a region and its handle was written out.
Translates the given virtual address from the view of the given task into a handle to the region that contains that address . A successful return code does not indicate that the pages actually exist ; just that there is a mapping that is prepared to handle faults for nonexistent pages . Perform an info request for this region for more information . @return Negative error code 0 if there is no VM mapping at the given address or 1 if there is a region and its handle was written out .
int VirtualGetHandleForAddrInTask(const uintptr_t taskHandle, const uintptr_t address,
        uintptr_t *regionHandle) {
    intptr_t err;
    err = __do_syscall2(taskHandle, address, SYS_VM_ADDR_TO_HANDLE);
    if(err < 0) {
        return err;
    } else if(!err) {
        return 0;
    }
    if(regionHandle) *regionHandle = (uintptr_t) err;
    return 1;
}
int VirtualGetHandleForAddrInTask ( const uintptr_t taskHandle , const uintptr_t address , uintptr_t * regionHandle ) { intptr_t err ; err = __do_syscall2 ( taskHandle , address , SYS_VM_ADDR_TO_HANDLE ) ; if ( err < 0 ) { return err ; } else if ( ! err ) { return 0 ; } if ( regionHandle ) * regionHandle = ( uintptr_t ) err ; return 1 ; }
Translates the given virtual address, from the view of the given task, into a handle to the
 region that contains that address.
Translates the given virtual address from the view of the given task into a handle to the region that contains that address .
// handle the error or non-existent mapping cases of the syscall // otherwise, extract the fields