From f7237cd69681ed69392d6f7fb7a0f507980b0673 Mon Sep 17 00:00:00 2001 From: wpaul Date: Wed, 4 Aug 2004 18:22:50 +0000 Subject: [PATCH] More minor cleanups and one small bug fix: - In ntoskrnl_var.h, I had defined compat macros for ntoskrnl_acquire_spinlock() and ntoskrnl_release_spinlock() but never used them. This is fortunate since they were stale. Fix them to work properly. (In Windows/x86 KeAcquireSpinLock() is a macro that calls KefAcquireSpinLock(), which lives in HAL.dll. To imitate this, ntoskrnl_acquire_spinlock() is just a macro that calls hal_lock(), which lives in subr_hal.o.) - Add macros for ntoskrnl_raise_irql() and ntoskrnl_lower_irql() that call hal_raise_irql() and hal_lower_irql(). - Use these macros in kern_ndis.c, subr_ndis.c and subr_ntoskrnl.c. - Along the way, I realised subr_ndis.c:ndis_lock() was not calling hal_lock() correctly (it was using the FASTCALL2() wrapper when in reality this routine is FASTCALL1()). Using the ntoskrnl_acquire_spinlock() fixes this. Not sure if this actually caused any bugs since hal_lock() would have just ignored what was in %edx, but it was still bogus. This hides many of the uses of the FASTCALLx() macros which makes the code a little cleaner. Should not have any effect on generated object code, other than the one fix in ndis_lock(). --- sys/compat/ndis/kern_ndis.c | 24 ++++++++++++------------ sys/compat/ndis/ntoskrnl_var.h | 8 ++++---- sys/compat/ndis/subr_ndis.c | 20 ++++++++------------ sys/compat/ndis/subr_ntoskrnl.c | 16 ++++++++-------- 4 files changed, 32 insertions(+), 36 deletions(-) diff --git a/sys/compat/ndis/kern_ndis.c b/sys/compat/ndis/kern_ndis.c index 49b012f2fc83..138f6b965401 100644 --- a/sys/compat/ndis/kern_ndis.c +++ b/sys/compat/ndis/kern_ndis.c @@ -782,9 +782,9 @@ ndis_return(arg) return; returnfunc = sc->ndis_chars.nmc_return_packet_func; - irql = FASTCALL1(hal_raise_irql, DISPATCH_LEVEL); + irql = ntoskrnl_raise_irql(DISPATCH_LEVEL); returnfunc(adapter, p); - FASTCALL1(hal_lower_irql, irql); + ntoskrnl_lower_irql(irql); return; } @@ -1132,10 +1132,10 @@ ndis_set_info(arg, oid, buf, buflen) if (adapter == NULL || setfunc == NULL) return(ENXIO); - irql = FASTCALL1(hal_raise_irql, DISPATCH_LEVEL); + irql = ntoskrnl_raise_irql(DISPATCH_LEVEL); rval = setfunc(adapter, oid, buf, *buflen, &byteswritten, &bytesneeded); - FASTCALL1(hal_lower_irql, irql); + ntoskrnl_lower_irql(irql); if (rval == NDIS_STATUS_PENDING) { PROC_LOCK(curthread->td_proc); @@ -1189,9 +1189,9 @@ ndis_send_packets(arg, packets, cnt) return(ENXIO); sendfunc = sc->ndis_chars.nmc_sendmulti_func; senddonefunc = sc->ndis_block.nmb_senddone_func; - irql = FASTCALL1(hal_raise_irql, DISPATCH_LEVEL); + irql = ntoskrnl_raise_irql(DISPATCH_LEVEL); sendfunc(adapter, packets, cnt); - FASTCALL1(hal_lower_irql, irql); + ntoskrnl_lower_irql(irql); for (i = 0; i < cnt; i++) { p = packets[i]; @@ -1228,9 +1228,9 @@ ndis_send_packet(arg, packet) sendfunc = sc->ndis_chars.nmc_sendsingle_func; senddonefunc = sc->ndis_block.nmb_senddone_func; - irql = FASTCALL1(hal_raise_irql, DISPATCH_LEVEL); + irql = ntoskrnl_raise_irql(DISPATCH_LEVEL); status = sendfunc(adapter, packet, packet->np_private.npp_flags); - FASTCALL1(hal_lower_irql, irql); + ntoskrnl_lower_irql(irql); if (status == NDIS_STATUS_PENDING) return(0); @@ -1317,9 +1317,9 @@ ndis_reset_nic(arg) if (adapter == NULL || resetfunc == NULL) return(EIO); - irql = FASTCALL1(hal_raise_irql, DISPATCH_LEVEL); + irql = ntoskrnl_raise_irql(DISPATCH_LEVEL); rval = resetfunc(&addressing_reset, adapter); - FASTCALL1(hal_lower_irql, irql); + ntoskrnl_lower_irql(irql); if (rval == NDIS_STATUS_PENDING) { PROC_LOCK(curthread->td_proc); @@ -1550,10 +1550,10 @@ ndis_get_info(arg, oid, buf, buflen) if (adapter == NULL || queryfunc == NULL) return(ENXIO); - irql = FASTCALL1(hal_raise_irql, DISPATCH_LEVEL); + irql = ntoskrnl_raise_irql(DISPATCH_LEVEL); rval = queryfunc(adapter, oid, buf, *buflen, &byteswritten, &bytesneeded); - FASTCALL1(hal_lower_irql, irql); + ntoskrnl_lower_irql(irql); /* Wait for requests that block. */ diff --git a/sys/compat/ndis/ntoskrnl_var.h b/sys/compat/ndis/ntoskrnl_var.h index 891fef84be93..117a177633b8 100644 --- a/sys/compat/ndis/ntoskrnl_var.h +++ b/sys/compat/ndis/ntoskrnl_var.h @@ -516,10 +516,10 @@ __fastcall extern void ntoskrnl_unlock_dpc(REGARGS1(kspin_lock *)); * routines live in the HAL. We try to imitate this behavior. */ #ifdef __i386__ -#define ntoskrnl_acquire_spinlock(a, b) \ - *(b) = FASTCALL(hal_lock, a, 0) -#define ntoskrnl_release_spinlock(a, b) \ - FASTCALL(hal_unlock, a, b) +#define ntoskrnl_acquire_spinlock(a, b) *(b) = FASTCALL1(hal_lock, a) +#define ntoskrnl_release_spinlock(a, b) FASTCALL2(hal_unlock, a, b) +#define ntoskrnl_raise_irql(a) FASTCALL1(hal_raise_irql, a) +#define ntoskrnl_lower_irql(a) FASTCALL1(hal_lower_irql, a) #endif /* __i386__ */ __END_DECLS diff --git a/sys/compat/ndis/subr_ndis.c b/sys/compat/ndis/subr_ndis.c index 8f271ce4a258..00ac9481dadc 100644 --- a/sys/compat/ndis/subr_ndis.c +++ b/sys/compat/ndis/subr_ndis.c @@ -809,8 +809,7 @@ __stdcall static void ndis_lock(lock) ndis_spin_lock *lock; { - lock->nsl_kirql = FASTCALL2(hal_lock, - &lock->nsl_spinlock, DISPATCH_LEVEL); + ntoskrnl_acquire_spinlock(&lock->nsl_spinlock, &lock->nsl_kirql); return; } @@ -822,7 +821,7 @@ __stdcall static void ndis_unlock(lock) ndis_spin_lock *lock; { - FASTCALL2(hal_unlock, &lock->nsl_spinlock, lock->nsl_kirql); + ntoskrnl_release_spinlock(&lock->nsl_spinlock, lock->nsl_kirql); return; } @@ -2317,14 +2316,13 @@ ndis_insert_head(head, entry, lock) { list_entry *flink; - lock->nsl_kirql = FASTCALL2(hal_lock, - &lock->nsl_spinlock, DISPATCH_LEVEL); + ntoskrnl_acquire_spinlock(&lock->nsl_spinlock, &lock->nsl_kirql); flink = head->nle_flink; entry->nle_flink = flink; entry->nle_blink = head; flink->nle_blink = entry; head->nle_flink = entry; - FASTCALL2(hal_unlock, &lock->nsl_spinlock, lock->nsl_kirql); + ntoskrnl_release_spinlock(&lock->nsl_spinlock, lock->nsl_kirql); return(flink); } @@ -2337,13 +2335,12 @@ ndis_remove_head(head, lock) list_entry *flink; list_entry *entry; - lock->nsl_kirql = FASTCALL2(hal_lock, - &lock->nsl_spinlock, DISPATCH_LEVEL); + ntoskrnl_acquire_spinlock(&lock->nsl_spinlock, &lock->nsl_kirql); entry = head->nle_flink; flink = entry->nle_flink; head->nle_flink = flink; flink->nle_blink = head; - FASTCALL2(hal_unlock, &lock->nsl_spinlock, lock->nsl_kirql); + ntoskrnl_release_spinlock(&lock->nsl_spinlock, lock->nsl_kirql); return(entry); } @@ -2356,14 +2353,13 @@ ndis_insert_tail(head, entry, lock) { list_entry *blink; - lock->nsl_kirql = FASTCALL2(hal_lock, - &lock->nsl_spinlock, DISPATCH_LEVEL); + ntoskrnl_acquire_spinlock(&lock->nsl_spinlock, &lock->nsl_kirql); blink = head->nle_blink; entry->nle_flink = head; entry->nle_blink = blink; blink->nle_flink = entry; head->nle_blink = entry; - FASTCALL2(hal_unlock, &lock->nsl_spinlock, lock->nsl_kirql); + ntoskrnl_release_spinlock(&lock->nsl_spinlock, lock->nsl_kirql); return(blink); } diff --git a/sys/compat/ndis/subr_ntoskrnl.c b/sys/compat/ndis/subr_ntoskrnl.c index 2a3937470a39..73c0d7fbd2d4 100644 --- a/sys/compat/ndis/subr_ntoskrnl.c +++ b/sys/compat/ndis/subr_ntoskrnl.c @@ -984,9 +984,9 @@ ntoskrnl_push_slist_ex(REGARGS2(slist_header *head, slist_entry *oldhead; uint8_t irql; - irql = FASTCALL2(hal_lock, lock, DISPATCH_LEVEL); + ntoskrnl_acquire_spinlock(lock, &irql); oldhead = ntoskrnl_pushsl(head, entry); - FASTCALL2(hal_unlock, lock, irql); + ntoskrnl_release_spinlock(lock, irql); return(oldhead); } @@ -997,9 +997,9 @@ ntoskrnl_pop_slist_ex(REGARGS2(slist_header *head, kspin_lock *lock)) slist_entry *first; uint8_t irql; - irql = FASTCALL2(hal_lock, lock, DISPATCH_LEVEL); + ntoskrnl_acquire_spinlock(lock, &irql); first = ntoskrnl_popsl(head); - FASTCALL2(hal_unlock, lock, irql); + ntoskrnl_release_spinlock(lock, irql); return(first); } @@ -1040,9 +1040,9 @@ ntoskrnl_interlock_addstat(REGARGS2(uint64_t *addend, uint32_t inc)) { uint8_t irql; - irql = FASTCALL2(hal_lock, &ntoskrnl_global, DISPATCH_LEVEL); + ntoskrnl_acquire_spinlock(&ntoskrnl_global, &irql); *addend += inc; - FASTCALL2(hal_unlock, &ntoskrnl_global, irql); + ntoskrnl_release_spinlock(&ntoskrnl_global, irql); return; }; @@ -1686,9 +1686,9 @@ ntoskrnl_run_dpc(arg) dpc = arg; dpcfunc = (kdpc_func)dpc->k_deferedfunc; - irql = FASTCALL1(hal_raise_irql, DISPATCH_LEVEL); + irql = ntoskrnl_raise_irql(DISPATCH_LEVEL); dpcfunc(dpc, dpc->k_deferredctx, dpc->k_sysarg1, dpc->k_sysarg2); - FASTCALL1(hal_lower_irql, irql); + ntoskrnl_lower_irql(irql); return; }