summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_ktrace.c
diff options
context:
space:
mode:
authorjkoshy <jkoshy@FreeBSD.org>2003-11-11 09:09:26 +0000
committerjkoshy <jkoshy@FreeBSD.org>2003-11-11 09:09:26 +0000
commitac83b0ec2b2285a6a30ba8875aafe4ed4d5fd352 (patch)
tree52b7a53677c3a899636d9bfd5b624d537168d34a /sys/kern/kern_ktrace.c
parentbf26c6db3dff0843a0a13469213db1071081eacb (diff)
downloadFreeBSD-src-ac83b0ec2b2285a6a30ba8875aafe4ed4d5fd352.zip
FreeBSD-src-ac83b0ec2b2285a6a30ba8875aafe4ed4d5fd352.tar.gz
Bound the number of iterations a thread can perform inside
ktr_resize_pool(); this eliminates a potential livelock. Return ENOSPC only if we encountered an out-of-memory condition when trying to increase the pool size. Reviewed by: jhb, bde (style)
Diffstat (limited to 'sys/kern/kern_ktrace.c')
-rw-r--r--sys/kern/kern_ktrace.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c
index 03e08b1..2ee758f 100644
--- a/sys/kern/kern_ktrace.c
+++ b/sys/kern/kern_ktrace.c
@@ -168,7 +168,7 @@ sysctl_kern_ktrace_request_pool(SYSCTL_HANDLER_ARGS)
error = SYSCTL_OUT(req, &oldsize, sizeof(u_int));
if (error)
return (error);
- if (newsize != wantsize)
+ if (wantsize > oldsize && newsize < wantsize)
return (ENOSPC);
return (0);
}
@@ -179,14 +179,16 @@ static u_int
ktrace_resize_pool(u_int newsize)
{
struct ktr_request *req;
+ int bound;
mtx_assert(&ktrace_mtx, MA_OWNED);
print_message = 1;
- if (newsize == ktr_requestpool)
- return (newsize);
- if (newsize < ktr_requestpool)
+ bound = newsize - ktr_requestpool;
+ if (bound == 0)
+ return (ktr_requestpool);
+ if (bound < 0)
/* Shrink pool down to newsize if possible. */
- while (ktr_requestpool > newsize) {
+ while (bound++ < 0) {
req = STAILQ_FIRST(&ktr_free);
if (req == NULL)
return (ktr_requestpool);
@@ -198,7 +200,7 @@ ktrace_resize_pool(u_int newsize)
}
else
/* Grow pool up to newsize. */
- while (ktr_requestpool < newsize) {
+ while (bound-- > 0) {
mtx_unlock(&ktrace_mtx);
req = malloc(sizeof(struct ktr_request), M_KTRACE,
M_WAITOK);
OpenPOWER on IntegriCloud