VirtualBox

Ignore:
Timestamp:
Aug 27, 2008 10:21:47 PM (16 years ago)
Author:
vboxsync
Message:

#3076: Merged in the branch with the alternate driver authentication method. (34468:HEAD)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/freebsd/SUPLib-freebsd.cpp

    r10256 r11725  
     1/* $Id: $ */
    12/** @file
    2  * SUPLib - FreeBSD Hosts,
     3 * VirtualBox Support Library - FreeBSD specific parts.
    34 */
    45
     
    2829 */
    2930
    30 
    3131/*******************************************************************************
    3232*   Header Files                                                               *
    3333*******************************************************************************/
    3434#define LOG_GROUP LOG_GROUP_SUP
     35#ifdef IN_SUP_HARDENED_R3
     36# undef DEBUG /* Warning: disables RT_STRICT */
     37# define LOG_DISABLED
     38  /** @todo RTLOGREL_DISABLED */
     39# include <iprt/log.h>
     40# undef LogRelIt
     41# define LogRelIt(pvInst, fFlags, iGroup, fmtargs) do { } while (0)
     42#endif
     43
    3544#include <VBox/types.h>
    3645#include <VBox/sup.h>
     
    6069
    6170
    62 /*******************************************************************************
    63 *   Global Variables                                                           *
    64 *******************************************************************************/
    65 /** Handle to the open device. */
    66 static int              g_hDevice = -1;
    6771
    68 
    69 int suplibOsInit(size_t cbReserve)
     72int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited)
    7073{
    7174    /*
    72      * Check if already initialized.
     75     * Nothing to do if pre-inited.
    7376     */
    74     if (g_hDevice >= 0)
     77    if (fPreInited)
    7578        return VINF_SUCCESS;
    7679
     
    7881     * Try open the BSD device.
    7982     */
     83    int hDevice = -1;
    8084    char szDevice[sizeof(DEVICE_NAME) + 16];
    8185    for (unsigned iUnit = 0; iUnit < 1024; iUnit++)
     
    8387        errno = 0;
    8488        RTStrPrintf(szDevice, sizeof(szDevice), DEVICE_NAME "%d", iUnit);
    85         g_hDevice = open(szDevice, O_RDWR, 0);
    86         if (g_hDevice >= 0 || errno != EBUSY)
     89        hDevice = open(szDevice, O_RDWR, 0);
     90        if (hDevice >= 0 || errno != EBUSY)
    8791            break;
    8892    }
    89     if (g_hDevice < 0)
     93    if (hDevice < 0)
    9094    {
    9195        int rc;
     
    105109     * Mark the file handle close on exec.
    106110     */
    107     if (fcntl(g_hDevice, F_SETFD, FD_CLOEXEC) != 0)
     111    if (fcntl(hDevice, F_SETFD, FD_CLOEXEC) != 0)
    108112    {
    109         int rc = errno;
    110         LogRel(("suplibOSInit: setting FD_CLOEXEC failed, errno=%d\n", rc));
    111         close(g_hDevice);
    112         g_hDevice = -1;
    113         return RTErrConvertFromErrno(rc);
     113#ifdef IN_SUP_HARDENED_R3
     114        int rc = VERR_INTERNAL_ERROR;
     115#else
     116        int err = errno;
     117        int rc = RTErrConvertFromErrno(err);
     118        LogRel(("suplibOSInit: setting FD_CLOEXEC failed, errno=%d (%Rrc)\n", err, rc));
     119#endif
     120        close(hDevice);
     121        return rc;
    114122    }
    115123
     
    117125     * We're done.
    118126     */
    119     NOREF(cbReserve);
     127    pThis->hDevice = hDevice;
    120128    return VINF_SUCCESS;
    121129}
    122130
    123131
    124 int suplibOsTerm(void)
     132#ifndef IN_SUP_HARDENED_R3
     133
     134int suplibOsTerm(PSUPLIBDATA pThis)
    125135{
    126136    /*
    127137     * Check if we're initited at all.
    128138     */
    129     if (g_hDevice >= 0)
     139    if (pThis->hDevice != NIL_RTFILE)
    130140    {
    131         if (close(g_hDevice))
     141        if (close(pThis->hDevice))
    132142            AssertFailed();
    133         g_hDevice = -1;
     143        pThis->hDevice = NIL_RTFILE;
    134144    }
    135145    return VINF_SUCCESS;
     
    149159
    150160
    151 int suplibOsIOCtl(uintptr_t uFunction, void *pvReq, size_t cbReq)
     161int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq)
    152162{
    153     AssertMsg(g_hDevice != -1, ("SUPLIB not initiated successfully!\n"));
    154 
    155     if (RT_LIKELY(ioctl(g_hDevice, uFunction, pvReq) >= 0))
     163    if (RT_LIKELY(ioctl(pThis->hDevice, uFunction, pvReq) >= 0))
    156164        return VINF_SUCCESS;
    157165    return RTErrConvertFromErrno(errno);
     
    159167
    160168
    161 int suplibOsIOCtlFast(uintptr_t uFunction)
     169int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction)
    162170{
    163     int rc = ioctl(g_hDevice, uFunction, NULL);
     171    int rc = ioctl(pThis->hDevice, uFunction, NULL);
    164172    if (rc == -1)
    165173        rc = errno;
     
    168176
    169177
    170 int suplibOsPageAlloc(size_t cPages, void **ppvPages)
     178int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages)
    171179{
     180    NOREF(pThis);
    172181    *ppvPages = RTMemPageAllocZ(cPages << PAGE_SHIFT);
    173182    if (*ppvPages)
     
    177186
    178187
    179 int suplibOsPageFree(void *pvPages, size_t /* cPages */)
     188int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t /* cPages */)
    180189{
     190    NOREF(pThis);
    181191    RTMemPageFree(pvPages);
    182192    return VINF_SUCCESS;
    183193}
    184194
     195#endif /* !IN_SUP_HARDENED_R3 */
     196
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette