From 749ae65481ebc70f310fdd79d2cb0139a636f27e Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Thu, 29 May 2008 14:31:41 +0000 Subject: [PATCH] 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. --- 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 aa1524a17..dc3817fb1 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 133283681..8c3568b5a 100644 --- a/src/rx/rx_user.c +++ b/src/rx/rx_user.c @@ -323,15 +323,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; @@ -353,12 +374,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