RTDECL(int) RTErrConvertFromDarwinIO(int iNativeCode)
{
    /*
     * 'optimized' success case.
     */
    if (iNativeCode == kIOReturnSuccess)
        return VINF_SUCCESS;
    return RTErrConvertFromDarwin(iNativeCode);
}
RTDECL(int) RTErrConvertFromDarwinKern(int iNativeCode)
{
    /*
     * 'optimized' success case.
     */
    if (iNativeCode == KERN_SUCCESS)
        return VINF_SUCCESS;
    return RTErrConvertFromDarwin(iNativeCode);
}
static int getProcessInfo(RTPROCESS process, struct proc_taskinfo *tinfo)
{
    LogAleksey(("getProcessInfo() getting info for %d", process));
    int nb = proc_pidinfo(process, PROC_PIDTASKINFO, 0,  tinfo, sizeof(*tinfo));
    if (nb <= 0)
    {
        int rc = errno;
        Log(("proc_pidinfo() -> %s", strerror(rc)));
        return RTErrConvertFromDarwin(rc);
    }
    else if ((unsigned int)nb < sizeof(*tinfo))
    {
        Log(("proc_pidinfo() -> too few bytes %d", nb));
        return VERR_INTERNAL_ERROR;
    }
    return VINF_SUCCESS;
}
RTDECL(int) RTSystemQueryAvailableRam(uint64_t *pcb)
{
    AssertPtrReturn(pcb, VERR_INVALID_POINTER);

    static mach_port_t volatile s_hSelfPort = 0;
    mach_port_t hSelfPort = s_hSelfPort;
    if (hSelfPort == 0)
        s_hSelfPort = hSelfPort = mach_host_self();

    vm_statistics_data_t    VmStats;
    mach_msg_type_number_t  cItems = sizeof(VmStats) / sizeof(natural_t);

    kern_return_t krc = host_statistics(hSelfPort, HOST_VM_INFO, (host_info_t)&VmStats, &cItems);
    if (krc == KERN_SUCCESS)
    {
        uint64_t cPages = VmStats.inactive_count;
        cPages += VmStats.free_count;
        *pcb = cPages * PAGE_SIZE;
        return VINF_SUCCESS;
    }
    return RTErrConvertFromDarwin(krc);
}