SUPLib-darwin.cpp revision c739fbc69330f4c750ef6c34a63d126145f426d3
/** @file
*
* VBox host drivers - Ring-0 support drivers - Darwin host:
* Darwin implementations for support library
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung GmbH
*
* 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 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* 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(("Couldn't find any matches.\n"));
return VERR_GENERAL_FAILURE;
}
/*
* Open the service.
* This will cause the user client class in SUPDrv-darwin.cpp to be instantiated.
*/
if (kr != kIOReturnSuccess)
{
return VERR_GENERAL_FAILURE;
}
/*
* Now, try open the BSD device.
*/
if (g_hDevice < 0)
{
if (kr != kIOReturnSuccess)
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;
}
/**
* Installs anything required by the support library.
*
* @returns 0 on success.
* @returns error code on failure.
*/
int suplibOsInstall(void)
{
// int rc = mknod(DEVICE_NAME, S_IFCHR, );
return VERR_NOT_IMPLEMENTED;
}
/**
* Installs anything required by the support library.
*
* @returns 0 on success.
* @returns error code on failure.
*/
int suplibOsUninstall(void)
{
// int rc = unlink(DEVICE_NAME);
return VERR_NOT_IMPLEMENTED;
}
/**
* Send a I/O Control request to the device.
*
* @returns 0 on success.
* @returns VBOX error code on failure.
* @param uFunction IO Control function.
* @param pvIn Input data buffer.
* @param cbIn Size of input data.
* @param pvOut Output data buffer.
* @param cbOut Size of output data.
*/
{
/*
* Issue device iocontrol.
*/
return 0;
/* This is the reverse operation of the one found in SUPDrv-linux.c */
switch (errno)
{
case EACCES: return VERR_GENERAL_FAILURE;
case EINVAL: return VERR_INVALID_PARAMETER;
case ENOSYS: return VERR_INVALID_MAGIC;
case ENXIO: return VERR_INVALID_HANDLE;
case EFAULT: return VERR_INVALID_POINTER;
case ENOLCK: return VERR_LOCK_FAILED;
case EEXIST: return VERR_ALREADY_LOADED;
}
return RTErrConvertFromErrno(errno);
}
#ifdef VBOX_WITHOUT_IDT_PATCHING
int suplibOSIOCtlFast(unsigned uFunction)
{
if (rc == -1)
return rc;
}
#endif
/**
* Allocate a number of zero-filled pages in user space.
*
* @returns VBox status code.
* @param cPages Number of pages to allocate.
* @param ppvPages Where to return the base pointer.
*/
{
if (*ppvPages)
{
return VINF_SUCCESS;
}
return RTErrConvertFromErrno(errno);
}
/**
* Frees pages allocated by suplibOsPageAlloc().
*
* @returns VBox status code.
* @param pvPages Pointer to pages.
*/
int suplibOsPageFree(void *pvPages)
{
return VINF_SUCCESS;
}