VirtualBox

Changeset 378 in vbox for trunk


Ignore:
Timestamp:
Jan 27, 2007 3:54:16 AM (18 years ago)
Author:
vboxsync
Message:

client/provider stuff (not complete). And some bugfixes.

Location:
trunk/src/VBox/HostDrivers/Support
Files:
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/Makefile

    r331 r378  
    182182VBoxDrv_DEFS          = IN_RT_R0 IN_SUP_R0 USE_NEW_OS_INTERFACE
    183183VBoxDrv_INCS          = $(VBOX_PATH_SUPPORT)
    184 VBoxDrv_LIBS          = $(PATH_LIB)/RuntimeR0Drv$(VBOX_SUFF_LIB) $(VBOX_GCC_LIBGCC)
     184VBoxDrv_LIBS          = $(PATH_LIB)/RuntimeR0Drv$(VBOX_SUFF_LIB)
    185185VBoxDrv_LDFLAGS       = -v -Wl,-whyload -Wl,-v -Wl,-whatsloaded
    186186VBoxDrv_INST          = bin/VBoxDrv.kext/Contents/MacOS/
    187187VBoxDrv_SOURCES       = \
    188188        $(VBOX_PATH_SUPPORT)/SUPDRVShared.c \
    189         $(VBOX_PATH_SUPPORT)/$(BUILD_TARGET)/SUPDrv-$(BUILD_TARGET).c
     189        $(VBOX_PATH_SUPPORT)/$(BUILD_TARGET)/SUPDrv-$(BUILD_TARGET).cpp
    190190
    191191INSTALLS += VBoxDrv.kext
  • trunk/src/VBox/HostDrivers/Support/SUPDRV.h

    r1 r378  
    171171
    172172/* dprintf2 - extended logging. */
    173 #if 0
     173#if defined(__DARWIN__)
    174174# define dprintf2 dprintf
    175175#else
     
    547547    PSUPDRVSESSION              pNextHash;
    548548#endif
     549#if defined(__DARWIN__)
     550    /** Pointer to the org_virtualbox_SupDrvClient client that's associated with the session. */
     551    void                       *pvClient;
     552#endif
    549553} SUPDRVSESSION;
    550554
  • trunk/src/VBox/HostDrivers/Support/SUPDRVShared.c

    r220 r378  
    18211821                    *ppvR0 = RTR0MemObjAddress(Mem.MemObj);
    18221822                *ppvR3 = RTR0MemObjAddress(Mem.MapObjR3);
     1823                *pHCPhys = RTR0MemObjGetPagePhysAddr(Mem.MemObj, 0);
    18231824                return 0;
    18241825            }
     1826
    18251827            rc2 = RTR0MemObjFree(Mem.MapObjR3, false);
    18261828            AssertRC(rc2);
     
    19311933                return 0;
    19321934            }
     1935
    19331936            rc2 = RTR0MemObjFree(Mem.MapObjR3, false);
    19341937            AssertRC(rc2);
  • trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp

    r219 r378  
    2828#include <sys/param.h>
    2929#undef PVM
     30#include <IOKit/IOLib.h> /* Assert as function */
    3031
    3132#include "SUPDRV.h"
     33#include <VBox/version.h>
    3234#include <iprt/types.h>
    3335#include <iprt/initterm.h>
     
    3537#include <iprt/spinlock.h>
    3638#include <iprt/semaphore.h>
     39#include <iprt/alloc.h>
    3740
    3841#include <mach/kmod.h>
     
    4346#include <sys/malloc.h>
    4447#include <sys/proc.h>
     48#include <IOKit/IOService.h>
     49#include <IOKit/IOUserclient.h>
    4550
    4651
     
    5762*   Internal Functions                                                         *
    5863*******************************************************************************/
     64__BEGIN_DECLS
    5965static kern_return_t    VBoxSupDrvStart(struct kmod_info *pKModInfo, void *pvData);
    6066static kern_return_t    VBoxSupDrvStop(struct kmod_info *pKModInfo, void *pvData);
     
    6672
    6773static int              VBoxSupDrvErr2DarwinErr(int rc);
     74__END_DECLS
     75
     76
     77/*******************************************************************************
     78*   Structures and Typedefs                                                    *
     79*******************************************************************************/
     80/**
     81 * The service class.
     82 * This is just a formality really.
     83 */
     84class org_virtualbox_SupDrv : public IOService
     85{
     86    OSDeclareDefaultStructors(org_virtualbox_SupDrv)
     87
     88public:
     89    virtual bool init(OSDictionary *pDictionary = 0);
     90    virtual void free(void);
     91    virtual bool start(IOService *pProvider);
     92    virtual void stop(IOService *pProvider);
     93    virtual IOService *probe(IOService *pProvider, SInt32 *pi32Score);
     94};
     95
     96OSDefineMetaClassAndStructors(org_virtualbox_SupDrv, IOService)
     97
     98
     99/**
     100 * An attempt at getting that clientDied() notification.
     101 * I don't think it'll work as I cannot figure out where/what creates the correct
     102 * port right.
     103 */
     104class org_virtualbox_SupDrvClient : public IOUserClient
     105{
     106    OSDeclareDefaultStructors(org_virtualbox_SupDrvClient)
     107
     108private:
     109    PSUPDRVSESSION          m_pSession;     /**< The session. */
     110    task_t                  m_Task;         /**< The client task. */
     111    org_virtualbox_SupDrv  *m_pProvider;    /**< The service provider. */
     112
     113public:
     114    virtual bool initWithTask(task_t OwningTask, void *pvSecurityId, UInt32 u32Type);
     115    virtual bool start(IOService *pProvider);
     116    virtual void stop(IOService *pProvider);
     117    virtual IOReturn clientClose(void);
     118    virtual IOReturn clientDied(void);
     119    virtual bool terminate(IOOptionBits fOptions = 0);
     120    virtual bool finalize(IOOptionBits fOptions);
     121};
     122
     123OSDefineMetaClassAndStructors(org_virtualbox_SupDrvClient, IOUserClient)
     124
    68125
    69126
     
    74131 * Declare the module stuff.
    75132 */
    76 KMOD_EXPLICIT_DECL(vboxdrv, "1.0", VBoxSupDrvStart, VBoxSupDrvStop)
     133__BEGIN_DECLS
     134extern kern_return_t _start(struct kmod_info *pKModInfo, void *pvData);
     135extern kern_return_t _stop(struct kmod_info *pKModInfo, void *pvData);
     136__private_extern__ kmod_start_func_t *_realmain;
     137__private_extern__ kmod_stop_func_t  *_antimain;
     138__private_extern__ int                _kext_apple_cc;
     139
     140KMOD_EXPLICIT_DECL(VBoxDrv, VBOX_VERSION_STRING, _start, _stop)
     141kmod_start_func_t *_realmain = VBoxSupDrvStart;
     142kmod_stop_func_t  *_antimain = VBoxSupDrvStop;
     143int                _kext_apple_cc = __APPLE_CC__;
     144__END_DECLS
     145
    77146
    78147/**
     
    86155static struct cdevsw    g_DevCW =
    87156{
    88     .d_open = VBoxSupDrvOpen,
    89     .d_close = VBoxSupDrvClose,
    90     .d_read = eno_rdwrt,
    91     .d_write = eno_rdwrt,
    92     .d_ioctl = VBoxSupDrvIOCtl,
    93     .d_stop = eno_stop,
    94     .d_reset = eno_reset,
    95     .d_ttys = NULL,
    96     .d_select = eno_select,
    97     .d_mmap = eno_mmap,
    98     .d_strategy = eno_strat,
    99     .d_getc = eno_getc,
    100     .d_putc = eno_putc,
    101     .d_type = 0
     157    /** @todo g++ doesn't like this syntax - it worked with gcc before renaming to .cpp. */
     158    /*.d_open  = */VBoxSupDrvOpen,
     159    /*.d_close = */VBoxSupDrvClose,
     160    /*.d_read  = */eno_rdwrt,
     161    /*.d_write = */eno_rdwrt,
     162    /*.d_ioctl = */VBoxSupDrvIOCtl,
     163    /*.d_stop  = */eno_stop,
     164    /*.d_reset = */eno_reset,
     165    /*.d_ttys  = */NULL,
     166    /*.d_select= */eno_select,
     167    /*.d_mmap  = */eno_mmap,
     168    /*.d_strategy = */eno_strat,
     169    /*.d_getc  = */eno_getc,
     170    /*.d_putc  = */eno_putc,
     171    /*.d_type  = */0
    102172};
    103173
    104174/** Major device number. */
    105 static int                  g_iMajorDeviceNo = -1;
     175static int              g_iMajorDeviceNo = -1;
    106176/** Registered devfs device handle. */
    107177static void            *g_hDevFsDevice = NULL;
     
    380450    void               *pvPageBuf = NULL;
    381451    void               *pvBuf = NULL;
    382     int                 cbBuf = 0;
     452    unsigned long       cbBuf = 0;
    383453    unsigned            cbOut = 0;
    384454    PSUPDRVIOCTLDATA    pArgs = (PSUPDRVIOCTLDATA)pData;
     
    400470    {
    401471        cbBuf = max(pArgs->cbIn, pArgs->cbOut);
    402         MALLOC(pvBuf, void *, cbBuf, M_TEMP, M_WAITOK);
     472        pvBuf = RTMemTmpAlloc(cbBuf);
    403473        if (pvBuf == NULL)
    404474            pvPageBuf = pvBuf = IOMallocAligned(cbBuf, 8);
     
    415485                IOFreeAligned(pvPageBuf, cbBuf);
    416486            else
    417                 FREE(pvBuf, M_TEMP);
     487                RTMemTmpFree(pvBuf);
    418488            return rc;
    419489        }
     
    456526        IOFreeAligned(pvPageBuf, cbBuf);
    457527    else if (pvBuf)
    458         FREE(pvBuf, M_TEMP);
     528        RTMemTmpFree(pvBuf);
    459529
    460530    dprintf2(("VBoxSupDrvIOCtl: returns %d\n", rc));
     
    524594RTDECL(int) SUPR0Printf(const char *pszFormat, ...)
    525595{
    526     va_list      args;
    527     char        szMsg[512];
     596    va_list    args;
     597    char        szMsg[512];
    528598
    529599    va_start(args, pszFormat);
     
    551621RTDECL(void) AssertMsg2(const char *pszFormat, ...)
    552622{   /* forwarder. */
    553     va_list      ap;
    554     char        msg[256];
     623    va_list    ap;
     624    char        msg[256];
    555625
    556626    va_start(ap, pszFormat);
     
    561631}
    562632
     633
     634/*
     635 *
     636 * org_virtualbox_SupDrv
     637 *
     638 */
     639
     640
     641/**
     642 * Initialize the object.
     643 */
     644bool org_virtualbox_SupDrv::init(OSDictionary *pDictionary)
     645{
     646    dprintf(("org_virtualbox_SupDrv::init([%p], %p)\n", this, pDictionary));
     647    if (IOService::init(pDictionary))
     648    {
     649        /* init members. */
     650        return true;
     651    }
     652    return false;
     653}
     654
     655
     656/**
     657 * Free the object.
     658 */
     659void org_virtualbox_SupDrv::free(void)
     660{
     661    dprintf(("IOService::free([%p])\n", this));
     662    IOService::free();
     663}
     664
     665
     666/**
     667 * Check if it's ok to start this service.
     668 * It's always ok by us, so it's up to IOService to decide really.
     669 */
     670IOService *org_virtualbox_SupDrv::probe(IOService *pProvider, SInt32 *pi32Score)
     671{
     672    dprintf(("org_virtualbox_SupDrv::probe([%p])\n", this));
     673    return IOService::probe(pProvider, pi32Score);
     674}
     675
     676
     677/**
     678 * Start this service.
     679 */
     680bool org_virtualbox_SupDrv::start(IOService *pProvider)
     681{
     682    dprintf(("org_virtualbox_SupDrv::start([%p])\n", this));
     683
     684    if (IOService::start(pProvider))
     685    {
     686        /* register the service. */
     687        registerService();
     688        return true;
     689    }
     690    return false;
     691}
     692
     693
     694/**
     695 * Stop this service.
     696 */
     697void org_virtualbox_SupDrv::stop(IOService *pProvider)
     698{
     699    dprintf(("org_virtualbox_SupDrv::stop([%p], %p)\n", this, pProvider));
     700    IOService::stop(pProvider);
     701}
     702
     703
     704/*
     705 *
     706 * org_virtualbox_SupDrvClient
     707 *
     708 */
     709
     710
     711/**
     712 * Initializer called when the client opens the service.
     713 */
     714bool org_virtualbox_SupDrvClient::initWithTask(task_t OwningTask, void *pvSecurityId, UInt32 u32Type)
     715{
     716    dprintf(("org_virtualbox_SupDrvClient::initWithTask([%p], %#x, %p, %#x)\n", this, OwningTask, pvSecurityId, u32Type));
     717
     718    if (!OwningTask)
     719        return false;
     720    if (IOUserClient::initWithTask(OwningTask, pvSecurityId , u32Type))
     721    {
     722        m_Task = OwningTask;
     723        m_pSession = NULL;
     724        m_pProvider = NULL;
     725        return true;
     726    }
     727    return false;
     728}
     729
     730
     731/**
     732 * Start the client service.
     733 */
     734bool org_virtualbox_SupDrvClient::start(IOService *pProvider)
     735{
     736    dprintf(("org_virtualbox_SupDrvClient::start([%p], %p)\n", this, pProvider));
     737    if (IOUserClient::start(pProvider))
     738    {
     739        m_pProvider = OSDynamicCast(org_virtualbox_SupDrv, pProvider);
     740        if (m_pProvider)
     741        {
     742            /* this is where we could create the section. */
     743            return true;
     744        }
     745        dprintf(("org_virtualbox_SupDrvClient::start: %p isn't org_virtualbox_SupDrv\n", pProvider));
     746    }
     747    return false;
     748}
     749
     750
     751/**
     752 * Client exits normally.
     753 */
     754IOReturn org_virtualbox_SupDrvClient::clientClose(void)
     755{
     756    dprintf(("org_virtualbox_SupDrvClient::clientClose([%p])\n", this));
     757
     758    m_pProvider = NULL;
     759    terminate();
     760
     761    return kIOReturnSuccess;
     762}
     763
     764
     765/**
     766 * The client exits abnormally / forgets to do cleanups.
     767 */
     768IOReturn org_virtualbox_SupDrvClient::clientDied(void)
     769{
     770    dprintf(("org_virtualbox_SupDrvClient::clientDied([%p])\n", this));
     771
     772    /* IOUserClient::clientDied() only calls calls close... */
     773    return IOUserClient::clientDied();
     774}
     775
     776
     777/**
     778 * Stop the client service.
     779 */
     780void org_virtualbox_SupDrvClient::stop(IOService *pProvider)
     781{
     782    dprintf(("org_virtualbox_SupDrvClient::stop([%p])\n", this));
     783    IOUserClient::stop(pProvider);
     784}
     785
     786
     787/**
     788 * Terminate the service (initiate the destruction).
     789 */
     790bool org_virtualbox_SupDrvClient::terminate(IOOptionBits fOptions)
     791{
     792    dprintf(("org_virtualbox_SupDrvClient::terminate([%p], %#x)\n", this, fOptions));
     793    return IOUserClient::terminate(fOptions);
     794}
     795
     796
     797/**
     798 * The final stage of the client service destruction.
     799 */
     800bool org_virtualbox_SupDrvClient::finalize(IOOptionBits fOptions)
     801{
     802    dprintf(("org_virtualbox_SupDrvClient::finalize([%p], %#x)\n", this, fOptions));
     803    return IOUserClient::finalize(fOptions);
     804}
     805
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