SUPLib-darwin.cpp revision b27991b512ea0b29ef75f62a9e54e4bba411f77e
/** @file
*
* VBox host drivers - Ring-0 support drivers - Darwin host:
* Darwin implementations for support library
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_SUP
#include "../SUPLibInternal.h"
#include "../SUPDrvIOC.h"
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <mach/mach_port.h>
#include <IOKit/IOKitLib.h>
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** BSD Device name. */
#define DEVICE_NAME "/dev/vboxdrv"
/** The IOClass key of the service (see SUPDrv-darwin.cpp / Info.plist). */
#define IOCLASS_NAME "org_virtualbox_SupDrv"
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Handle to the open device. */
static int g_hDevice = -1;
/** The IOMasterPort. */
static mach_port_t g_MasterPort = 0;
/** The current service connection. */
{
/*
* Check if already initialized.
*/
if (g_hDevice >= 0)
return VINF_SUCCESS;
/*
* Open the IOKit client first - The first step is finding the service.
*/
if (kr != kIOReturnSuccess)
{
return VERR_GENERAL_FAILURE;
}
if (!ClassToMatch)
{
return VERR_GENERAL_FAILURE;
}
/* Create an io_iterator_t for all instances of our drivers class that exist in the IORegistry. */
if (kr != kIOReturnSuccess)
{
return VERR_GENERAL_FAILURE;
}
/* Get the first item in the iterator and release it. */
if (!ServiceObject)
{
LogRel(("SUP: Couldn't find any matches. The kernel module is probably not loaded.\n"));
return VERR_VM_DRIVER_NOT_INSTALLED;
}
/*
* Open the service.
* This will cause the user client class in SUPDrv-darwin.cpp to be instantiated.
*/
if (kr != kIOReturnSuccess)
{
return VERR_VM_DRIVER_OPEN_ERROR;
}
/*
* Now, try open the BSD device.
*/
if (g_hDevice < 0)
{
int rc;
switch (errno)
{
case EPERM:
default: rc = VERR_VM_DRIVER_OPEN_ERROR; break;
}
if (kr != kIOReturnSuccess)
return rc;
}
/*
* Mark the file handle close on exec.
*/
{
g_hDevice = -1;
return RTErrConvertFromErrno(rc);
}
/*
* We're done.
*/
return VINF_SUCCESS;
}
int suplibOsTerm(void)
{
/*
* Check if we're initited at all.
*/
if (g_hDevice >= 0)
{
AssertFailed();
g_hDevice = -1;
}
/*
* Close the connection to the IOService and destroy the connection handle.
*/
if (g_Connection)
{
if (kr != kIOReturnSuccess)
{
AssertFailed();
}
g_Connection = NULL;
}
return VINF_SUCCESS;
}
int suplibOsInstall(void)
{
return VERR_NOT_IMPLEMENTED;
}
int suplibOsUninstall(void)
{
return VERR_NOT_IMPLEMENTED;
}
{
return VINF_SUCCESS;
return RTErrConvertFromErrno(errno);
}
{
if (rc == -1)
return rc;
}
{
if (*ppvPages)
{
return VINF_SUCCESS;
}
return RTErrConvertFromErrno(errno);
}
{
return VINF_SUCCESS;
}