3349N/A/* $Id$ */
3349N/A/** @file
3349N/A * IPRT - Convert Darwin Mach returns codes to iprt status codes.
3349N/A */
3349N/A
3349N/A/*
3349N/A * Copyright (C) 2006-2012 Oracle Corporation
3349N/A *
3349N/A * This file is part of VirtualBox Open Source Edition (OSE), as
3349N/A * available from http://www.virtualbox.org. This file is free software;
3349N/A * you can redistribute it and/or modify it under the terms of the GNU
3349N/A * General Public License (GPL) as published by the Free Software
3349N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
3349N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3349N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3349N/A *
3349N/A * The contents of this file may alternatively be used under the terms
3349N/A * of the Common Development and Distribution License Version 1.0
3349N/A * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
3349N/A * VirtualBox OSE distribution, in which case the provisions of the
3349N/A * CDDL are applicable instead of those of the GPL.
3349N/A *
3349N/A * You may elect to license modified versions of this file under the
3349N/A * terms and conditions of either the GPL or the CDDL or both.
3349N/A */
3349N/A
3349N/A/*******************************************************************************
3349N/A* Header Files *
3349N/A*******************************************************************************/
3349N/A#include <mach/kern_return.h>
3349N/A#include <IOKit/IOReturn.h>
3349N/A
3349N/A#include <iprt/err.h>
3349N/A#include <iprt/assert.h>
3349N/A
3349N/A
3349N/ARTDECL(int) RTErrConvertFromDarwin(int iNativeCode)
3349N/A{
3349N/A /*
3349N/A * 'optimized' success case.
3349N/A */
3349N/A if (iNativeCode == KERN_SUCCESS)
3349N/A return VINF_SUCCESS;
3349N/A
3349N/A switch (iNativeCode)
3349N/A {
3349N/A /*
3349N/A * Mach.
3349N/A */
3349N/A case KERN_INVALID_ADDRESS: return VERR_INVALID_POINTER;
3349N/A case KERN_PROTECTION_FAILURE: return VERR_PERMISSION_DENIED;
3349N/A //case KERN_NO_SPACE:
3349N/A case KERN_INVALID_ARGUMENT: return VERR_INVALID_PARAMETER;
3349N/A //case KERN_FAILURE:
3349N/A //case KERN_RESOURCE_SHORTAGE:
3349N/A //case KERN_NOT_RECEIVER:
3349N/A case KERN_NO_ACCESS: return VERR_ACCESS_DENIED;
3349N/A //case KERN_MEMORY_FAILURE:
3349N/A //case KERN_MEMORY_ERROR:
3349N/A //case KERN_ALREADY_IN_SET:
3349N/A //case KERN_NOT_IN_SET:
3349N/A //case KERN_NAME_EXISTS:
3349N/A //case KERN_ABORTED:
3349N/A //case KERN_INVALID_NAME:
3349N/A //case KERN_INVALID_TASK:
3349N/A //case KERN_INVALID_RIGHT:
3349N/A //case KERN_INVALID_VALUE:
3349N/A //case KERN_UREFS_OVERFLOW:
3349N/A //case KERN_INVALID_CAPABILITY:
3349N/A //case KERN_RIGHT_EXISTS:
3349N/A //case KERN_INVALID_HOST:
3349N/A //case KERN_MEMORY_PRESENT:
3349N/A //case KERN_MEMORY_DATA_MOVED:
3349N/A //case KERN_MEMORY_RESTART_COPY:
3349N/A //case KERN_INVALID_PROCESSOR_SET:
3349N/A //case KERN_POLICY_LIMIT:
3349N/A //case KERN_INVALID_POLICY:
3349N/A //case KERN_INVALID_OBJECT:
3349N/A //case KERN_ALREADY_WAITING:
3349N/A //case KERN_DEFAULT_SET:
3349N/A //case KERN_EXCEPTION_PROTECTED:
3349N/A //case KERN_INVALID_LEDGER:
3349N/A //case KERN_INVALID_MEMORY_CONTROL:
3349N/A //case KERN_INVALID_SECURITY:
3349N/A //case KERN_NOT_DEPRESSED:
3349N/A //case KERN_TERMINATED:
3349N/A //case KERN_LOCK_SET_DESTROYED:
3349N/A //case KERN_LOCK_UNSTABLE:
3349N/A case KERN_LOCK_OWNED: return VERR_SEM_BUSY;
3349N/A //case KERN_LOCK_OWNED_SELF:
3349N/A case KERN_SEMAPHORE_DESTROYED: return VERR_SEM_DESTROYED;
3349N/A //case KERN_RPC_SERVER_TERMINATED:
3349N/A //case KERN_RPC_TERMINATE_ORPHAN:
3349N/A //case KERN_RPC_CONTINUE_ORPHAN:
3349N/A case KERN_NOT_SUPPORTED: return VERR_NOT_SUPPORTED;
3349N/A //case KERN_NODE_DOWN:
3349N/A //case KERN_NOT_WAITING:
3349N/A case KERN_OPERATION_TIMED_OUT: return VERR_TIMEOUT;
3349N/A
3349N/A
3349N/A /*
3349N/A * I/O Kit.
3349N/A */
3349N/A case kIOReturnNoDevice: return VERR_IO_BAD_UNIT;
3349N/A case kIOReturnUnsupported: return VERR_NOT_SUPPORTED;
3349N/A case kIOReturnInternalError: return VERR_INTERNAL_ERROR;
3349N/A case kIOReturnNoResources: return VERR_OUT_OF_RESOURCES;
3349N/A case kIOReturnBadArgument: return VERR_INVALID_PARAMETER;
3349N/A case kIOReturnCannotWire: return VERR_LOCK_FAILED;
3349N/A
3349N/A#ifdef IN_RING3
3349N/A /*
3349N/A * CoreFoundation COM (may overlap with I/O Kit and Mach).
3349N/A */
3349N/A default:
3349N/A if ( (unsigned)iNativeCode >= 0x80000000U
3349N/A && (unsigned)iNativeCode >= 0x8000FFFFU)
3349N/A return RTErrConvertFromDarwinCOM(iNativeCode);
3349N/A break;
3349N/A#endif /* IN_RING3 */
3349N/A }
3349N/A
3349N/A /* unknown error. */
3349N/A AssertMsgFailed(("Unhandled error %#x\n", iNativeCode));
3349N/A return VERR_UNRESOLVED_ERROR;
3349N/A}
3349N/A
3349N/A