SUPDrv-freebsd.c revision 0a769a6be37f526faeabe88f77422ee6291afa37
/* $Id$ */
/** @file
* VBoxDrv - FreeBSD specifics.
*/
/*
* Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/* Deal with conflicts first. */
#include "SUPDRV.h"
#include <iprt/initterm.h>
#include <iprt/spinlock.h>
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static int VBoxDrvFreeBSDLoad(void);
static int VBoxDrvFreeBSDUnload(void);
static d_fdopen_t VBoxDrvFreeBSDOpen;
static d_close_t VBoxDrvFreeBSDClose;
static d_ioctl_t VBoxDrvFreeBSDIOCtl;
static int VBoxDrvFreeBsdErr2Native(int rc);
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/**
* Module info structure used by the kernel.
*/
static moduledata_t g_VBoxDrvFreeBSDModule =
{
"vboxdrv",
};
/** Declare the module as a pseudo device. */
/**
*/
static struct cdevsw g_VBoxDrvFreeBSDChrDevSW =
{
.d_flags = D_TRACKCLOSE,
.d_name = "vboxdrv"
};
/** The make_dev result. */
static struct cdev *g_pVBoxDrvFreeBSDChrDev;
/** The device extention. */
static SUPDRVDEVEXT g_DevExt;
/** Spinlock protecting g_apSessionHashTab. */
/** Hash table */
/** Calculates the index into g_apSessionHashTab.*/
/**
* Module event handler.
*
* @param pMod The module structure.
* @param enmEventType The event type (modeventtype_t).
* @param pvArg Module argument. NULL.
*
* @return 0 on success, errno.h status code on failure.
*/
{
int rc;
switch (enmEventType)
{
case MOD_LOAD:
rc = VBoxDrvFreeBSDLoad();
break;
case MOD_UNLOAD:
rc = VBoxDrvFreeBSDUnload();
break;
case MOD_SHUTDOWN:
case MOD_QUIESCE:
default:
return EOPNOTSUPP;
}
if (RT_SUCCESS(rc))
return 0;
return VBoxDrvFreeBsdErr2Native(rc);
}
static int VBoxDrvFreeBSDLoad(void)
{
dprintf(("VBoxDrvFreeBSDLoad:\n"));
/*
* Initialize the runtime.
*/
if (RT_SUCCESS(rc))
{
/*
* Initialize the device extension.
*/
if (RT_SUCCESS(rc))
{
/*
* Initialize the session hash table.
*/
if (RT_SUCCESS(rc))
{
/*
* Create our device node.
*/
/** @todo find a way to fix this 0666 permission issue. Perhaps by defining some vboxusers group with a fixed gid? */
0,
0666,
"vboxdrv");
{
dprintf(("VBoxDrvFreeBSDLoad: returns successfully\n"));
return VINF_SUCCESS;
}
printf("vboxdrv: make_dev failed\n");
}
else
}
else
RTR0Term();
}
else
return rc;
}
static int VBoxDrvFreeBSDUnload(void)
{
int rc;
dprintf(("VBoxDrvFreeBSDUnload:\n"));
/** @todo verify that FreeBSD does reference counting. */
/*
* Reserve what we did in VBoxDrvFreeBSDInit.
*/
{
}
RTR0Term();
dprintf(("VBoxDrvFreeBSDUnload: returns\n"));
return VINF_SUCCESS;
}
{
dprintf(("VBoxDrvFreeBSDOpen:\n"));
return EOPNOTSUPP;
}
{
dprintf(("VBoxDrvFreeBSDClose:\n"));
return EBADF;
}
static int VBoxDrvFreeBSDIOCtl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
{
dprintf(("VBoxDrvFreeBSDIOCtl:\n"));
return EINVAL;
}
/**
* Converts an supdrv error code to a FreeBSD error code.
*
* @returns corresponding FreeBSD error code.
* @param rc supdrv error code (SUPDRV_ERR_* defines).
*/
static int VBoxDrvFreeBsdErr2Native(int rc)
{
switch (rc)
{
case 0: return 0;
case SUPDRV_ERR_GENERAL_FAILURE: return EACCES;
case SUPDRV_ERR_INVALID_PARAM: return EINVAL;
case SUPDRV_ERR_INVALID_MAGIC: return EILSEQ;
case SUPDRV_ERR_INVALID_HANDLE: return ENXIO;
case SUPDRV_ERR_INVALID_POINTER: return EFAULT;
case SUPDRV_ERR_LOCK_FAILED: return ENOLCK;
case SUPDRV_ERR_ALREADY_LOADED: return EEXIST;
case SUPDRV_ERR_PERMISSION_DENIED: return EPERM;
case SUPDRV_ERR_VERSION_MISMATCH: return ENOSYS;
}
return EPERM;
}
{
}
bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc)
{
return false;
}
{
char szMsg[256];
int cch;
return cch;
}