Re: [PATCH liburing] examples/ucontext-cp.c: cope with variable SIGSTKSZ

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

 



On Tue, Apr 13, 2021 at 04:03:19PM +0100, Stefan Hajnoczi wrote:
> 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@xxxxxxxxx>
>   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@xxxxxxxxx>
> Signed-off-by: Stefan Hajnoczi <stefanha@xxxxxxxxxx>
> ---
> 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.

glibc folks, please take a look. The commit referenced above broke
compilation of liburing's tests. It's possible that applications will
hit similar issues. Can you check whether the SIGSTKSZ change needs to
be reverted/fixed before releasing glibc 2.34?

Thanks,
Stefan

> ---
>  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
> 

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux