From f38c0c46c5e7e71f7e449de7c98ccd52afad3135 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Fri, 6 Oct 2017 21:52:28 +0000 Subject: [PATCH] Let stack_create(9) take a malloc flags argument. Reviewed by: cem Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D12614 --- share/man/man9/stack.9 | 11 +++++++---- sys/kern/kern_proc.c | 2 +- sys/kern/subr_sleepqueue.c | 2 +- sys/kern/subr_stack.c | 4 ++-- sys/sys/stack.h | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/share/man/man9/stack.9 b/share/man/man9/stack.9 index 06065bde31ae..6da1d0408704 100644 --- a/share/man/man9/stack.9 +++ b/share/man/man9/stack.9 @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 10, 2015 +.Dd October 6, 2017 .Dt STACK 9 .Os .Sh NAME @@ -42,7 +42,7 @@ In the kernel configuration file: .Cd "options STACK" .Pp .Ft struct stack * -.Fn stack_create "void" +.Fn stack_create "int flags" .Ft void .Fn stack_destroy "struct stack *st" .Ft int @@ -85,8 +85,11 @@ Each stack trace is described by a .Vt "struct stack" . Before a trace may be created or otherwise manipulated, storage for the trace must be allocated with -.Fn stack_create , -which may sleep. +.Fn stack_create . +The +.Ar flags +argument is passed to +.Xr malloc 9 . Memory associated with a trace is freed by calling .Fn stack_destroy . .Pp diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 72eb06013fe7..de829228b1d4 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -2547,7 +2547,7 @@ sysctl_kern_proc_kstack(SYSCTL_HANDLER_ARGS) return (error); kkstp = malloc(sizeof(*kkstp), M_TEMP, M_WAITOK); - st = stack_create(); + st = stack_create(M_WAITOK); lwpidarray = NULL; PROC_LOCK(p); diff --git a/sys/kern/subr_sleepqueue.c b/sys/kern/subr_sleepqueue.c index 7edc605d96a1..5d8fdda8db56 100644 --- a/sys/kern/subr_sleepqueue.c +++ b/sys/kern/subr_sleepqueue.c @@ -1163,7 +1163,7 @@ sleepq_sbuf_print_stacks(struct sbuf *sb, void *wchan, int queue, M_TEMP, M_WAITOK); for (stack_idx = 0; stack_idx < stacks_to_allocate; stack_idx++) - st[stack_idx] = stack_create(); + st[stack_idx] = stack_create(M_WAITOK); /* Where we will store the td name, tid, etc. */ td_infos = malloc(sizeof(struct sbuf *) * stacks_to_allocate, diff --git a/sys/kern/subr_stack.c b/sys/kern/subr_stack.c index 85102c04f03d..eb155726f00c 100644 --- a/sys/kern/subr_stack.c +++ b/sys/kern/subr_stack.c @@ -50,11 +50,11 @@ static int stack_symbol(vm_offset_t pc, char *namebuf, u_int buflen, static int stack_symbol_ddb(vm_offset_t pc, const char **name, long *offset); struct stack * -stack_create(void) +stack_create(int flags) { struct stack *st; - st = malloc(sizeof *st, M_STACK, M_WAITOK | M_ZERO); + st = malloc(sizeof(*st), M_STACK, flags | M_ZERO); return (st); } diff --git a/sys/sys/stack.h b/sys/sys/stack.h index e26b535e12ab..113269b1a966 100644 --- a/sys/sys/stack.h +++ b/sys/sys/stack.h @@ -34,7 +34,7 @@ struct sbuf; /* MI Routines. */ -struct stack *stack_create(void); +struct stack *stack_create(int); void stack_destroy(struct stack *); int stack_put(struct stack *, vm_offset_t); void stack_copy(const struct stack *, struct stack *);