VirtualBox

Changeset 63345 in vbox for trunk/src/VBox/Runtime/r0drv


Ignore:
Timestamp:
Aug 11, 2016 6:25:33 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
109979
Message:

r0drv/netbsd: re-import r0drv support for NetBSD on top of svn copy of
FreeBSD sources for cases where the differences are obvious and
minimal.

From Haomai Wang GSoC project with additional changes by Arto Huusko.

Location:
trunk/src/VBox/Runtime/r0drv/netbsd
Files:
11 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/netbsd/assert-r0drv-netbsd.c

    r63342 r63345  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Assertion Workers, Ring-0 Drivers, FreeBSD.
     3 * IPRT - Assertion Workers, Ring-0 Drivers, NetBSD.
    44 */
    55
     
    2929 */
    3030
    31 
    3231/*********************************************************************************************************************************
    3332*   Header Files                                                                                                                 *
    3433*********************************************************************************************************************************/
    35 #include "the-freebsd-kernel.h"
     34#include "the-netbsd-kernel.h"
    3635
    3736#include <iprt/assert.h>
    3837#include <iprt/log.h>
    39 #include <iprt/string.h>
    4038#include <iprt/stdarg.h>
    4139
     
    5452DECLHIDDEN(void) rtR0AssertNativeMsg2V(bool fInitial, const char *pszFormat, va_list va)
    5553{
    56     char szMsg[256];
    57 
    58     RTStrPrintfV(szMsg, sizeof(szMsg) - 1, pszFormat, va);
    59     szMsg[sizeof(szMsg) - 1] = '\0';
    60     printf("%s", szMsg);
    61 
    62     NOREF(fInitial);
     54    /** @todo implement rtR0AssertNativeMsg2V. */
    6355}
    6456
     
    6658RTR0DECL(void) RTR0AssertPanicSystem(void)
    6759{
    68     /** @todo implement RTR0AssertPanicSystem. */
     60    panic("%s%s", g_szRTAssertMsg1, g_szRTAssertMsg2);
     61
    6962}
    70 
  • trunk/src/VBox/Runtime/r0drv/netbsd/initterm-r0drv-netbsd.c

    r63342 r63345  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Initialization & Termination, Ring-0 Driver, FreeBSD.
     3 * IPRT - Initialization & Termination, Ring-0 Driver, NetBSD.
    44 */
    55
     
    2929 */
    3030
    31 
    3231/*********************************************************************************************************************************
    3332*   Header Files                                                                                                                 *
    3433*********************************************************************************************************************************/
    35 #include "the-freebsd-kernel.h"
     34#include "the-netbsd-kernel.h"
    3635
    3736#include <iprt/err.h>
     
    5150    /* nothing to undo */
    5251}
    53 
  • trunk/src/VBox/Runtime/r0drv/netbsd/memuserkernel-r0drv-netbsd.c

    r63342 r63345  
    11/* $Id$ */
    22/** @file
    3  * IPRT - User & Kernel Memory, Ring-0 Driver, FreeBSD.
     3 * IPRT - User & Kernel Memory, Ring-0 Driver, NetBSD.
    44 */
    55
    66/*
    7  * Copyright (C) 2009-2016 Oracle Corporation
     7 * Copyright (C) 2009-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2929*   Header Files                                                                                                                 *
    3030*********************************************************************************************************************************/
    31 #include "the-freebsd-kernel.h"
     31#include "the-netbsd-kernel.h"
    3232
    3333#include <iprt/mem.h>
     
    8181    return VERR_NOT_SUPPORTED;
    8282}
    83 
  • trunk/src/VBox/Runtime/r0drv/netbsd/process-r0drv-netbsd.c

    r63342 r63345  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Process Management, Ring-0 Driver, FreeBSD.
     3 * IPRT - Process Management, Ring-0 Driver, NetBSD.
    44 */
    55
    66/*
    7  * Copyright (c) 2007 knut st. osmundsen <[email protected]>
    8  *
    97 * Permission is hereby granted, free of charge, to any person
    108 * obtaining a copy of this software and associated documentation
     
    2927 */
    3028
    31 
    3229/*********************************************************************************************************************************
    3330*   Header Files                                                                                                                 *
    3431*********************************************************************************************************************************/
    35 #include "the-freebsd-kernel.h"
     32#include "the-netbsd-kernel.h"
    3633
    3734#include <iprt/process.h>
     
    4946    return (RTR0PROCESS)curproc;
    5047}
    51 
  • trunk/src/VBox/Runtime/r0drv/netbsd/semevent-r0drv-netbsd.c

    r63342 r63345  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Single Release Event Semaphores, Ring-0 Driver, FreeBSD.
     3 * IPRT - Single Release Event Semaphores, Ring-0 Driver, NetBSD.
    44 */
    55
     
    2929 */
    3030
    31 
    3231/*********************************************************************************************************************************
    3332*   Header Files                                                                                                                 *
    3433*********************************************************************************************************************************/
    3534#define RTSEMEVENT_WITHOUT_REMAPPING
    36 #include "the-freebsd-kernel.h"
     35#include "the-netbsd-kernel.h"
    3736#include "internal/iprt.h"
    3837#include <iprt/semaphore.h>
     
    4443#include <iprt/mem.h>
    4544
    46 #include "sleepqueue-r0drv-freebsd.h"
     45#include "sleepqueue-r0drv-netbsd.h"
    4746#include "internal/magics.h"
    4847
     
    5251*********************************************************************************************************************************/
    5352/**
    54  * FreeBSD event semaphore.
     53 * NetBSD event semaphore.
    5554 */
    5655typedef struct RTSEMEVENTINTERNAL
     
    254253    return 1000000000 / hz;
    255254}
    256 
  • trunk/src/VBox/Runtime/r0drv/netbsd/semeventmulti-r0drv-netbsd.c

    r63342 r63345  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Multiple Release Event Semaphores, Ring-0 Driver, FreeBSD.
     3 * IPRT - Multiple Release Event Semaphores, Ring-0 Driver, NetBSD.
    44 */
    55
     
    2929 */
    3030
    31 
    3231/*********************************************************************************************************************************
    3332*   Header Files                                                                                                                 *
    3433*********************************************************************************************************************************/
    3534#define RTSEMEVENTMULTI_WITHOUT_REMAPPING
    36 #include "the-freebsd-kernel.h"
     35#include "the-netbsd-kernel.h"
    3736#include "internal/iprt.h"
    3837#include <iprt/semaphore.h>
     
    4443#include <iprt/lockvalidator.h>
    4544
    46 #include "sleepqueue-r0drv-freebsd.h"
     45#include "sleepqueue-r0drv-netbsd.h"
    4746#include "internal/magics.h"
    4847
     
    6564/** @}  */
    6665
    67 
    6866/*********************************************************************************************************************************
    6967*   Structures and Typedefs                                                                                                      *
    7068*********************************************************************************************************************************/
    7169/**
    72  * FreeBSD multiple release event semaphore.
     70 * NetBSD multiple release event semaphore.
    7371 */
    7472typedef struct RTSEMEVENTMULTIINTERNAL
     
    318316}
    319317RT_EXPORT_SYMBOL(RTSemEventMultiGetResolution);
    320 
  • trunk/src/VBox/Runtime/r0drv/netbsd/semfastmutex-r0drv-netbsd.c

    r63342 r63345  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Fast Mutex Semaphores, Ring-0 Driver, FreeBSD.
     3 * IPRT - Fast Mutex Semaphores, Ring-0 Driver, NetBSD.
    44 */
    55
     
    2929 */
    3030
    31 
    3231/*********************************************************************************************************************************
    3332*   Header Files                                                                                                                 *
    3433*********************************************************************************************************************************/
    35 #include "the-freebsd-kernel.h"
     34#include "the-netbsd-kernel.h"
    3635
    3736#include <iprt/semaphore.h>
     
    4847*********************************************************************************************************************************/
    4948/**
    50  * Wrapper for the FreeBSD (sleep) mutex.
     49 * Wrapper for the NetBSD (sleep) mutex.
    5150 */
    5251typedef struct RTSEMFASTMUTEXINTERNAL
     
    5453    /** Magic value (RTSEMFASTMUTEX_MAGIC). */
    5554    uint32_t            u32Magic;
    56     /** The FreeBSD shared/exclusive lock mutex. */
    57     struct sx           SxLock;
     55    /** The NetBSD shared/exclusive lock mutex. */
     56    krwlock_t           Mtx;
    5857} RTSEMFASTMUTEXINTERNAL, *PRTSEMFASTMUTEXINTERNAL;
    5958
     
    6867    {
    6968        pThis->u32Magic = RTSEMFASTMUTEX_MAGIC;
    70         sx_init_flags(&pThis->SxLock, "IPRT Fast Mutex Semaphore", SX_DUPOK);
     69        rw_init(&pThis->Mtx);
    7170
    7271        *phFastMtx = pThis;
     
    8685
    8786    ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
    88     sx_destroy(&pThis->SxLock);
     87    rw_destroy(&pThis->Mtx);
    8988    RTMemFree(pThis);
    9089
     
    9998    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    10099
    101     sx_xlock(&pThis->SxLock);
     100    rw_enter(&pThis->Mtx, RW_WRITER);
    102101    return VINF_SUCCESS;
    103102}
     
    110109    AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
    111110
    112     sx_xunlock(&pThis->SxLock);
     111    rw_exit(&pThis->Mtx);
    113112    return VINF_SUCCESS;
    114113}
    115 
  • trunk/src/VBox/Runtime/r0drv/netbsd/semmutex-r0drv-netbsd.c

    r63342 r63345  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Mutex Semaphores, Ring-0 Driver, FreeBSD.
     3 * IPRT - Mutex Semaphores, Ring-0 Driver, NetBSD.
    44 */
    55
    66/*
    7  * Copyright (C) 2010-2016 Oracle Corporation
     7 * Copyright (C) 2010-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3030*********************************************************************************************************************************/
    3131#define RTSEMMUTEX_WITHOUT_REMAPPING
    32 #include "the-freebsd-kernel.h"
     32#include "the-netbsd-kernel.h"
    3333#include "internal/iprt.h"
    3434#include <iprt/semaphore.h>
     
    4848*********************************************************************************************************************************/
    4949/**
    50  * Wrapper for the FreeBSD (sleep) mutex.
     50 * Wrapper for the NetBSD (sleep) mutex.
    5151 */
    5252typedef struct RTSEMMUTEXINTERNAL
     
    5454    /** Magic value (RTSEMMUTEX_MAGIC). */
    5555    uint32_t            u32Magic;
    56     /** The FreeBSD shared/exclusive lock mutex. */
     56    /** The NetBSD shared/exclusive lock mutex. */
    5757    struct sx           SxLock;
    5858} RTSEMMUTEXINTERNAL, *PRTSEMMUTEXINTERNAL;
     
    134134    }
    135135
    136     return VINF_SUCCESS;
     136    return rc;
    137137}
    138138
     
    187187    }
    188188
    189     return VINF_SUCCESS;
     189    return rc;
    190190}
    191191
     
    217217    return sx_xlocked(&pThis->SxLock);
    218218}
    219 
  • trunk/src/VBox/Runtime/r0drv/netbsd/thread-r0drv-netbsd.c

    r63342 r63345  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Threads (Part 1), Ring-0 Driver, FreeBSD.
     3 * IPRT - Threads (Part 1), Ring-0 Driver, NetBSD.
    44 */
    55
    66/*
    7  * Copyright (C) 2007-2016 Oracle Corporation
     7 * Copyright (C) 2007-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2525 */
    2626
    27 
    2827/*********************************************************************************************************************************
    2928*   Header Files                                                                                                                 *
    3029*********************************************************************************************************************************/
    31 #include "the-freebsd-kernel.h"
     30#include "the-netbsd-kernel.h"
    3231#include "internal/iprt.h"
    3332#include <iprt/thread.h>
     
    4342RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
    4443{
    45     return (RTNATIVETHREAD)curthread;
     44    return (RTNATIVETHREAD)curlwp;
    4645}
    4746
    4847
    49 static int rtR0ThreadFbsdSleepCommon(RTMSINTERVAL cMillies)
     48static int rtR0ThreadNbsdSleepCommon(RTMSINTERVAL cMillies)
    5049{
    5150    int rc;
     
    103102RTDECL(int) RTThreadSleep(RTMSINTERVAL cMillies)
    104103{
    105     return rtR0ThreadFbsdSleepCommon(cMillies);
     104    return rtR0ThreadNbsdSleepCommon(cMillies);
    106105}
    107106
     
    109108RTDECL(int) RTThreadSleepNoLog(RTMSINTERVAL cMillies)
    110109{
    111     return rtR0ThreadFbsdSleepCommon(cMillies);
     110    return rtR0ThreadNbsdSleepCommon(cMillies);
    112111}
    113112
     
    115114RTDECL(bool) RTThreadYield(void)
    116115{
    117 #if __FreeBSD_version >= 900032
    118     kern_yield(curthread->td_user_pri);
    119 #else
    120     uio_yield();
    121 #endif
    122     return false; /** @todo figure this one ... */
     116    yield();
     117    return true;
    123118}
    124119
     
    128123    Assert(hThread == NIL_RTTHREAD);
    129124
    130     return curthread->td_critnest == 0
    131         && ASMIntAreEnabled(); /** @todo is there a native freebsd function/macro for this? */
     125    return curlwp->l_dopreempt == 0
     126        && ASMIntAreEnabled(); /** @todo is there a native netbsd function/macro for this? */
    132127}
    133128
     
    137132    Assert(hThread == NIL_RTTHREAD);
    138133
    139     return curthread->td_owepreempt == 1;
     134    return curlwp->l_dopreempt;
    140135}
    141136
     
    154149}
    155150
    156 
    157151RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
    158152{
    159153    AssertPtr(pState);
    160     Assert(pState->u32Reserved == 0);
    161     pState->u32Reserved = 42;
    162154
    163     critical_enter();
    164     RT_ASSERT_PREEMPT_CPUID_DISABLE(pState);
     155    curlwp->l_nopreempt++;
     156    __insn_barrier();
    165157}
    166158
     
    168160RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
    169161{
     162
    170163    AssertPtr(pState);
    171     Assert(pState->u32Reserved == 42);
    172     pState->u32Reserved = 0;
    173 
    174     RT_ASSERT_PREEMPT_CPUID_RESTORE(pState);
    175     critical_exit();
     164    __insn_barrier();
     165    if (--curlwp->l_nopreempt != 0)
     166        return;
     167    __insn_barrier();
     168    if (__predict_false(curlwp->l_dopreempt))
     169        kpreempt(0);
     170    __insn_barrier();
    176171}
    177 
    178172
    179173RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
    180174{
    181175    Assert(hThread == NIL_RTTHREAD); NOREF(hThread);
    182     /** @todo FreeBSD: Implement RTThreadIsInInterrupt. Required for guest
     176    /** @todo NetBSD: Implement RTThreadIsInInterrupt. Required for guest
    183177     *        additions! */
    184178    return !ASMIntAreEnabled();
    185179}
    186 
  • trunk/src/VBox/Runtime/r0drv/netbsd/thread2-r0drv-netbsd.c

    r63342 r63345  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Threads (Part 2), Ring-0 Driver, FreeBSD.
     3 * IPRT - Threads (Part 2), Ring-0 Driver, NetBSD.
    44 */
    55
     
    2929 */
    3030
    31 
    3231/*********************************************************************************************************************************
    3332*   Header Files                                                                                                                 *
    3433*********************************************************************************************************************************/
    35 #include "the-freebsd-kernel.h"
     34#include "the-netbsd-kernel.h"
    3635
    3736#include <iprt/thread.h>
     
    6564        case RTTHREADTYPE_MSG_PUMP:             iPriority = PZERO - 4;      break;
    6665        case RTTHREADTYPE_IO:                   iPriority = PRIBIO;         break;
    67         case RTTHREADTYPE_TIMER:                iPriority = PRI_MIN_KERN;   break;
     66        case RTTHREADTYPE_TIMER:                iPriority = PSWP;           break;
    6867        default:
    6968            AssertMsgFailed(("enmType=%d\n", enmType));
     
    7170    }
    7271
    73 #if __FreeBSD_version < 700000
    74     /* Do like they're doing in subr_ntoskrnl.c... */
    75     mtx_lock_spin(&sched_lock);
    76 #else
    77     thread_lock(curthread);
    78 #endif
    79     sched_prio(curthread, iPriority);
    80 #if __FreeBSD_version < 600000
    81     curthread->td_base_pri = iPriority;
    82 #endif
    83 #if __FreeBSD_version < 700000
    84     mtx_unlock_spin(&sched_lock);
    85 #else
    86     thread_unlock(curthread);
    87 #endif
     72    lwp_lock(curlwp);
     73    sched_nice(curproc, iPriority);
     74    curlwp->l_priority = iPriority;
     75    lwp_unlock(curlwp);
    8876
    8977    return VINF_SUCCESS;
     
    9785       user really better know what he's cooking. */
    9886    return VINF_SUCCESS;
    99 }
    100 
    101 
    102 DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
    103 {
    104     /** @todo fix RTThreadWait/RTR0Term race on freebsd. */
    105     RTThreadSleep(1);
    10687}
    10788
     
    120101static void rtThreadNativeMain(void *pvThreadInt)
    121102{
    122     const struct thread *Self = curthread;
     103    const struct lwp *Self = curlwp;
    123104    PRTTHREADINT pThreadInt = (PRTTHREADINT)pvThreadInt;
    124105    int rc;
     
    126107    rc = rtThreadMain(pThreadInt, (RTNATIVETHREAD)Self, &pThreadInt->szName[0]);
    127108
    128 #if __FreeBSD_version >= 800002
    129     kproc_exit(rc);
    130 #else
    131109    kthread_exit(rc);
    132 #endif
    133110}
    134111
     
    138115    int rc;
    139116    struct proc *pProc;
     117    struct lwp *l;
    140118
    141 #if __FreeBSD_version >= 800002
    142     rc = kproc_create(rtThreadNativeMain, pThreadInt, &pProc, RFHIGHPID, 0, "%s", pThreadInt->szName);
    143 #else
    144     rc = kthread_create(rtThreadNativeMain, pThreadInt, &pProc, RFHIGHPID, 0, "%s", pThreadInt->szName);
    145 #endif
     119    rc = kthread_create(PRI_NONE, 0, NULL, rtThreadNativeMain, (void *)pThreadInt, &l, "%s", pThreadInt->szName);
     120
    146121    if (!rc)
    147122    {
    148         *pNativeThread = (RTNATIVETHREAD)FIRST_THREAD_IN_PROC(pProc);
     123        *pNativeThread = (RTNATIVETHREAD)l;
    149124        rc = VINF_SUCCESS;
    150125    }
     
    153128    return rc;
    154129}
    155 
  • trunk/src/VBox/Runtime/r0drv/netbsd/time-r0drv-netbsd.c

    r63342 r63345  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Time, Ring-0 Driver, FreeBSD.
     3 * IPRT - Time, Ring-0 Driver, NetBSD.
    44 */
    55
     
    3333*   Header Files                                                                                                                 *
    3434*********************************************************************************************************************************/
    35 #include "the-freebsd-kernel.h"
     35#include "the-netbsd-kernel.h"
    3636#define RTTIME_INCL_TIMESPEC
    3737
     
    4242{
    4343    struct timespec tsp;
    44     nanouptime(&tsp);
    45     return tsp.tv_sec * RT_NS_1SEC_64
     44    nanotime(&tsp);
     45    return tsp.tv_sec * UINT64_C(1000000000)
    4646         + tsp.tv_nsec;
    4747}
     
    5050RTDECL(uint64_t) RTTimeMilliTS(void)
    5151{
    52     return RTTimeNanoTS() / RT_NS_1MS;
     52    return RTTimeNanoTS() / 1000000;
    5353}
    5454
     
    7272    return RTTimeSpecSetTimespec(pTime, &tsp);
    7373}
    74 
Note: See TracChangeset for help on using the changeset viewer.

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