From nobody Mon Feb 9 01:19:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1619282039; cv=none; d=zohomail.com; s=zohoarc; b=k0ovGBWEyBuOgz2EJL7uLoDRyzIheL1hvIsQC1lDvuzQtZRFKiF1jCSbvMuMaQFumD6+ELoIYOTue14ma6CHeB/gTaAlIRA3lKAZM9pA2b8suE/CB64bpXRnK46raglEBDERtyjPIV3rNRNtNtI8GKFLomlD9qxSawwFoXdFJmE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619282039; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CfTfHjIplvFUCZ6Pf4s7liZGutXFFwjfMMaiBUf8GIA=; b=OxdXT6eRy7l1xeznD5vuE7msH/YEbB1OMeyhJuHrEuCoko3rrPLcy5oEJ7Hw2EmTd8CxZ6BKca/XAQ5JOMLsvhI0MdH8AjWvi8Qp3WrdBmzpxrcQKrXupEk/adcqcekwrPUesr0+rjCwgj1RgWmTPV0XAJ7XeaNJ1y1hGJsEHwg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1619282039480897.2676769851223; Sat, 24 Apr 2021 09:33:59 -0700 (PDT) Received: from localhost ([::1]:48702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1laLEE-0004JG-1B for importer@patchew.org; Sat, 24 Apr 2021 12:33:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1laKih-0005m3-H8 for qemu-devel@nongnu.org; Sat, 24 Apr 2021 12:01:23 -0400 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]:44999) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1laKiD-0004It-VR for qemu-devel@nongnu.org; Sat, 24 Apr 2021 12:01:23 -0400 Received: by mail-io1-xd2c.google.com with SMTP id p8so3349321iol.11 for ; Sat, 24 Apr 2021 09:00:52 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id h4sm4055901ili.52.2021.04.24.09.00.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Apr 2021 09:00:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CfTfHjIplvFUCZ6Pf4s7liZGutXFFwjfMMaiBUf8GIA=; b=zHfIIbhGBLKTq4iSnIgjQtOOGgkkwDuTtOmNMJLOiX0GTzERlYiqyNlbE1ZKkHfyZw QX07CjdM61ju7/6NAtsOPoQCtGSstOMe6/vqbBiMweJokSagr9nCGbh6nYr6njXantYP kR2qFAXqLvVID4pHGPvWqr7xGU6EhtVifZLfTQZv82QzPu2r4VvF1jpwqb1soTrr7NCN J1KXrtmQYZO/w1FXBo8JVlApNIawYI92KyUGYGivZUpIUoyZBDRwpSn1T0WunZWQYBWu hHgV8AxRbXNl3oVvsAbYZEiLyakD12fXPdAfiP/s16Ro6s1j8MJ+p1z9f0+22tc3jy1t itEw== 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=CfTfHjIplvFUCZ6Pf4s7liZGutXFFwjfMMaiBUf8GIA=; b=Yq6ohARrrKpFke6hbz+lHDaL3YsEL7jBaparoU+sJfZlDxjnZr2uXVhXajPjW90S1/ VGDkP4uiPa4mbUuBdj21FBakZNjSuN++GDkTboRa0pOeVh0HE6SWYfQmvWltoVHohnm9 TTeUKgxe/srw+RK9ipTkUeVPHJHjskzGMkz5ZvwRPFb2KsNV01Chcp1XsK++32S15daV nnQnWZApIC9hdQ+hxsOVJvRQ2nR9s4BeYKV+QkjALcggMs2WgRrCaRDGpi+VRo1Skszb Sk7XhPqMdOnD/3V+7yQ6A6yw0YFZN6m35i0vz2i6hs5Nh5ayDLCPv43ndF56oslY4X6I bzyg== X-Gm-Message-State: AOAM531NXwL+oojc7Zt9jYHesYTPdwq3crlN17qHJmN/LevehtQKuDj1 b3g0DulnJ43K8GEoEiOj58nk5zKYRUZFZh3d X-Google-Smtp-Source: ABdhPJy4zq7Nl6O0irR3o3kt/DBk39curpy7aTTvMnhymF+fP2xIlmJj4iHzZAzUJhT8UnHA+7NsXQ== X-Received: by 2002:a02:7f86:: with SMTP id r128mr8504270jac.136.1619280051067; Sat, 24 Apr 2021 09:00:51 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PATCH v2 29/48] bsd-user: style tweak: use {} correctly Date: Sat, 24 Apr 2021 09:59:57 -0600 Message-Id: <20210424160016.15200-30-imp@bsdimp.com> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20210424160016.15200-1-imp@bsdimp.com> References: <20210424160016.15200-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d2c; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: kevans@freebsd.org, arichardson@freebsd.org, Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @bsdimp-com.20150623.gappssmtp.com) Content-Type: text/plain; charset="utf-8" From: Warner Losh Format if/for/while statements with {} always, on a separate line and fix a couple indentations issues for singletons. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/elfload.c | 147 ++++++++++++++++++++++++++++----------------- 1 file changed, 92 insertions(+), 55 deletions(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 75ccc06719..437ee82637 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -93,10 +93,12 @@ static const char *get_elf_platform(void) { static char elf_platform[] =3D "i386"; int family =3D object_property_get_int(OBJECT(thread_cpu), "family", N= ULL); - if (family > 6) + if (family > 6) { family =3D 6; - if (family >=3D 3) + } + if (family >=3D 3) { elf_platform[1] =3D '0' + family; + } return elf_platform; } =20 @@ -188,8 +190,9 @@ static inline void init_thread(struct target_pt_regs *r= egs, abi_long stack =3D infop->start_stack; memset(regs, 0, sizeof(*regs)); regs->ARM_cpsr =3D 0x10; - if (infop->entry & 1) + if (infop->entry & 1) { regs->ARM_cpsr |=3D CPSR_T; + } regs->ARM_pc =3D infop->entry & 0xfffffffe; regs->ARM_sp =3D infop->start_stack; /* FIXME - what to for failure of get_user()? */ @@ -205,8 +208,7 @@ static inline void init_thread(struct target_pt_regs *r= egs, #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 =20 -enum -{ +enum { ARM_HWCAP_ARM_SWP =3D 1 << 0, ARM_HWCAP_ARM_HALF =3D 1 << 1, ARM_HWCAP_ARM_THUMB =3D 1 << 2, @@ -252,9 +254,9 @@ static inline void init_thread(struct target_pt_regs *r= egs, #ifdef TARGET_ABI32 regs->u_regs[14] =3D infop->start_stack - 16 * 4; #else - if (personality(infop->personality) =3D=3D PER_LINUX32) + if (personality(infop->personality) =3D=3D PER_LINUX32) { regs->u_regs[14] =3D infop->start_stack - 16 * 4; - else { + } else { regs->u_regs[14] =3D infop->start_stack - 16 * 8 - STACK_BIAS; if (bsd_type =3D=3D target_freebsd) { regs->u_regs[8] =3D infop->start_stack; @@ -520,8 +522,7 @@ static inline void init_thread(struct target_pt_regs *r= egs, =20 #include "elf.h" =20 -struct exec -{ +struct exec { unsigned int a_info; /* Use macros N_MAGIC, etc for access */ unsigned int a_text; /* length of text, in bytes */ unsigned int a_data; /* length of data, in bytes */ @@ -640,7 +641,9 @@ static abi_ulong copy_elf_strings(int argc, char **argv= , void **page, exit(-1); } tmp1 =3D tmp; - while (*tmp++); + while (*tmp++) { + continue; + } len =3D tmp - tmp1; if (p < len) { /* this shouldn't happen - 128kB */ return 0; @@ -653,14 +656,14 @@ static abi_ulong copy_elf_strings(int argc, char **ar= gv, void **page, if (!pag) { pag =3D g_try_malloc0(TARGET_PAGE_SIZE); page[p / TARGET_PAGE_SIZE] =3D pag; - if (!pag) + if (!pag) { return 0; + } } } if (len =3D=3D 0 || offset =3D=3D 0) { *(pag + offset) =3D *tmp; - } - else { + } else { int bytes_to_copy =3D (len > offset) ? offset : len; tmp -=3D bytes_to_copy; p -=3D bytes_to_copy; @@ -684,8 +687,9 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct li= nux_binprm *bprm, * we'll use it for something else... */ size =3D x86_stack_size; - if (size < MAX_ARG_PAGES * TARGET_PAGE_SIZE) + if (size < MAX_ARG_PAGES * TARGET_PAGE_SIZE) { size =3D MAX_ARG_PAGES * TARGET_PAGE_SIZE; + } error =3D target_mmap(0, size + qemu_host_page_size, PROT_READ | PROT_WRITE, @@ -718,8 +722,9 @@ static void set_brk(abi_ulong start, abi_ulong end) /* page-align the start and end addresses... */ start =3D HOST_PAGE_ALIGN(start); end =3D HOST_PAGE_ALIGN(end); - if (end <=3D start) + if (end <=3D start) { return; + } if (target_mmap(start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) =3D=3D -= 1) { @@ -738,8 +743,9 @@ static void padzero(abi_ulong elf_bss, abi_ulong last_b= ss) { abi_ulong nbyte; =20 - if (elf_bss >=3D last_bss) - return; + if (elf_bss >=3D last_bss) { + return; + } =20 /* * XXX: this is really a hack : if the real host page size is smal= ler @@ -798,16 +804,18 @@ static abi_ulong create_elf_tables(abi_ulong p, int a= rgc, int envc, */ sp =3D sp & ~(abi_ulong)15; size =3D (DLINFO_ITEMS + 1) * 2; - if (k_platform) - size +=3D 2; + if (k_platform) { + size +=3D 2; + } #ifdef DLINFO_ARCH_ITEMS size +=3D DLINFO_ARCH_ITEMS * 2; #endif size +=3D envc + argc + 2; size +=3D (!ibcs ? 3 : 1); /* argc itself */ size *=3D n; - if (size & 15) - sp -=3D 16 - (size & 15); + if (size & 15) { + sp -=3D 16 - (size & 15); + } =20 /* * This is correct because Linux defines @@ -834,8 +842,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int arg= c, int envc, NEW_AUX_ENT(AT_EGID, (abi_ulong) getegid()); NEW_AUX_ENT(AT_HWCAP, (abi_ulong) ELF_HWCAP); NEW_AUX_ENT(AT_CLKTCK, (abi_ulong) sysconf(_SC_CLK_TCK)); - if (k_platform) + if (k_platform) { NEW_AUX_ENT(AT_PLATFORM, u_platform); + } #ifdef ARCH_DLINFO /* * ARCH_DLINFO must come last so platform specific code can enforce @@ -879,15 +888,16 @@ static abi_ulong load_elf_interp(struct elfhdr *inter= p_elf_ex, =20 =20 /* Now read in all of the header information */ - - if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZ= E) + if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZ= E) { return ~(abi_ulong)0UL; + } =20 elf_phdata =3D (struct elf_phdr *) malloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum); =20 - if (!elf_phdata) + if (!elf_phdata) { return ~((abi_ulong)0UL); + } =20 /* * If the size of this structure has changed, then punt, since @@ -934,16 +944,22 @@ static abi_ulong load_elf_interp(struct elfhdr *inter= p_elf_ex, } =20 eppnt =3D elf_phdata; - for (i =3D 0; i < interp_elf_ex->e_phnum; i++, eppnt++) + for (i =3D 0; i < interp_elf_ex->e_phnum; i++, eppnt++) { if (eppnt->p_type =3D=3D PT_LOAD) { int elf_type =3D MAP_PRIVATE | MAP_DENYWRITE; int elf_prot =3D 0; abi_ulong vaddr =3D 0; abi_ulong k; =20 - if (eppnt->p_flags & PF_R) elf_prot =3D PROT_READ; - if (eppnt->p_flags & PF_W) elf_prot |=3D PROT_WRITE; - if (eppnt->p_flags & PF_X) elf_prot |=3D PROT_EXEC; + if (eppnt->p_flags & PF_R) { + elf_prot =3D PROT_READ; + } + if (eppnt->p_flags & PF_W) { + elf_prot |=3D PROT_WRITE; + } + if (eppnt->p_flags & PF_X) { + elf_prot |=3D PROT_EXEC; + } if (interp_elf_ex->e_type =3D=3D ET_EXEC || load_addr_set) { elf_type |=3D MAP_FIXED; vaddr =3D eppnt->p_vaddr; @@ -972,15 +988,20 @@ static abi_ulong load_elf_interp(struct elfhdr *inter= p_elf_ex, * track of the largest address we see for this. */ k =3D load_addr + eppnt->p_vaddr + eppnt->p_filesz; - if (k > elf_bss) elf_bss =3D k; + if (k > elf_bss) { + elf_bss =3D k; + } =20 /* * Do the same thing for the memory mapping - between * elf_bss and last_bss is the bss section. */ k =3D load_addr + eppnt->p_memsz + eppnt->p_vaddr; - if (k > last_bss) last_bss =3D k; + if (k > last_bss) { + last_bss =3D k; + } } + } =20 /* Now use mmap to map the library into memory. */ =20 @@ -1061,8 +1082,9 @@ static void load_symbols(struct elfhdr *hdr, int fd) =20 lseek(fd, hdr->e_shoff, SEEK_SET); for (i =3D 0; i < hdr->e_shnum; i++) { - if (read(fd, &sechdr, sizeof(sechdr)) !=3D sizeof(sechdr)) + if (read(fd, &sechdr, sizeof(sechdr)) !=3D sizeof(sechdr)) { return; + } #ifdef BSWAP_NEEDED bswap_shdr(&sechdr); #endif @@ -1244,14 +1266,13 @@ int load_elf_binary(struct linux_binprm *bprm, stru= ct target_pt_regs *regs, elf_interpreter =3D NULL; start_code =3D ~((abi_ulong)0UL); end_code =3D 0; - start_data =3Dn 0; + start_data =3D 0; end_data =3D 0; interp_ex.a_info =3D 0; =20 for (i =3D 0; i < elf_ex.e_phnum; i++) { if (elf_ppnt->p_type =3D=3D PT_INTERP) { - if (elf_interpreter !=3D NULL) - { + if (elf_interpreter !=3D NULL) { free(elf_phdata); free(elf_interpreter); close(bprm->fd); @@ -1296,8 +1317,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct= target_pt_regs *regs, retval =3D open(path(elf_interpreter), O_RDONLY); if (retval >=3D 0) { interpreter_fd =3D retval; - } - else { + } else { perror(elf_interpreter); exit(-1); } @@ -1392,8 +1412,9 @@ int load_elf_binary(struct linux_binprm *bprm, struct= target_pt_regs *regs, */ for (i =3D 0, elf_ppnt =3D elf_phdata; i < elf_ex.e_phnum; i++, elf_ppnt++) { - if (elf_ppnt->p_type !=3D PT_LOAD) + if (elf_ppnt->p_type !=3D PT_LOAD) { continue; + } if (HOST_PAGE_ALIGN(elf_ppnt->p_vaddr) < mmap_min_addr) { guest_base =3D HOST_PAGE_ALIGN(mmap_min_addr); break; @@ -1419,12 +1440,19 @@ int load_elf_binary(struct linux_binprm *bprm, stru= ct target_pt_regs *regs, int elf_flags =3D 0; abi_ulong error; =20 - if (elf_ppnt->p_type !=3D PT_LOAD) + if (elf_ppnt->p_type !=3D PT_LOAD) { continue; + } =20 - if (elf_ppnt->p_flags & PF_R) elf_prot |=3D PROT_READ; - if (elf_ppnt->p_flags & PF_W) elf_prot |=3D PROT_WRITE; - if (elf_ppnt->p_flags & PF_X) elf_prot |=3D PROT_EXEC; + if (elf_ppnt->p_flags & PF_R) { + elf_prot |=3D PROT_READ; + } + if (elf_ppnt->p_flags & PF_W) { + elf_prot |=3D PROT_WRITE; + } + if (elf_ppnt->p_flags & PF_X) { + elf_prot |=3D PROT_EXEC; + } elf_flags =3D MAP_PRIVATE | MAP_DENYWRITE; if (elf_ex.e_type =3D=3D ET_EXEC || load_addr_set) { elf_flags |=3D MAP_FIXED; @@ -1460,8 +1488,9 @@ int load_elf_binary(struct linux_binprm *bprm, struct= target_pt_regs *regs, } =20 #ifdef LOW_ELF_STACK - if (TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr) < elf_stack) + if (TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr) < elf_stack) { elf_stack =3D TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr); + } #endif =20 if (!load_addr_set) { @@ -1475,19 +1504,26 @@ int load_elf_binary(struct linux_binprm *bprm, stru= ct target_pt_regs *regs, } } k =3D elf_ppnt->p_vaddr; - if (k < start_code) + if (k < start_code) { start_code =3D k; - if (start_data < k) + } + if (start_data < k) { start_data =3D k; + } k =3D elf_ppnt->p_vaddr + elf_ppnt->p_filesz; - if (k > elf_bss) + if (k > elf_bss) { elf_bss =3D k; - if ((elf_ppnt->p_flags & PF_X) && end_code < k) + } + if ((elf_ppnt->p_flags & PF_X) && end_code < k) { end_code =3D k; - if (end_data < k) + } + if (end_data < k) { end_data =3D k; + } k =3D elf_ppnt->p_vaddr + elf_ppnt->p_memsz; - if (k > elf_brk) elf_brk =3D k; + if (k > elf_brk) { + elf_brk =3D k; + } } =20 elf_entry +=3D load_bias; @@ -1501,8 +1537,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct= target_pt_regs *regs, if (elf_interpreter) { if (interpreter_type & 1) { elf_entry =3D load_aout_interp(&interp_ex, interpreter_fd); - } - else if (interpreter_type & 2) { + } else if (interpreter_type & 2) { elf_entry =3D load_elf_interp(&interp_elf_ex, interpreter_fd, &interp_load_addr); } @@ -1521,10 +1556,13 @@ int load_elf_binary(struct linux_binprm *bprm, stru= ct target_pt_regs *regs, =20 free(elf_phdata); =20 - if (qemu_log_enabled()) + if (qemu_log_enabled()) { load_symbols(&elf_ex, bprm->fd); + } =20 - if (interpreter_type !=3D INTERPRETER_AOUT) close(bprm->fd); + if (interpreter_type !=3D INTERPRETER_AOUT) { + close(bprm->fd); + } info->personality =3D (ibcs2_interpreter ? PER_SVR4 : PER_LINUX); =20 #ifdef LOW_ELF_STACK @@ -1554,8 +1592,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct= target_pt_regs *regs, =20 padzero(elf_bss, elf_brk); =20 - if (info->personality =3D=3D PER_SVR4) - { + if (info->personality =3D=3D PER_SVR4) { /* * Why this, you ask??? Well SVr4 maps page 0 as read-only, a= nd * some applications "depend" upon this behavior. Since we do= not --=20 2.22.1