From: Stefan Hajnoczi <stefanha@redhat.com>
To: linux-block@vger.kernel.org
Cc: libc-alpha@sourceware.org, Jens Axboe <axboe@kernel.dk>,
Stefan Hajnoczi <stefanha@redhat.com>,
"H . J . Lu" <hjl.tools@gmail.com>
Subject: [PATCH liburing] examples/ucontext-cp.c: cope with variable SIGSTKSZ
Date: Tue, 13 Apr 2021 16:03:19 +0100 [thread overview]
Message-ID: <20210413150319.764600-1-stefanha@redhat.com> (raw)
The size of C arrays at file scope must be constant. The following
compiler error occurs with recent upstream glibc (2.33.9000):
CC ucontext-cp
ucontext-cp.c:31:23: error: variably modified ‘stack_buf’ at file scope
31 | unsigned char stack_buf[SIGSTKSZ];
| ^~~~~~~~~
make[1]: *** [Makefile:26: ucontext-cp] Error 1
The following glibc commit changed SIGSTKSZ from a constant value to a
variable:
commit 6c57d320484988e87e446e2e60ce42816bf51d53
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Mon Feb 1 11:00:38 2021 -0800
sysconf: Add _SC_MINSIGSTKSZ/_SC_SIGSTKSZ [BZ #20305]
...
+# define SIGSTKSZ sysconf (_SC_SIGSTKSZ)
Allocate the stack buffer explicitly to avoid declaring an array at file
scope.
Cc: H.J. Lu <hjl.tools@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
Perhaps the glibc change needs to be revised before releasing glibc 2.34
since it might break applications. That's up to the glibc folks. It
doesn't hurt for liburing to take a safer approach that copes with the
SIGSTKSZ change in any case.
---
examples/ucontext-cp.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/examples/ucontext-cp.c b/examples/ucontext-cp.c
index 0b2a6b5..ea0c934 100644
--- a/examples/ucontext-cp.c
+++ b/examples/ucontext-cp.c
@@ -28,7 +28,7 @@
typedef struct {
struct io_uring *ring;
- unsigned char stack_buf[SIGSTKSZ];
+ unsigned char *stack_buf;
ucontext_t ctx_main, ctx_fnew;
} async_context;
@@ -115,8 +115,13 @@ static int setup_context(async_context *pctx, struct io_uring *ring)
perror("getcontext");
return -1;
}
- pctx->ctx_fnew.uc_stack.ss_sp = &pctx->stack_buf;
- pctx->ctx_fnew.uc_stack.ss_size = sizeof(pctx->stack_buf);
+ pctx->stack_buf = malloc(SIGSTKSZ);
+ if (!pctx->stack_buf) {
+ perror("malloc");
+ return -1;
+ }
+ pctx->ctx_fnew.uc_stack.ss_sp = pctx->stack_buf;
+ pctx->ctx_fnew.uc_stack.ss_size = SIGSTKSZ;
pctx->ctx_fnew.uc_link = &pctx->ctx_main;
return 0;
@@ -174,6 +179,7 @@ static void copy_file_wrapper(arguments_bundle *pbundle)
free(iov.iov_base);
close(pbundle->infd);
close(pbundle->outfd);
+ free(pbundle->pctx->stack_buf);
free(pbundle->pctx);
free(pbundle);
--
2.30.2
next reply other threads:[~2021-04-13 15:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-13 15:03 Stefan Hajnoczi [this message]
2021-04-19 14:34 ` [PATCH liburing] examples/ucontext-cp.c: cope with variable SIGSTKSZ Stefan Hajnoczi
2021-04-19 18:38 ` H.J. Lu
2021-04-22 9:59 ` Stefan Hajnoczi
2021-04-22 14:22 ` Stefano Garzarella
2021-04-23 14:13 ` Pavel Begunkov
2021-04-20 0:05 ` Paul Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210413150319.764600-1-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=axboe@kernel.dk \
--cc=hjl.tools@gmail.com \
--cc=libc-alpha@sourceware.org \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).