From patchwork Fri May 7 14:42:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475551 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VRIbKc9x; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcCsd3g6nz9sXL for ; Sat, 8 May 2021 00:45:09 +1000 (AEST) Received: from localhost ([::1]:34956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1j1-0007Qp-Bo for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:45:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38666) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1hR-0007Ou-T4 for qemu-devel@nongnu.org; Fri, 07 May 2021 10:43:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37524) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1hQ-0000Wn-6X for qemu-devel@nongnu.org; Fri, 07 May 2021 10:43:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398605; 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: in-reply-to:in-reply-to:references:references; bh=TX2Xz11Yxqn3cVVJ/gzPo0vFUN0FblHfQJn4P/Y+Hk0=; b=VRIbKc9xeT5EBBykfg3piVaJ+oJ5DyKaIqsujgchXmbpiDkBeSdW/iBc8b+uFx1sgZbuD8 2x31q6pT3dnlYns6oqWMr/jdVyfZY4QRZ6zofFv+Zl/obaOF2HJJMDVWJlww+l7+TKo2Wx Ia/XmI7fINKbMWld8Up4Df8HOuikmno= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-21-JiIxie_pNkCuK9pKV4qpFQ-1; Fri, 07 May 2021 10:43:24 -0400 X-MC-Unique: JiIxie_pNkCuK9pKV4qpFQ-1 Received: by mail-wr1-f69.google.com with SMTP id x10-20020adfc18a0000b029010d83c83f2aso3695089wre.8 for ; Fri, 07 May 2021 07:43:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TX2Xz11Yxqn3cVVJ/gzPo0vFUN0FblHfQJn4P/Y+Hk0=; b=Sy/lNCOVXLyL5OHzBBxX6F66Opk+wJP8cp3w0m7lwejyK+tSIr782p02atuworolSA 2crEkSxoeH9eWi7sK6ABdYHB2Z1iws668nuuLtBs1hY+KakgxZ0+FLO+t6a997XEOr5w 3OkJWIAODGyW2lR19SFViLT8YjezUqfZAecCzA3ss6+/dx8KWgy6fccDaIlHbLirBPDf 91TK4VLmoO5u0MjEgxdxGvB6386h+/NIUDfmD3IXuUB8m1rJeWxE2v1JOODo2qkyGDmv pBJ9lXWT1LAiH9/n5/d27Os04P0nK4oJbVoS2i054MWRUWmv54OIWhFqD9ScSTeW9VRv 7HvQ== X-Gm-Message-State: AOAM531B+WOY9GUH8yKaO62p0SOOuW1GMeyb/XqP7aj3QnSasv333KK+ HLpfQqqouiTtb2uEb5hsuPYg4EHmxQvrwlbnYa2z0CqITQV6MYG8jkjk1KXFGLzXdGE4TguX4I4 wtnZpuT8jBswaSi9vFbZD4EO/fJETFF9gvqOpEAsqsWa+njR80umOlLtLKTGhgkn+ X-Received: by 2002:a5d:4810:: with SMTP id l16mr12460000wrq.44.1620398602713; Fri, 07 May 2021 07:43:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbBHiRPbLZTqg/6vC8WRerq8TTv4Coun5JgZZb3kUj3oCXgJlkY4EzdyWqLFhr8EGOc5a3pw== X-Received: by 2002:a5d:4810:: with SMTP id l16mr12459975wrq.44.1620398602565; Fri, 07 May 2021 07:43:22 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id i14sm23099111wmq.1.2021.05.07.07.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:43:22 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 01/17] bsd-user/syscall: Replace alloca() by g_try_new() Date: Fri, 7 May 2021 16:42:59 +0200 Message-Id: <20210507144315.1994337-2-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Kyle Evans , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ALLOCA(3) man-page mentions its "use is discouraged". Use autofree heap allocation instead (returning ENOMEM on failure). Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- bsd-user/syscall.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c index 4abff796c76..6db05988f1b 100644 --- a/bsd-user/syscall.c +++ b/bsd-user/syscall.c @@ -355,9 +355,12 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, case TARGET_FREEBSD_NR_writev: { int count = arg3; - struct iovec *vec; + g_autofree struct iovec *vec = g_try_new(struct iovec, count); - vec = alloca(count * sizeof(struct iovec)); + if (!vec) { + ret = -TARGET_ENOMEM; + goto fail; + } if (lock_iovec(VERIFY_READ, vec, arg2, count, 1) < 0) goto efault; ret = get_errno(writev(arg1, vec, count)); From patchwork Fri May 7 14:43:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475554 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZaB6gKev; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcCvH6Fbyz9sXL for ; Sat, 8 May 2021 00:46:35 +1000 (AEST) Received: from localhost ([::1]:36828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1kL-0008P3-9l for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:46:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1hY-0007YA-94 for qemu-devel@nongnu.org; Fri, 07 May 2021 10:43:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54585) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1hU-0000aG-KM for qemu-devel@nongnu.org; Fri, 07 May 2021 10:43:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398611; 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: in-reply-to:in-reply-to:references:references; bh=cWe+dxIQxlwOjXTVq4nmSO21Ag5LIQeGVfXOgPjRmt8=; b=ZaB6gKevzPVzKBe3fJgPItBVYmUHv/bwN0gfdmm0dfg3tRtRd/R1l1o9zO3oT88Uy2AMvE ZwUNW4L9mhpu6QkIWk0o7qcUf63+fo3ZjHtuOGU4r3FFOZKzmjrI9XvOA8iN/fYZToI9EO /Pl48VEDcNb0G5bhepCWg7Scn6UTGBc= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-LfkmTJtnNaWIuXSdolMoCw-1; Fri, 07 May 2021 10:43:29 -0400 X-MC-Unique: LfkmTJtnNaWIuXSdolMoCw-1 Received: by mail-wr1-f70.google.com with SMTP id x10-20020adfc18a0000b029010d83c83f2aso3695189wre.8 for ; Fri, 07 May 2021 07:43:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cWe+dxIQxlwOjXTVq4nmSO21Ag5LIQeGVfXOgPjRmt8=; b=uBMdc1sg+cIIy9gpi6xFReb8tZAZKOXUb1OoFjXpVSPpirYAWSvSh+foSX/N0aUkvh pCpwrNMuDLwSdVC6VDSihFCRRoqnZLZiVPkyEIfdG8SCLODcuGIKtROWJlBMqwD3Aqof Q18xYFvOSt9eexyOG9ly1LuFji3cIK2BLIks+5qmTzRQi2zXVo/zbMGip/BhvHY+tWN9 AlYGZ3xWuM0AeOD48pL+GKqVEa8JYyYVdQ3v1dMOwSfeg/W00TEGcBQ6V2mwkJ4GsbZa yZA8+h1XFAtqJ1b+ELjphtr19QjiuaBrSeArCyVGRUuDWMst+YEsosOe0CmlyVti/QRL XC8g== X-Gm-Message-State: AOAM531s6v5eHWH52zNhHMlLmj45SZs9FFP8rYXc0Xkx2YfpfLTlSmqO NxZccuSc8gQxGAwQCbaHxeQR+zS0k8bzuZAJ0kKaDq/+hJEaMTgak/atiy7S1/xFz09bsNQxbTv t9S+mCHUZ8vpGgWOKEfGzd3i5WFGfaevMLqft/06MjnWEXFl/4Iu0oe5efunjvcK7 X-Received: by 2002:a05:600c:293:: with SMTP id 19mr10481696wmk.144.1620398607383; Fri, 07 May 2021 07:43:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzJXjh5EIUZ5UvBdcTDtVAODkhggy3oiheKgCV4ZKOSMg1GrJfTFeIVPOdUMHt/oXW6+6GrQ== X-Received: by 2002:a05:600c:293:: with SMTP id 19mr10481664wmk.144.1620398607116; Fri, 07 May 2021 07:43:27 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id o15sm8521863wru.42.2021.05.07.07.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:43:26 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 02/17] linux-user/elfload: Replace alloca() by g_try_malloc() Date: Fri, 7 May 2021 16:43:00 +0200 Message-Id: <20210507144315.1994337-3-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ALLOCA(3) man-page mentions its "use is discouraged". Use autofree heap allocation instead (returning ENOMEM on failure). Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- linux-user/elfload.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c6731013fde..dad2dac24a4 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2591,6 +2591,7 @@ static void load_elf_image(const char *image_name, int image_fd, { struct elfhdr *ehdr = (struct elfhdr *)bprm_buf; struct elf_phdr *phdr; + g_autofree void *phdr_alloc = NULL; abi_ulong load_addr, load_bias, loaddr, hiaddr, error; int i, retval, prot_exec; Error *err = NULL; @@ -2610,7 +2611,12 @@ static void load_elf_image(const char *image_name, int image_fd, if (ehdr->e_phoff + i <= BPRM_BUF_SIZE) { phdr = (struct elf_phdr *)(bprm_buf + ehdr->e_phoff); } else { - phdr = (struct elf_phdr *) alloca(i); + phdr_alloc = g_try_malloc(i); + if (!phdr_alloc) { + error_setg(&err, "Not enough memory to load ELF program header"); + goto exit_errmsg; + } + phdr = (struct elf_phdr *) phdr_alloc; retval = pread(image_fd, phdr, i, ehdr->e_phoff); if (retval != i) { goto exit_read; @@ -2979,15 +2985,15 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) { int i, shnum, nsyms, sym_idx = 0, str_idx = 0; uint64_t segsz; - struct elf_shdr *shdr; + g_autofree struct elf_shdr *shdr; char *strings = NULL; struct syminfo *s = NULL; struct elf_sym *new_syms, *syms = NULL; shnum = hdr->e_shnum; i = shnum * sizeof(struct elf_shdr); - shdr = (struct elf_shdr *)alloca(i); - if (pread(fd, shdr, i, hdr->e_shoff) != i) { + shdr = (struct elf_shdr *)g_try_malloc(i); + if (shdr == NULL || pread(fd, shdr, i, hdr->e_shoff) != i) { return; } From patchwork Fri May 7 14:43:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475553 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RqX2sDCf; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcCv94QKjz9sXL for ; Sat, 8 May 2021 00:46:29 +1000 (AEST) Received: from localhost ([::1]:36692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1kJ-0008KT-IO for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:46:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1hb-0007fF-Ft for qemu-devel@nongnu.org; Fri, 07 May 2021 10:43:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28633) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1hZ-0000eg-PD for qemu-devel@nongnu.org; Fri, 07 May 2021 10:43:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398617; 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: in-reply-to:in-reply-to:references:references; bh=q+bUpux/oO0InwS7O+3v+yDI8KzcveNX4OlpMmGvtIA=; b=RqX2sDCfg/Ljhm8GoECKUtCPfVD7QowQQvshscBbcNqkS8tur9nyvA9DQdgrraVGpg/SnK mIsmB2olNwGeypF4Yxb89AW/2hBs+4Wn/eV9ru0PoXs30q6HWVTIx17i/7r15XapUY0Mjo qr7AlCerfwL/lBr75CScD36rU9yVGRc= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-602-g4VYKLy-MLea2A4Lfs7MyQ-1; Fri, 07 May 2021 10:43:33 -0400 X-MC-Unique: g4VYKLy-MLea2A4Lfs7MyQ-1 Received: by mail-wm1-f72.google.com with SMTP id y193-20020a1c32ca0000b029014cbf30c3f2so3952033wmy.1 for ; Fri, 07 May 2021 07:43:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=q+bUpux/oO0InwS7O+3v+yDI8KzcveNX4OlpMmGvtIA=; b=oalzdU8pfJdbMdMNzkcnNzMp5VXvQSfAI1P+FlO5G2n5sWhmzCFT3/KAAVDrwi9RrE X/HTJ2n+J/WNIgQxJ8Y7lRzo1c1OkyG7s6faLeMeNv9CnVGZlsqcHXkaSPugxuUm9WsO HY8alPqHlhmihRgaT8W/2ikfgSNOhGYBK5PLc4ZphxXeMqYHEss3q1JiZDZbUMNaEhSf VlEGSZaAtqWjuRgjFxLHFW1RohVHNqq82OVDV4H50HPIraRUGdWZ2If/P22CQ+z/Ojcv +REQ2IsBF+BkxdWoBVUo60Uw16Z8psLuoVZIejtZsMzREkhMvw0xcY7J8xuDB6sYCspM GV7Q== X-Gm-Message-State: AOAM532W+MCOwzheaT5yi80kgaxdwbjjCua/tE9vgkilWh/j6hb80HM+ y2B7Im5MdBPKE5oTIBjzydW+lA+EIFybDjT7pyWEnpfbZv233BuhzosF/nLO1rCt+aBJ8k/NPd3 UYGP9TGSv+RSTr7O///kLlmwRf+U5Be8Vty3/xIOdUqHlQk2T37WTUogaEEkjBkMf X-Received: by 2002:a05:600c:89a:: with SMTP id l26mr21147126wmp.18.1620398612199; Fri, 07 May 2021 07:43:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTDpcS06ZVNaty9w4yRm1eFVAUeaEhTHfn0l9iOi64at9nD5MlVi8qUE4UwL2wbZeJV4QBHA== X-Received: by 2002:a05:600c:89a:: with SMTP id l26mr21147100wmp.18.1620398611969; Fri, 07 May 2021 07:43:31 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id f7sm10176565wrg.34.2021.05.07.07.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:43:31 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 03/17] linux-user/syscall: Replace alloca() by g_try_new() Date: Fri, 7 May 2021 16:43:01 +0200 Message-Id: <20210507144315.1994337-4-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ALLOCA(3) man-page mentions its "use is discouraged". Use autofree heap allocation instead (returning ENOMEM on failure). Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- linux-user/syscall.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 95d79ddc437..08ab4cee805 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11417,10 +11417,12 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, { int gidsetsize = arg1; target_id *target_grouplist; - gid_t *grouplist; + g_autofree gid_t *grouplist = g_try_new(gid_t, gidsetsize); int i; - grouplist = alloca(gidsetsize * sizeof(gid_t)); + if (!grouplist) { + return -TARGET_ENOMEM; + } ret = get_errno(getgroups(gidsetsize, grouplist)); if (gidsetsize == 0) return ret; @@ -11438,10 +11440,13 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, { int gidsetsize = arg1; target_id *target_grouplist; - gid_t *grouplist = NULL; + g_autofree gid_t *grouplist = NULL; int i; if (gidsetsize) { - grouplist = alloca(gidsetsize * sizeof(gid_t)); + grouplist = g_try_new(gid_t, gidsetsize); + if (!grouplist) { + return -TARGET_ENOMEM; + } target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * sizeof(target_id), 1); if (!target_grouplist) { return -TARGET_EFAULT; @@ -11736,10 +11741,12 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, { int gidsetsize = arg1; uint32_t *target_grouplist; - gid_t *grouplist; + g_autofree gid_t *grouplist = g_try_new(gid_t, gidsetsize); int i; - grouplist = alloca(gidsetsize * sizeof(gid_t)); + if (!grouplist) { + return -TARGET_ENOMEM; + } ret = get_errno(getgroups(gidsetsize, grouplist)); if (gidsetsize == 0) return ret; @@ -11760,10 +11767,12 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, { int gidsetsize = arg1; uint32_t *target_grouplist; - gid_t *grouplist; + g_autofree gid_t *grouplist = g_try_new(gid_t, gidsetsize); int i; - grouplist = alloca(gidsetsize * sizeof(gid_t)); + if (!grouplist) { + return -TARGET_ENOMEM; + } target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 4, 1); if (!target_grouplist) { return -TARGET_EFAULT; From patchwork Fri May 7 14:43:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475555 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=S3JiuQIs; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcCyh3FcCz9sXS for ; Sat, 8 May 2021 00:49:32 +1000 (AEST) Received: from localhost ([::1]:45306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1nG-0003VQ-EG for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:49:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1hj-0007gR-6N for qemu-devel@nongnu.org; Fri, 07 May 2021 10:43:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21583) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1hc-0000g9-52 for qemu-devel@nongnu.org; Fri, 07 May 2021 10:43:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398619; 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: in-reply-to:in-reply-to:references:references; bh=Vgjfb8PbNnIcn3GQZwYI0ZjOYyIxocLAAFSxTQwWgvo=; b=S3JiuQIspYj4SnOncLaO6snj3w8sWw0rorrWs8bxm+oApEGx5mhkuIKxu3/H6nvbIOl6wL /x2M5SU37TG0hb0R1sB5sEeO9FUWbeyHdL78gnwRawmcaCWzdHgGTq/Dwf2eusfZZpJdtv klLJmlrSfGgh/0d+2xTf8MM9DUn7M2U= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-373-A8SUl6lAMlm0GGDO-8lAqw-1; Fri, 07 May 2021 10:43:38 -0400 X-MC-Unique: A8SUl6lAMlm0GGDO-8lAqw-1 Received: by mail-wr1-f70.google.com with SMTP id i102-20020adf90ef0000b029010dfcfc46c0so3707352wri.1 for ; Fri, 07 May 2021 07:43:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vgjfb8PbNnIcn3GQZwYI0ZjOYyIxocLAAFSxTQwWgvo=; b=Cl0Gs11gDJCG4NxdQkTj5l09RjH5lzQppu6Wkvfc2BVh3BDqVoY4lfUE2eNFzXsQLd 5mFp3YBQa2Wy1jnmcutSwWqtf4I505dZ/AlIO1rr1iPtFkZ2Ub42q5qd8HfxoBS8ktQm TtiQ72GsYmTItq/O6irO+yc7AgY9kSGGb31A8cJSIZMzOj7yov0gwL05lGJU8zAHpX9p sH1nju0C27J39KxLcCVzhataw/eurZmtaleTITQeD3MkAdHElFNv4XEP7mLDBuFudgba KwJSeFy0n2VOErt0krHGQ0zQROutNG5hYT/RFHbKDxeBsG/kdz/COAd5tipsdX1DAPDv rpcA== X-Gm-Message-State: AOAM532XQ1epJLviJDMqTVWaqfy8bLDmPPn5WvuoRfo7bhsAUcKL7iGg jgMH31EvVQQs+l4AoinxsExgpLelLRvYChfyxYLCWymoXmWJ1a3Gov1PCaJyN2hY9NAeOxNs10z XVdfllmgq7ouNjjAyyjUFh7IhvmXV2oQQNhir2lzCfP/T5oq+tJ0n5hrsQy/B3s5s X-Received: by 2002:a05:6000:188b:: with SMTP id a11mr12357190wri.275.1620398616937; Fri, 07 May 2021 07:43:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8z6+nLnCBt+Vj4iXQ1ZSB8G5e+MxGMDopF4RIQpyJSA59dPldQXb0CcFy166g96XArEjxog== X-Received: by 2002:a05:6000:188b:: with SMTP id a11mr12357169wri.275.1620398616770; Fri, 07 May 2021 07:43:36 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id z7sm8704053wrl.11.2021.05.07.07.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:43:36 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 04/17] linux-user/syscall: Replace alloca() by g_try_malloc() Date: Fri, 7 May 2021 16:43:02 +0200 Message-Id: <20210507144315.1994337-5-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ALLOCA(3) man-page mentions its "use is discouraged". Use autofree heap allocation instead (returning ENOMEM on failure). Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- linux-user/syscall.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 08ab4cee805..2fa6b89b3de 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -10630,7 +10630,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, case TARGET_NR_sched_getaffinity: { unsigned int mask_size; - unsigned long *mask; + g_autofree unsigned long *mask = NULL; /* * sched_getaffinity needs multiples of ulong, so need to take @@ -10641,8 +10641,10 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, } mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1); - mask = alloca(mask_size); - memset(mask, 0, mask_size); + mask = g_try_malloc0(mask_size); + if (!mask) { + return -TARGET_ENOMEM; + } ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask)); if (!is_error(ret)) { @@ -10670,7 +10672,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, case TARGET_NR_sched_setaffinity: { unsigned int mask_size; - unsigned long *mask; + g_autofree unsigned long *mask = NULL; /* * sched_setaffinity needs multiples of ulong, so need to take @@ -10680,7 +10682,10 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, return -TARGET_EINVAL; } mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1); - mask = alloca(mask_size); + mask = g_try_malloc(mask_size); + if (!mask) { + return -TARGET_ENOMEM; + } ret = target_to_host_cpu_mask(mask, mask_size, arg3, arg2); if (ret) { From patchwork Fri May 7 14:43:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475558 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T4RiVvDI; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcCzd5CVRz9sXS for ; Sat, 8 May 2021 00:50:21 +1000 (AEST) Received: from localhost ([::1]:48450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1o3-0004lU-Ez for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:50:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1hr-0007hb-Qs for qemu-devel@nongnu.org; Fri, 07 May 2021 10:43:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55850) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1hh-0000hd-Mq for qemu-devel@nongnu.org; Fri, 07 May 2021 10:43:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398624; 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: in-reply-to:in-reply-to:references:references; bh=0Q+1JmkmHePwynNhULjY5tlZHv+f3d17hAW4SIJc660=; b=T4RiVvDIsugnH8QYf7EtaNA6TDsGSgyjnEhDhhIe6sXlCOL/k+zkJwt+Rxhq20rM8PR3ko gJyP35CVkwehN5RfafacaQhNg6tR8RPMlXMN+Q4rQIS6C+FAI084drmPNP64PgSnqMJOF4 EGUA2uQh+U7oPfTuKYux0OTT+uWZGUM= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-580-OOUbTT5DNKS9HXWrc-s-Mw-1; Fri, 07 May 2021 10:43:43 -0400 X-MC-Unique: OOUbTT5DNKS9HXWrc-s-Mw-1 Received: by mail-wr1-f71.google.com with SMTP id 67-20020adf81490000b029010756d109e6so3654274wrm.13 for ; Fri, 07 May 2021 07:43:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0Q+1JmkmHePwynNhULjY5tlZHv+f3d17hAW4SIJc660=; b=ZVVgMt7xNGkZA75wnbiArWxNhY187UJXc22PCSCkkSBU2OX17qmBYMO2F1I/NyLkkD mrXl2xBomfRXXnjxHWU/quY+hrqLiXhZgjWSCPTuVfE5njYVRmzCffSXy14aRz7mHeEP EWBcBXIHMfZFT4tKSSvBX/SkyegAQBZxROblZHuiSuxAPz7MlIyUQECtuoh2glsea86W ZWVAAUKGToQg9B70adXnvi/CLARy+IeBV/pSfJUtIedT5a2Zk4reok2OPzvOpKfUNWZL fb5s9Sl0RQ+aeUfqviZ/jHs0nY8n0AHDziNYxsolwA+HrJuWK++AbL3uBjGy2P+CBK0J EmcQ== X-Gm-Message-State: AOAM532lW92EeFU2HS1YAu+aSnZERMkaWkisno2CJq/2qxOfdAHy8aut x4zFvQBuRGV2RrF7P+pIp0qUVF06tGXRw/l3jOGv0/4k/KxXWmF6V9yVAW0rajDprAy0U99k48T 7inIPt5eIEkg+sCzghvZ29OvHPGUaYCp/aUApS1xN6yiHtzrWZa7d18oydsYKrKGj X-Received: by 2002:a5d:64e4:: with SMTP id g4mr12745262wri.366.1620398621603; Fri, 07 May 2021 07:43:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzq+8a9eTWd9LLo0lKbFnav+n6uJJCUttMkNpC1ladPYpd+vHRsfQgfmgc2chAdH48leiYagg== X-Received: by 2002:a5d:64e4:: with SMTP id g4mr12745233wri.366.1620398621414; Fri, 07 May 2021 07:43:41 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id i2sm10411140wro.0.2021.05.07.07.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:43:41 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 05/17] linux-user: Replace alloca() by g_try_new() in ppoll() syscall Date: Fri, 7 May 2021 16:43:03 +0200 Message-Id: <20210507144315.1994337-6-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ALLOCA(3) man-page mentions its "use is discouraged". Use autofree heap allocation instead (returning ENOMEM on failure). Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- linux-user/syscall.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2fa6b89b3de..0bf4273fc7a 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1605,11 +1605,10 @@ static abi_long do_ppoll(abi_long arg1, abi_long arg2, abi_long arg3, { struct target_pollfd *target_pfd; unsigned int nfds = arg2; - struct pollfd *pfd; + g_autofree struct pollfd *pfd = NULL; unsigned int i; abi_long ret; - pfd = NULL; target_pfd = NULL; if (nfds) { if (nfds > (INT_MAX / sizeof(struct target_pollfd))) { @@ -1621,7 +1620,10 @@ static abi_long do_ppoll(abi_long arg1, abi_long arg2, abi_long arg3, return -TARGET_EFAULT; } - pfd = alloca(sizeof(struct pollfd) * nfds); + pfd = g_try_new(struct pollfd, nfds); + if (!pfd) { + return -TARGET_ENOMEM; + } for (i = 0; i < nfds; i++) { pfd[i].fd = tswap32(target_pfd[i].fd); pfd[i].events = tswap16(target_pfd[i].events); From patchwork Fri May 7 14:43:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475556 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SorAX5dc; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcCyt5cYWz9sXS for ; Sat, 8 May 2021 00:49:42 +1000 (AEST) Received: from localhost ([::1]:46358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1nQ-0003ul-Rm for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:49:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1ht-0007jF-R4 for qemu-devel@nongnu.org; Fri, 07 May 2021 10:43:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20419) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1hn-0000jC-6d for qemu-devel@nongnu.org; Fri, 07 May 2021 10:43:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398629; 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: in-reply-to:in-reply-to:references:references; bh=2L5mr2b7hhw5EkGSTWl47QqXXqBmVyFmMYU/e54ubTE=; b=SorAX5dc2LcT4RbwUVVxlDFS3JFsyE7ZGfeLCAt6dgaG16f21fb8ociBNSiMy1ws2ImotF uFiXdzPZXVwcEVkVOzF7GeuJWsqxuqTh9Usx7hcBLZSPu65iXNmunNSoAoH1KyTCEy0S6v 3sCpu08MnZkh8cwH4ZCZkBGgstgSZ8U= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-74-vO9o92F_MKaqPCSSjIe2RQ-1; Fri, 07 May 2021 10:43:47 -0400 X-MC-Unique: vO9o92F_MKaqPCSSjIe2RQ-1 Received: by mail-wr1-f70.google.com with SMTP id 88-20020adf95610000b029010758d8d7e2so3647576wrs.19 for ; Fri, 07 May 2021 07:43:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2L5mr2b7hhw5EkGSTWl47QqXXqBmVyFmMYU/e54ubTE=; b=b35c0JsA5r4nZcrGhLn86snbtb9npBi4hL3KJTQf+BmH9F56USczddbjgSVALDY20y khU2xTcdBBHATM2XngwqD7CVHSgmLjAhx+7Is4xw3X19XrmJ6dAvlmWYcftYemLBpns1 pzQxP7Cn1dVVNPUTJ+mdsAWez4w6GW528wWWTuMt+eJcDdGom3sa8DF7edQ6F5g/4Bmv j4DUVxssyzx3ND9SfFql1isBjnNkVdCNF8AeWzV11R+op+rFSv8yrPAJilrSlsCeBtaD rmohBfg46RGSVoU1ltYSm2/uztFH6GAxPxoiAU1DwK96ZKGb62Hdq4rh3DiigtIEQJSJ 2wLw== X-Gm-Message-State: AOAM5311y0mUJLI+v5MtVgyquxQQ8MSrGitu7g0s1X5ArgtNWd8OKYKu jMY7GOPEyBCGZkmRFCx4MbdaeT55N1QWF/vz2se0g9+UVqxXMRp18LPSiIGtTutVjd/wNjEeOi2 dB8R08zrUAQ46jrFTFethfJuZUzcmHIOeF2NHrV7azrOqeUmY1jGWSTs8CZu7Ur5u X-Received: by 2002:a5d:6682:: with SMTP id l2mr12867725wru.15.1620398626421; Fri, 07 May 2021 07:43:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9DMJA8+x/NYI0yJJsbEcLCTwgBtgsQmZh7JNyu0BIiNXSApGIllKxUmvSifBrFhmtnMgQDw== X-Received: by 2002:a5d:6682:: with SMTP id l2mr12867692wru.15.1620398626166; Fri, 07 May 2021 07:43:46 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id f4sm9261707wrz.33.2021.05.07.07.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:43:45 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 06/17] linux-user: Replace alloca() by g_try_malloc() in setsockopt() syscall Date: Fri, 7 May 2021 16:43:04 +0200 Message-Id: <20210507144315.1994337-7-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ALLOCA(3) man-page mentions its "use is discouraged". Use autofree heap allocation instead (returning ENOMEM on failure). Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- linux-user/syscall.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 0bf4273fc7a..a263aea85ff 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2191,7 +2191,6 @@ static abi_long do_setsockopt(int sockfd, int level, int optname, { abi_long ret; int val; - struct ip_mreqn *ip_mreq; struct ip_mreq_source *ip_mreq_source; switch(level) { @@ -2235,15 +2234,21 @@ static abi_long do_setsockopt(int sockfd, int level, int optname, break; case IP_ADD_MEMBERSHIP: case IP_DROP_MEMBERSHIP: + { + g_autofree struct ip_mreqn *ip_mreq = NULL; + if (optlen < sizeof (struct target_ip_mreq) || optlen > sizeof (struct target_ip_mreqn)) return -TARGET_EINVAL; - ip_mreq = (struct ip_mreqn *) alloca(optlen); + ip_mreq = g_try_malloc(optlen); + if (!ip_mreq) { + return -TARGET_ENOMEM; + } target_to_host_ip_mreq(ip_mreq, optval_addr, optlen); ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq, optlen)); break; - + } case IP_BLOCK_SOURCE: case IP_UNBLOCK_SOURCE: case IP_ADD_SOURCE_MEMBERSHIP: @@ -2492,7 +2497,8 @@ set_timeout: } case TARGET_SO_BINDTODEVICE: { - char *dev_ifname, *addr_ifname; + char *dev_ifname; + g_autofree char *addr_ifname = NULL; if (optlen > IFNAMSIZ - 1) { optlen = IFNAMSIZ - 1; @@ -2502,7 +2508,10 @@ set_timeout: return -TARGET_EFAULT; } optname = SO_BINDTODEVICE; - addr_ifname = alloca(IFNAMSIZ); + addr_ifname = g_try_malloc(IFNAMSIZ); + if (!addr_ifname) { + return -TARGET_ENOMEM; + } memcpy(addr_ifname, dev_ifname, optlen); addr_ifname[optlen] = 0; ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, From patchwork Fri May 7 14:43:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475557 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Z3tUKWZ9; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcCzD2rGqz9sj5 for ; Sat, 8 May 2021 00:50:00 +1000 (AEST) Received: from localhost ([::1]:47574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1ni-0004Pg-Df for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:49:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1i3-0007ku-Tr for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27402) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1hr-0000jV-KD for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398633; 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: in-reply-to:in-reply-to:references:references; bh=9UwtNiSXhDRvxxEBq2bA0+BsvH/APBPHI+6JmS4Uqh4=; b=Z3tUKWZ9TUSCHr0eJ+j0Joj1SNoMTA+JHbfKMN0oFp3bUgrueeCIuWmxwUqUhNHuqrz/tl o0pWiut8HlVTx5rFWVUu5ydsE4wnJZZFa7AzpGBLTWarFwhvt7y7gqA0sjPOTwEUxm1H4z gpyXmHOd14+hqFQ/Mtimm89lNxpl644= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-9-L2JHnGSXNYmVyKjz2IoFKA-1; Fri, 07 May 2021 10:43:52 -0400 X-MC-Unique: L2JHnGSXNYmVyKjz2IoFKA-1 Received: by mail-wr1-f72.google.com with SMTP id r12-20020adfc10c0000b029010d83323601so3663105wre.22 for ; Fri, 07 May 2021 07:43:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9UwtNiSXhDRvxxEBq2bA0+BsvH/APBPHI+6JmS4Uqh4=; b=rFhW0WtVBkGhC0/Ue36cJPmhjaL6NJimiUXLmiZxlGIjtIfuNH+7vYoFf7iLkTd8yL EGtzy5PRd1+0WwxeN6GwJvyZx3x61OIA54g/edujQnGGjlRrPvOLz0pRSW8w43uBADE5 n4L0Rw5h16USt/y7F5aBXVh6sJOm85TIPI+fJ2cT+eLkfRkOFN+Mu+LMZ2wWW7nRUq7G nQOAz8qdr4UkixmXae1nRy6y48hrdfXNTrTLFis2E30bGyj6ju8zOzRK7m1oIVp6ZnIb iFEJvH8H5erpCRpVq9mQw/wHwsvqCcbaxlHcNVzaGXuvLBROwamfqHml+eC5t9ExUsCj FMtg== X-Gm-Message-State: AOAM5300zklv4Kk4Jer8/T+bBCbKm++iR1rxdUJ/2XlROwOAWbFld7O1 cDUl/amHr4+mrTHgHIQQVekZg+sYlgA1kMs87EABEh++l4/1xXtG8I7Uk7c65ycKUzpj9gKH/r/ rePqGVrgeO9/hKgvzZG4KnO84Blx+uYZbcZBwhEqGi0R+sKbsFjG5Vw9GJInKCXuW X-Received: by 2002:a5d:4acc:: with SMTP id y12mr12640296wrs.233.1620398631138; Fri, 07 May 2021 07:43:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpO9HD46hd1zWh+qoigRuizkz+et7j2kyahnyJH43scB9tmRKhQTHHgYM62Qg0Bn5FVKcPCg== X-Received: by 2002:a5d:4acc:: with SMTP id y12mr12640261wrs.233.1620398630869; Fri, 07 May 2021 07:43:50 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id d3sm8221624wri.75.2021.05.07.07.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:43:50 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 07/17] linux-user: Replace alloca() by g_try_malloc() in various socket syscall Date: Fri, 7 May 2021 16:43:05 +0200 Message-Id: <20210507144315.1994337-8-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ALLOCA(3) man-page mentions its "use is discouraged". Use autofree heap allocation instead (returning ENOMEM on failure). Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- linux-user/syscall.c | 50 +++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index a263aea85ff..7c5c821f48d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3307,14 +3307,17 @@ static abi_long do_socket(int domain, int type, int protocol) static abi_long do_bind(int sockfd, abi_ulong target_addr, socklen_t addrlen) { - void *addr; + g_autofree void *addr = NULL; abi_long ret; if ((int)addrlen < 0) { return -TARGET_EINVAL; } - addr = alloca(addrlen+1); + addr = g_try_malloc(addrlen + 1); + if (!addr) { + return -TARGET_ENOMEM; + } ret = target_to_host_sockaddr(sockfd, addr, target_addr, addrlen); if (ret) @@ -3327,14 +3330,17 @@ static abi_long do_bind(int sockfd, abi_ulong target_addr, static abi_long do_connect(int sockfd, abi_ulong target_addr, socklen_t addrlen) { - void *addr; + g_autofree void *addr = NULL; abi_long ret; if ((int)addrlen < 0) { return -TARGET_EINVAL; } - addr = alloca(addrlen+1); + addr = g_try_malloc(addrlen + 1); + if (!addr) { + return -TARGET_ENOMEM; + } ret = target_to_host_sockaddr(sockfd, addr, target_addr, addrlen); if (ret) @@ -3519,7 +3525,7 @@ static abi_long do_accept4(int fd, abi_ulong target_addr, abi_ulong target_addrlen_addr, int flags) { socklen_t addrlen, ret_addrlen; - void *addr; + g_autofree void *addr = NULL; abi_long ret; int host_flags; @@ -3541,7 +3547,10 @@ static abi_long do_accept4(int fd, abi_ulong target_addr, return -TARGET_EFAULT; } - addr = alloca(addrlen); + addr = g_try_malloc(addrlen); + if (!addr) { + return -TARGET_ENOMEM; + } ret_addrlen = addrlen; ret = get_errno(safe_accept4(fd, addr, &ret_addrlen, host_flags)); @@ -3559,7 +3568,7 @@ static abi_long do_getpeername(int fd, abi_ulong target_addr, abi_ulong target_addrlen_addr) { socklen_t addrlen, ret_addrlen; - void *addr; + g_autofree void *addr = NULL; abi_long ret; if (get_user_u32(addrlen, target_addrlen_addr)) @@ -3573,7 +3582,10 @@ static abi_long do_getpeername(int fd, abi_ulong target_addr, return -TARGET_EFAULT; } - addr = alloca(addrlen); + addr = g_try_malloc(addrlen); + if (!addr) { + return -TARGET_ENOMEM; + } ret_addrlen = addrlen; ret = get_errno(getpeername(fd, addr, &ret_addrlen)); @@ -3591,7 +3603,7 @@ static abi_long do_getsockname(int fd, abi_ulong target_addr, abi_ulong target_addrlen_addr) { socklen_t addrlen, ret_addrlen; - void *addr; + g_autofree void *addr = NULL; abi_long ret; if (get_user_u32(addrlen, target_addrlen_addr)) @@ -3605,7 +3617,10 @@ static abi_long do_getsockname(int fd, abi_ulong target_addr, return -TARGET_EFAULT; } - addr = alloca(addrlen); + addr = g_try_malloc(addrlen); + if (!addr) { + return -TARGET_ENOMEM; + } ret_addrlen = addrlen; ret = get_errno(getsockname(fd, addr, &ret_addrlen)); @@ -3640,7 +3655,6 @@ static abi_long do_socketpair(int domain, int type, int protocol, static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags, abi_ulong target_addr, socklen_t addrlen) { - void *addr; void *host_msg; void *copy_msg = NULL; abi_long ret; @@ -3662,7 +3676,11 @@ static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags, } } if (target_addr) { - addr = alloca(addrlen+1); + g_autofree void *addr = g_try_malloc(addrlen + 1); + + if (!addr) { + return -TARGET_ENOMEM; + } ret = target_to_host_sockaddr(fd, addr, target_addr, addrlen); if (ret) { goto fail; @@ -3686,7 +3704,7 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags, abi_ulong target_addrlen) { socklen_t addrlen, ret_addrlen; - void *addr; + g_autofree void *addr = NULL; void *host_msg; abi_long ret; @@ -3707,12 +3725,14 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags, ret = -TARGET_EINVAL; goto fail; } - addr = alloca(addrlen); + addr = g_try_malloc(addrlen); + if (!addr) { + return -TARGET_ENOMEM; + } ret_addrlen = addrlen; ret = get_errno(safe_recvfrom(fd, host_msg, len, flags, addr, &ret_addrlen)); } else { - addr = NULL; /* To keep compiler quiet. */ addrlen = 0; /* To keep compiler quiet. */ ret = get_errno(safe_recvfrom(fd, host_msg, len, flags, NULL, 0)); } From patchwork Fri May 7 14:43:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475561 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XjDmLzn0; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcD3h47KDz9sCD for ; Sat, 8 May 2021 00:53:51 +1000 (AEST) Received: from localhost ([::1]:58984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1rQ-0000fF-0r for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:53:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1i5-0007oE-Fr for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28988) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1hz-0000lr-3q for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398639; 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: in-reply-to:in-reply-to:references:references; bh=0aEFCYf2HLWMKyL3vu/hasMYJfVES1sketKqALkOn8E=; b=XjDmLzn0JnJ9VZvoF6bTxrHPLA2LQUIUK0G7C9O+G7oE8cxPRjvo8Gn6pcKqrpdE8qIQ/R Cqk5Ys/eZ7Wy5A2YzyW05+1xP41kj5fuT2oXmuU2s87MSdPAnEZVniZtDNGDGakiuoBXAM 6kNqr7TeQNsu5nHprRQ0oE51Elx0cR4= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-506-oF72ux7RPXaQbh8mxqHTug-1; Fri, 07 May 2021 10:43:57 -0400 X-MC-Unique: oF72ux7RPXaQbh8mxqHTug-1 Received: by mail-wr1-f69.google.com with SMTP id 88-20020adf95610000b029010758d8d7e2so3647753wrs.19 for ; Fri, 07 May 2021 07:43:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0aEFCYf2HLWMKyL3vu/hasMYJfVES1sketKqALkOn8E=; b=ODIyPbzDsrKDyutY2cF55ZppOBkGzqX/fjYFySjViVOw6gwCQfl1E9nnkoJPUvsuXI xMUJo2PXZhbCa1VCrDWHHOioD9NQL+42QMh4k9jVUa2KRTR5jGP7DdxVfXFHGlHIDjJt 6Bc3B57FoetW1rxYO4S/5T/X6F91D24wtqqoCGEDnR4EejMZkAUlVTS32JYRp2C2Xox1 P6q06FEhBi3Mc1KOkqmliat16oaQVHZLsWP9/O4B2qOin0bzEO/GmX9+syvm7SY4DHvv 5BFjOFfJO12blep900u+sr6wkrTHcjCiFySI8laPsE4naU3LDzx2b165XrJZYlD5fGfw iLoQ== X-Gm-Message-State: AOAM533+xvOE9olgtfFIlQjTLmRMwXJTKgr90qFwjsgdv1yGyPKgd8Ec dlS/WsCiBqiMzomVDSud+YF6VC3zTaFJFXmgw343UiJDTRaaZVnAmgB1A0uTJEGOE1SL5cNMRUq CLJDlCQzqqVGKSpplGTgiO+SaGQ4JXqmapgLUeBkerL5UR++Jfiux6F6X0V918nuN X-Received: by 2002:a1c:e912:: with SMTP id q18mr21780868wmc.59.1620398635922; Fri, 07 May 2021 07:43:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuxDw+Z5ejCnnQGzrscKMxB38QYBMH5R95NR75yg2DPkosJ/eaQfVzqQPNjxuH9z1wWTJ1gA== X-Received: by 2002:a1c:e912:: with SMTP id q18mr21780843wmc.59.1620398635604; Fri, 07 May 2021 07:43:55 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id q12sm9079882wrx.17.2021.05.07.07.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:43:55 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 08/17] linux-user/syscall: Move code around in do_sendrecvmsg_locked() Date: Fri, 7 May 2021 16:43:06 +0200 Message-Id: <20210507144315.1994337-9-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Avoid initializing variables too early, since there is 2 possible failure points before they get used. Move them after the lock_iovec() call. Signed-off-by: Philippe Mathieu-Daudé --- linux-user/syscall.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 7c5c821f48d..593241362a9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3379,15 +3379,8 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, msg.msg_name = NULL; msg.msg_namelen = 0; } - msg.msg_controllen = 2 * tswapal(msgp->msg_controllen); - msg.msg_control = alloca(msg.msg_controllen); - memset(msg.msg_control, 0, msg.msg_controllen); - - msg.msg_flags = tswap32(msgp->msg_flags); count = tswapal(msgp->msg_iovlen); - target_vec = tswapal(msgp->msg_iov); - if (count > IOV_MAX) { /* sendrcvmsg returns a different errno for this condition than * readv/writev, so we must catch it here before lock_iovec() does. @@ -3396,14 +3389,20 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, goto out2; } + target_vec = tswapal(msgp->msg_iov); vec = lock_iovec(send ? VERIFY_READ : VERIFY_WRITE, target_vec, count, send); if (vec == NULL) { ret = -host_to_target_errno(errno); goto out2; } + msg.msg_iovlen = count; msg.msg_iov = vec; + msg.msg_flags = tswap32(msgp->msg_flags); + msg.msg_controllen = 2 * tswapal(msgp->msg_controllen); + msg.msg_control = alloca(msg.msg_controllen); + memset(msg.msg_control, 0, msg.msg_controllen); if (send) { if (fd_trans_target_to_host_data(fd)) { From patchwork Fri May 7 14:43:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475559 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NdV3KcBa; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcD1p3rpDz9sXV for ; Sat, 8 May 2021 00:52:14 +1000 (AEST) Received: from localhost ([::1]:54274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1ps-0007DL-Gc for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:52:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1i6-0007q4-9N for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1i3-0000nJ-LX for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398643; 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: in-reply-to:in-reply-to:references:references; bh=VXb/SdsglaW/QeR809+FkWbDDukXToeT9LG+jBzD2Ak=; b=NdV3KcBaBxPdcdPawJGW+qo0sV7BVOUVGrszLU/9qcz7zpAPjXoHay0i9/pdpiM+Kq0Dgg 316Xc/zDa6O27uQm2rcM8antPHx1WVFHMjwuQa43L+Nn+Z/xGEFMeZ0JOHKJSYR46s1oKf 7XYtQy536rtL4oGTXN6gj+qbsJmU73c= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-499-Lty4evigOQWdlqHgvfzylQ-1; Fri, 07 May 2021 10:44:02 -0400 X-MC-Unique: Lty4evigOQWdlqHgvfzylQ-1 Received: by mail-wr1-f72.google.com with SMTP id h104-20020adf90710000b029010de8455a3aso3686385wrh.12 for ; Fri, 07 May 2021 07:44:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VXb/SdsglaW/QeR809+FkWbDDukXToeT9LG+jBzD2Ak=; b=d4C1Rhdi2Y5bSEdKWp0Ncvgq6gAziaPcKls5Ej7uvsfThi0QPB1UwShaimdo2mX8AD BsRVVFsZnpHoXjyXpHvg3WmBFWUUTtRGk9qu87gT2aL6Yrd0QQUGf2sk+YUYQDOVXD/G PCx0/1CQHT0r4VytoM7qCPxpnTUfFH1GyDEg/9S9EmqddAKu3eqmyGvNNfk19g2j+/nQ hsn0xE/Se2GRRFA15GhXvOBL/RDNt6LDDQnvwXvOBwx6hYCJicOVJZ1l75R1fwyvhSE7 FQj6OE0MeVfZiFSDM0YPG6+MlBh1+bfIwpaRVKz6XNahI8Vt+8AcIX4iF5puqcmFkEPZ xACg== X-Gm-Message-State: AOAM533ae7czLzsepcnUCaVR29QM8QKaq75Mbn/nJ3WtpJsonBgLxdsb JxC9HiDvcuPg7QLg9Jq7yIWEMwTK+IYFhJhPrIQdbLraZiyzFFyTrHyKuB26UxBz9FlVT7tXC/v hnvg/F8F5f19cCOTWci5p7rGquGkBStrhl5JcgkyxHgJbVtnjOcuisUF9B7Ogu4Xj X-Received: by 2002:adf:f5c6:: with SMTP id k6mr13450308wrp.338.1620398640790; Fri, 07 May 2021 07:44:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIYqu7g0FIq8SCVQnMmTws2rDcXfTUEbAeQnUtRQ+O103KeVplYGEoYEo0zclOShBCiqkK6w== X-Received: by 2002:adf:f5c6:: with SMTP id k6mr13450277wrp.338.1620398640536; Fri, 07 May 2021 07:44:00 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id v13sm8883864wrt.65.2021.05.07.07.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:44:00 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 09/17] linux-user/syscall: Replace alloca() by GLib alloc() in sendrecvmsg Date: Fri, 7 May 2021 16:43:07 +0200 Message-Id: <20210507144315.1994337-10-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ALLOCA(3) man-page mentions its "use is discouraged". Use autofree heap allocation instead (returning ENOMEM on failure). Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- linux-user/syscall.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 593241362a9..c88e240ff93 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3358,13 +3358,19 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, abi_ulong count; struct iovec *vec; abi_ulong target_vec; + g_autofree void *msg_control = NULL; if (msgp->msg_name) { msg.msg_namelen = tswap32(msgp->msg_namelen); - msg.msg_name = alloca(msg.msg_namelen+1); + msg.msg_name = g_try_malloc(msg.msg_namelen + 1); + if (!msg.msg_name) { + ret = -TARGET_ENOMEM; + goto out2; + } ret = target_to_host_sockaddr(fd, msg.msg_name, tswapal(msgp->msg_name), msg.msg_namelen); + g_free(msg.msg_name); if (ret == -TARGET_EFAULT) { /* For connected sockets msg_name and msg_namelen must * be ignored, so returning EFAULT immediately is wrong. @@ -3401,8 +3407,7 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, msg.msg_iov = vec; msg.msg_flags = tswap32(msgp->msg_flags); msg.msg_controllen = 2 * tswapal(msgp->msg_controllen); - msg.msg_control = alloca(msg.msg_controllen); - memset(msg.msg_control, 0, msg.msg_controllen); + msg.msg_control = msg_control = g_malloc0(msg.msg_controllen); if (send) { if (fd_trans_target_to_host_data(fd)) { From patchwork Fri May 7 14:43:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475562 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RBmkarIQ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcD5J479Tz9sCD for ; Sat, 8 May 2021 00:55:16 +1000 (AEST) Received: from localhost ([::1]:34652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1so-0002Dd-IQ for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:55:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39168) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1i9-0007s7-7a for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38390) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1i5-0000oT-2w for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398648; 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: in-reply-to:in-reply-to:references:references; bh=/bdOhY3sBOcIHJeoCe6CkJ1QfZvAaT12hvfPxmFulM0=; b=RBmkarIQePHLIY2cHeYblK3Le+SfkAv/DMlfnWz3Z80p4bfKAtHk9C0ErRYKaZyZ8YGo0F FpmJVndZIkwN0Rd9LgDGpBsUoNqJ4lFKq8Ziv3sH+snifJQh7Qf9rULgip1liuMTEgsBQh qExhO4BWsLQaKm/GOMqSghWN4Tsa720= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-488-o28EOKUwOAOyS25y7haaPw-1; Fri, 07 May 2021 10:44:07 -0400 X-MC-Unique: o28EOKUwOAOyS25y7haaPw-1 Received: by mail-wm1-f70.google.com with SMTP id t7-20020a1cc3070000b029014131bbe82eso3990978wmf.3 for ; Fri, 07 May 2021 07:44:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/bdOhY3sBOcIHJeoCe6CkJ1QfZvAaT12hvfPxmFulM0=; b=afM9w84B+3xaTKnbZ1rXmh8/zNA2byYuWJUqD6LNfcnhi00rRlHhKpOBrWAtE89wIT 7rLj9Dwc1ma169biXKtV7OlB9Wc+j3Cv6rCe0sNjVdtD7btY2zqhGUwtoCknO+vcq1I/ rvpNKWpFLXutKpx9Exi1+ZdKVNuJrhXB7IL6m6T7hydqIfcdMNKl3kpF5Pa/990raqkX DMZU4bRXHEkm4qcGk7qU2kn5mmUNSgqXq/q9WAPWXCHyHvu7d8/x/JIfzURIzmF6boZo 64yeEM7jDfeYyc5fx4AzRxK8QukOZEwqXfAvt6vbHKdKqTS2GaZRiZwgXMKOBp9gCK3f Cmyg== X-Gm-Message-State: AOAM530HZyc52FOuZydekbi0z6IFhUg47quHReZZrA8CaB1GaQgPmH4A cXbEJ/xmJiRKY8/aNO3oZwuYVdBTGzSdN1nUgOdN+oghu97/sb3nIZMxQYCVAV3moWCClt/QpWq obvHshjc3HXlKmZRGW+i5xPrsHvfxu21Y7t3zFDmLTg/v2O/B5UqU6J3QoYqDhyZn X-Received: by 2002:a5d:4a51:: with SMTP id v17mr9368909wrs.259.1620398645592; Fri, 07 May 2021 07:44:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAGBqHXqPnxWmUTdUgr41RWwEb2R01PCsDEiapDu7vy61qLy24zEvVbo/zgUT9ufemsXGN8A== X-Received: by 2002:a5d:4a51:: with SMTP id v17mr9368879wrs.259.1620398645319; Fri, 07 May 2021 07:44:05 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id r5sm7924414wmh.23.2021.05.07.07.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:44:04 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 10/17] audio/alsaaudio: Replace ALSA alloca() by malloc() equivalent Date: Fri, 7 May 2021 16:43:08 +0200 Message-Id: <20210507144315.1994337-11-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ALLOCA(3) man-page mentions its "use is discouraged". Define the cleanup functions for the snd_pcm_[hw/sw]_params_t types, and replace the ALSA alloca() calls by equivalent ALSA malloc(). Signed-off-by: Philippe Mathieu-Daudé --- audio/alsaaudio.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c index fcc2f62864f..f39061ebc42 100644 --- a/audio/alsaaudio.c +++ b/audio/alsaaudio.c @@ -70,6 +70,9 @@ struct alsa_params_obt { snd_pcm_uframes_t samples; }; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(snd_pcm_hw_params_t, snd_pcm_hw_params_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(snd_pcm_sw_params_t, snd_pcm_sw_params_free) + static void GCC_FMT_ATTR (2, 3) alsa_logerr (int err, const char *fmt, ...) { va_list ap; @@ -410,9 +413,9 @@ static void alsa_dump_info (struct alsa_params_req *req, static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold) { int err; - snd_pcm_sw_params_t *sw_params; + g_autoptr(snd_pcm_sw_params_t) sw_params = NULL; - snd_pcm_sw_params_alloca (&sw_params); + snd_pcm_sw_params_malloc(&sw_params); err = snd_pcm_sw_params_current (handle, sw_params); if (err < 0) { @@ -444,7 +447,7 @@ static int alsa_open(bool in, struct alsa_params_req *req, AudiodevAlsaOptions *aopts = &dev->u.alsa; AudiodevAlsaPerDirectionOptions *apdo = in ? aopts->in : aopts->out; snd_pcm_t *handle; - snd_pcm_hw_params_t *hw_params; + g_autoptr(snd_pcm_hw_params_t) hw_params = NULL; int err; unsigned int freq, nchannels; const char *pcm_name = apdo->has_dev ? apdo->dev : "default"; @@ -455,7 +458,7 @@ static int alsa_open(bool in, struct alsa_params_req *req, freq = req->freq; nchannels = req->nchannels; - snd_pcm_hw_params_alloca (&hw_params); + snd_pcm_hw_params_malloc(&hw_params); err = snd_pcm_open ( &handle, From patchwork Fri May 7 14:43:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475565 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Q5ALLYdq; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcD7Y6P7rz9sCD for ; Sat, 8 May 2021 00:57:13 +1000 (AEST) Received: from localhost ([::1]:40308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1ug-0004d3-Lw for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:57:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1iH-0007uG-To for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34999) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1iD-0000t3-9r for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398655; 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: in-reply-to:in-reply-to:references:references; bh=LTsvX/otw5M7TG+3dUKEvSePlS48V26N+Mr55ie/fDA=; b=Q5ALLYdqkbtvgdor1xU7NN1i68mFvzcPItsP3k01nAsChVoqNSOcxtWtpzaxNJNerZy4VN 2nEISdhu35UBcIM3Rc0Wg5xk0vyZW7VKhsZ/EsfhM+sm8D6NkcL7dYTHL+8WtNLHfAGg3X Wvh3nXq1tF4B9ONIQiefn0Oq/dRfcXg= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-161-o4OMZ7OrNzuhMTx99WkZ1g-1; Fri, 07 May 2021 10:44:11 -0400 X-MC-Unique: o4OMZ7OrNzuhMTx99WkZ1g-1 Received: by mail-wm1-f69.google.com with SMTP id o18-20020a1ca5120000b02901333a56d46eso3990950wme.8 for ; Fri, 07 May 2021 07:44:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LTsvX/otw5M7TG+3dUKEvSePlS48V26N+Mr55ie/fDA=; b=SXwO/PkIakUf/iA2+KIwmeSr4PrYJRokZhLdwMRBeXaYdNrHzEVObkPMZnusFL2BxK UR4jc51/6MtqY/mDHVB5sxqKyq4vgh91ZfbRdzPG9OlFgl/Kt+UZT8K7GXsgWmQwAJME Sd+LOR1LVLNB04LiJT7wf4gKBxzv6nw97y+D6Bkc7iZT4pI3oloUJDfZZ1LZtYYJrKTD OkqObC97gWC1BU4hCNnoJGpwYBcf/oJXi52ycV3Xi8t6a21fWczelNzbinh/Fasu2TDB v8bWYuXMLKLUt/KYpuMpylJnn7HhB3tcUwcJ6Zaj2A569cZ9LWqQEDZuLsOt7w65vY8W GWcA== X-Gm-Message-State: AOAM533y9Qfh7ccSUCOjQa0ndsCgHkzDA4WmrNmMGQ5zQbSdNOkx4olS UdVbKDeyrTUCnht8C24fkTufPLR1kfGlbBK1bR/jke8fPsl8R6AWMglWqAEjxZRm9enhQBf7UXx d+RJpJiYorXYsFrCJtOF+DY94/Gsd6ER/5+1AAFkvpUdGfc2ZmZghFCgJaDispKpj X-Received: by 2002:a5d:498c:: with SMTP id r12mr12851521wrq.31.1620398650447; Fri, 07 May 2021 07:44:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTUSY9yat3Yq68EUlkMCcRoADc9UMIi0CNyQErfTSuxO4A4BB59fJXUwarlSImz3l6WDzCOA== X-Received: by 2002:a5d:498c:: with SMTP id r12mr12851489wrq.31.1620398650237; Fri, 07 May 2021 07:44:10 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id w25sm6720771wmk.39.2021.05.07.07.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:44:09 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 11/17] backends/tpm: Replace g_alloca() by g_malloc() Date: Fri, 7 May 2021 16:43:09 +0200 Message-Id: <20210507144315.1994337-12-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stefan Berger , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Stefan Berger Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ALLOCA(3) man-page mentions its "use is discouraged". Replace a g_alloca() call by a autofree g_malloc() one, moving the allocation before the MUTEX guarded block. Reviewed-by: Stefan Berger Signed-off-by: Philippe Mathieu-Daudé --- backends/tpm/tpm_emulator.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c index a012adc1934..9553cdd891f 100644 --- a/backends/tpm/tpm_emulator.c +++ b/backends/tpm/tpm_emulator.c @@ -123,12 +123,11 @@ static int tpm_emulator_ctrlcmd(TPMEmulator *tpm, unsigned long cmd, void *msg, CharBackend *dev = &tpm->ctrl_chr; uint32_t cmd_no = cpu_to_be32(cmd); ssize_t n = sizeof(uint32_t) + msg_len_in; - uint8_t *buf = NULL; + g_autofree uint8_t *buf = g_malloc(n); int ret = -1; qemu_mutex_lock(&tpm->mutex); - buf = g_alloca(n); memcpy(buf, &cmd_no, sizeof(cmd_no)); memcpy(buf + sizeof(cmd_no), msg, msg_len_in); From patchwork Fri May 7 14:43:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475566 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aJNLB13U; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcD9h5Zbhz9sW7 for ; Sat, 8 May 2021 00:59:03 +1000 (AEST) Received: from localhost ([::1]:44994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1wS-0006YD-Ee for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:59:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1iJ-0007yd-G6 for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50391) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1iE-0000tI-Hk for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398658; 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: in-reply-to:in-reply-to:references:references; bh=B3vDcPc2Lwo5z0s8ItWutJUQDssHj4SCpM1PcCRAn5U=; b=aJNLB13UeAwzpZ0nkWLiX9eixamiE4ZiKKYiOSiNhL3RBqxcE/sQ320Lp7PoGlaK7BFf/M gC5yz9iupfmhJOo9KoRSU/n8+eU9LU0vFhdpymfk/CUxanJoCkc2Hox1MG8/cktxHmUgQO wh+hu9saFFSETjUDt7SKJDAOMR1M1GA= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-129-7hT27Y75N6-4D4CFmiM-bg-1; Fri, 07 May 2021 10:44:16 -0400 X-MC-Unique: 7hT27Y75N6-4D4CFmiM-bg-1 Received: by mail-wm1-f72.google.com with SMTP id b16-20020a7bc2500000b029014587f5376dso3125481wmj.1 for ; Fri, 07 May 2021 07:44:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B3vDcPc2Lwo5z0s8ItWutJUQDssHj4SCpM1PcCRAn5U=; b=qKgR0dYpzGORczra6Ew35Bm5GcCciFWwr6mN6gvCxtD7iIpOGEhgegLguBrMj3fBWX J3wi68qXYBp1dhnVzLi9yhm0trLxIOKaxmQCpRXdTdMbQBf7Po1erzw2qiMPykyZnd7L Bej+g2ViQQ83cMl1Ap0GjuMF11xjOS/tlM6izlSKsl4oG8kaAegCO1sYS075t8d9qxy9 UqBpbshrKDSMCQ2E6YFQ1MKmMqTGeS6uL8Ed+T/YIHeoJZ8csBfIbUDEAJQj3JjRSb6g 9+qgygB0vmhn9hrRzuZaoSjuv8bkbYPx2ebP7wf8EkdbDy/aHdtMs8FMGMvlqAdSIg26 WbXA== X-Gm-Message-State: AOAM531TiSSqRFRGng84QFOP26ln8zEyFM2a9qJtgdtkjXou6+ufZwfj EDV4p9HQDBSZqqP/0plkqatrhM0jnz233+k3aDAlYq+3fsk/DDc3wXIel6LGmnfmtEOAd9CgzdH aTHOrx7F94+Vjlh00SzlNc+2c557MMZ49GPr9WCvwiBcOqskDvpr9l3OlDZ+3CPHu X-Received: by 2002:a7b:cc15:: with SMTP id f21mr21011239wmh.86.1620398655152; Fri, 07 May 2021 07:44:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzepcSCNHFzx7Vk1l7Yecw5eu3JmKlqle2NYs72V/81IbdrlCspu8WvBmn62kYIs0w4K4g+cA== X-Received: by 2002:a7b:cc15:: with SMTP id f21mr21011214wmh.86.1620398654950; Fri, 07 May 2021 07:44:14 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id r5sm7924795wmh.23.2021.05.07.07.44.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:44:14 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 12/17] gdbstub: Constify GdbCmdParseEntry Date: Fri, 7 May 2021 16:43:10 +0200 Message-Id: <20210507144315.1994337-13-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Alex Bennée Signed-off-by: Philippe Mathieu-Daudé --- gdbstub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 9103ffc9028..83d47c67325 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1981,7 +1981,7 @@ static void handle_v_kill(GdbCmdContext *gdb_ctx, void *user_ctx) exit(0); } -static GdbCmdParseEntry gdb_v_commands_table[] = { +static const GdbCmdParseEntry gdb_v_commands_table[] = { /* Order is important if has same prefix */ { .handler = handle_v_cont_query, @@ -2324,7 +2324,7 @@ static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx) } #endif -static GdbCmdParseEntry gdb_gen_query_set_common_table[] = { +static const GdbCmdParseEntry gdb_gen_query_set_common_table[] = { /* Order is important if has same prefix */ { .handler = handle_query_qemu_sstepbits, @@ -2342,7 +2342,7 @@ static GdbCmdParseEntry gdb_gen_query_set_common_table[] = { }, }; -static GdbCmdParseEntry gdb_gen_query_table[] = { +static const GdbCmdParseEntry gdb_gen_query_table[] = { { .handler = handle_query_curr_tid, .cmd = "C", @@ -2420,7 +2420,7 @@ static GdbCmdParseEntry gdb_gen_query_table[] = { #endif }; -static GdbCmdParseEntry gdb_gen_set_table[] = { +static const GdbCmdParseEntry gdb_gen_set_table[] = { /* Order is important if has same prefix */ { .handler = handle_set_qemu_sstep, From patchwork Fri May 7 14:43:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475570 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ioggl7Dd; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcDGk1x2Mz9sW7 for ; Sat, 8 May 2021 01:03:26 +1000 (AEST) Received: from localhost ([::1]:52162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf20i-0001PE-6n for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 11:03:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1iT-00080U-KL for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27602) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1iK-0000yf-Sl for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398664; 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: in-reply-to:in-reply-to:references:references; bh=kLWd0gsOs/zJbnWSmwYcEDNmDuRZ+yJPcTXC6c2hf6w=; b=ioggl7DdGnfygA+p4dweBA2Km5UicuzRmVPVYBitTeyqLQKVRVt5affTLFsfCw2QQhQ7zF Wsvhcp1iuMb9BlIFsEWVfbRLWttxnaaH7JoBzUwS9oTY6IszqIp3v56NM1hSu8uJoZFjWW JC5zSi7AS56C96YY2qp9ZyUl45skTZU= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-273-16j5O8zHMCyQndiwZ1J9aw-1; Fri, 07 May 2021 10:44:22 -0400 X-MC-Unique: 16j5O8zHMCyQndiwZ1J9aw-1 Received: by mail-wr1-f72.google.com with SMTP id s7-20020adfc5470000b0290106eef17cbdso3677887wrf.11 for ; Fri, 07 May 2021 07:44:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kLWd0gsOs/zJbnWSmwYcEDNmDuRZ+yJPcTXC6c2hf6w=; b=KZu/VEUO8dCwOMQicT2knp8SGaXr1/u+P8P7ouQWjvhXV8ciLP7IXhbhnJ17M6pZe2 xSGdEibWpNOqmsNAYVpJC+X5azu92o3rp7vBus1K5FpqeGTMqd1dQxlursteMCK0+HyF 7imk8GkS+yFca/GHe7e8XMvHidEl8n299HbKGz2mj1oBsce1u8+2P4w2mE7LbseoJwbi FMIl0JvJ2nC+RzO+MQKUwMiu5grrgCDpnXP5WVmN3B401PtXQ9k29Mwmrg+0H3PZVysJ UwZxUwfwnPT26PY49H7IKFrg7e6/z0wc3DU9x+fIiaMKaQMd3QdV/cd9JhGD5Zg7qBV/ JWRw== X-Gm-Message-State: AOAM531xzAX4QhUqtQgb4ORD342dQ6hfZgpgRfTe7Xv3+F/er1knz+vR uX3Zz/hLfpZ/h0mmw73cfoxDrku2//9glwDkId68vHcHZsWdVf/Z+b7BXzc8RrT/O9hmmpBCh7x 93rhv59ke9QbVdxjVNxOV0pFH6tPrc/y9+DsK2RPZV7l5i0/QHMyS9qPU8fiE7hSO X-Received: by 2002:a05:600c:284:: with SMTP id 4mr10237640wmk.88.1620398660682; Fri, 07 May 2021 07:44:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAOOvRCHRw9pYpzgMzgqmnnpC9HZrmREjC7M9ldlWU6MI2H0ObL9x1a/PosyHMj8fhzWACXw== X-Received: by 2002:a05:600c:284:: with SMTP id 4mr10237606wmk.88.1620398660291; Fri, 07 May 2021 07:44:20 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id f11sm13853458wmq.41.2021.05.07.07.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:44:19 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 13/17] gdbstub: Replace GdbCmdContext with plain g_array() Date: Fri, 7 May 2021 16:43:11 +0200 Message-Id: <20210507144315.1994337-14-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée Instead of jumping through hoops let glib deal with both tracking the number of elements and auto freeing the memory once we are done. This allows is to drop the usage of ALLOCA(3) which the man-page mentions its "use is discouraged". Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20210506160741.9841-1-alex.bennee@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- gdbstub.c | 314 +++++++++++++++++++++++++----------------------------- 1 file changed, 146 insertions(+), 168 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 83d47c67325..5e9e8e3e006 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1338,6 +1338,8 @@ typedef union GdbCmdVariant { } thread_id; } GdbCmdVariant; +#define get_param(p, i) (&g_array_index(p, GdbCmdVariant, i)) + static const char *cmd_next_param(const char *param, const char delimiter) { static const char all_delimiters[] = ",;:="; @@ -1363,54 +1365,46 @@ static const char *cmd_next_param(const char *param, const char delimiter) } static int cmd_parse_params(const char *data, const char *schema, - GdbCmdVariant *params, int *num_params) + GArray *params) { - int curr_param; const char *curr_schema, *curr_data; - *num_params = 0; - - if (!schema) { - return 0; - } + g_assert(schema); + g_assert(params->len == 0); curr_schema = schema; - curr_param = 0; curr_data = data; while (curr_schema[0] && curr_schema[1] && *curr_data) { + GdbCmdVariant this_param; + switch (curr_schema[0]) { case 'l': if (qemu_strtoul(curr_data, &curr_data, 16, - ¶ms[curr_param].val_ul)) { + &this_param.val_ul)) { return -EINVAL; } - curr_param++; curr_data = cmd_next_param(curr_data, curr_schema[1]); break; case 'L': if (qemu_strtou64(curr_data, &curr_data, 16, - (uint64_t *)¶ms[curr_param].val_ull)) { + (uint64_t *)&this_param.val_ull)) { return -EINVAL; } - curr_param++; curr_data = cmd_next_param(curr_data, curr_schema[1]); break; case 's': - params[curr_param].data = curr_data; - curr_param++; + this_param.data = curr_data; curr_data = cmd_next_param(curr_data, curr_schema[1]); break; case 'o': - params[curr_param].opcode = *(uint8_t *)curr_data; - curr_param++; + this_param.opcode = *(uint8_t *)curr_data; curr_data = cmd_next_param(curr_data, curr_schema[1]); break; case 't': - params[curr_param].thread_id.kind = + this_param.thread_id.kind = read_thread_id(curr_data, &curr_data, - ¶ms[curr_param].thread_id.pid, - ¶ms[curr_param].thread_id.tid); - curr_param++; + &this_param.thread_id.pid, + &this_param.thread_id.tid); curr_data = cmd_next_param(curr_data, curr_schema[1]); break; case '?': @@ -1419,19 +1413,14 @@ static int cmd_parse_params(const char *data, const char *schema, default: return -EINVAL; } + g_array_append_val(params, this_param); curr_schema += 2; } - *num_params = curr_param; return 0; } -typedef struct GdbCmdContext { - GdbCmdVariant *params; - int num_params; -} GdbCmdContext; - -typedef void (*GdbCmdHandler)(GdbCmdContext *gdb_ctx, void *user_ctx); +typedef void (*GdbCmdHandler)(GArray *params, void *user_ctx); /* * cmd_startswith -> cmd is compared using startswith @@ -1471,8 +1460,8 @@ static inline int startswith(const char *string, const char *pattern) static int process_string_cmd(void *user_ctx, const char *data, const GdbCmdParseEntry *cmds, int num_cmds) { - int i, schema_len, max_num_params = 0; - GdbCmdContext gdb_ctx; + int i; + g_autoptr(GArray) params = g_array_new(false, true, sizeof(GdbCmdVariant)); if (!cmds) { return -1; @@ -1488,24 +1477,13 @@ static int process_string_cmd(void *user_ctx, const char *data, } if (cmd->schema) { - schema_len = strlen(cmd->schema); - if (schema_len % 2) { - return -2; + if (cmd_parse_params(&data[strlen(cmd->cmd)], + cmd->schema, params)) { + return -1; } - - max_num_params = schema_len / 2; } - gdb_ctx.params = - (GdbCmdVariant *)alloca(sizeof(*gdb_ctx.params) * max_num_params); - memset(gdb_ctx.params, 0, sizeof(*gdb_ctx.params) * max_num_params); - - if (cmd_parse_params(&data[strlen(cmd->cmd)], cmd->schema, - gdb_ctx.params, &gdb_ctx.num_params)) { - return -1; - } - - cmd->handler(&gdb_ctx, user_ctx); + cmd->handler(params, user_ctx); return 0; } @@ -1528,18 +1506,18 @@ static void run_cmd_parser(const char *data, const GdbCmdParseEntry *cmd) } } -static void handle_detach(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_detach(GArray *params, void *user_ctx) { GDBProcess *process; uint32_t pid = 1; if (gdbserver_state.multiprocess) { - if (!gdb_ctx->num_params) { + if (!params->len) { put_packet("E22"); return; } - pid = gdb_ctx->params[0].val_ul; + pid = get_param(params, 0)->val_ul; } process = gdb_get_process(pid); @@ -1562,22 +1540,22 @@ static void handle_detach(GdbCmdContext *gdb_ctx, void *user_ctx) put_packet("OK"); } -static void handle_thread_alive(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_thread_alive(GArray *params, void *user_ctx) { CPUState *cpu; - if (!gdb_ctx->num_params) { + if (!params->len) { put_packet("E22"); return; } - if (gdb_ctx->params[0].thread_id.kind == GDB_READ_THREAD_ERR) { + if (get_param(params, 0)->thread_id.kind == GDB_READ_THREAD_ERR) { put_packet("E22"); return; } - cpu = gdb_get_cpu(gdb_ctx->params[0].thread_id.pid, - gdb_ctx->params[0].thread_id.tid); + cpu = gdb_get_cpu(get_param(params, 0)->thread_id.pid, + get_param(params, 0)->thread_id.tid); if (!cpu) { put_packet("E22"); return; @@ -1586,17 +1564,17 @@ static void handle_thread_alive(GdbCmdContext *gdb_ctx, void *user_ctx) put_packet("OK"); } -static void handle_continue(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_continue(GArray *params, void *user_ctx) { - if (gdb_ctx->num_params) { - gdb_set_cpu_pc(gdb_ctx->params[0].val_ull); + if (params->len) { + gdb_set_cpu_pc(get_param(params, 0)->val_ull); } gdbserver_state.signal = 0; gdb_continue(); } -static void handle_cont_with_sig(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_cont_with_sig(GArray *params, void *user_ctx) { unsigned long signal = 0; @@ -1604,8 +1582,8 @@ static void handle_cont_with_sig(GdbCmdContext *gdb_ctx, void *user_ctx) * Note: C sig;[addr] is currently unsupported and we simply * omit the addr parameter */ - if (gdb_ctx->num_params) { - signal = gdb_ctx->params[0].val_ul; + if (params->len) { + signal = get_param(params, 0)->val_ul; } gdbserver_state.signal = gdb_signal_to_target(signal); @@ -1615,27 +1593,27 @@ static void handle_cont_with_sig(GdbCmdContext *gdb_ctx, void *user_ctx) gdb_continue(); } -static void handle_set_thread(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_set_thread(GArray *params, void *user_ctx) { CPUState *cpu; - if (gdb_ctx->num_params != 2) { + if (params->len != 2) { put_packet("E22"); return; } - if (gdb_ctx->params[1].thread_id.kind == GDB_READ_THREAD_ERR) { + if (get_param(params, 1)->thread_id.kind == GDB_READ_THREAD_ERR) { put_packet("E22"); return; } - if (gdb_ctx->params[1].thread_id.kind != GDB_ONE_THREAD) { + if (get_param(params, 1)->thread_id.kind != GDB_ONE_THREAD) { put_packet("OK"); return; } - cpu = gdb_get_cpu(gdb_ctx->params[1].thread_id.pid, - gdb_ctx->params[1].thread_id.tid); + cpu = gdb_get_cpu(get_param(params, 1)->thread_id.pid, + get_param(params, 1)->thread_id.tid); if (!cpu) { put_packet("E22"); return; @@ -1645,7 +1623,7 @@ static void handle_set_thread(GdbCmdContext *gdb_ctx, void *user_ctx) * Note: This command is deprecated and modern gdb's will be using the * vCont command instead. */ - switch (gdb_ctx->params[0].opcode) { + switch (get_param(params, 0)->opcode) { case 'c': gdbserver_state.c_cpu = cpu; put_packet("OK"); @@ -1660,18 +1638,18 @@ static void handle_set_thread(GdbCmdContext *gdb_ctx, void *user_ctx) } } -static void handle_insert_bp(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_insert_bp(GArray *params, void *user_ctx) { int res; - if (gdb_ctx->num_params != 3) { + if (params->len != 3) { put_packet("E22"); return; } - res = gdb_breakpoint_insert(gdb_ctx->params[0].val_ul, - gdb_ctx->params[1].val_ull, - gdb_ctx->params[2].val_ull); + res = gdb_breakpoint_insert(get_param(params, 0)->val_ul, + get_param(params, 1)->val_ull, + get_param(params, 2)->val_ull); if (res >= 0) { put_packet("OK"); return; @@ -1683,18 +1661,18 @@ static void handle_insert_bp(GdbCmdContext *gdb_ctx, void *user_ctx) put_packet("E22"); } -static void handle_remove_bp(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_remove_bp(GArray *params, void *user_ctx) { int res; - if (gdb_ctx->num_params != 3) { + if (params->len != 3) { put_packet("E22"); return; } - res = gdb_breakpoint_remove(gdb_ctx->params[0].val_ul, - gdb_ctx->params[1].val_ull, - gdb_ctx->params[2].val_ull); + res = gdb_breakpoint_remove(get_param(params, 0)->val_ul, + get_param(params, 1)->val_ull, + get_param(params, 2)->val_ull); if (res >= 0) { put_packet("OK"); return; @@ -1717,7 +1695,7 @@ static void handle_remove_bp(GdbCmdContext *gdb_ctx, void *user_ctx) * the remote gdb to fallback to older methods. */ -static void handle_set_reg(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_set_reg(GArray *params, void *user_ctx) { int reg_size; @@ -1726,19 +1704,19 @@ static void handle_set_reg(GdbCmdContext *gdb_ctx, void *user_ctx) return; } - if (gdb_ctx->num_params != 2) { + if (params->len != 2) { put_packet("E22"); return; } - reg_size = strlen(gdb_ctx->params[1].data) / 2; - hextomem(gdbserver_state.mem_buf, gdb_ctx->params[1].data, reg_size); + reg_size = strlen(get_param(params, 1)->data) / 2; + hextomem(gdbserver_state.mem_buf, get_param(params, 1)->data, reg_size); gdb_write_register(gdbserver_state.g_cpu, gdbserver_state.mem_buf->data, - gdb_ctx->params[0].val_ull); + get_param(params, 0)->val_ull); put_packet("OK"); } -static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_get_reg(GArray *params, void *user_ctx) { int reg_size; @@ -1747,14 +1725,14 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx) return; } - if (!gdb_ctx->num_params) { + if (!params->len) { put_packet("E14"); return; } reg_size = gdb_read_register(gdbserver_state.g_cpu, gdbserver_state.mem_buf, - gdb_ctx->params[0].val_ull); + get_param(params, 0)->val_ull); if (!reg_size) { put_packet("E14"); return; @@ -1766,22 +1744,22 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx) put_strbuf(); } -static void handle_write_mem(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_write_mem(GArray *params, void *user_ctx) { - if (gdb_ctx->num_params != 3) { + if (params->len != 3) { put_packet("E22"); return; } /* hextomem() reads 2*len bytes */ - if (gdb_ctx->params[1].val_ull > strlen(gdb_ctx->params[2].data) / 2) { + if (get_param(params, 1)->val_ull > strlen(get_param(params, 2)->data) / 2) { put_packet("E22"); return; } - hextomem(gdbserver_state.mem_buf, gdb_ctx->params[2].data, - gdb_ctx->params[1].val_ull); - if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].val_ull, + hextomem(gdbserver_state.mem_buf, get_param(params, 2)->data, + get_param(params, 1)->val_ull); + if (target_memory_rw_debug(gdbserver_state.g_cpu, get_param(params, 0)->val_ull, gdbserver_state.mem_buf->data, gdbserver_state.mem_buf->len, true)) { put_packet("E14"); @@ -1791,22 +1769,22 @@ static void handle_write_mem(GdbCmdContext *gdb_ctx, void *user_ctx) put_packet("OK"); } -static void handle_read_mem(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_read_mem(GArray *params, void *user_ctx) { - if (gdb_ctx->num_params != 2) { + if (params->len != 2) { put_packet("E22"); return; } /* memtohex() doubles the required space */ - if (gdb_ctx->params[1].val_ull > MAX_PACKET_LENGTH / 2) { + if (get_param(params, 1)->val_ull > MAX_PACKET_LENGTH / 2) { put_packet("E22"); return; } - g_byte_array_set_size(gdbserver_state.mem_buf, gdb_ctx->params[1].val_ull); + g_byte_array_set_size(gdbserver_state.mem_buf, get_param(params, 1)->val_ull); - if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].val_ull, + if (target_memory_rw_debug(gdbserver_state.g_cpu, get_param(params, 0)->val_ull, gdbserver_state.mem_buf->data, gdbserver_state.mem_buf->len, false)) { put_packet("E14"); @@ -1818,19 +1796,19 @@ static void handle_read_mem(GdbCmdContext *gdb_ctx, void *user_ctx) put_strbuf(); } -static void handle_write_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_write_all_regs(GArray *params, void *user_ctx) { target_ulong addr, len; uint8_t *registers; int reg_size; - if (!gdb_ctx->num_params) { + if (!params->len) { return; } cpu_synchronize_state(gdbserver_state.g_cpu); - len = strlen(gdb_ctx->params[0].data) / 2; - hextomem(gdbserver_state.mem_buf, gdb_ctx->params[0].data, len); + len = strlen(get_param(params, 0)->data) / 2; + hextomem(gdbserver_state.mem_buf, get_param(params, 0)->data, len); registers = gdbserver_state.mem_buf->data; for (addr = 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs && len > 0; addr++) { @@ -1841,7 +1819,7 @@ static void handle_write_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) put_packet("OK"); } -static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_read_all_regs(GArray *params, void *user_ctx) { target_ulong addr, len; @@ -1859,14 +1837,14 @@ static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) put_strbuf(); } -static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_file_io(GArray *params, void *user_ctx) { - if (gdb_ctx->num_params >= 1 && gdbserver_state.current_syscall_cb) { + if (params->len >= 1 && gdbserver_state.current_syscall_cb) { target_ulong ret, err; - ret = (target_ulong)gdb_ctx->params[0].val_ull; - if (gdb_ctx->num_params >= 2) { - err = (target_ulong)gdb_ctx->params[1].val_ull; + ret = (target_ulong)get_param(params, 0)->val_ull; + if (params->len >= 2) { + err = (target_ulong)get_param(params, 1)->val_ull; } else { err = 0; } @@ -1874,7 +1852,7 @@ static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) gdbserver_state.current_syscall_cb = NULL; } - if (gdb_ctx->num_params >= 3 && gdb_ctx->params[2].opcode == (uint8_t)'C') { + if (params->len >= 3 && get_param(params, 2)->opcode == (uint8_t)'C') { put_packet("T02"); return; } @@ -1882,23 +1860,23 @@ static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) gdb_continue(); } -static void handle_step(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_step(GArray *params, void *user_ctx) { - if (gdb_ctx->num_params) { - gdb_set_cpu_pc((target_ulong)gdb_ctx->params[0].val_ull); + if (params->len) { + gdb_set_cpu_pc((target_ulong)get_param(params, 0)->val_ull); } cpu_single_step(gdbserver_state.c_cpu, get_sstep_flags()); gdb_continue(); } -static void handle_backward(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_backward(GArray *params, void *user_ctx) { if (replay_mode != REPLAY_MODE_PLAY) { put_packet("E22"); } - if (gdb_ctx->num_params == 1) { - switch (gdb_ctx->params[0].opcode) { + if (params->len == 1) { + switch (get_param(params, 0)->opcode) { case 's': if (replay_reverse_step()) { gdb_continue(); @@ -1920,20 +1898,20 @@ static void handle_backward(GdbCmdContext *gdb_ctx, void *user_ctx) put_packet(""); } -static void handle_v_cont_query(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_v_cont_query(GArray *params, void *user_ctx) { put_packet("vCont;c;C;s;S"); } -static void handle_v_cont(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_v_cont(GArray *params, void *user_ctx) { int res; - if (!gdb_ctx->num_params) { + if (!params->len) { return; } - res = gdb_handle_vcont(gdb_ctx->params[0].data); + res = gdb_handle_vcont(get_param(params, 0)->data); if ((res == -EINVAL) || (res == -ERANGE)) { put_packet("E22"); } else if (res) { @@ -1941,17 +1919,17 @@ static void handle_v_cont(GdbCmdContext *gdb_ctx, void *user_ctx) } } -static void handle_v_attach(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_v_attach(GArray *params, void *user_ctx) { GDBProcess *process; CPUState *cpu; g_string_assign(gdbserver_state.str_buf, "E22"); - if (!gdb_ctx->num_params) { + if (!params->len) { goto cleanup; } - process = gdb_get_process(gdb_ctx->params[0].val_ul); + process = gdb_get_process(get_param(params, 0)->val_ul); if (!process) { goto cleanup; } @@ -1972,7 +1950,7 @@ cleanup: put_strbuf(); } -static void handle_v_kill(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_v_kill(GArray *params, void *user_ctx) { /* Kill the target */ put_packet("OK"); @@ -2007,43 +1985,43 @@ static const GdbCmdParseEntry gdb_v_commands_table[] = { }, }; -static void handle_v_commands(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_v_commands(GArray *params, void *user_ctx) { - if (!gdb_ctx->num_params) { + if (!params->len) { return; } - if (process_string_cmd(NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, get_param(params, 0)->data, gdb_v_commands_table, ARRAY_SIZE(gdb_v_commands_table))) { put_packet(""); } } -static void handle_query_qemu_sstepbits(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_qemu_sstepbits(GArray *params, void *user_ctx) { g_string_printf(gdbserver_state.str_buf, "ENABLE=%x,NOIRQ=%x,NOTIMER=%x", SSTEP_ENABLE, SSTEP_NOIRQ, SSTEP_NOTIMER); put_strbuf(); } -static void handle_set_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_set_qemu_sstep(GArray *params, void *user_ctx) { - if (!gdb_ctx->num_params) { + if (!params->len) { return; } - sstep_flags = gdb_ctx->params[0].val_ul; + sstep_flags = get_param(params, 0)->val_ul; put_packet("OK"); } -static void handle_query_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_qemu_sstep(GArray *params, void *user_ctx) { g_string_printf(gdbserver_state.str_buf, "0x%x", sstep_flags); put_strbuf(); } -static void handle_query_curr_tid(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_curr_tid(GArray *params, void *user_ctx) { CPUState *cpu; GDBProcess *process; @@ -2060,7 +2038,7 @@ static void handle_query_curr_tid(GdbCmdContext *gdb_ctx, void *user_ctx) put_strbuf(); } -static void handle_query_threads(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_threads(GArray *params, void *user_ctx) { if (!gdbserver_state.query_cpu) { put_packet("l"); @@ -2073,25 +2051,25 @@ static void handle_query_threads(GdbCmdContext *gdb_ctx, void *user_ctx) gdbserver_state.query_cpu = gdb_next_attached_cpu(gdbserver_state.query_cpu); } -static void handle_query_first_threads(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_first_threads(GArray *params, void *user_ctx) { gdbserver_state.query_cpu = gdb_first_attached_cpu(); - handle_query_threads(gdb_ctx, user_ctx); + handle_query_threads(params, user_ctx); } -static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_thread_extra(GArray *params, void *user_ctx) { g_autoptr(GString) rs = g_string_new(NULL); CPUState *cpu; - if (!gdb_ctx->num_params || - gdb_ctx->params[0].thread_id.kind == GDB_READ_THREAD_ERR) { + if (!params->len || + get_param(params, 0)->thread_id.kind == GDB_READ_THREAD_ERR) { put_packet("E22"); return; } - cpu = gdb_get_cpu(gdb_ctx->params[0].thread_id.pid, - gdb_ctx->params[0].thread_id.tid); + cpu = gdb_get_cpu(get_param(params, 0)->thread_id.pid, + get_param(params, 0)->thread_id.tid); if (!cpu) { return; } @@ -2116,7 +2094,7 @@ static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx) } #ifdef CONFIG_USER_ONLY -static void handle_query_offsets(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_offsets(GArray *params, void *user_ctx) { TaskState *ts; @@ -2131,17 +2109,17 @@ static void handle_query_offsets(GdbCmdContext *gdb_ctx, void *user_ctx) put_strbuf(); } #else -static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_rcmd(GArray *params, void *user_ctx) { const guint8 zero = 0; int len; - if (!gdb_ctx->num_params) { + if (!params->len) { put_packet("E22"); return; } - len = strlen(gdb_ctx->params[0].data); + len = strlen(get_param(params, 0)->data); if (len % 2) { put_packet("E01"); return; @@ -2149,7 +2127,7 @@ static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) g_assert(gdbserver_state.mem_buf->len == 0); len = len / 2; - hextomem(gdbserver_state.mem_buf, gdb_ctx->params[0].data, len); + hextomem(gdbserver_state.mem_buf, get_param(params, 0)->data, len); g_byte_array_append(gdbserver_state.mem_buf, &zero, 1); qemu_chr_be_write(gdbserver_state.mon_chr, gdbserver_state.mem_buf->data, gdbserver_state.mem_buf->len); @@ -2157,7 +2135,7 @@ static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) } #endif -static void handle_query_supported(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_supported(GArray *params, void *user_ctx) { CPUClass *cc; @@ -2178,8 +2156,8 @@ static void handle_query_supported(GdbCmdContext *gdb_ctx, void *user_ctx) } #endif - if (gdb_ctx->num_params && - strstr(gdb_ctx->params[0].data, "multiprocess+")) { + if (params->len && + strstr(get_param(params, 0)->data, "multiprocess+")) { gdbserver_state.multiprocess = true; } @@ -2187,7 +2165,7 @@ static void handle_query_supported(GdbCmdContext *gdb_ctx, void *user_ctx) put_strbuf(); } -static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_xfer_features(GArray *params, void *user_ctx) { GDBProcess *process; CPUClass *cc; @@ -2195,7 +2173,7 @@ static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) const char *xml; const char *p; - if (gdb_ctx->num_params < 3) { + if (params->len < 3) { put_packet("E22"); return; } @@ -2208,15 +2186,15 @@ static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) } gdb_has_xml = true; - p = gdb_ctx->params[0].data; + p = get_param(params, 0)->data; xml = get_feature_xml(p, &p, process); if (!xml) { put_packet("E00"); return; } - addr = gdb_ctx->params[1].val_ul; - len = gdb_ctx->params[2].val_ul; + addr = get_param(params, 1)->val_ul; + len = get_param(params, 2)->val_ul; total_len = strlen(xml); if (addr > total_len) { put_packet("E00"); @@ -2240,18 +2218,18 @@ static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) } #if defined(CONFIG_USER_ONLY) && defined(CONFIG_LINUX_USER) -static void handle_query_xfer_auxv(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_xfer_auxv(GArray *params, void *user_ctx) { TaskState *ts; unsigned long offset, len, saved_auxv, auxv_len; - if (gdb_ctx->num_params < 2) { + if (params->len < 2) { put_packet("E22"); return; } - offset = gdb_ctx->params[0].val_ul; - len = gdb_ctx->params[1].val_ul; + offset = get_param(params, 0)->val_ul; + len = get_param(params, 1)->val_ul; ts = gdbserver_state.c_cpu->opaque; saved_auxv = ts->info->saved_auxv; auxv_len = ts->info->auxv_len; @@ -2286,12 +2264,12 @@ static void handle_query_xfer_auxv(GdbCmdContext *gdb_ctx, void *user_ctx) } #endif -static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_attached(GArray *params, void *user_ctx) { put_packet(GDB_ATTACHED); } -static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_qemu_supported(GArray *params, void *user_ctx) { g_string_printf(gdbserver_state.str_buf, "sstepbits;sstep"); #ifndef CONFIG_USER_ONLY @@ -2301,21 +2279,21 @@ static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void *user_ctx) } #ifndef CONFIG_USER_ONLY -static void handle_query_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, +static void handle_query_qemu_phy_mem_mode(GArray *params, void *user_ctx) { g_string_printf(gdbserver_state.str_buf, "%d", phy_memory_mode); put_strbuf(); } -static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_set_qemu_phy_mem_mode(GArray *params, void *user_ctx) { - if (!gdb_ctx->num_params) { + if (!params->len) { put_packet("E22"); return; } - if (!gdb_ctx->params[0].val_ul) { + if (!get_param(params, 0)->val_ul) { phy_memory_mode = 0; } else { phy_memory_mode = 1; @@ -2438,45 +2416,45 @@ static const GdbCmdParseEntry gdb_gen_set_table[] = { #endif }; -static void handle_gen_query(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_gen_query(GArray *params, void *user_ctx) { - if (!gdb_ctx->num_params) { + if (!params->len) { return; } - if (!process_string_cmd(NULL, gdb_ctx->params[0].data, + if (!process_string_cmd(NULL, get_param(params, 0)->data, gdb_gen_query_set_common_table, ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } - if (process_string_cmd(NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, get_param(params, 0)->data, gdb_gen_query_table, ARRAY_SIZE(gdb_gen_query_table))) { put_packet(""); } } -static void handle_gen_set(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_gen_set(GArray *params, void *user_ctx) { - if (!gdb_ctx->num_params) { + if (!params->len) { return; } - if (!process_string_cmd(NULL, gdb_ctx->params[0].data, + if (!process_string_cmd(NULL, get_param(params, 0)->data, gdb_gen_query_set_common_table, ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } - if (process_string_cmd(NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, get_param(params, 0)->data, gdb_gen_set_table, ARRAY_SIZE(gdb_gen_set_table))) { put_packet(""); } } -static void handle_target_halt(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_target_halt(GArray *params, void *user_ctx) { g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNAL_TRAP); gdb_append_thread_id(gdbserver_state.c_cpu, gdbserver_state.str_buf); From patchwork Fri May 7 14:43:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475563 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HUWWL7eg; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcD7305Twz9sCD for ; Sat, 8 May 2021 00:56:46 +1000 (AEST) Received: from localhost ([::1]:38062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1uG-0003bx-S7 for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:56:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1iU-00080V-Jy for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28954) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1iP-00010r-Ez for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398668; 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: in-reply-to:in-reply-to:references:references; bh=YCw70biCZtmrujveEn0uP9uiPeh7MzcdOYuA3fJ6mTo=; b=HUWWL7eg4mmxqZTApji8l28Ldnju2ZLtC0eSGAohTRiG9/D5/aasyDII3lEa2EjdCl6Zo1 +CoxQxwqSIpuRZ08c7ZRlHmP3hnQfaJ22Qvd6Sz1FCbStUZwISs6WcqmXK8qJAoq6mX2KY +52ywsn6HtwAVdw/hH4sISk58P8ZxyY= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-559-Bq-Unt5-MW2RnpMGEbn7wQ-1; Fri, 07 May 2021 10:44:26 -0400 X-MC-Unique: Bq-Unt5-MW2RnpMGEbn7wQ-1 Received: by mail-wm1-f69.google.com with SMTP id l185-20020a1c25c20000b029014b0624775eso3984717wml.6 for ; Fri, 07 May 2021 07:44:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YCw70biCZtmrujveEn0uP9uiPeh7MzcdOYuA3fJ6mTo=; b=WVUUMoBTzP0Q6QyF8Sj4FcQMj/RAbGbC6LvK7BaTHDDxV/CxnCYIDSot4L9z8popkq qt4ERJzYQwPo8j1/CeilXgXPbTU+yuwevA2nIkM4e8O2zbwlAznUDb5xlBBJFEACLPlT sqeVxCLmqUtA9wfki9uNs4KGnj1VQeTJNNIT+heEHG5OZJcHqhKySQUy5Bjd2X12IXbA 9jMHG26vd6xaEnv8HU2UaH0zUI65H0YNHqjj8oqO7OF+BDUEINib/+uZVRfRVwPYbBtU UKi0UUYL/998qJgKnz7Nv0jadYejP8To1giMKp7PtaJX4r/sgRhuYWl8qUeHpOyyal44 sQ7g== X-Gm-Message-State: AOAM532qlCF3wo+w8ZqRRVHSXHRI7YdR3EJTKCiY4xfIAkmSewIhjtkn 9ZleHWeAnFdVJ/FCmrh1fdUX10ng7j9kYy0pz+0f5z//pucm/FllktGg1C/rs/04uEWfFk+tucC qaecEsVlc/ebLmJIN11pVrAcpBCivGyQvH3GQKM3SYQCl20UyMf0E233NZMia9pXU X-Received: by 2002:adf:eb82:: with SMTP id t2mr9296103wrn.337.1620398665189; Fri, 07 May 2021 07:44:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSRPyNjkkgTHtIXUz9NIoTTHnH7rmh5hjO3wk8/LS9dlME7+ZDoSyRfzMsFicSB1f9FbtI1A== X-Received: by 2002:adf:eb82:: with SMTP id t2mr9296078wrn.337.1620398665044; Fri, 07 May 2021 07:44:25 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id l22sm12827268wmq.28.2021.05.07.07.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:44:24 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 14/17] hw/misc/pca9552: Replace g_newa() by g_new() Date: Fri, 7 May 2021 16:43:12 +0200 Message-Id: <20210507144315.1994337-15-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jeffery , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Laurent Vivier , Joel Stanley , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?C=C3=A9dri?= =?utf-8?q?c_Le_Goater?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ALLOCA(3) man-page mentions its "use is discouraged". Use autofree heap allocation instead, replacing g_newa() by g_new(). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater --- hw/misc/pca9552.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c index b7686e27d7f..facf103cbfb 100644 --- a/hw/misc/pca9552.c +++ b/hw/misc/pca9552.c @@ -71,7 +71,7 @@ static void pca955x_display_pins_status(PCA955xState *s, return; } if (trace_event_get_state_backends(TRACE_PCA955X_GPIO_STATUS)) { - char *buf = g_newa(char, k->pin_count + 1); + g_autofree char *buf = g_new(char, k->pin_count + 1); for (i = 0; i < k->pin_count; i++) { if (extract32(pins_status, i, 1)) { From patchwork Fri May 7 14:43:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475560 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=C08KcZ1k; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcD3F4y5fz9sXS for ; Sat, 8 May 2021 00:53:29 +1000 (AEST) Received: from localhost ([::1]:58078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1r5-0000II-Mu for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:53:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1if-00085L-KQ for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1iW-000142-ST for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398675; 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: in-reply-to:in-reply-to:references:references; bh=C+MYJWIsLohbCHlMSEIGcZQyDaEDuU9Kl0ow5213YNc=; b=C08KcZ1kPHCiN59eRkWnfgLji7+7c2gy17NPT6hPF+uMpXmQyagPqB5S1hKivR39p9fnhv HZwBYmukYos5R9b/G13xNley3m0SywM5tMbwfel/Z1PwBNpRMqQkXPvQNkOXVaKeXljkio UPb8mzrzK8Xp2IVD9iH1/JQiuVd3m2s= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-269-xljEdoMGPFGkQmFvHex3Og-1; Fri, 07 May 2021 10:44:31 -0400 X-MC-Unique: xljEdoMGPFGkQmFvHex3Og-1 Received: by mail-wm1-f71.google.com with SMTP id w21-20020a7bc1150000b029014a850581efso2319704wmi.6 for ; Fri, 07 May 2021 07:44:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C+MYJWIsLohbCHlMSEIGcZQyDaEDuU9Kl0ow5213YNc=; b=nNtApEeL4F0L8Q69hLrv4qa/iSxNFbHLXEVIpwxQopRJwOb7M5pRRsoBpWcXi4i0Lq z9ysnWPrZLinqmvdXsmcSBHi8DUmdKQIyc6/u6fLGxybS9PEb+E4lHbGeMld6jNlwtd2 cV1uFYFxcwNBx0q8cMGQBk5ocC0ndHPmO/e15/0kSpwdRGtRVeDB8UB4dCiJpQT1U3gk MijXHVV1JKZFDtOuDAI0o0Au7O/qqs9HAu7aKImHEsGZyQNEJXC5F9LWDo9AXqKZYsMT wqjreR4+QqUnhti+BTpgqn6hxAH8dixc8VP7LvvOUd8S0qcremAq80JpqqENwjj9mPGo CySg== X-Gm-Message-State: AOAM530MhfB+ezqf/lQk4Qtm5rxldb0vkMvk7MOyxPYAWZcNtuKAsTQN RmQ84bxzGPyGoXbjVaw3H3jrJcj2+Iq9HS4nnJ+g6xsVMyVF1VfUvhRvz+aW10yLSXAX1aPyKBn 9jSMuAsCUYcoB9AZKbvtg5qshhPkEJwKhoA4el6fuECwLkpAssFcPqeH8u1ivTfK7 X-Received: by 2002:adf:f80f:: with SMTP id s15mr12876035wrp.341.1620398670283; Fri, 07 May 2021 07:44:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyV3LXdgDeT9W3nPy2PYFEyT0xnL/c2fIbnfgtcygElbhUWgwrD2nI+U4GtCxZ9QE5ZsaU17g== X-Received: by 2002:adf:f80f:: with SMTP id s15mr12876009wrp.341.1620398670157; Fri, 07 May 2021 07:44:30 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id r13sm8833726wrn.2.2021.05.07.07.44.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:44:29 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 15/17] target/ppc/kvm: Replace alloca() by g_malloc() Date: Fri, 7 May 2021 16:43:13 +0200 Message-Id: <20210507144315.1994337-16-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "open list:Overall KVM CPUs" , =?utf-8?q?Philippe_Math?= =?utf-8?q?ieu-Daud=C3=A9?= , Laurent Vivier , Greg Kurz , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ALLOCA(3) man-page mentions its "use is discouraged". Use autofree heap allocation instead, replacing it by a g_malloc call. Reviewed-by: Greg Kurz Signed-off-by: Philippe Mathieu-Daudé Acked-by: David Gibson --- target/ppc/kvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 104a308abb5..23c4ea377e8 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2698,11 +2698,11 @@ int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns) int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index, uint16_t n_valid, uint16_t n_invalid, Error **errp) { - struct kvm_get_htab_header *buf; + g_autofree struct kvm_get_htab_header *buf = NULL; size_t chunksize = sizeof(*buf) + n_valid * HASH_PTE_SIZE_64; ssize_t rc; - buf = alloca(chunksize); + buf = g_malloc(chunksize); buf->index = index; buf->n_valid = n_valid; buf->n_invalid = n_invalid; From patchwork Fri May 7 14:43:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475564 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=b+lmaPB1; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcD775VL2z9sCD for ; Sat, 8 May 2021 00:56:51 +1000 (AEST) Received: from localhost ([::1]:38494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf1uL-0003mT-L8 for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 10:56:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1ii-0008CH-Bc for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46522) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1ic-00016R-2f for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398680; 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: in-reply-to:in-reply-to:references:references; bh=ZhnR5sl6IQkPWyz310rG2u37bBKdYZca+FWR4sH4smk=; b=b+lmaPB1mIOv6vsS5qpY+naTHzrYqavCja3GAJVzhVzDXSIIUuYZ3+Br9n5gmwN3wquORh R1aHq/Cagw2mRdgxPqzdg/8juBvhYYGEPvFV6aJ8wMYcDTLYPF+5Co33KdOvE11jdOHNRN /7pzKTOoWmnf+DR9GuXOP7DozqljlHQ= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-505--vS3DOM6PiOwt6qVs9MHSw-1; Fri, 07 May 2021 10:44:36 -0400 X-MC-Unique: -vS3DOM6PiOwt6qVs9MHSw-1 Received: by mail-wm1-f70.google.com with SMTP id j3-20020a1c55030000b029012e7c06101aso1464674wmb.5 for ; Fri, 07 May 2021 07:44:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZhnR5sl6IQkPWyz310rG2u37bBKdYZca+FWR4sH4smk=; b=fjmS/U6TuEXjS9cJybZFPpIEarEY/4RoeMldrqfs/N0LmOM7t4EF8bwyXBDVaGp193 kYWj3o3/fEufiOtsDib4SG05iPf3fVq1nbRKEUrF6gwfK3xisQJi4zn0ynfwsAPgLjzr 6fEVPZkAkdui9nyD9Qp9skX2qN2A94ShV8JNKjtMfbEVxd/MY0ZsVu0hlMn5z7Om6QrK wk0UAN25+Va+8tK/3uu+cOOlwPG+M7cMhJzSK+yRXw7KroYAOLVmFoppYYJwrIzi4DYJ v4u23I6vV5cs8RgcQsK1dNneWpGmHxNBE+YqbvKqcsCudSZvDIcDROoK8eX7dDJcb/95 9KFw== X-Gm-Message-State: AOAM530duUBUBM0q9n38dSK1Ad/Upi5AEp/EI4KynRRMzJgmSoNiHtCQ krpv2hJtNz/3Zf3a1C8jJk3kVFc6eRaL8QNW9IH046YIoJxDK8Xw7mItPHkzp2anDHkWH+7cQqW XCMhPMgmVXsFi8Yemdc4X/HFpnf1NTtb4sSaQP/m99c6LhfrjWBbu+4HMSWVTG0Wb X-Received: by 2002:a5d:6981:: with SMTP id g1mr12599763wru.426.1620398675169; Fri, 07 May 2021 07:44:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzy8lnmrGYH8Fsy8pQZm8qEaMhZejrbeQOUztL4n5JHO8452/CrhiGGEhSj68CBg7KRdDUmFg== X-Received: by 2002:a5d:6981:: with SMTP id g1mr12599729wru.426.1620398674953; Fri, 07 May 2021 07:44:34 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id v21sm13520162wml.5.2021.05.07.07.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:44:34 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 16/17] configure: Prohibit alloca() by using -Walloca CPPFLAG Date: Fri, 7 May 2021 16:43:14 +0200 Message-Id: <20210507144315.1994337-17-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Now that we removed all alloca() calls in the repository, add the -Walloca CPPFLAG to trigger a build failure if such stack allocation is used. Rationale: The ALLOCA(3) man-page mentions its "use is discouraged". Signed-off-by: Philippe Mathieu-Daudé --- As there is an alloca() call in libslirp, this patch is pending on the following libslirp patch to be merged: https://lists.freedesktop.org/archives/slirp/2021-May/000150.html (and the submodule updated). --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 4f374b48890..67cb6d5421c 100755 --- a/configure +++ b/configure @@ -552,7 +552,7 @@ ARFLAGS="${ARFLAGS-rv}" # provides these semantics.) QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv $QEMU_CFLAGS" QEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS" -QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS" +QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls -Walloca $QEMU_CFLAGS" QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS" # Flags that are needed during configure but later taken care of by Meson From patchwork Fri May 7 14:43:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475569 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T+CYQsN0; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcDGf5P4Tz9sW7 for ; Sat, 8 May 2021 01:03:22 +1000 (AEST) Received: from localhost ([::1]:52012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf20e-0001LP-F9 for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 11:03:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1ih-00089g-9q for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59163) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf1ie-00016t-M7 for qemu-devel@nongnu.org; Fri, 07 May 2021 10:44:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398682; 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: in-reply-to:in-reply-to:references:references; bh=3LzYOi9y3/bAg2bf530/ErMOAU+nSy3193hDlzyrvOQ=; b=T+CYQsN0PkVXYgqaHMxK+gvJwsXsfdqrvJ3vKUt9/VapK8iwtF79BIOtBjD2Q5anSizQeS 3bGbj5ByttxYMzDMKWm2DfITFKpj0rnJ3PKOkmmT7uIFMa743XXfaYE+8lUZp9CznJiAOn 19jK9C7W+H9J8lc0vgtMm68Fr+btBC4= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-250-jF6J3VrTNQ-BHGE-SUq0QQ-1; Fri, 07 May 2021 10:44:41 -0400 X-MC-Unique: jF6J3VrTNQ-BHGE-SUq0QQ-1 Received: by mail-wr1-f71.google.com with SMTP id a7-20020adfc4470000b029010d875c66edso3673144wrg.23 for ; Fri, 07 May 2021 07:44:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3LzYOi9y3/bAg2bf530/ErMOAU+nSy3193hDlzyrvOQ=; b=gpFrX6ma5Ai/l36sS6lUSS+mpE/QNUj6pI/sXUubKYu89nEp9EfkVqfLdEBoADg8u5 FxaxgndxCmKlPv6C2731xRFk9NjSQNKoqohJG+pMbAMK0g7K4ruZ1dUbPTqbv44WKRiF uMLF3S/kgiRTuS8/5tXWwzDX7i11c1if9LLu6jUoyh6xoClhlJwOB5tj5p5m9/SrIass ETN9QzQDYQWimpjOyj65Dwy6wzA0WkoEKJ7ozI0nUmzt7CuzfgKi8Vmij59mpAoEQ0cS qKEyTJhAwaMmoknEKrs+/VgITAnLjZ+Kq9g/bSPIaHoCAtFf+abNaZsPeEyCvBXuI+vu N1zA== X-Gm-Message-State: AOAM530bIAG7e1S5a5KNQIevRMDxBWlQ/4Yy9GDCjw4tJsq81jXR+u3c plP/HG4OO9zlNLi7TAhNNWEqUvVI8MsPUOviLfkPlucAle2wmBJsid06VUxbnnz4qwsdQAf0SHS jt+TBA9Mv877aeDoANCtVVx8V9zC/8wmv2Dba0vSy4hfVol33WmhU+gsfYg9zUPdq X-Received: by 2002:a05:6000:144:: with SMTP id r4mr12809731wrx.128.1620398679911; Fri, 07 May 2021 07:44:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqPj6e70tDk+0Kapo/Q8l2xehNQRZ54fEglCYWvPkgmcAvqV1wQP9ylia+jNgLIxhdTdu4Bw== X-Received: by 2002:a05:6000:144:: with SMTP id r4mr12809703wrx.128.1620398679711; Fri, 07 May 2021 07:44:39 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id a9sm7223387wmj.1.2021.05.07.07.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:44:39 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [NOTFORMERGE PATCH v3 17/17] configure: libSLiRP buildsys kludge Date: Fri, 7 May 2021 16:43:15 +0200 Message-Id: <20210507144315.1994337-18-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Laurent Vivier , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Only enable -Walloca when libSLiRP is not built. Signed-off-by: Philippe Mathieu-Daudé --- configure | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 67cb6d5421c..ab5b6248253 100755 --- a/configure +++ b/configure @@ -552,7 +552,7 @@ ARFLAGS="${ARFLAGS-rv}" # provides these semantics.) QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv $QEMU_CFLAGS" QEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS" -QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls -Walloca $QEMU_CFLAGS" +QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS" QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS" # Flags that are needed during configure but later taken care of by Meson @@ -5255,6 +5255,14 @@ case "$slirp" in ;; esac +# Kludge pending an alloca() call removed from libSLiRP, see: +# https://lists.freedesktop.org/archives/slirp/2021-May/000150.html +case "$slirp" in + internal | disabled) + QEMU_CFLAGS="-Walloca $QEMU_CFLAGS" + ;; +esac + ########################################## # check for usable __NR_keyctl syscall From patchwork Fri May 7 17:19:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1475612 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QV1FKTqj; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcHLY1dTtz9sXS for ; Sat, 8 May 2021 03:21:56 +1000 (AEST) Received: from localhost ([::1]:51948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf4Ak-0003kF-1e for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 13:21:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf48x-0003is-Cw for qemu-devel@nongnu.org; Fri, 07 May 2021 13:20:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35681) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf48v-0006BW-Oh for qemu-devel@nongnu.org; Fri, 07 May 2021 13:20:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620408000; 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: in-reply-to:in-reply-to:references:references; bh=wOFcyNIJjuiw01s2VBdGQ50UDrGE+IFT929JvHJBSgU=; b=QV1FKTqj1W14XJOBqxjr+6gNbZjXaEvJG9NnRtnCvE0YVe5etOt9/Kdmj6Zpy1l6mQt1L5 pxGT3Mw0xtgEGa42yayur0RQt4Q5lxmoGb0UT3zD7Y3Giq2pVp0pmB9GVcz17VItwbSxfy xQ3LbGVx3I90O2ofjR1WSZtDy1PUerA= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-460-6BBUGffTPDWlLZQIloiv5g-1; Fri, 07 May 2021 13:19:58 -0400 X-MC-Unique: 6BBUGffTPDWlLZQIloiv5g-1 Received: by mail-wm1-f71.google.com with SMTP id y193-20020a1c32ca0000b029014cbf30c3f2so4095183wmy.1 for ; Fri, 07 May 2021 10:19:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wOFcyNIJjuiw01s2VBdGQ50UDrGE+IFT929JvHJBSgU=; b=phxVyYc4lL3cV77IKDSv3iUZP+lZedJeFyY5lFMnrIQP6VXYU0IzyfYvUP8zGg/pkh 5jmBL693FHjDhg0lRMBAy/HQ5EfJqsFeIkkVoe1QIFIBQbHdT4ltwW9fzH5Tv1QlsGsl 1UCzNMj99LybWo2NyiF3OoS5BMI3R1APRUo8LrsTcsDGlFxG1qS3f2z/k+UDoNV9gQ2v 1I6giDhaf5XyazmAkNA4ZMbDVdQbwiznIb3Dleyt6NyQEC4uRdaCJrH0R70AFFFmg22o YXZa1oS1xPW3MkYRj8zPCKtEtL6taA06hqdGDOmsJcOMr9mz1hBjVa2dIB2oY/HMe9xN DeeA== X-Gm-Message-State: AOAM533sqIR+W5ax3EBoRAqOfv5BWT2I6mlnnTd0N8UlOEM6pP/2K3D6 c8AIaaLw1zGBwjJYq5Dwr85GVJnM97GhfA3FdRttWSZ3jrNA90Ak38Nkhg6fUWK3kxPVQXsA0BP 8+GAMIy6GQscfbaY= X-Received: by 2002:a05:6000:508:: with SMTP id a8mr13680522wrf.315.1620407997132; Fri, 07 May 2021 10:19:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwg84xHcRqOfwXcWS/7YUAZoCtC8jV/rXCCK4OED+w2zkmovp5Als6sBpwh/F9cPaEN8+yiqQ== X-Received: by 2002:a05:6000:508:: with SMTP id a8mr13680500wrf.315.1620407996964; Fri, 07 May 2021 10:19:56 -0700 (PDT) Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id z14sm10304337wrt.54.2021.05.07.10.19.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 10:19:56 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Subject: [PATCH v3 18/17] tests/unit/test-char: Replace g_alloca() by buffer on the stack Date: Fri, 7 May 2021 19:19:48 +0200 Message-Id: <20210507171948.2062076-1-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ALLOCA(3) man-page mentions its "use is discouraged". Directly reserve the CharBackend on the stack. Signed-off-by: Philippe Mathieu-Daudé --- tests/unit/test-char.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/unit/test-char.c b/tests/unit/test-char.c index 5b3b48ebacd..54ce26226b3 100644 --- a/tests/unit/test-char.c +++ b/tests/unit/test-char.c @@ -574,7 +574,7 @@ static void char_udp_test_internal(Chardev *reuse_chr, int sock) struct sockaddr_in other; SocketIdleData d = { 0, }; Chardev *chr; - CharBackend *be; + CharBackend tmpbe, *be = &tmpbe; socklen_t alen = sizeof(other); int ret; char buf[10]; @@ -590,7 +590,6 @@ static void char_udp_test_internal(Chardev *reuse_chr, int sock) chr = qemu_chr_new("client", tmp, NULL); g_assert_nonnull(chr); - be = g_alloca(sizeof(CharBackend)); qemu_chr_fe_init(be, chr, &error_abort); }