From 775630172b43fa9eafa762ef661e2199a328c75e Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Thu, 29 May 2008 14:33:29 +0000 Subject: [PATCH] DEVEL15-rx-init-more-packets-20080529 LICENSE MIT It is frequently the case that rx_getAllAddr() is called before rx_Init() or rx_InitHost(). rx_getAllAddr() obtains the list of interfaces by using rx_GetIFInfo() which in turn computes and allocates the number of addition rx packets. Unfortunately, rxi_MorePackets() relies on the existence of an initialized mutex and the mutex is not initialized (on Windows) until the rx_InitHost() call. Therefore, we must delay the rxi_MorePackets() call until after rx_InitHost() if rx_getAllAddr() is called previously. Failure to do so results in a panic. (cherry picked from commit 749ae65481ebc70f310fdd79d2cb0139a636f27e) --- src/rx/rx.c | 5 ++++- src/rx/rx_user.c | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/rx/rx.c b/src/rx/rx.c index 8dd3fe090..c4c782372 100644 --- a/src/rx/rx.c +++ b/src/rx/rx.c @@ -358,7 +358,10 @@ rx_SetEpoch(afs_uint32 epoch) * by the kernel. Whether this will ever overlap anything in * /etc/services is anybody's guess... Returns 0 on success, -1 on * error. */ -static int rxinit_status = 1; +#ifndef AFS_NT40_ENV +static +#endif +int rxinit_status = 1; #ifdef AFS_PTHREAD_ENV /* * This mutex protects the following global variables: diff --git a/src/rx/rx_user.c b/src/rx/rx_user.c index a1100aea4..c20c9bfcc 100644 --- a/src/rx/rx_user.c +++ b/src/rx/rx_user.c @@ -325,15 +325,36 @@ rx_getAllAddr(afs_int32 * buffer, int maxSize) #endif #ifdef AFS_NT40_ENV +extern int rxinit_status; +void +rxi_InitMorePackets(void) { + int npackets, ncbufs; + + ncbufs = (rx_maxJumboRecvSize - RX_FIRSTBUFFERSIZE); + if (ncbufs > 0) { + ncbufs = ncbufs / RX_CBUFFERSIZE; + npackets = rx_initSendWindow - 1; + rxi_MorePackets(npackets * (ncbufs + 1)); + } +} void rx_GetIFInfo(void) { u_int maxsize; u_int rxsize; - int npackets, ncbufs; afs_uint32 i; LOCK_IF_INIT; + if (Inited) { + if (Inited < 2 && rxinit_status == 0) { + /* We couldn't initialize more packets earlier. + * Do it now. */ + rxi_InitMorePackets(); + Inited = 2; + } + UNLOCK_IF_INIT; + return; + } Inited = 1; UNLOCK_IF_INIT; @@ -355,12 +376,16 @@ rx_GetIFInfo(void) } UNLOCK_IF; - ncbufs = (rx_maxJumboRecvSize - RX_FIRSTBUFFERSIZE); - if (ncbufs > 0) { - ncbufs = ncbufs / RX_CBUFFERSIZE; - npackets = rx_initSendWindow - 1; - rxi_MorePackets(npackets * (ncbufs + 1)); - } + + /* + * If rxinit_status is still set, rx_InitHost() has yet to be called + * and we therefore do not have any mutex locks initialized. As a + * result we cannot call rxi_MorePackets() without crashing. + */ + if (rxinit_status) + return; + + rxi_InitMorePackets(); } #endif -- 2.39.5