Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Oct 2005 22:10:45 +0000 (GMT)
From:      wpaul@FreeBSD.ORG (Bill Paul)
To:        maksim.yevmenkin@savvis.net (Maksim Yevmenkin)
Cc:        current@freebsd.org
Subject:   Re: buildkernel is broken in if_ndis
Message-ID:  <20051011221045.5875516A424@hub.freebsd.org>
In-Reply-To: <434C01D2.4040003@savvis.net> from Maksim Yevmenkin at "Oct 11, 2005 11:17:54 am"

next in thread | previous in thread | raw e-mail | index | archive | help
[Charset ISO-8859-1 unsupported, filtering to ASCII...]
> dear hackers,
> 
> make buildworld is broken for me. since NDIS_LOCK(sc) does not uses 
> sc->ndis_mtx anymore, shouldn't the following patch be put in place?
> 
> max
> 
> p.s. i could not find KeIsInitializedSpinLock function in subr_ndis.c. 
> quick look at msdn did not reveal it either
> 
> 
> --- if_ndis.c.orig      Tue Oct 11 11:11:52 2005
> +++ if_ndis.c   Tue Oct 11 11:11:31 2005
> @@ -917,8 +917,6 @@
>          driver_object           *drv;
> 
>          sc = device_get_softc(dev);
> -       KASSERT(mtx_initialized(&sc->ndis_mtx),
> -           ("ndis mutex not initialized"));
>          NDIS_LOCK(sc);
>          ifp = sc->ifp;
>          ifp->if_flags &= ~IFF_UP;
> 

Fixed. The KASSERT just doesn't need to be there anymore. In Windows,
a spinlock is just a 32-bit long, and the only thing
KeInitializeSpinLock() does is set spinlock = 0. There is no
KeDestroySpinLock(): when you're done with the spinlock, you just
free the storage in which it resides (after unlocking it for the
last time, of course).

Now, the NDIS API has NdisAllocateSpinLock() and NdisFreeSpinLock(),
however I think Microsoft put them there based on the assumption that
someone might want to implement the NDIS API on another OS where
you really do have to allocate and free resources for spinlocks.
However, NdisAllocateSpinLock() doesn't really allocate anything:
it just calls KeInitializeSpinLock(), and NdisFreeSpinLock() does
nothing.

(Note also there's at least one driver out there which calls
NdisFreeSpinLock() _AFTER_ releasing the storage in which the spinlock
resides. But since NdisFreeSpinLock() is a no-op in Windows, the
Microsoft driver verified never flags the error.)

-Bill

--
=============================================================================
-Bill Paul            (510) 749-2329 | Senior Engineer, Master of Unix-Fu
                 wpaul@windriver.com | Wind River Systems
=============================================================================
              <adamw> you're just BEGGING to face the moose
=============================================================================



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051011221045.5875516A424>