summaryrefslogtreecommitdiff
path: root/sys/kern/sys_pipe.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/kern/sys_pipe.c')
-rw-r--r--sys/kern/sys_pipe.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index 2d2c2210e5e..9d337f0622a 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_pipe.c,v 1.88 2019/06/22 06:48:25 semarie Exp $ */
+/* $OpenBSD: sys_pipe.c,v 1.89 2019/07/09 11:35:06 semarie Exp $ */
/*
* Copyright (c) 1996 John S. Dyson
@@ -198,6 +198,7 @@ free3:
free2:
fdpunlock(fdp);
free1:
+ /* fine without KERNEL_LOCK because just created */
pipeclose(wpipe);
pipeclose(rpipe);
return (error);
@@ -214,12 +215,18 @@ pipespace(struct pipe *cpipe, u_int size)
{
caddr_t buffer;
+ /* pipe should be uninitialized or locked */
+ KASSERT((cpipe->pipe_buffer.buffer == NULL) ||
+ (cpipe->pipe_state & PIPE_LOCK));
+
+ /* buffer should be empty */
+ KASSERT(cpipe->pipe_buffer.cnt == 0);
+
KERNEL_LOCK();
buffer = km_alloc(size, &kv_any, &kp_pageable, &kd_waitok);
KERNEL_UNLOCK();
- if (buffer == NULL) {
+ if (buffer == NULL)
return (ENOMEM);
- }
/* free old resources if we are resizing */
pipe_free_kmem(cpipe);
@@ -227,7 +234,6 @@ pipespace(struct pipe *cpipe, u_int size)
cpipe->pipe_buffer.size = size;
cpipe->pipe_buffer.in = 0;
cpipe->pipe_buffer.out = 0;
- cpipe->pipe_buffer.cnt = 0;
atomic_add_int(&amountpipekva, cpipe->pipe_buffer.size);
@@ -244,6 +250,8 @@ pipe_create(struct pipe *cpipe)
/* so pipe_free_kmem() doesn't follow junk pointer */
cpipe->pipe_buffer.buffer = NULL;
+ cpipe->pipe_buffer.cnt = 0;
+
/*
* protect so pipeclose() doesn't follow a junk pointer
* if pipespace() fails.
@@ -303,6 +311,7 @@ pipeselwakeup(struct pipe *cpipe)
selwakeup(&cpipe->pipe_sel);
} else
KNOTE(&cpipe->pipe_sel.si_note, 0);
+
if (cpipe->pipe_state & PIPE_ASYNC)
pgsigio(&cpipe->pipe_sigio, SIGIO, 0);
}