From patchwork Tue Apr 13 15:03:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 12200781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2850DC433ED for ; Tue, 13 Apr 2021 15:03:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB3E6613B8 for ; Tue, 13 Apr 2021 15:03:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345601AbhDMPDz (ORCPT ); Tue, 13 Apr 2021 11:03:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54846 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345591AbhDMPDv (ORCPT ); Tue, 13 Apr 2021 11:03:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618326211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Bt8EIkbFjk1rFc17+/fNBv57ahjZWmhXLRdzCsXZB1c=; b=cmGYTRRUbkxd/NgZNksM3Y/9iwbKGe8WQX/oTdkpukvAVYTvlCqBQ+TfwoTQZMe6OYQg7x DPd6UVHthvZGz/Hgs2oCU6Ho2mOQC6u+pm19NiRTYXE8+t2a/D94N1dzgI0UkAN4Gv1yrB WHzjrfSyREouN7/UYThaeTsgpVSymGY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-385-9p7Ue2JWNDe_RjaGIagM_w-1; Tue, 13 Apr 2021 11:03:28 -0400 X-MC-Unique: 9p7Ue2JWNDe_RjaGIagM_w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9E5D41B2C984; Tue, 13 Apr 2021 15:03:27 +0000 (UTC) Received: from localhost (ovpn-115-75.ams2.redhat.com [10.36.115.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id E02335D9DE; Tue, 13 Apr 2021 15:03:20 +0000 (UTC) From: Stefan Hajnoczi To: linux-block@vger.kernel.org Cc: libc-alpha@sourceware.org, Jens Axboe , Stefan Hajnoczi , "H . J . Lu" Subject: [PATCH liburing] examples/ucontext-cp.c: cope with variable SIGSTKSZ Date: Tue, 13 Apr 2021 16:03:19 +0100 Message-Id: <20210413150319.764600-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org 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 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 Signed-off-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella --- 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);