Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/mpl/bind/dist/lib/isc Avoid retiring a thread with ...



details:   https://anonhg.NetBSD.org/src/rev/48306bd856f0
branches:  trunk
changeset: 359905:48306bd856f0
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jan 30 13:11:46 2022 +0000

description:
Avoid retiring a thread with a xtid >= isc__hp_max_threads and crashing.
XXX: need to fix the real bug, but this will do for now.

diffstat:

 external/mpl/bind/dist/lib/isc/hp.c |  37 ++++++++++++++++++++++++++-----------
 1 files changed, 26 insertions(+), 11 deletions(-)

diffs (76 lines):

diff -r 7646ca539fc4 -r 48306bd856f0 external/mpl/bind/dist/lib/isc/hp.c
--- a/external/mpl/bind/dist/lib/isc/hp.c       Sun Jan 30 11:58:29 2022 +0000
+++ b/external/mpl/bind/dist/lib/isc/hp.c       Sun Jan 30 13:11:46 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hp.c,v 1.4 2021/04/29 17:26:12 christos Exp $  */
+/*     $NetBSD: hp.c,v 1.5 2022/01/30 13:11:46 christos Exp $  */
 
 /*
  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
@@ -55,6 +55,9 @@
 #include <isc/thread.h>
 #include <isc/util.h>
 
+#include <syslog.h>
+#include <stdlib.h>
+
 #define HP_MAX_THREADS 128
 static int isc__hp_max_threads = HP_MAX_THREADS;
 #define HP_MAX_HPS     4 /* This is named 'K' in the HP paper */
@@ -84,6 +87,8 @@
 
 void
 isc_hp_init(int max_threads) {
+       syslog(LOG_ERR|LOG_CONS, "setting maxthreads to %d from %d", max_threads,
+           isc__hp_max_threads);
        isc__hp_max_threads = max_threads;
        isc__hp_max_retired = max_threads * HP_MAX_HPS;
 }
@@ -175,15 +180,25 @@
 
 void
 isc_hp_retire(isc_hp_t *hp, uintptr_t ptr) {
-       hp->rl[tid()]->list[hp->rl[tid()]->size++] = ptr;
-       INSIST(hp->rl[tid()]->size < isc__hp_max_retired);
+       int xtid = tid();
+       if (xtid < 0 || xtid >= isc__hp_max_threads) {
+               syslog(LOG_ERR, "bad thread id %d >= %d", xtid,
+                   isc__hp_max_threads);
+               return;
+       }
+       if (hp->rl[xtid] == NULL) {
+               syslog(LOG_ERR, "null rl for thread id %d", xtid);
+               abort();
+       }
+       hp->rl[xtid]->list[hp->rl[xtid]->size++] = ptr;
+       INSIST(hp->rl[xtid]->size < isc__hp_max_retired);
 
-       if (hp->rl[tid()]->size < HP_THRESHOLD_R) {
+       if (hp->rl[xtid]->size < HP_THRESHOLD_R) {
                return;
        }
 
-       for (int iret = 0; iret < hp->rl[tid()]->size; iret++) {
-               uintptr_t obj = hp->rl[tid()]->list[iret];
+       for (int iret = 0; iret < hp->rl[xtid]->size; iret++) {
+               uintptr_t obj = hp->rl[xtid]->list[iret];
                bool can_delete = true;
                for (int itid = 0; itid < isc__hp_max_threads && can_delete;
                     itid++) {
@@ -196,11 +211,11 @@
                }
 
                if (can_delete) {
-                       size_t bytes = (hp->rl[tid()]->size - iret) *
-                                      sizeof(hp->rl[tid()]->list[0]);
-                       memmove(&hp->rl[tid()]->list[iret],
-                               &hp->rl[tid()]->list[iret + 1], bytes);
-                       hp->rl[tid()]->size--;
+                       size_t bytes = (hp->rl[xtid]->size - iret) *
+                                      sizeof(hp->rl[xtid]->list[0]);
+                       memmove(&hp->rl[xtid]->list[iret],
+                               &hp->rl[xtid]->list[iret + 1], bytes);
+                       hp->rl[xtid]->size--;
                        hp->deletefunc((void *)obj);
                }
        }



Home | Main Index | Thread Index | Old Index