qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/48] bsd-user style and reorg patches
@ 2021-04-24 15:59 imp
  2021-04-24 15:59 ` [PATCH v2 01/48] bsd-user: whitespace changes imp
                   ` (48 more replies)
  0 siblings, 49 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Version 2:

In version 2 I've fixed all the checkpatch.pl issues for all the files that I
touched. Since files are changed incrementally, some of the individual changes
may not pass checkpatch.pl due to pre-existing problems, but the cumulative
diff passes with just warnings. I've folded the 'if 0 should just be lost'
advice in the relevant hunks, as well as in a few places where things were
commented out.

I've included all the reviews I've got so far, but since this is my first time
with such a complex review here please let me know if I've missed following all
the conventions somehow.

I had to tweak patches 025 and 026, which had been previously reviewed (adding
static in 2 places to fix a warning). So I removed the Reviewed By: line from
it. I hope that's the proper protocol here, but if not I'm keen on suggestions.

Version 1:

This series starts to cleanup bsd-user. The current checkpatch.pl output is on
the order of 4500 lines long. These cleanups don't fix everything (there's still
plenty of errors, even in some of the files the patches touch). I've tried to
make things better in every case, but be advised that checkpatch.pl is unhappy
with many of the files still in the first 15 commits. I do plan on addressing
the issues in the future as I need to make real commits to those files. The
changes were ones that were trivial to do with scripts that I had to do for
main.c anyway. main.c is now completely clean. All the cleanup I've done
myself, and at the end of this patch trail the output is only 3500 lines...

Next, I've started to reorg the bsd-user sources. There's really 4 BSDs in the
wild (FreeBSD, NetBSD, OpenBSD and Dragonfly) that these could, in theory,
target. In the bsd-user branch, we've broken the emulation of these apart. It
largely preserves the other BSD's as is, and greatly expands FreeBSD so that we
can do package builds in user-land emulation. The other BSDs have not been
run-time tested, though the CI tooling builds some of them. It's my belief that
in the current state, even an old-school cat(1) would fail, though I am to fix
that at least for FreeBSD...

We've also added a number of other architectures than sparc and i386. Those
additions, though, are dependent on other things not yet reshuffled and or
merged, so they will be coming along in due time: mips (32 and 64 bit), arm,
aarch64 and riscv willl come in due time. powerpc might, but it's in a frightful
state. I'm open to other BSDs that wish to work along with me as well, though it
may be best to wait until after future patch sets as much is still set to
change. CHERI and related work may also happen, but that's still TBD.

In this installement, after the style stuff, I've created a
target_arch_cpu.h. Here, all the functions related to the cpu loop and similar
things are moved into there on a per-architecture basis to start to tame the
number of #ifdefs in mail. Linux-user did a similar thing years after we had
done it in the repo, and a number of different choices were made. Rather than
redo all the work from the bsd-user repo, I'm recreating / rebasing it on a
current qemu. Future patch series will address other aspects. Once they are
complete, we can look, potentially, at any refactoring between linux-user and
bsd-user. I very much explicitly want to push that to the end because otherwise
I'm completely recreating a lot of the work on the bsd-user branch rather than
just transitioning it forward to a newer qemu. This reorg was started by Stacey
Son and I've redone it with the latest code. I've added his signoff (with his
blanket permission) to those commits. Also, all of these commits pass
checkpatch.pl

Please let me know what you think, and how I might structure future patches if
there's ways I can do them better. I've switched to pull-requests with this series
since it will be easier to keep track of, especially in the future.

Warner

P.S. This has no relevance to 6.0 at all: we're too late and this feature
isn't fully integrated by this patch trail.



Warner Losh (48):
  bsd-user: whitespace changes
  bsd-user: whitespace changes
  bsd-user: whitespace changes
  bsd-user: style tweak: keyword space (
  bsd-user: style tweak: keyword space (
  bsd-user: style tweak: keyword space (
  bsd-user: style tweak: keyword space (
  bsd-user: style tweak: use C not C++ comments
  bsd-user: style tweak: use C not C++ comments
  bsd-user: Remove commented out code
  bsd-user: style tweak: Remove #if 0'd code
  bsd-user: style tweak: Remove #if 0'd code
  bsd-user: style tweak: Remove #if 0'd code
  bsd-user: style tweak: Remove #if 0'd code
  bsd-user: style tweak: return is not a function, eliminate ()
  bsd-user: style tweak: Put {} around all if/else/for statements
  bsd-user: style tweak: Fix commentary issues
  bsd-user: style tweak: Use preferred block comments
  bsd-user: style tweak: move extern to header file
  bsd-user: style tweak: use {} consistently in for / if / else
    statements
  bsd-user: style nits: return is not a function
  bsd-user: use qemu_strtoul in preference to strtol
  bsd-user: introduce host_os.h for bsd-specific code and defaults
  bsd-user: create target_arch_cpu.h
  bsd-user: move x86 (i386 and x86_64) cpu_loop to target_arch_cpu.h
  bsd-user: move sparc cpu_loop into target_arch_cpu.h as
    target_cpu_loop
  bsd-user: style tweak: space pedantry
  bsd-user: style tweak: comments
  bsd-user: style tweak: use {} correctly
  bsd-user: style tweak: fix block comments
  bsd-user: style tweak: use {} for all if statements, format else
    correctly
  bsd-user: style tweak: remove spacing after '*' and add after }
  bsd-user: style tweak: Use preferred block comments
  bsd-user: style tweak: don't assign in if statements
  bsd-user: style tweak: use {} for all if statements, format else
    correctly
  bsd-user: style tweak: Use preferred block comments
  bsd-user: style tweak: don't assign in if statements
  bsd-user: style tweak: use {} for all if statements, format else
    correctly
  bsd-user: style tweak: spaces around =, remove stray space
  bsd-user: style tweak: Use preferred block comments
  bsd-user: style tweak: don't assign in if statements
  bsd-user: style tweak: spaces around operators and commas
  bsd-user: style tweak: fold long lines
  bsd-user: style tweak: use preferred block comments
  bsd-user: style tweak: Use preferred {} in if/else statements.
  bsd-user: style tweak: Return is not a function call.
  bsd-user: style tweak: don't assign in if statement.
  bsd-user: put back a break; that had gone missing...

 bsd-user/arm/target_arch_cpu.h     |  22 +
 bsd-user/bsd-mman.h                |  42 +-
 bsd-user/bsdload.c                 |  55 +--
 bsd-user/elfload.c                 | 677 ++++++++++++++++-------------
 bsd-user/freebsd/host_os.h         |  25 ++
 bsd-user/i386/target_arch_cpu.h    | 197 +++++++++
 bsd-user/main.c                    | 657 +++-------------------------
 bsd-user/mmap.c                    | 185 +++++---
 bsd-user/netbsd/host_os.h          |  25 ++
 bsd-user/openbsd/host_os.h         |  25 ++
 bsd-user/qemu.h                    | 128 +++---
 bsd-user/sparc/target_arch_cpu.h   | 287 ++++++++++++
 bsd-user/sparc64/target_arch_cpu.h |  19 +
 bsd-user/strace.c                  |  21 +-
 bsd-user/syscall.c                 | 222 ++++++----
 bsd-user/uaccess.c                 |  27 +-
 bsd-user/x86_64/target_arch_cpu.h  |  19 +
 bsd-user/x86_64/target_syscall.h   |  15 -
 18 files changed, 1449 insertions(+), 1199 deletions(-)
 create mode 100644 bsd-user/arm/target_arch_cpu.h
 create mode 100644 bsd-user/freebsd/host_os.h
 create mode 100644 bsd-user/i386/target_arch_cpu.h
 create mode 100644 bsd-user/netbsd/host_os.h
 create mode 100644 bsd-user/openbsd/host_os.h
 create mode 100644 bsd-user/sparc/target_arch_cpu.h
 create mode 100644 bsd-user/sparc64/target_arch_cpu.h
 create mode 100644 bsd-user/x86_64/target_arch_cpu.h

-- 
2.22.1



^ permalink raw reply	[flat|nested] 84+ messages in thread

* [PATCH v2 01/48] bsd-user: whitespace changes
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 02/48] " imp
                   ` (47 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, Richard Henderson, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

keyword space paren, no space before ( in function calls, spaces around
operators.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsdload.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c
index f38c4faacf..546946b91d 100644
--- a/bsd-user/bsdload.c
+++ b/bsd-user/bsdload.c
@@ -20,11 +20,11 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
     return 0;
 }
 
-static int count(char ** vec)
+static int count(char **vec)
 {
     int         i;
 
-    for(i = 0; *vec; i++) {
+    for (i = 0; *vec; i++) {
         vec++;
     }
 
@@ -37,15 +37,15 @@ static int prepare_binprm(struct linux_binprm *bprm)
     int mode;
     int retval;
 
-    if(fstat(bprm->fd, &st) < 0) {
+    if (fstat(bprm->fd, &st) < 0) {
         return(-errno);
     }
 
     mode = st.st_mode;
-    if(!S_ISREG(mode)) {        /* Must be regular file */
+    if (!S_ISREG(mode)) {        /* Must be regular file */
         return(-EACCES);
     }
-    if(!(mode & 0111)) {        /* Must have at least one execute bit set */
+    if (!(mode & 0111)) {        /* Must have at least one execute bit set */
         return(-EACCES);
     }
 
@@ -53,7 +53,7 @@ static int prepare_binprm(struct linux_binprm *bprm)
     bprm->e_gid = getegid();
 
     /* Set-uid? */
-    if(mode & S_ISUID) {
+    if (mode & S_ISUID) {
         bprm->e_uid = st.st_uid;
     }
 
@@ -69,10 +69,10 @@ static int prepare_binprm(struct linux_binprm *bprm)
 
     memset(bprm->buf, 0, sizeof(bprm->buf));
     retval = lseek(bprm->fd, 0L, SEEK_SET);
-    if(retval >= 0) {
+    if (retval >= 0) {
         retval = read(bprm->fd, bprm->buf, 128);
     }
-    if(retval < 0) {
+    if (retval < 0) {
         perror("prepare_binprm");
         exit(-1);
         /* return(-errno); */
@@ -125,15 +125,15 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
     return sp;
 }
 
-int loader_exec(const char * filename, char ** argv, char ** envp,
-             struct target_pt_regs * regs, struct image_info *infop)
+int loader_exec(const char *filename, char **argv, char **envp,
+             struct target_pt_regs *regs, struct image_info *infop)
 {
     struct linux_binprm bprm;
     int retval;
     int i;
 
-    bprm.p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
-    for (i=0 ; i<MAX_ARG_PAGES ; i++)       /* clear page-table */
+    bprm.p = TARGET_PAGE_SIZE * MAX_ARG_PAGES - sizeof(unsigned int);
+    for (i = 0 ; i < MAX_ARG_PAGES ; i++)       /* clear page-table */
             bprm.page[i] = NULL;
     retval = open(filename, O_RDONLY);
     if (retval < 0)
@@ -147,26 +147,26 @@ int loader_exec(const char * filename, char ** argv, char ** envp,
 
     retval = prepare_binprm(&bprm);
 
-    if(retval>=0) {
+    if (retval >= 0) {
         if (bprm.buf[0] == 0x7f
                 && bprm.buf[1] == 'E'
                 && bprm.buf[2] == 'L'
                 && bprm.buf[3] == 'F') {
-            retval = load_elf_binary(&bprm,regs,infop);
+            retval = load_elf_binary(&bprm, regs, infop);
         } else {
             fprintf(stderr, "Unknown binary format\n");
             return -1;
         }
     }
 
-    if(retval>=0) {
+    if (retval >= 0) {
         /* success.  Initialize important registers */
         do_init_thread(regs, infop);
         return retval;
     }
 
     /* Something went wrong, return the inode and free the argument pages*/
-    for (i=0 ; i<MAX_ARG_PAGES ; i++) {
+    for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
         g_free(bprm.page[i]);
     }
     return(retval);
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 02/48] bsd-user: whitespace changes
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
  2021-04-24 15:59 ` [PATCH v2 01/48] bsd-user: whitespace changes imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 03/48] " imp
                   ` (46 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, Richard Henderson, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Fix various whitespace-only issues from checkpatch:
    keyword space (
    no space before ( on function calls
    spaces around operators
    suspect indentations (including one functions reindented)
    extra spaces around unary operators

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/elfload.c | 326 ++++++++++++++++++++++-----------------------
 1 file changed, 163 insertions(+), 163 deletions(-)

diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index 5f4d824d78..3c9d8c2845 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -111,7 +111,7 @@ static uint32_t get_elf_hwcap(void)
 
 #ifdef TARGET_X86_64
 #define ELF_START_MMAP 0x2aaaaab000ULL
-#define elf_check_arch(x) ( ((x) == ELF_ARCH) )
+#define elf_check_arch(x) (((x) == ELF_ARCH))
 
 #define ELF_CLASS      ELFCLASS64
 #define ELF_DATA       ELFDATA2LSB
@@ -134,7 +134,7 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x) ( ((x) == EM_386) || ((x) == EM_486) )
+#define elf_check_arch(x) (((x) == EM_386) || ((x) == EM_486))
 
 /*
  * These are used to set parameters in the core dumps.
@@ -168,7 +168,7 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 
 #define ELF_START_MMAP 0x80000000
 
-#define elf_check_arch(x) ( (x) == EM_ARM )
+#define elf_check_arch(x) ((x) == EM_ARM)
 
 #define ELF_CLASS       ELFCLASS32
 #ifdef TARGET_WORDS_BIGENDIAN
@@ -184,7 +184,7 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
     memset(regs, 0, sizeof(*regs));
     regs->ARM_cpsr = 0x10;
     if (infop->entry & 1)
-      regs->ARM_cpsr |= CPSR_T;
+        regs->ARM_cpsr |= CPSR_T;
     regs->ARM_pc = infop->entry & 0xfffffffe;
     regs->ARM_sp = infop->start_stack;
     /* FIXME - what to for failure of get_user()? */
@@ -224,9 +224,9 @@ enum
 #define ELF_START_MMAP 0x80000000
 
 #ifndef TARGET_ABI32
-#define elf_check_arch(x) ( (x) == EM_SPARCV9 || (x) == EM_SPARC32PLUS )
+#define elf_check_arch(x) ((x) == EM_SPARCV9 || (x) == EM_SPARC32PLUS)
 #else
-#define elf_check_arch(x) ( (x) == EM_SPARC32PLUS || (x) == EM_SPARC )
+#define elf_check_arch(x) ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
 #endif
 
 #define ELF_CLASS   ELFCLASS64
@@ -261,7 +261,7 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #else
 #define ELF_START_MMAP 0x80000000
 
-#define elf_check_arch(x) ( (x) == EM_SPARC )
+#define elf_check_arch(x) ((x) == EM_SPARC)
 
 #define ELF_CLASS   ELFCLASS32
 #define ELF_DATA    ELFDATA2MSB
@@ -285,13 +285,13 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 
 #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
 
-#define elf_check_arch(x) ( (x) == EM_PPC64 )
+#define elf_check_arch(x) ((x) == EM_PPC64)
 
 #define ELF_CLASS       ELFCLASS64
 
 #else
 
-#define elf_check_arch(x) ( (x) == EM_PPC )
+#define elf_check_arch(x) ((x) == EM_PPC)
 
 #define ELF_CLASS       ELFCLASS32
 
@@ -376,7 +376,7 @@ static inline void init_thread(struct target_pt_regs *_regs, struct image_info *
 
 #define ELF_START_MMAP 0x80000000
 
-#define elf_check_arch(x) ( (x) == EM_MIPS )
+#define elf_check_arch(x) ((x) == EM_MIPS)
 
 #ifdef TARGET_MIPS64
 #define ELF_CLASS   ELFCLASS64
@@ -406,7 +406,7 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 
 #define ELF_START_MMAP 0x80000000
 
-#define elf_check_arch(x) ( (x) == EM_SH )
+#define elf_check_arch(x) ((x) == EM_SH)
 
 #define ELF_CLASS ELFCLASS32
 #define ELF_DATA  ELFDATA2LSB
@@ -428,7 +428,7 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 
 #define ELF_START_MMAP 0x80000000
 
-#define elf_check_arch(x) ( (x) == EM_CRIS )
+#define elf_check_arch(x) ((x) == EM_CRIS)
 
 #define ELF_CLASS ELFCLASS32
 #define ELF_DATA  ELFDATA2LSB
@@ -448,7 +448,7 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 
 #define ELF_START_MMAP 0x80000000
 
-#define elf_check_arch(x) ( (x) == EM_68K )
+#define elf_check_arch(x) ((x) == EM_68K)
 
 #define ELF_CLASS       ELFCLASS32
 #define ELF_DATA        ELFDATA2MSB
@@ -473,7 +473,7 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 
 #define ELF_START_MMAP (0x30000000000ULL)
 
-#define elf_check_arch(x) ( (x) == ELF_ARCH )
+#define elf_check_arch(x) ((x) == ELF_ARCH)
 
 #define ELF_CLASS      ELFCLASS64
 #define ELF_DATA       ELFDATA2MSB
@@ -538,8 +538,8 @@ struct exec
 
 /* Necessary parameters */
 #define TARGET_ELF_EXEC_PAGESIZE TARGET_PAGE_SIZE
-#define TARGET_ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE-1))
-#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE-1))
+#define TARGET_ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE - 1))
+#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1))
 
 #define INTERPRETER_NONE 0
 #define INTERPRETER_AOUT 1
@@ -547,12 +547,12 @@ struct exec
 
 #define DLINFO_ITEMS 12
 
-static inline void memcpy_fromfs(void * to, const void * from, unsigned long n)
+static inline void memcpy_fromfs(void *to, const void *from, unsigned long n)
 {
         memcpy(to, from, n);
 }
 
-static int load_aout_interp(void * exptr, int interp_fd);
+static int load_aout_interp(void *exptr, int interp_fd);
 
 #ifdef BSWAP_NEEDED
 static void bswap_ehdr(struct elfhdr *ehdr)
@@ -613,7 +613,7 @@ static void bswap_sym(struct elf_sym *sym)
  * to be put directly into the top of new user memory.
  *
  */
-static abi_ulong copy_elf_strings(int argc,char ** argv, void **page,
+static abi_ulong copy_elf_strings(int argc, char **argv, void **page,
                                   abi_ulong p)
 {
     char *tmp, *tmp1, *pag = NULL;
@@ -638,10 +638,10 @@ static abi_ulong copy_elf_strings(int argc,char ** argv, void **page,
             --p; --tmp; --len;
             if (--offset < 0) {
                 offset = p % TARGET_PAGE_SIZE;
-                pag = (char *)page[p/TARGET_PAGE_SIZE];
+                pag = (char *)page[p / TARGET_PAGE_SIZE];
                 if (!pag) {
                     pag = g_try_malloc0(TARGET_PAGE_SIZE);
-                    page[p/TARGET_PAGE_SIZE] = pag;
+                    page[p / TARGET_PAGE_SIZE] = pag;
                     if (!pag)
                         return 0;
                 }
@@ -672,8 +672,8 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct linux_binprm *bprm,
      * it for args, we'll use it for something else...
      */
     size = x86_stack_size;
-    if (size < MAX_ARG_PAGES*TARGET_PAGE_SIZE)
-        size = MAX_ARG_PAGES*TARGET_PAGE_SIZE;
+    if (size < MAX_ARG_PAGES * TARGET_PAGE_SIZE)
+        size = MAX_ARG_PAGES * TARGET_PAGE_SIZE;
     error = target_mmap(0,
                         size + qemu_host_page_size,
                         PROT_READ | PROT_WRITE,
@@ -686,7 +686,7 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct linux_binprm *bprm,
     /* we reserve one extra page at the top of the stack as guard */
     target_mprotect(error + size, qemu_host_page_size, PROT_NONE);
 
-    stack_base = error + size - MAX_ARG_PAGES*TARGET_PAGE_SIZE;
+    stack_base = error + size - MAX_ARG_PAGES * TARGET_PAGE_SIZE;
     p += stack_base;
 
     for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
@@ -708,7 +708,7 @@ static void set_brk(abi_ulong start, abi_ulong end)
         end = HOST_PAGE_ALIGN(end);
         if (end <= start)
                 return;
-        if(target_mmap(start, end - start,
+        if (target_mmap(start, end - start,
                        PROT_READ | PROT_WRITE | PROT_EXEC,
                        MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) == -1) {
             perror("cannot mmap brk");
@@ -738,12 +738,12 @@ static void padzero(abi_ulong elf_bss, abi_ulong last_bss)
             end_addr = HOST_PAGE_ALIGN(elf_bss);
             if (end_addr1 < end_addr) {
                 mmap((void *)g2h_untagged(end_addr1), end_addr - end_addr1,
-                     PROT_READ|PROT_WRITE|PROT_EXEC,
-                     MAP_FIXED|MAP_PRIVATE|MAP_ANON, -1, 0);
+                     PROT_READ | PROT_WRITE | PROT_EXEC,
+                     MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0);
             }
         }
 
-        nbyte = elf_bss & (qemu_host_page_size-1);
+        nbyte = elf_bss & (qemu_host_page_size - 1);
         if (nbyte) {
             nbyte = qemu_host_page_size - nbyte;
             do {
@@ -781,10 +781,10 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
         /*
          * Force 16 byte _final_ alignment here for generality.
          */
-        sp = sp &~ (abi_ulong)15;
+        sp = sp & ~(abi_ulong)15;
         size = (DLINFO_ITEMS + 1) * 2;
         if (k_platform)
-          size += 2;
+                size += 2;
 #ifdef DLINFO_ARCH_ITEMS
         size += DLINFO_ARCH_ITEMS * 2;
 #endif
@@ -792,7 +792,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
         size += (!ibcs ? 3 : 1);        /* argc itself */
         size *= n;
         if (size & 15)
-            sp -= 16 - (size & 15);
+                sp -= 16 - (size & 15);
 
         /* This is correct because Linux defines
          * elf_addr_t as Elf32_Off / Elf64_Off
@@ -800,13 +800,13 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
 #define NEW_AUX_ENT(id, val) do {               \
             sp -= n; put_user_ual(val, sp);     \
             sp -= n; put_user_ual(id, sp);      \
-          } while(0)
+          } while (0)
 
-        NEW_AUX_ENT (AT_NULL, 0);
+        NEW_AUX_ENT(AT_NULL, 0);
 
         /* There must be exactly DLINFO_ITEMS entries here.  */
         NEW_AUX_ENT(AT_PHDR, (abi_ulong)(load_addr + exec->e_phoff));
-        NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof (struct elf_phdr)));
+        NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof(struct elf_phdr)));
         NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum));
         NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE));
         NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_load_addr));
@@ -834,90 +834,90 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
 }
 
 
-static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex,
+static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,
                                  int interpreter_fd,
                                  abi_ulong *interp_load_addr)
 {
-        struct elf_phdr *elf_phdata  =  NULL;
-        struct elf_phdr *eppnt;
-        abi_ulong load_addr = 0;
-        int load_addr_set = 0;
-        int retval;
-        abi_ulong last_bss, elf_bss;
-        abi_ulong error;
-        int i;
+    struct elf_phdr *elf_phdata  =  NULL;
+    struct elf_phdr *eppnt;
+    abi_ulong load_addr = 0;
+    int load_addr_set = 0;
+    int retval;
+    abi_ulong last_bss, elf_bss;
+    abi_ulong error;
+    int i;
 
-        elf_bss = 0;
-        last_bss = 0;
-        error = 0;
+    elf_bss = 0;
+    last_bss = 0;
+    error = 0;
 
 #ifdef BSWAP_NEEDED
-        bswap_ehdr(interp_elf_ex);
+    bswap_ehdr(interp_elf_ex);
 #endif
-        /* First of all, some simple consistency checks */
-        if ((interp_elf_ex->e_type != ET_EXEC &&
-             interp_elf_ex->e_type != ET_DYN) ||
-           !elf_check_arch(interp_elf_ex->e_machine)) {
-                return ~((abi_ulong)0UL);
-        }
+    /* First of all, some simple consistency checks */
+    if ((interp_elf_ex->e_type != ET_EXEC &&
+         interp_elf_ex->e_type != ET_DYN) ||
+        !elf_check_arch(interp_elf_ex->e_machine)) {
+        return ~((abi_ulong)0UL);
+    }
 
 
-        /* Now read in all of the header information */
+    /* Now read in all of the header information */
 
-        if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZE)
-            return ~(abi_ulong)0UL;
+    if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZE)
+        return ~(abi_ulong)0UL;
 
-        elf_phdata =  (struct elf_phdr *)
-                malloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum);
+    elf_phdata =  (struct elf_phdr *)
+        malloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum);
 
-        if (!elf_phdata)
-          return ~((abi_ulong)0UL);
+    if (!elf_phdata)
+        return ~((abi_ulong)0UL);
 
-        /*
-         * If the size of this structure has changed, then punt, since
-         * we will be doing the wrong thing.
-         */
-        if (interp_elf_ex->e_phentsize != sizeof(struct elf_phdr)) {
-            free(elf_phdata);
-            return ~((abi_ulong)0UL);
-        }
+    /*
+     * If the size of this structure has changed, then punt, since
+     * we will be doing the wrong thing.
+     */
+    if (interp_elf_ex->e_phentsize != sizeof(struct elf_phdr)) {
+        free(elf_phdata);
+        return ~((abi_ulong)0UL);
+    }
 
-        retval = lseek(interpreter_fd, interp_elf_ex->e_phoff, SEEK_SET);
-        if(retval >= 0) {
-            retval = read(interpreter_fd,
-                           (char *) elf_phdata,
-                           sizeof(struct elf_phdr) * interp_elf_ex->e_phnum);
-        }
-        if (retval < 0) {
-                perror("load_elf_interp");
-                exit(-1);
-                free (elf_phdata);
-                return retval;
-        }
+    retval = lseek(interpreter_fd, interp_elf_ex->e_phoff, SEEK_SET);
+    if (retval >= 0) {
+        retval = read(interpreter_fd,
+                      (char *) elf_phdata,
+                      sizeof(struct elf_phdr) * interp_elf_ex->e_phnum);
+    }
+    if (retval < 0) {
+        perror("load_elf_interp");
+        exit(-1);
+        free (elf_phdata);
+        return retval;
+    }
 #ifdef BSWAP_NEEDED
-        eppnt = elf_phdata;
-        for (i=0; i<interp_elf_ex->e_phnum; i++, eppnt++) {
-            bswap_phdr(eppnt);
-        }
+    eppnt = elf_phdata;
+    for (i = 0; i<interp_elf_ex->e_phnum; i++, eppnt++) {
+        bswap_phdr(eppnt);
+    }
 #endif
 
-        if (interp_elf_ex->e_type == ET_DYN) {
-            /* in order to avoid hardcoding the interpreter load
-               address in qemu, we allocate a big enough memory zone */
-            error = target_mmap(0, INTERP_MAP_SIZE,
-                                PROT_NONE, MAP_PRIVATE | MAP_ANON,
-                                -1, 0);
-            if (error == -1) {
-                perror("mmap");
-                exit(-1);
-            }
-            load_addr = error;
-            load_addr_set = 1;
+    if (interp_elf_ex->e_type == ET_DYN) {
+        /* in order to avoid hardcoding the interpreter load
+           address in qemu, we allocate a big enough memory zone */
+        error = target_mmap(0, INTERP_MAP_SIZE,
+                            PROT_NONE, MAP_PRIVATE | MAP_ANON,
+                            -1, 0);
+        if (error == -1) {
+            perror("mmap");
+            exit(-1);
         }
+        load_addr = error;
+        load_addr_set = 1;
+    }
 
-        eppnt = elf_phdata;
-        for(i=0; i<interp_elf_ex->e_phnum; i++, eppnt++)
-          if (eppnt->p_type == PT_LOAD) {
+    eppnt = elf_phdata;
+    for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++)
+        if (eppnt->p_type == PT_LOAD) {
             int elf_type = MAP_PRIVATE | MAP_DENYWRITE;
             int elf_prot = 0;
             abi_ulong vaddr = 0;
@@ -930,23 +930,23 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex,
                 elf_type |= MAP_FIXED;
                 vaddr = eppnt->p_vaddr;
             }
-            error = target_mmap(load_addr+TARGET_ELF_PAGESTART(vaddr),
-                 eppnt->p_filesz + TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr),
-                 elf_prot,
-                 elf_type,
-                 interpreter_fd,
-                 eppnt->p_offset - TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr));
+            error = target_mmap(load_addr + TARGET_ELF_PAGESTART(vaddr),
+                                eppnt->p_filesz + TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr),
+                                elf_prot,
+                                elf_type,
+                                interpreter_fd,
+                                eppnt->p_offset - TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr));
 
             if (error == -1) {
-              /* Real error */
-              close(interpreter_fd);
-              free(elf_phdata);
-              return ~((abi_ulong)0UL);
+                /* Real error */
+                close(interpreter_fd);
+                free(elf_phdata);
+                return ~((abi_ulong)0UL);
             }
 
             if (!load_addr_set && interp_elf_ex->e_type == ET_DYN) {
-              load_addr = error;
-              load_addr_set = 1;
+                load_addr = error;
+                load_addr_set = 1;
             }
 
             /*
@@ -962,31 +962,31 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex,
              */
             k = load_addr + eppnt->p_memsz + eppnt->p_vaddr;
             if (k > last_bss) last_bss = k;
-          }
+        }
 
-        /* Now use mmap to map the library into memory. */
+    /* Now use mmap to map the library into memory. */
 
-        close(interpreter_fd);
+    close(interpreter_fd);
 
-        /*
-         * Now fill out the bss section.  First pad the last page up
-         * to the page boundary, and then perform a mmap to make sure
-         * that there are zeromapped pages up to and including the last
-         * bss page.
-         */
-        padzero(elf_bss, last_bss);
-        elf_bss = TARGET_ELF_PAGESTART(elf_bss + qemu_host_page_size - 1); /* What we have mapped so far */
-
-        /* Map the last of the bss segment */
-        if (last_bss > elf_bss) {
-            target_mmap(elf_bss, last_bss-elf_bss,
-                        PROT_READ|PROT_WRITE|PROT_EXEC,
-                        MAP_FIXED|MAP_PRIVATE|MAP_ANON, -1, 0);
-        }
-        free(elf_phdata);
+    /*
+     * Now fill out the bss section.  First pad the last page up
+     * to the page boundary, and then perform a mmap to make sure
+     * that there are zeromapped pages up to and including the last
+     * bss page.
+     */
+    padzero(elf_bss, last_bss);
+    elf_bss = TARGET_ELF_PAGESTART(elf_bss + qemu_host_page_size - 1); /* What we have mapped so far */
+
+    /* Map the last of the bss segment */
+    if (last_bss > elf_bss) {
+        target_mmap(elf_bss, last_bss - elf_bss,
+                    PROT_READ | PROT_WRITE | PROT_EXEC,
+                    MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0);
+    }
+    free(elf_phdata);
 
-        *interp_load_addr = load_addr;
-        return ((abi_ulong) interp_elf_ex->e_entry) + load_addr;
+    *interp_load_addr = load_addr;
+    return ((abi_ulong) interp_elf_ex->e_entry) + load_addr;
 }
 
 static int symfind(const void *s0, const void *s1)
@@ -1102,7 +1102,7 @@ static void load_symbols(struct elfhdr *hdr, int fd)
             }
             continue;
         }
-#if defined(TARGET_ARM) || defined (TARGET_MIPS)
+#if defined(TARGET_ARM) || defined(TARGET_MIPS)
         /* The bottom address bit marks a Thumb or MIPS16 symbol.  */
         syms[i].st_value &= ~(target_ulong)1;
 #endif
@@ -1143,8 +1143,8 @@ static void load_symbols(struct elfhdr *hdr, int fd)
     syminfos = s;
 }
 
-int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
-                    struct image_info * info)
+int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
+                    struct image_info *info)
 {
     struct elfhdr elf_ex;
     struct elfhdr interp_elf_ex;
@@ -1178,13 +1178,13 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
 
     /* First of all, some simple consistency checks */
     if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) ||
-                                (! elf_check_arch(elf_ex.e_machine))) {
+                                (!elf_check_arch(elf_ex.e_machine))) {
             return -ENOEXEC;
     }
 
     bprm->p = copy_elf_strings(1, &bprm->filename, bprm->page, bprm->p);
-    bprm->p = copy_elf_strings(bprm->envc,bprm->envp,bprm->page,bprm->p);
-    bprm->p = copy_elf_strings(bprm->argc,bprm->argv,bprm->page,bprm->p);
+    bprm->p = copy_elf_strings(bprm->envc, bprm->envp, bprm->page,bprm->p);
+    bprm->p = copy_elf_strings(bprm->argc, bprm->argv, bprm->page,bprm->p);
     if (!bprm->p) {
         retval = -E2BIG;
     }
@@ -1196,21 +1196,21 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
     }
 
     retval = lseek(bprm->fd, elf_ex.e_phoff, SEEK_SET);
-    if(retval > 0) {
-        retval = read(bprm->fd, (char *) elf_phdata,
+    if (retval > 0) {
+        retval = read(bprm->fd, (char *)elf_phdata,
                                 elf_ex.e_phentsize * elf_ex.e_phnum);
     }
 
     if (retval < 0) {
         perror("load_elf_binary");
         exit(-1);
-        free (elf_phdata);
+        free(elf_phdata);
         return -errno;
     }
 
 #ifdef BSWAP_NEEDED
     elf_ppnt = elf_phdata;
-    for (i=0; i<elf_ex.e_phnum; i++, elf_ppnt++) {
+    for (i = 0; i < elf_ex.e_phnum; i++, elf_ppnt++) {
         bswap_phdr(elf_ppnt);
     }
 #endif
@@ -1227,11 +1227,11 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
     end_data = 0;
     interp_ex.a_info = 0;
 
-    for(i=0;i < elf_ex.e_phnum; i++) {
+    for (i = 0;i < elf_ex.e_phnum; i++) {
         if (elf_ppnt->p_type == PT_INTERP) {
-            if ( elf_interpreter != NULL )
+            if (elf_interpreter != NULL)
             {
-                free (elf_phdata);
+                free(elf_phdata);
                 free(elf_interpreter);
                 close(bprm->fd);
                 return -EINVAL;
@@ -1245,16 +1245,16 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
             elf_interpreter = (char *)malloc(elf_ppnt->p_filesz);
 
             if (elf_interpreter == NULL) {
-                free (elf_phdata);
+                free(elf_phdata);
                 close(bprm->fd);
                 return -ENOMEM;
             }
 
             retval = lseek(bprm->fd, elf_ppnt->p_offset, SEEK_SET);
-            if(retval >= 0) {
+            if (retval >= 0) {
                 retval = read(bprm->fd, elf_interpreter, elf_ppnt->p_filesz);
             }
-            if(retval < 0) {
+            if (retval < 0) {
                 perror("load_elf_binary2");
                 exit(-1);
             }
@@ -1265,8 +1265,8 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
 
             /* JRP - Need to add X86 lib dir stuff here... */
 
-            if (strcmp(elf_interpreter,"/usr/lib/libc.so.1") == 0 ||
-                strcmp(elf_interpreter,"/usr/lib/ld.so.1") == 0) {
+            if (strcmp(elf_interpreter, "/usr/lib/libc.so.1") == 0 ||
+                strcmp(elf_interpreter, "/usr/lib/ld.so.1") == 0) {
               ibcs2_interpreter = 1;
             }
 
@@ -1275,7 +1275,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
 #endif
             if (retval >= 0) {
                 retval = open(path(elf_interpreter), O_RDONLY);
-                if(retval >= 0) {
+                if (retval >= 0) {
                     interpreter_fd = retval;
                 }
                 else {
@@ -1287,8 +1287,8 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
 
             if (retval >= 0) {
                 retval = lseek(interpreter_fd, 0, SEEK_SET);
-                if(retval >= 0) {
-                    retval = read(interpreter_fd,bprm->buf,128);
+                if (retval >= 0) {
+                    retval = read(interpreter_fd, bprm->buf, 128);
                 }
             }
             if (retval >= 0) {
@@ -1298,7 +1298,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
             if (retval < 0) {
                 perror("load_elf_binary3");
                 exit(-1);
-                free (elf_phdata);
+                free(elf_phdata);
                 free(elf_interpreter);
                 close(bprm->fd);
                 return retval;
@@ -1308,17 +1308,17 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
     }
 
     /* Some simple consistency checks for the interpreter */
-    if (elf_interpreter){
+    if (elf_interpreter) {
         interpreter_type = INTERPRETER_ELF | INTERPRETER_AOUT;
 
         /* Now figure out which format our binary is */
         if ((N_MAGIC(interp_ex) != OMAGIC) && (N_MAGIC(interp_ex) != ZMAGIC) &&
                 (N_MAGIC(interp_ex) != QMAGIC)) {
-          interpreter_type = INTERPRETER_ELF;
+            interpreter_type = INTERPRETER_ELF;
         }
 
         if (interp_elf_ex.e_ident[0] != 0x7f ||
-                strncmp((char *)&interp_elf_ex.e_ident[1], "ELF",3) != 0) {
+                strncmp((char *)&interp_elf_ex.e_ident[1], "ELF", 3) != 0) {
             interpreter_type &= ~INTERPRETER_ELF;
         }
 
@@ -1334,20 +1334,20 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
        and then start this sucker up */
 
     {
-        char * passed_p;
+        char *passed_p;
 
         if (interpreter_type == INTERPRETER_AOUT) {
             snprintf(passed_fileno, sizeof(passed_fileno), "%d", bprm->fd);
             passed_p = passed_fileno;
 
             if (elf_interpreter) {
-                bprm->p = copy_elf_strings(1,&passed_p,bprm->page,bprm->p);
+                bprm->p = copy_elf_strings(1, &passed_p, bprm->page, bprm->p);
                 bprm->argc++;
             }
         }
         if (!bprm->p) {
             free(elf_interpreter);
-            free (elf_phdata);
+            free(elf_phdata);
             close(bprm->fd);
             return -E2BIG;
         }
@@ -1393,7 +1393,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
      * address.
      */
 
-    for(i = 0, elf_ppnt = elf_phdata; i < elf_ex.e_phnum; i++, elf_ppnt++) {
+    for (i = 0, elf_ppnt = elf_phdata; i < elf_ex.e_phnum; i++, elf_ppnt++) {
         int elf_prot = 0;
         int elf_flags = 0;
         abi_ulong error;
@@ -1538,7 +1538,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
     printf("(brk) %x\n" , info->brk);
 #endif
 
-    if ( info->personality == PER_SVR4 )
+    if (info->personality == PER_SVR4)
     {
             /* Why this, you ask???  Well SVr4 maps page 0 as read-only,
                and some applications "depend" upon this behavior.
@@ -1553,7 +1553,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
     return 0;
 }
 
-static int load_aout_interp(void * exptr, int interp_fd)
+static int load_aout_interp(void *exptr, int interp_fd)
 {
     printf("a.out interpreter not yet supported\n");
     return(0);
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 03/48] bsd-user: whitespace changes
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
  2021-04-24 15:59 ` [PATCH v2 01/48] bsd-user: whitespace changes imp
  2021-04-24 15:59 ` [PATCH v2 02/48] " imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 04/48] bsd-user: style tweak: keyword space ( imp
                   ` (45 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, Richard Henderson, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Space after keywords, no space for function calls and spaces around operators.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/main.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 798aba512c..455b8eddab 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -150,13 +150,13 @@ void cpu_loop(CPUX86State *env)
     abi_ulong pc;
     //target_siginfo_t info;
 
-    for(;;) {
+    for (;;) {
         cpu_exec_start(cs);
         trapnr = cpu_exec(cs);
         cpu_exec_end(cs);
         process_queued_cpu_work(cs);
 
-        switch(trapnr) {
+        switch (trapnr) {
         case 0x80:
             /* syscall from int $0x80 */
             if (bsd_type == target_freebsd) {
@@ -345,7 +345,7 @@ void cpu_loop(CPUX86State *env)
             {
                 int sig;
 
-                sig = gdb_handlesig (env, TARGET_SIGTRAP);
+                sig = gdb_handlesig(env, TARGET_SIGTRAP);
                 if (sig)
                   {
                     info.si_signo = sig;
@@ -398,7 +398,7 @@ static inline void save_window_offset(CPUSPARCState *env, int cwp1)
     printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx " save_cwp=%d\n",
            sp_ptr, cwp1);
 #endif
-    for(i = 0; i < 16; i++) {
+    for (i = 0; i < 16; i++) {
         /* FIXME - what to do if put_user() fails? */
         put_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
         sp_ptr += sizeof(abi_ulong);
@@ -448,7 +448,7 @@ static void restore_window(CPUSPARCState *env)
     printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx " load_cwp=%d\n",
            sp_ptr, cwp1);
 #endif
-    for(i = 0; i < 16; i++) {
+    for (i = 0; i < 16; i++) {
         /* FIXME - what to do if get_user() fails? */
         get_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
         sp_ptr += sizeof(abi_ulong);
@@ -468,7 +468,7 @@ static void flush_windows(CPUSPARCState *env)
     int offset, cwp1;
 
     offset = 1;
-    for(;;) {
+    for (;;) {
         /* if restore would invoke restore_window(), then we can stop */
         cwp1 = cpu_cwp_inc(env, env->cwp + offset);
 #ifndef TARGET_SPARC64
@@ -648,11 +648,11 @@ void cpu_loop(CPUSPARCState *env)
 #ifdef TARGET_SPARC64
         badtrap:
 #endif
-            printf ("Unhandled trap: 0x%x\n", trapnr);
+            printf("Unhandled trap: 0x%x\n", trapnr);
             cpu_dump_state(cs, stderr, 0);
-            exit (1);
+            exit(1);
         }
-        process_pending_signals (env);
+        process_pending_signals(env);
     }
 }
 
@@ -825,15 +825,15 @@ int main(int argc, char **argv)
         } else if (!strcmp(r, "cpu")) {
             cpu_model = argv[optind++];
             if (is_help_option(cpu_model)) {
-/* XXX: implement xxx_cpu_list for targets that still miss it */
+                /* XXX: implement xxx_cpu_list for targets that still miss it */
 #if defined(cpu_list)
-                    cpu_list();
+                cpu_list();
 #endif
                 exit(1);
             }
         } else if (!strcmp(r, "B")) {
-           guest_base = strtol(argv[optind++], NULL, 0);
-           have_guest_base = true;
+            guest_base = strtol(argv[optind++], NULL, 0);
+            have_guest_base = true;
         } else if (!strcmp(r, "drop-ld-preload")) {
             (void) envlist_unsetenv(envlist, "LD_PRELOAD");
         } else if (!strcmp(r, "bsd")) {
@@ -958,7 +958,7 @@ int main(int argc, char **argv)
         }
     }
 
-    if (loader_exec(filename, argv+optind, target_environ, regs, info) != 0) {
+    if (loader_exec(filename, argv + optind, target_environ, regs, info) != 0) {
         printf("Error loading %s\n", filename);
         _exit(1);
     }
@@ -1053,8 +1053,8 @@ int main(int argc, char **argv)
     env->idt.limit = 255;
 #endif
     env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1),
-                                PROT_READ|PROT_WRITE,
-                                MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+                                PROT_READ | PROT_WRITE,
+                                MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
     idt_table = g2h_untagged(env->idt.base);
     set_idt(0, 0);
     set_idt(1, 0);
@@ -1082,8 +1082,8 @@ int main(int argc, char **argv)
     {
         uint64_t *gdt_table;
         env->gdt.base = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES,
-                                    PROT_READ|PROT_WRITE,
-                                    MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+                                    PROT_READ | PROT_WRITE,
+                                    MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
         env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1;
         gdt_table = g2h_untagged(env->gdt.base);
 #ifdef TARGET_ABI32
@@ -1123,9 +1123,9 @@ int main(int argc, char **argv)
         env->pc = regs->pc;
         env->npc = regs->npc;
         env->y = regs->y;
-        for(i = 0; i < 8; i++)
+        for (i = 0; i < 8; i++)
             env->gregs[i] = regs->u_regs[i];
-        for(i = 0; i < 8; i++)
+        for (i = 0; i < 8; i++)
             env->regwptr[i] = regs->u_regs[i + 8];
     }
 #else
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 04/48] bsd-user: style tweak: keyword space (
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (2 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 03/48] " imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 05/48] " imp
                   ` (44 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, Richard Henderson, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/mmap.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index 01ec808003..0ac1b92706 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -93,11 +93,11 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
     if (start > host_start) {
         /* handle host page containing start */
         prot1 = prot;
-        for(addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) {
+        for (addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) {
             prot1 |= page_get_flags(addr);
         }
         if (host_end == host_start + qemu_host_page_size) {
-            for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
+            for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
                 prot1 |= page_get_flags(addr);
             }
             end = host_end;
@@ -110,7 +110,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
     }
     if (end < host_end) {
         prot1 = prot;
-        for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
+        for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
             prot1 |= page_get_flags(addr);
         }
         ret = mprotect(g2h_untagged(host_end - qemu_host_page_size),
@@ -148,7 +148,7 @@ static int mmap_frag(abi_ulong real_start,
 
     /* get the protection of the target pages outside the mapping */
     prot1 = 0;
-    for(addr = real_start; addr < real_end; addr++) {
+    for (addr = real_start; addr < real_end; addr++) {
         if (addr < start || addr >= end)
             prot1 |= page_get_flags(addr);
     }
@@ -225,9 +225,9 @@ static abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size)
     if (addr == 0)
         addr = mmap_next_start;
     addr_start = addr;
-    for(;;) {
+    for (;;) {
         prot = 0;
-        for(addr1 = addr; addr1 < (addr + size); addr1 += TARGET_PAGE_SIZE) {
+        for (addr1 = addr; addr1 < (addr + size); addr1 += TARGET_PAGE_SIZE) {
             prot |= page_get_flags(addr1);
         }
         if (prot == 0)
@@ -262,7 +262,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
             printf("MAP_FIXED ");
         if (flags & MAP_ANON)
             printf("MAP_ANON ");
-        switch(flags & TARGET_BSD_MAP_FLAGMASK) {
+        switch (flags & TARGET_BSD_MAP_FLAGMASK) {
         case MAP_PRIVATE:
             printf("MAP_PRIVATE ");
             break;
@@ -321,7 +321,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
         end = start + len;
         real_end = HOST_PAGE_ALIGN(end);
 
-        for(addr = real_start; addr < real_end; addr += TARGET_PAGE_SIZE) {
+        for (addr = real_start; addr < real_end; addr += TARGET_PAGE_SIZE) {
             flg = page_get_flags(addr);
             if (flg & PAGE_RESERVED) {
                 errno = ENXIO;
@@ -433,11 +433,11 @@ int target_munmap(abi_ulong start, abi_ulong len)
     if (start > real_start) {
         /* handle host page containing start */
         prot = 0;
-        for(addr = real_start; addr < start; addr += TARGET_PAGE_SIZE) {
+        for (addr = real_start; addr < start; addr += TARGET_PAGE_SIZE) {
             prot |= page_get_flags(addr);
         }
         if (real_end == real_start + qemu_host_page_size) {
-            for(addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
+            for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
                 prot |= page_get_flags(addr);
             }
             end = real_end;
@@ -447,7 +447,7 @@ int target_munmap(abi_ulong start, abi_ulong len)
     }
     if (end < real_end) {
         prot = 0;
-        for(addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
+        for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
             prot |= page_get_flags(addr);
         }
         if (prot != 0)
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 05/48] bsd-user: style tweak: keyword space (
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (3 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 04/48] bsd-user: style tweak: keyword space ( imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 06/48] " imp
                   ` (43 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, Richard Henderson, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/qemu.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index d2bcaab741..b836b603af 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -233,7 +233,7 @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
 #define __put_user(x, hptr)\
 ({\
     int size = sizeof(*hptr);\
-    switch(size) {\
+    switch (size) {\
     case 1:\
         *(uint8_t *)(hptr) = (uint8_t)(typeof(*hptr))(x);\
         break;\
@@ -255,7 +255,7 @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
 #define __get_user(x, hptr) \
 ({\
     int size = sizeof(*hptr);\
-    switch(size) {\
+    switch (size) {\
     case 1:\
         x = (typeof(*hptr))*(uint8_t *)(hptr);\
         break;\
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 06/48] bsd-user: style tweak: keyword space (
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (4 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 05/48] " imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 07/48] " imp
                   ` (42 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, Richard Henderson, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/syscall.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c
index adc3d21b54..3352735c68 100644
--- a/bsd-user/syscall.c
+++ b/bsd-user/syscall.c
@@ -95,7 +95,7 @@ static abi_long do_freebsd_sysarch(CPUX86State *env, int op, abi_ulong parms)
     abi_ulong val;
     int idx;
 
-    switch(op) {
+    switch (op) {
 #ifdef TARGET_ABI32
     case TARGET_FREEBSD_I386_SET_GSBASE:
     case TARGET_FREEBSD_I386_SET_FSBASE:
@@ -271,7 +271,7 @@ static abi_long lock_iovec(int type, struct iovec *vec, abi_ulong target_addr,
     target_vec = lock_user(VERIFY_READ, target_addr, count * sizeof(struct target_iovec), 1);
     if (!target_vec)
         return -TARGET_EFAULT;
-    for(i = 0;i < count; i++) {
+    for (i = 0;i < count; i++) {
         base = tswapl(target_vec[i].iov_base);
         vec[i].iov_len = tswapl(target_vec[i].iov_len);
         if (vec[i].iov_len != 0) {
@@ -297,7 +297,7 @@ static abi_long unlock_iovec(struct iovec *vec, abi_ulong target_addr,
     target_vec = lock_user(VERIFY_READ, target_addr, count * sizeof(struct target_iovec), 1);
     if (!target_vec)
         return -TARGET_EFAULT;
-    for(i = 0;i < count; i++) {
+    for (i = 0;i < count; i++) {
         if (target_vec[i].iov_base) {
             base = tswapl(target_vec[i].iov_base);
             unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0);
@@ -325,10 +325,10 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
 #endif
     record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
 
-    if(do_strace)
+    if (do_strace)
         print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
 
-    switch(num) {
+    switch (num) {
     case TARGET_FREEBSD_NR_exit:
 #ifdef CONFIG_GPROF
         _mcleanup();
@@ -427,10 +427,10 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
 
     record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
 
-    if(do_strace)
+    if (do_strace)
         print_netbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
 
-    switch(num) {
+    switch (num) {
     case TARGET_NETBSD_NR_exit:
 #ifdef CONFIG_GPROF
         _mcleanup();
@@ -506,10 +506,10 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
 
     record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
 
-    if(do_strace)
+    if (do_strace)
         print_openbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
 
-    switch(num) {
+    switch (num) {
     case TARGET_OPENBSD_NR_exit:
 #ifdef CONFIG_GPROF
         _mcleanup();
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 07/48] bsd-user: style tweak: keyword space (
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (5 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 06/48] " imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 08/48] bsd-user: style tweak: use C not C++ comments imp
                   ` (41 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, Richard Henderson, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/uaccess.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bsd-user/uaccess.c b/bsd-user/uaccess.c
index 91e2067933..89163257f4 100644
--- a/bsd-user/uaccess.c
+++ b/bsd-user/uaccess.c
@@ -46,7 +46,7 @@ abi_long target_strlen(abi_ulong guest_addr1)
     int max_len, len;
 
     guest_addr = guest_addr1;
-    for(;;) {
+    for (;;) {
         max_len = TARGET_PAGE_SIZE - (guest_addr & ~TARGET_PAGE_MASK);
         ptr = lock_user(VERIFY_READ, guest_addr, max_len, 1);
         if (!ptr)
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 08/48] bsd-user: style tweak: use C not C++ comments
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (6 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 07/48] " imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 09/48] " imp
                   ` (40 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, Richard Henderson, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/elfload.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index 3c9d8c2845..87154283ef 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -1010,7 +1010,7 @@ static const char *lookup_symbolxx(struct syminfo *s, target_ulong orig_addr)
     struct elf_sym *syms = s->disas_symtab.elf64;
 #endif
 
-    // binary search
+    /* binary search */
     struct elf_sym *sym;
 
     sym = bsearch(&orig_addr, syms, s->disas_num_syms, sizeof(*syms), symfind);
@@ -1092,7 +1092,7 @@ static void load_symbols(struct elfhdr *hdr, int fd)
 #ifdef BSWAP_NEEDED
         bswap_sym(syms + i);
 #endif
-        // Throw away entries which we do not need.
+        /* Throw away entries which we do not need. */
         if (syms[i].st_shndx == SHN_UNDEF ||
                 syms[i].st_shndx >= SHN_LORESERVE ||
                 ELF_ST_TYPE(syms[i].st_info) != STT_FUNC) {
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 09/48] bsd-user: style tweak: use C not C++ comments
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (7 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 08/48] bsd-user: style tweak: use C not C++ comments imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 10/48] bsd-user: Remove commented out code imp
                   ` (39 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, Richard Henderson, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/main.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 455b8eddab..ff886de98e 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -148,7 +148,7 @@ void cpu_loop(CPUX86State *env)
     CPUState *cs = env_cpu(env);
     int trapnr;
     abi_ulong pc;
-    //target_siginfo_t info;
+    /* target_siginfo_t info; */
 
     for (;;) {
         cpu_exec_start(cs);
@@ -197,7 +197,7 @@ void cpu_loop(CPUX86State *env)
                                                       arg6,
                                                       arg7,
                                                       arg8);
-            } else { //if (bsd_type == target_openbsd)
+            } else { /* if (bsd_type == target_openbsd) */
                 env->regs[R_EAX] = do_openbsd_syscall(env,
                                                       env->regs[R_EAX],
                                                       env->regs[R_EBX],
@@ -226,7 +226,7 @@ void cpu_loop(CPUX86State *env)
                                                       env->regs[R_ECX],
                                                       env->regs[8],
                                                       env->regs[9], 0, 0);
-            else { //if (bsd_type == target_openbsd)
+            else { /* if (bsd_type == target_openbsd) */
                 env->regs[R_EAX] = do_openbsd_syscall(env,
                                                       env->regs[R_EAX],
                                                       env->regs[R_EDI],
@@ -370,7 +370,7 @@ void cpu_loop(CPUX86State *env)
 #ifdef TARGET_SPARC
 #define SPARC64_STACK_BIAS 2047
 
-//#define DEBUG_WIN
+/* #define DEBUG_WIN */
 /* WARNING: dealing with register windows _is_ complicated. More info
    can be found at http://www.sics.se/~psm/sparcstack.html */
 static inline int get_reg_index(CPUSPARCState *env, int cwp, int index)
@@ -497,7 +497,7 @@ void cpu_loop(CPUSPARCState *env)
 {
     CPUState *cs = env_cpu(env);
     int trapnr, ret, syscall_nr;
-    //target_siginfo_t info;
+    /* target_siginfo_t info; */
 
     while (1) {
         cpu_exec_start(cs);
@@ -527,7 +527,7 @@ void cpu_loop(CPUSPARCState *env)
                                         env->regwptr[0], env->regwptr[1],
                                         env->regwptr[2], env->regwptr[3],
                                         env->regwptr[4], env->regwptr[5]);
-            else { //if (bsd_type == target_openbsd)
+            else { /* if (bsd_type == target_openbsd) */
 #if defined(TARGET_SPARC64)
                 syscall_nr &= ~(TARGET_OPENBSD_SYSCALL_G7RFLAG |
                                 TARGET_OPENBSD_SYSCALL_G2RFLAG);
@@ -619,7 +619,7 @@ void cpu_loop(CPUSPARCState *env)
                     info._sifields._sigfault._addr = env->dmmuregs[4];
                 else
                     info._sifields._sigfault._addr = env->tsptr->tpc;
-                //queue_signal(env, info.si_signo, &info);
+                /* queue_signal(env, info.si_signo, &info); */
             }
 #endif
             break;
@@ -639,7 +639,7 @@ void cpu_loop(CPUSPARCState *env)
                     info.si_signo = sig;
                     info.si_errno = 0;
                     info.si_code = TARGET_TRAP_BRKPT;
-                    //queue_signal(env, info.si_signo, &info);
+                    /* queue_signal(env, info.si_signo, &info); */
                   }
 #endif
             }
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 10/48] bsd-user: Remove commented out code
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (8 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 09/48] " imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:19   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 11/48] bsd-user: style tweak: Remove #if 0'd code imp
                   ` (38 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Remove dead code that's been commented out forever.

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/qemu.h | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index b836b603af..7ccc8ad397 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -71,7 +71,6 @@ struct image_info {
 
 struct sigqueue {
     struct sigqueue *next;
-    //target_siginfo_t info;
 };
 
 struct emulated_sigtable {
@@ -193,9 +192,6 @@ extern int do_strace;
 /* signal.c */
 void process_pending_signals(CPUArchState *cpu_env);
 void signal_init(void);
-//int queue_signal(CPUArchState *env, int sig, target_siginfo_t *info);
-//void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info);
-//void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo);
 long do_sigreturn(CPUArchState *env);
 long do_rt_sigreturn(CPUArchState *env);
 abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp);
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 11/48] bsd-user: style tweak: Remove #if 0'd code
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (9 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 10/48] bsd-user: Remove commented out code imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:21   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 12/48] " imp
                   ` (37 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/elfload.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index 87154283ef..2c6764d372 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -1270,9 +1270,6 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
               ibcs2_interpreter = 1;
             }
 
-#if 0
-            printf("Using ELF interpreter %s\n", path(elf_interpreter));
-#endif
             if (retval >= 0) {
                 retval = open(path(elf_interpreter), O_RDONLY);
                 if (retval >= 0) {
@@ -1529,15 +1526,6 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
 
     padzero(elf_bss, elf_brk);
 
-#if 0
-    printf("(start_brk) %x\n" , info->start_brk);
-    printf("(end_code) %x\n" , info->end_code);
-    printf("(start_code) %x\n" , info->start_code);
-    printf("(end_data) %x\n" , info->end_data);
-    printf("(start_stack) %x\n" , info->start_stack);
-    printf("(brk) %x\n" , info->brk);
-#endif
-
     if (info->personality == PER_SVR4)
     {
             /* Why this, you ask???  Well SVr4 maps page 0 as read-only,
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 12/48] bsd-user: style tweak: Remove #if 0'd code
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (10 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 11/48] bsd-user: style tweak: Remove #if 0'd code imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:23   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 13/48] " imp
                   ` (36 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/main.c | 143 ------------------------------------------------
 1 file changed, 143 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index ff886de98e..3c6c0ec687 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -244,118 +244,10 @@ void cpu_loop(CPUX86State *env)
                 env->eflags &= ~CC_C;
             }
             break;
-#endif
-#if 0
-        case EXCP0B_NOSEG:
-        case EXCP0C_STACK:
-            info.si_signo = SIGBUS;
-            info.si_errno = 0;
-            info.si_code = TARGET_SI_KERNEL;
-            info._sifields._sigfault._addr = 0;
-            queue_signal(env, info.si_signo, &info);
-            break;
-        case EXCP0D_GPF:
-            /* XXX: potential problem if ABI32 */
-#ifndef TARGET_X86_64
-            if (env->eflags & VM_MASK) {
-                handle_vm86_fault(env);
-            } else
-#endif
-            {
-                info.si_signo = SIGSEGV;
-                info.si_errno = 0;
-                info.si_code = TARGET_SI_KERNEL;
-                info._sifields._sigfault._addr = 0;
-                queue_signal(env, info.si_signo, &info);
-            }
-            break;
-        case EXCP0E_PAGE:
-            info.si_signo = SIGSEGV;
-            info.si_errno = 0;
-            if (!(env->error_code & 1))
-                info.si_code = TARGET_SEGV_MAPERR;
-            else
-                info.si_code = TARGET_SEGV_ACCERR;
-            info._sifields._sigfault._addr = env->cr[2];
-            queue_signal(env, info.si_signo, &info);
-            break;
-        case EXCP00_DIVZ:
-#ifndef TARGET_X86_64
-            if (env->eflags & VM_MASK) {
-                handle_vm86_trap(env, trapnr);
-            } else
-#endif
-            {
-                /* division by zero */
-                info.si_signo = SIGFPE;
-                info.si_errno = 0;
-                info.si_code = TARGET_FPE_INTDIV;
-                info._sifields._sigfault._addr = env->eip;
-                queue_signal(env, info.si_signo, &info);
-            }
-            break;
-        case EXCP01_DB:
-        case EXCP03_INT3:
-#ifndef TARGET_X86_64
-            if (env->eflags & VM_MASK) {
-                handle_vm86_trap(env, trapnr);
-            } else
-#endif
-            {
-                info.si_signo = SIGTRAP;
-                info.si_errno = 0;
-                if (trapnr == EXCP01_DB) {
-                    info.si_code = TARGET_TRAP_BRKPT;
-                    info._sifields._sigfault._addr = env->eip;
-                } else {
-                    info.si_code = TARGET_SI_KERNEL;
-                    info._sifields._sigfault._addr = 0;
-                }
-                queue_signal(env, info.si_signo, &info);
-            }
-            break;
-        case EXCP04_INTO:
-        case EXCP05_BOUND:
-#ifndef TARGET_X86_64
-            if (env->eflags & VM_MASK) {
-                handle_vm86_trap(env, trapnr);
-            } else
-#endif
-            {
-                info.si_signo = SIGSEGV;
-                info.si_errno = 0;
-                info.si_code = TARGET_SI_KERNEL;
-                info._sifields._sigfault._addr = 0;
-                queue_signal(env, info.si_signo, &info);
-            }
-            break;
-        case EXCP06_ILLOP:
-            info.si_signo = SIGILL;
-            info.si_errno = 0;
-            info.si_code = TARGET_ILL_ILLOPN;
-            info._sifields._sigfault._addr = env->eip;
-            queue_signal(env, info.si_signo, &info);
-            break;
 #endif
         case EXCP_INTERRUPT:
             /* just indicate that signals should be handled asap */
             break;
-#if 0
-        case EXCP_DEBUG:
-            {
-                int sig;
-
-                sig = gdb_handlesig(env, TARGET_SIGTRAP);
-                if (sig)
-                  {
-                    info.si_signo = sig;
-                    info.si_errno = 0;
-                    info.si_code = TARGET_TRAP_BRKPT;
-                    queue_signal(env, info.si_signo, &info);
-                  }
-            }
-            break;
-#endif
         default:
             pc = env->segs[R_CS].base + env->eip;
             fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
@@ -589,16 +481,6 @@ void cpu_loop(CPUSPARCState *env)
             break;
         case TT_TFAULT:
         case TT_DFAULT:
-#if 0
-            {
-                info.si_signo = SIGSEGV;
-                info.si_errno = 0;
-                /* XXX: check env->error_code */
-                info.si_code = TARGET_SEGV_MAPERR;
-                info._sifields._sigfault._addr = env->mmuregs[4];
-                queue_signal(env, info.si_signo, &info);
-            }
-#endif
             break;
 #else
         case TT_SPILL: /* window overflow */
@@ -609,19 +491,6 @@ void cpu_loop(CPUSPARCState *env)
             break;
         case TT_TFAULT:
         case TT_DFAULT:
-#if 0
-            {
-                info.si_signo = SIGSEGV;
-                info.si_errno = 0;
-                /* XXX: check env->error_code */
-                info.si_code = TARGET_SEGV_MAPERR;
-                if (trapnr == TT_DFAULT)
-                    info._sifields._sigfault._addr = env->dmmuregs[4];
-                else
-                    info._sifields._sigfault._addr = env->tsptr->tpc;
-                /* queue_signal(env, info.si_signo, &info); */
-            }
-#endif
             break;
 #endif
         case EXCP_INTERRUPT:
@@ -629,19 +498,7 @@ void cpu_loop(CPUSPARCState *env)
             break;
         case EXCP_DEBUG:
             {
-#if 0
-                int sig =
-#endif
                 gdb_handlesig(cs, TARGET_SIGTRAP);
-#if 0
-                if (sig)
-                  {
-                    info.si_signo = sig;
-                    info.si_errno = 0;
-                    info.si_code = TARGET_TRAP_BRKPT;
-                    /* queue_signal(env, info.si_signo, &info); */
-                  }
-#endif
             }
             break;
         default:
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 13/48] bsd-user: style tweak: Remove #if 0'd code
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (11 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 12/48] " imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:23   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 14/48] " imp
                   ` (35 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/strace.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/bsd-user/strace.c b/bsd-user/strace.c
index 2c3b59caf0..be40b8a20c 100644
--- a/bsd-user/strace.c
+++ b/bsd-user/strace.c
@@ -128,14 +128,6 @@ static void print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
     }
 }
 
-#if 0 /* currently unused */
-static void
-print_syscall_ret_raw(struct syscallname *name, abi_long ret)
-{
-        gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
-}
-#endif
-
 /*
  * An array of all of the syscalls we know about
  */
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 14/48] bsd-user: style tweak: Remove #if 0'd code
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (12 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 13/48] " imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:24   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 15/48] bsd-user: style tweak: return is not a function, eliminate () imp
                   ` (34 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/x86_64/target_syscall.h | 15 ---------------
 1 file changed, 15 deletions(-)

diff --git a/bsd-user/x86_64/target_syscall.h b/bsd-user/x86_64/target_syscall.h
index a8e6274b76..ec99354e15 100644
--- a/bsd-user/x86_64/target_syscall.h
+++ b/bsd-user/x86_64/target_syscall.h
@@ -59,27 +59,12 @@ struct target_pt_regs {
 #define TARGET_GDT_ENTRY_TLS_MIN 12
 #define TARGET_GDT_ENTRY_TLS_MAX 14
 
-#if 0 // Redefine this
-struct target_modify_ldt_ldt_s {
-	unsigned int  entry_number;
-        abi_ulong     base_addr;
-	unsigned int  limit;
-	unsigned int  seg_32bit:1;
-	unsigned int  contents:2;
-	unsigned int  read_exec_only:1;
-	unsigned int  limit_in_pages:1;
-	unsigned int  seg_not_present:1;
-	unsigned int  useable:1;
-	unsigned int  lm:1;
-};
-#else
 struct target_modify_ldt_ldt_s {
 	unsigned int  entry_number;
         abi_ulong     base_addr;
 	unsigned int  limit;
         unsigned int flags;
 };
-#endif
 
 struct target_ipc64_perm
 {
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 15/48] bsd-user: style tweak: return is not a function, eliminate ()
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (13 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 14/48] " imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:24   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 16/48] bsd-user: style tweak: Put {} around all if/else/for statements imp
                   ` (33 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsdload.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c
index 546946b91d..fd14ffa4cd 100644
--- a/bsd-user/bsdload.c
+++ b/bsd-user/bsdload.c
@@ -28,7 +28,7 @@ static int count(char **vec)
         vec++;
     }
 
-    return(i);
+    return i;
 }
 
 static int prepare_binprm(struct linux_binprm *bprm)
@@ -38,15 +38,15 @@ static int prepare_binprm(struct linux_binprm *bprm)
     int retval;
 
     if (fstat(bprm->fd, &st) < 0) {
-        return(-errno);
+        return -errno;
     }
 
     mode = st.st_mode;
     if (!S_ISREG(mode)) {        /* Must be regular file */
-        return(-EACCES);
+        return -EACCES;
     }
     if (!(mode & 0111)) {        /* Must have at least one execute bit set */
-        return(-EACCES);
+        return -EACCES;
     }
 
     bprm->e_uid = geteuid();
@@ -75,10 +75,9 @@ static int prepare_binprm(struct linux_binprm *bprm)
     if (retval < 0) {
         perror("prepare_binprm");
         exit(-1);
-        /* return(-errno); */
     }
     else {
-        return(retval);
+        return retval;
     }
 }
 
@@ -169,5 +168,5 @@ int loader_exec(const char *filename, char **argv, char **envp,
     for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
         g_free(bprm.page[i]);
     }
-    return(retval);
+    return retval;
 }
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 16/48] bsd-user: style tweak: Put {} around all if/else/for statements
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (14 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 15/48] bsd-user: style tweak: return is not a function, eliminate () imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:25   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 17/48] bsd-user: style tweak: Fix commentary issues imp
                   ` (32 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsdload.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c
index fd14ffa4cd..e1ed3b7b60 100644
--- a/bsd-user/bsdload.c
+++ b/bsd-user/bsdload.c
@@ -13,8 +13,9 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
     void *host_ptr;
 
     host_ptr = lock_user(VERIFY_WRITE, dest, len, 0);
-    if (!host_ptr)
+    if (!host_ptr) {
         return -TARGET_EFAULT;
+    }
     memcpy(host_ptr, src, len);
     unlock_user(host_ptr, dest, 1);
     return 0;
@@ -75,8 +76,7 @@ static int prepare_binprm(struct linux_binprm *bprm)
     if (retval < 0) {
         perror("prepare_binprm");
         exit(-1);
-    }
-    else {
+    } else {
         return retval;
     }
 }
@@ -132,11 +132,13 @@ int loader_exec(const char *filename, char **argv, char **envp,
     int i;
 
     bprm.p = TARGET_PAGE_SIZE * MAX_ARG_PAGES - sizeof(unsigned int);
-    for (i = 0 ; i < MAX_ARG_PAGES ; i++)       /* clear page-table */
+    for (i = 0 ; i < MAX_ARG_PAGES ; i++) {     /* clear page-table */
             bprm.page[i] = NULL;
+    }
     retval = open(filename, O_RDONLY);
-    if (retval < 0)
+    if (retval < 0) {
         return retval;
+    }
     bprm.fd = retval;
     bprm.filename = (char *)filename;
     bprm.argc = count(argv);
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 17/48] bsd-user: style tweak: Fix commentary issues
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (15 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 16/48] bsd-user: style tweak: Put {} around all if/else/for statements imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 18/48] bsd-user: style tweak: Use preferred block comments imp
                   ` (31 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, Richard Henderson, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Lines > 80 or 90 characters
C++ comments
BSD /*- block comment convention removed.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-mman.h | 42 ++++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/bsd-user/bsd-mman.h b/bsd-user/bsd-mman.h
index 910e8c1921..5a64d0d425 100644
--- a/bsd-user/bsd-mman.h
+++ b/bsd-user/bsd-mman.h
@@ -1,4 +1,4 @@
-/*-
+/*
  * Copyright (c) 1982, 1986, 1993
  *      The Regents of the University of California.  All rights reserved.
  *
@@ -30,16 +30,20 @@
  * $FreeBSD: src/sys/sys/mman.h,v 1.42 2008/03/28 04:29:27 ps Exp $
  */
 
-#define TARGET_FREEBSD_MAP_RESERVED0080 0x0080  /* previously misimplemented MAP_INHERIT */
-#define TARGET_FREEBSD_MAP_RESERVED0100 0x0100  /* previously unimplemented MAP_NOEXTEND */
-#define TARGET_FREEBSD_MAP_STACK        0x0400  /* region grows down, like a stack */
-#define TARGET_FREEBSD_MAP_NOSYNC       0x0800  /* page to but do not sync underlying file */
+#define TARGET_FREEBSD_MAP_RESERVED0080 0x0080
+                                 /* previously misimplemented MAP_INHERIT */
+#define TARGET_FREEBSD_MAP_RESERVED0100 0x0100
+                                 /* previously unimplemented MAP_NOEXTEND */
+#define TARGET_FREEBSD_MAP_STACK        0x0400
+                                 /* region grows down, like a stack */
+#define TARGET_FREEBSD_MAP_NOSYNC       0x0800
+                                 /* page to but do not sync underlying file */
 
 #define TARGET_FREEBSD_MAP_FLAGMASK     0x1ff7
 
 /*      $NetBSD: mman.h,v 1.42 2008/11/18 22:13:49 ad Exp $     */
 
-/*-
+/*
  * Copyright (c) 1982, 1986, 1993
  *      The Regents of the University of California.  All rights reserved.
  *
@@ -69,18 +73,21 @@
  *
  *      @(#)mman.h      8.2 (Berkeley) 1/9/95
  */
-#define TARGET_NETBSD_MAP_INHERIT       0x0080  /* region is retained after exec */
-#define TARGET_NETBSD_MAP_TRYFIXED      0x0400 /* attempt hint address, even within break */
-#define TARGET_NETBSD_MAP_WIRED         0x0800  /* mlock() mapping when it is established */
-
-#define TARGET_NETBSD_MAP_STACK         0x2000  /* allocated from memory, swap space (stack) */
+#define TARGET_NETBSD_MAP_INHERIT       0x0080
+                                /* region is retained after exec */
+#define TARGET_NETBSD_MAP_TRYFIXED      0x0400
+                                /* attempt hint address, even within break */
+#define TARGET_NETBSD_MAP_WIRED         0x0800
+                                /* mlock() mapping when it is established */
+#define TARGET_NETBSD_MAP_STACK         0x2000
+                                /* allocated from memory, swap space (stack) */
 
 #define TARGET_NETBSD_MAP_FLAGMASK      0x3ff7
 
 /*      $OpenBSD: mman.h,v 1.18 2003/07/21 22:52:19 tedu Exp $  */
 /*      $NetBSD: mman.h,v 1.11 1995/03/26 20:24:23 jtc Exp $    */
 
-/*-
+/*
  * Copyright (c) 1982, 1986, 1993
  *      The Regents of the University of California.  All rights reserved.
  *
@@ -111,11 +118,14 @@
  *      @(#)mman.h      8.1 (Berkeley) 6/2/93
  */
 
-#define TARGET_OPENBSD_MAP_INHERIT      0x0080  /* region is retained after exec */
-#define TARGET_OPENBSD_MAP_NOEXTEND     0x0100  /* for MAP_FILE, don't change file size */
-#define TARGET_OPENBSD_MAP_TRYFIXED     0x0400  /* attempt hint address, even within heap */
+#define TARGET_OPENBSD_MAP_INHERIT      0x0080
+                                /* region is retained after exec */
+#define TARGET_OPENBSD_MAP_NOEXTEND     0x0100
+                                /* for MAP_FILE, don't change file size */
+#define TARGET_OPENBSD_MAP_TRYFIXED     0x0400
+                                /* attempt hint address, even within heap */
 
 #define TARGET_OPENBSD_MAP_FLAGMASK     0x17f7
 
-// XXX
+/* XXX what to do in the future? */
 #define TARGET_BSD_MAP_FLAGMASK         0x3ff7
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 18/48] bsd-user: style tweak: Use preferred block comments
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (16 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 17/48] bsd-user: style tweak: Fix commentary issues imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 19/48] bsd-user: style tweak: move extern to header file imp
                   ` (30 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, Richard Henderson, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Use the preferred block comment style.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/main.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 3c6c0ec687..60a62e016a 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -51,9 +51,11 @@ const char *qemu_uname_release;
 extern char **environ;
 enum BSDType bsd_type;
 
-/* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
-   we allocate a bigger stack. Need a better solution, for example
-   by remapping the process stack directly at the right place */
+/*
+ * XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
+ * we allocate a bigger stack. Need a better solution, for example
+ * by remapping the process stack directly at the right place
+ */
 unsigned long x86_stack_size = 512 * 1024;
 
 void gemu_log(const char *fmt, ...)
@@ -263,13 +265,17 @@ void cpu_loop(CPUX86State *env)
 #define SPARC64_STACK_BIAS 2047
 
 /* #define DEBUG_WIN */
-/* WARNING: dealing with register windows _is_ complicated. More info
-   can be found at http://www.sics.se/~psm/sparcstack.html */
+/*
+ * WARNING: dealing with register windows _is_ complicated. More info
+ * can be found at http://www.sics.se/~psm/sparcstack.html
+ */
 static inline int get_reg_index(CPUSPARCState *env, int cwp, int index)
 {
     index = (index + cwp * 16) % (16 * env->nwindows);
-    /* wrap handling : if cwp is on the last window, then we use the
-       registers 'after' the end */
+    /*
+     * wrap handling : if cwp is on the last window, then we use the
+     * registers 'after' the end
+     */
     if (index < 8 && env->cwp == env->nwindows - 1)
         index += 16 * env->nwindows;
     return index;
@@ -847,9 +853,11 @@ int main(int argc, char **argv)
     syscall_init();
     signal_init();
 
-    /* Now that we've loaded the binary, GUEST_BASE is fixed.  Delay
-       generating the prologue until now so that the prologue can take
-       the real value of GUEST_BASE into account.  */
+    /*
+     * Now that we've loaded the binary, GUEST_BASE is fixed.  Delay
+     * generating the prologue until now so that the prologue can take
+     * the real value of GUEST_BASE into account.
+     */
     tcg_prologue_init(tcg_ctx);
     tcg_region_init();
 
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 19/48] bsd-user: style tweak: move extern to header file
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (17 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 18/48] bsd-user: style tweak: Use preferred block comments imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 20/48] bsd-user: style tweak: use {} consistently in for / if / else statements imp
                   ` (29 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, Richard Henderson, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

extern char **environ has no standard home, so move the declaration from the .c
file to a handy .h file. Since this is a standard, old-school UNIX interface
dating from the 5th edition, it's not quite the same issue that the rule is
supposed to protect against, though.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/main.c | 1 -
 bsd-user/qemu.h | 2 ++
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 60a62e016a..1b5d815c3a 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -48,7 +48,6 @@ unsigned long reserved_va;
 
 static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX;
 const char *qemu_uname_release;
-extern char **environ;
 enum BSDType bsd_type;
 
 /*
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index 7ccc8ad397..5a82722281 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -27,6 +27,8 @@
 
 #include "exec/user/abitypes.h"
 
+extern char **environ;
+
 enum BSDType {
     target_freebsd,
     target_netbsd,
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 20/48] bsd-user: style tweak: use {} consistently in for / if / else statements
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (18 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 19/48] bsd-user: style tweak: move extern to header file imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 21/48] bsd-user: style nits: return is not a function imp
                   ` (28 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, Richard Henderson, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Fix various issues with {} not being present on if / for statements.
Minor line length tweaks
Move an assignment in an if out.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/main.c | 66 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 43 insertions(+), 23 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 1b5d815c3a..8f5cb7162d 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -218,7 +218,7 @@ void cpu_loop(CPUX86State *env)
 #ifndef TARGET_ABI32
         case EXCP_SYSCALL:
             /* syscall from syscall instruction */
-            if (bsd_type == target_freebsd)
+            if (bsd_type == target_freebsd) {
                 env->regs[R_EAX] = do_freebsd_syscall(env,
                                                       env->regs[R_EAX],
                                                       env->regs[R_EDI],
@@ -227,7 +227,7 @@ void cpu_loop(CPUX86State *env)
                                                       env->regs[R_ECX],
                                                       env->regs[8],
                                                       env->regs[9], 0, 0);
-            else { /* if (bsd_type == target_openbsd) */
+            } else { /* if (bsd_type == target_openbsd) */
                 env->regs[R_EAX] = do_openbsd_syscall(env,
                                                       env->regs[R_EAX],
                                                       env->regs[R_EDI],
@@ -251,7 +251,8 @@ void cpu_loop(CPUX86State *env)
             break;
         default:
             pc = env->segs[R_CS].base + env->eip;
-            fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
+            fprintf(stderr,
+                    "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
                     (long)pc, trapnr);
             abort();
         }
@@ -275,8 +276,9 @@ static inline int get_reg_index(CPUSPARCState *env, int cwp, int index)
      * wrap handling : if cwp is on the last window, then we use the
      * registers 'after' the end
      */
-    if (index < 8 && env->cwp == env->nwindows - 1)
+    if (index < 8 && env->cwp == env->nwindows - 1) {
         index += 16 * env->nwindows;
+    }
     return index;
 }
 
@@ -288,8 +290,9 @@ static inline void save_window_offset(CPUSPARCState *env, int cwp1)
 
     sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
 #ifdef TARGET_SPARC64
-    if (sp_ptr & 3)
+    if (sp_ptr & 3) {
         sp_ptr += SPARC64_STACK_BIAS;
+    }
 #endif
 #if defined(DEBUG_WIN)
     printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx " save_cwp=%d\n",
@@ -338,8 +341,9 @@ static void restore_window(CPUSPARCState *env)
     cwp1 = cpu_cwp_inc(env, env->cwp + 1);
     sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
 #ifdef TARGET_SPARC64
-    if (sp_ptr & 3)
+    if (sp_ptr & 3) {
         sp_ptr += SPARC64_STACK_BIAS;
+    }
 #endif
 #if defined(DEBUG_WIN)
     printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx " load_cwp=%d\n",
@@ -352,8 +356,9 @@ static void restore_window(CPUSPARCState *env)
     }
 #ifdef TARGET_SPARC64
     env->canrestore++;
-    if (env->cleanwin < env->nwindows - 1)
+    if (env->cleanwin < env->nwindows - 1) {
         env->cleanwin++;
+    }
     env->cansave--;
 #else
     env->wim = new_wim;
@@ -369,11 +374,13 @@ static void flush_windows(CPUSPARCState *env)
         /* if restore would invoke restore_window(), then we can stop */
         cwp1 = cpu_cwp_inc(env, env->cwp + offset);
 #ifndef TARGET_SPARC64
-        if (env->wim & (1 << cwp1))
+        if (env->wim & (1 << cwp1)) {
             break;
+        }
 #else
-        if (env->canrestore == 0)
+        if (env->canrestore == 0) {
             break;
+        }
         env->cansave++;
         env->canrestore--;
 #endif
@@ -408,8 +415,9 @@ void cpu_loop(CPUSPARCState *env)
 #else
         /* FreeBSD uses 0x141 for syscalls too */
         case 0x141:
-            if (bsd_type != target_freebsd)
+            if (bsd_type != target_freebsd) {
                 goto badtrap;
+            }
             /* fallthrough */
         case 0x100:
 #endif
@@ -418,7 +426,8 @@ void cpu_loop(CPUSPARCState *env)
                 ret = do_freebsd_syscall(env, syscall_nr,
                                          env->regwptr[0], env->regwptr[1],
                                          env->regwptr[2], env->regwptr[3],
-                                         env->regwptr[4], env->regwptr[5], 0, 0);
+                                         env->regwptr[4], env->regwptr[5],
+                                         0, 0);
             else if (bsd_type == target_netbsd)
                 ret = do_netbsd_syscall(env, syscall_nr,
                                         env->regwptr[0], env->regwptr[1],
@@ -611,8 +620,9 @@ int main(int argc, char **argv)
     envlist_t *envlist = NULL;
     bsd_type = target_openbsd;
 
-    if (argc <= 1)
+    if (argc <= 1) {
         usage();
+    }
 
     error_init(argv[0]);
     module_call_init(MODULE_INIT_TRACE);
@@ -632,11 +642,13 @@ int main(int argc, char **argv)
 
     optind = 1;
     for (;;) {
-        if (optind >= argc)
+        if (optind >= argc) {
             break;
+        }
         r = argv[optind];
-        if (r[0] != '-')
+        if (r[0] != '-') {
             break;
+        }
         optind++;
         r++;
         if (!strcmp(r, "-")) {
@@ -653,24 +665,28 @@ int main(int argc, char **argv)
             log_file = argv[optind++];
         } else if (!strcmp(r, "E")) {
             r = argv[optind++];
-            if (envlist_setenv(envlist, r) != 0)
+            if (envlist_setenv(envlist, r) != 0) {
                 usage();
+            }
         } else if (!strcmp(r, "ignore-environment")) {
             envlist_free(envlist);
             envlist = envlist_create();
         } else if (!strcmp(r, "U")) {
             r = argv[optind++];
-            if (envlist_unsetenv(envlist, r) != 0)
+            if (envlist_unsetenv(envlist, r) != 0) {
                 usage();
+            }
         } else if (!strcmp(r, "s")) {
             r = argv[optind++];
             x86_stack_size = strtol(r, (char **)&r, 0);
-            if (x86_stack_size <= 0)
+            if (x86_stack_size <= 0) {
                 usage();
-            if (*r == 'M')
+            }
+            if (*r == 'M') {
                 x86_stack_size *= MiB;
-            else if (*r == 'k' || *r == 'K')
+            } else if (*r == 'k' || *r == 'K') {
                 x86_stack_size *= KiB;
+            }
         } else if (!strcmp(r, "L")) {
             interp_prefix = argv[optind++];
         } else if (!strcmp(r, "p")) {
@@ -810,11 +826,13 @@ int main(int argc, char **argv)
     if (!have_guest_base) {
         FILE *fp;
 
-        if ((fp = fopen("/proc/sys/vm/mmap_min_addr", "r")) != NULL) {
+        fp = fopen("/proc/sys/vm/mmap_min_addr", "r");
+        if (fp != NULL) {
             unsigned long tmp;
             if (fscanf(fp, "%lu", &tmp) == 1) {
                 mmap_min_addr = tmp;
-                qemu_log_mask(CPU_LOG_PAGE, "host mmap_min_addr=0x%lx\n", mmap_min_addr);
+                qemu_log_mask(CPU_LOG_PAGE, "host mmap_min_addr=0x%lx\n",
+                              mmap_min_addr);
             }
             fclose(fp);
         }
@@ -987,10 +1005,12 @@ int main(int argc, char **argv)
         env->pc = regs->pc;
         env->npc = regs->npc;
         env->y = regs->y;
-        for (i = 0; i < 8; i++)
+        for (i = 0; i < 8; i++) {
             env->gregs[i] = regs->u_regs[i];
-        for (i = 0; i < 8; i++)
+        }
+        for (i = 0; i < 8; i++) {
             env->regwptr[i] = regs->u_regs[i + 8];
+        }
     }
 #else
 #error unsupported target CPU
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 21/48] bsd-user: style nits: return is not a function
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (19 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 20/48] bsd-user: style tweak: use {} consistently in for / if / else statements imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:27   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 22/48] bsd-user: use qemu_strtoul in preference to strtol imp
                   ` (27 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/elfload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index 2c6764d372..243a5a5048 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -1544,7 +1544,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
 static int load_aout_interp(void *exptr, int interp_fd)
 {
     printf("a.out interpreter not yet supported\n");
-    return(0);
+    return 0;
 }
 
 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop)
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 22/48] bsd-user: use qemu_strtoul in preference to strtol
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (20 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 21/48] bsd-user: style nits: return is not a function imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:34   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 23/48] bsd-user: introduce host_os.h for bsd-specific code and defaults imp
                   ` (26 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/main.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 8f5cb7162d..a98a45df21 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -37,6 +37,7 @@
 #include "tcg/tcg.h"
 #include "qemu/timer.h"
 #include "qemu/envlist.h"
+#include "qemu/cutils.h"
 #include "exec/log.h"
 #include "trace/control.h"
 
@@ -613,7 +614,7 @@ int main(int argc, char **argv)
     TaskState ts1, *ts = &ts1;
     CPUArchState *env;
     CPUState *cpu;
-    int optind;
+    int optind, rv;
     const char *r;
     const char *gdbstub = NULL;
     char **target_environ, **wrk;
@@ -678,8 +679,8 @@ int main(int argc, char **argv)
             }
         } else if (!strcmp(r, "s")) {
             r = argv[optind++];
-            x86_stack_size = strtol(r, (char **)&r, 0);
-            if (x86_stack_size <= 0) {
+            rv = qemu_strtoul(r, &r, 0, &x86_stack_size);
+            if (rv < 0 || x86_stack_size <= 0) {
                 usage();
             }
             if (*r == 'M') {
@@ -710,7 +711,10 @@ int main(int argc, char **argv)
                 exit(1);
             }
         } else if (!strcmp(r, "B")) {
-            guest_base = strtol(argv[optind++], NULL, 0);
+            rv = qemu_strtoul(argv[optind++], NULL, 0, &guest_base);
+            if (rv < 0) {
+                usage();
+            }
             have_guest_base = true;
         } else if (!strcmp(r, "drop-ld-preload")) {
             (void) envlist_unsetenv(envlist, "LD_PRELOAD");
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 23/48] bsd-user: introduce host_os.h for bsd-specific code and defaults
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (21 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 22/48] bsd-user: use qemu_strtoul in preference to strtol imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 24/48] bsd-user: create target_arch_cpu.h imp
                   ` (25 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: kevans, Richard Henderson, arichardson, Warner Losh, Stacey Son

From: Warner Losh <imp@bsdimp.com>

Introduce host_os.h for frebsd, netbsd and openbsd. This sets the default bsd
being implemented today. In the future it will have code that is per-BSD
specific. Abstracted from a larger c93465b6208c4c95cc0a394ffef4180ba6ccf27a in
the qemu-bsd-user repo.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/freebsd/host_os.h | 25 +++++++++++++++++++++++++
 bsd-user/main.c            |  4 +++-
 bsd-user/netbsd/host_os.h  | 25 +++++++++++++++++++++++++
 bsd-user/openbsd/host_os.h | 25 +++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 1 deletion(-)
 create mode 100644 bsd-user/freebsd/host_os.h
 create mode 100644 bsd-user/netbsd/host_os.h
 create mode 100644 bsd-user/openbsd/host_os.h

diff --git a/bsd-user/freebsd/host_os.h b/bsd-user/freebsd/host_os.h
new file mode 100644
index 0000000000..ceb1543d06
--- /dev/null
+++ b/bsd-user/freebsd/host_os.h
@@ -0,0 +1,25 @@
+/*
+ *  FreeBSD host dependent code and definitions
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HOST_OS_H_
+#define __HOST_OS_H_
+
+#define HOST_DEFAULT_BSD_TYPE target_freebsd
+
+#endif /*!__HOST_OS_H_ */
diff --git a/bsd-user/main.c b/bsd-user/main.c
index a98a45df21..a81a70f8ac 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -41,6 +41,8 @@
 #include "exec/log.h"
 #include "trace/control.h"
 
+#include "host_os.h"
+
 int singlestep;
 unsigned long mmap_min_addr;
 uintptr_t guest_base;
@@ -619,7 +621,7 @@ int main(int argc, char **argv)
     const char *gdbstub = NULL;
     char **target_environ, **wrk;
     envlist_t *envlist = NULL;
-    bsd_type = target_openbsd;
+    bsd_type = HOST_DEFAULT_BSD_TYPE;
 
     if (argc <= 1) {
         usage();
diff --git a/bsd-user/netbsd/host_os.h b/bsd-user/netbsd/host_os.h
new file mode 100644
index 0000000000..ccbea076e6
--- /dev/null
+++ b/bsd-user/netbsd/host_os.h
@@ -0,0 +1,25 @@
+/*
+ *  NetBSD host dependent code and definitions
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HOST_OS_H_
+#define __HOST_OS_H_
+
+#define HOST_DEFAULT_BSD_TYPE target_netbsd
+
+#endif /*!__HOST_OS_H_ */
diff --git a/bsd-user/openbsd/host_os.h b/bsd-user/openbsd/host_os.h
new file mode 100644
index 0000000000..79468073e4
--- /dev/null
+++ b/bsd-user/openbsd/host_os.h
@@ -0,0 +1,25 @@
+/*
+ *  OpenBSD host dependent code and definitions
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HOST_OS_H_
+#define __HOST_OS_H_
+
+#define HOST_DEFAULT_BSD_TYPE target_openbsd
+
+#endif /*!__HOST_OS_H_ */
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 24/48] bsd-user: create target_arch_cpu.h
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (22 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 23/48] bsd-user: introduce host_os.h for bsd-specific code and defaults imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 15:59 ` [PATCH v2 25/48] bsd-user: move x86 (i386 and x86_64) cpu_loop to target_arch_cpu.h imp
                   ` (24 subsequent siblings)
  48 siblings, 0 replies; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: kevans, Richard Henderson, arichardson, Warner Losh, Stacey Son

From: Warner Losh <imp@bsdimp.com>

Create target_arch_cpu.h to house the target_cpu_loop and target_cpu_init
functions. These are the empty files that will be populated by moving the
appropriate cpu-specific functions out of main.c. This work pre-dates the
linux-user work that moved these to cpu-loop.c, so was done differently. As
there's a number of things linux-user did differently than bsd-user in their
time of divergence, and as the recertification of the code to redo it the same
way will take a fair amount of effort, a separate effort to address the
divergence once everything is in the tree and we can create a common qemu-user
directory for the munane common elements between the two.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/arm/target_arch_cpu.h     | 22 ++++++++++++++++++++++
 bsd-user/i386/target_arch_cpu.h    | 22 ++++++++++++++++++++++
 bsd-user/main.c                    |  1 +
 bsd-user/sparc/target_arch_cpu.h   | 22 ++++++++++++++++++++++
 bsd-user/sparc64/target_arch_cpu.h | 19 +++++++++++++++++++
 bsd-user/x86_64/target_arch_cpu.h  | 19 +++++++++++++++++++
 6 files changed, 105 insertions(+)
 create mode 100644 bsd-user/arm/target_arch_cpu.h
 create mode 100644 bsd-user/i386/target_arch_cpu.h
 create mode 100644 bsd-user/sparc/target_arch_cpu.h
 create mode 100644 bsd-user/sparc64/target_arch_cpu.h
 create mode 100644 bsd-user/x86_64/target_arch_cpu.h

diff --git a/bsd-user/arm/target_arch_cpu.h b/bsd-user/arm/target_arch_cpu.h
new file mode 100644
index 0000000000..71c89174f2
--- /dev/null
+++ b/bsd-user/arm/target_arch_cpu.h
@@ -0,0 +1,22 @@
+/*
+ *  arm cpu init and loop
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _TARGET_ARCH_CPU_H_
+#define _TARGET_ARCH_CPU_H_
+
+#endif /* ! _TARGET_ARCH_CPU_H_ */
diff --git a/bsd-user/i386/target_arch_cpu.h b/bsd-user/i386/target_arch_cpu.h
new file mode 100644
index 0000000000..c05e048b9b
--- /dev/null
+++ b/bsd-user/i386/target_arch_cpu.h
@@ -0,0 +1,22 @@
+/*
+ *  i386 cpu init and loop
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _TARGET_ARCH_CPU_H_
+#define _TARGET_ARCH_CPU_H_
+
+#endif /* ! _TARGET_ARCH_CPU_H_ */
diff --git a/bsd-user/main.c b/bsd-user/main.c
index a81a70f8ac..8a270ccfe6 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -42,6 +42,7 @@
 #include "trace/control.h"
 
 #include "host_os.h"
+#include "target_arch_cpu.h"
 
 int singlestep;
 unsigned long mmap_min_addr;
diff --git a/bsd-user/sparc/target_arch_cpu.h b/bsd-user/sparc/target_arch_cpu.h
new file mode 100644
index 0000000000..dcf7694cba
--- /dev/null
+++ b/bsd-user/sparc/target_arch_cpu.h
@@ -0,0 +1,22 @@
+/*
+ *  sparc cpu init and loop
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _TARGET_ARCH_CPU_H_
+#define _TARGET_ARCH_CPU_H_
+
+#endif /* ! _TARGET_ARCH_CPU_H_ */
diff --git a/bsd-user/sparc64/target_arch_cpu.h b/bsd-user/sparc64/target_arch_cpu.h
new file mode 100644
index 0000000000..c3962a8e9a
--- /dev/null
+++ b/bsd-user/sparc64/target_arch_cpu.h
@@ -0,0 +1,19 @@
+/*
+ *  sparc64 cpu init and loop
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#include "../sparc/target_arch_cpu.h"
diff --git a/bsd-user/x86_64/target_arch_cpu.h b/bsd-user/x86_64/target_arch_cpu.h
new file mode 100644
index 0000000000..56cb59ae0b
--- /dev/null
+++ b/bsd-user/x86_64/target_arch_cpu.h
@@ -0,0 +1,19 @@
+/*
+ *  x86_64 cpu init and loop
+ *
+ *  Copyright (c) 2013 Stacey D. Son
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#include "../i386/target_arch_cpu.h"
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 25/48] bsd-user: move x86 (i386 and x86_64) cpu_loop to target_arch_cpu.h
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (23 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 24/48] bsd-user: create target_arch_cpu.h imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:43   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 26/48] bsd-user: move sparc cpu_loop into target_arch_cpu.h as target_cpu_loop imp
                   ` (23 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh, Stacey Son

From: Warner Losh <imp@bsdimp.com>

Move the x86 version of the cpu_loop to target_arch_cpu.h as
target_cpu_loop. Create a cpu_loop that calls the target_cpu_loop function, but
only for x86 for now. This is code-movement only commit.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/i386/target_arch_cpu.h | 177 +++++++++++++++++++++++++++++++-
 bsd-user/main.c                 | 176 +------------------------------
 2 files changed, 179 insertions(+), 174 deletions(-)

diff --git a/bsd-user/i386/target_arch_cpu.h b/bsd-user/i386/target_arch_cpu.h
index c05e048b9b..e8b306c832 100644
--- a/bsd-user/i386/target_arch_cpu.h
+++ b/bsd-user/i386/target_arch_cpu.h
@@ -19,4 +19,179 @@
 #ifndef _TARGET_ARCH_CPU_H_
 #define _TARGET_ARCH_CPU_H_
 
-#endif /* ! _TARGET_ARCH_CPU_H_ */
+/***********************************************************/
+/* CPUX86 core interface */
+
+uint64_t cpu_get_tsc(CPUX86State *env)
+{
+    return cpu_get_host_ticks();
+}
+
+static void write_dt(void *ptr, unsigned long addr, unsigned long limit,
+                     int flags)
+{
+    unsigned int e1, e2;
+    uint32_t *p;
+    e1 = (addr << 16) | (limit & 0xffff);
+    e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000);
+    e2 |= flags;
+    p = ptr;
+    p[0] = tswap32(e1);
+    p[1] = tswap32(e2);
+}
+
+static uint64_t *idt_table;
+#ifdef TARGET_X86_64
+static void set_gate64(void *ptr, unsigned int type, unsigned int dpl,
+                       uint64_t addr, unsigned int sel)
+{
+    uint32_t *p, e1, e2;
+    e1 = (addr & 0xffff) | (sel << 16);
+    e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8);
+    p = ptr;
+    p[0] = tswap32(e1);
+    p[1] = tswap32(e2);
+    p[2] = tswap32(addr >> 32);
+    p[3] = 0;
+}
+/* only dpl matters as we do only user space emulation */
+static void set_idt(int n, unsigned int dpl)
+{
+    set_gate64(idt_table + n * 2, 0, dpl, 0, 0);
+}
+#else
+static void set_gate(void *ptr, unsigned int type, unsigned int dpl,
+                     uint32_t addr, unsigned int sel)
+{
+    uint32_t *p, e1, e2;
+    e1 = (addr & 0xffff) | (sel << 16);
+    e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8);
+    p = ptr;
+    p[0] = tswap32(e1);
+    p[1] = tswap32(e2);
+}
+
+/* only dpl matters as we do only user space emulation */
+static void set_idt(int n, unsigned int dpl)
+{
+    set_gate(idt_table + n, 0, dpl, 0, 0);
+}
+#endif
+
+static void target_cpu_loop(CPUArchState *env)
+{
+    CPUState *cs = env_cpu(env);
+    int trapnr;
+    abi_ulong pc;
+    /* target_siginfo_t info; */
+
+    for (;;) {
+        cpu_exec_start(cs);
+        trapnr = cpu_exec(cs);
+        cpu_exec_end(cs);
+        process_queued_cpu_work(cs);
+
+        switch (trapnr) {
+        case 0x80:
+            /* syscall from int $0x80 */
+            if (bsd_type == target_freebsd) {
+                abi_ulong params = (abi_ulong) env->regs[R_ESP] +
+                    sizeof(int32_t);
+                int32_t syscall_nr = env->regs[R_EAX];
+                int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8;
+
+                if (syscall_nr == TARGET_FREEBSD_NR_syscall) {
+                    get_user_s32(syscall_nr, params);
+                    params += sizeof(int32_t);
+                } else if (syscall_nr == TARGET_FREEBSD_NR___syscall) {
+                    get_user_s32(syscall_nr, params);
+                    params += sizeof(int64_t);
+                }
+                get_user_s32(arg1, params);
+                params += sizeof(int32_t);
+                get_user_s32(arg2, params);
+                params += sizeof(int32_t);
+                get_user_s32(arg3, params);
+                params += sizeof(int32_t);
+                get_user_s32(arg4, params);
+                params += sizeof(int32_t);
+                get_user_s32(arg5, params);
+                params += sizeof(int32_t);
+                get_user_s32(arg6, params);
+                params += sizeof(int32_t);
+                get_user_s32(arg7, params);
+                params += sizeof(int32_t);
+                get_user_s32(arg8, params);
+                env->regs[R_EAX] = do_freebsd_syscall(env,
+                                                      syscall_nr,
+                                                      arg1,
+                                                      arg2,
+                                                      arg3,
+                                                      arg4,
+                                                      arg5,
+                                                      arg6,
+                                                      arg7,
+                                                      arg8);
+            } else { /* if (bsd_type == target_openbsd) */
+                env->regs[R_EAX] = do_openbsd_syscall(env,
+                                                      env->regs[R_EAX],
+                                                      env->regs[R_EBX],
+                                                      env->regs[R_ECX],
+                                                      env->regs[R_EDX],
+                                                      env->regs[R_ESI],
+                                                      env->regs[R_EDI],
+                                                      env->regs[R_EBP]);
+            }
+            if (((abi_ulong)env->regs[R_EAX]) >= (abi_ulong)(-515)) {
+                env->regs[R_EAX] = -env->regs[R_EAX];
+                env->eflags |= CC_C;
+            } else {
+                env->eflags &= ~CC_C;
+            }
+            break;
+#ifndef TARGET_ABI32
+        case EXCP_SYSCALL:
+            /* syscall from syscall instruction */
+            if (bsd_type == target_freebsd) {
+                env->regs[R_EAX] = do_freebsd_syscall(env,
+                                                      env->regs[R_EAX],
+                                                      env->regs[R_EDI],
+                                                      env->regs[R_ESI],
+                                                      env->regs[R_EDX],
+                                                      env->regs[R_ECX],
+                                                      env->regs[8],
+                                                      env->regs[9], 0, 0);
+            } else { /* if (bsd_type == target_openbsd) */
+                env->regs[R_EAX] = do_openbsd_syscall(env,
+                                                      env->regs[R_EAX],
+                                                      env->regs[R_EDI],
+                                                      env->regs[R_ESI],
+                                                      env->regs[R_EDX],
+                                                      env->regs[10],
+                                                      env->regs[8],
+                                                      env->regs[9]);
+            }
+            env->eip = env->exception_next_eip;
+            if (((abi_ulong)env->regs[R_EAX]) >= (abi_ulong)(-515)) {
+                env->regs[R_EAX] = -env->regs[R_EAX];
+                env->eflags |= CC_C;
+            } else {
+                env->eflags &= ~CC_C;
+            }
+            break;
+#endif
+        case EXCP_INTERRUPT:
+            /* just indicate that signals should be handled asap */
+            break;
+        default:
+            pc = env->segs[R_CS].base + env->eip;
+            fprintf(stderr,
+                    "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
+                    (long)pc, trapnr);
+            abort();
+        }
+        process_pending_signals(env);
+    }
+}
+
+#endif /* _TARGET_ARCH_CPU_H_ */
diff --git a/bsd-user/main.c b/bsd-user/main.c
index 8a270ccfe6..43c578c760 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -88,180 +88,10 @@ void fork_end(int child)
     }
 }
 
-#ifdef TARGET_I386
-/***********************************************************/
-/* CPUX86 core interface */
-
-uint64_t cpu_get_tsc(CPUX86State *env)
-{
-    return cpu_get_host_ticks();
-}
-
-static void write_dt(void *ptr, unsigned long addr, unsigned long limit,
-                     int flags)
-{
-    unsigned int e1, e2;
-    uint32_t *p;
-    e1 = (addr << 16) | (limit & 0xffff);
-    e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000);
-    e2 |= flags;
-    p = ptr;
-    p[0] = tswap32(e1);
-    p[1] = tswap32(e2);
-}
-
-static uint64_t *idt_table;
-#ifdef TARGET_X86_64
-static void set_gate64(void *ptr, unsigned int type, unsigned int dpl,
-                       uint64_t addr, unsigned int sel)
-{
-    uint32_t *p, e1, e2;
-    e1 = (addr & 0xffff) | (sel << 16);
-    e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8);
-    p = ptr;
-    p[0] = tswap32(e1);
-    p[1] = tswap32(e2);
-    p[2] = tswap32(addr >> 32);
-    p[3] = 0;
-}
-/* only dpl matters as we do only user space emulation */
-static void set_idt(int n, unsigned int dpl)
-{
-    set_gate64(idt_table + n * 2, 0, dpl, 0, 0);
-}
-#else
-static void set_gate(void *ptr, unsigned int type, unsigned int dpl,
-                     uint32_t addr, unsigned int sel)
-{
-    uint32_t *p, e1, e2;
-    e1 = (addr & 0xffff) | (sel << 16);
-    e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8);
-    p = ptr;
-    p[0] = tswap32(e1);
-    p[1] = tswap32(e2);
-}
-
-/* only dpl matters as we do only user space emulation */
-static void set_idt(int n, unsigned int dpl)
-{
-    set_gate(idt_table + n, 0, dpl, 0, 0);
-}
-#endif
-
-void cpu_loop(CPUX86State *env)
+#ifdef TARGET_I386 /* stopgap ifdef */
+void cpu_loop(CPUArchState *env)
 {
-    CPUState *cs = env_cpu(env);
-    int trapnr;
-    abi_ulong pc;
-    /* target_siginfo_t info; */
-
-    for (;;) {
-        cpu_exec_start(cs);
-        trapnr = cpu_exec(cs);
-        cpu_exec_end(cs);
-        process_queued_cpu_work(cs);
-
-        switch (trapnr) {
-        case 0x80:
-            /* syscall from int $0x80 */
-            if (bsd_type == target_freebsd) {
-                abi_ulong params = (abi_ulong) env->regs[R_ESP] +
-                    sizeof(int32_t);
-                int32_t syscall_nr = env->regs[R_EAX];
-                int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8;
-
-                if (syscall_nr == TARGET_FREEBSD_NR_syscall) {
-                    get_user_s32(syscall_nr, params);
-                    params += sizeof(int32_t);
-                } else if (syscall_nr == TARGET_FREEBSD_NR___syscall) {
-                    get_user_s32(syscall_nr, params);
-                    params += sizeof(int64_t);
-                }
-                get_user_s32(arg1, params);
-                params += sizeof(int32_t);
-                get_user_s32(arg2, params);
-                params += sizeof(int32_t);
-                get_user_s32(arg3, params);
-                params += sizeof(int32_t);
-                get_user_s32(arg4, params);
-                params += sizeof(int32_t);
-                get_user_s32(arg5, params);
-                params += sizeof(int32_t);
-                get_user_s32(arg6, params);
-                params += sizeof(int32_t);
-                get_user_s32(arg7, params);
-                params += sizeof(int32_t);
-                get_user_s32(arg8, params);
-                env->regs[R_EAX] = do_freebsd_syscall(env,
-                                                      syscall_nr,
-                                                      arg1,
-                                                      arg2,
-                                                      arg3,
-                                                      arg4,
-                                                      arg5,
-                                                      arg6,
-                                                      arg7,
-                                                      arg8);
-            } else { /* if (bsd_type == target_openbsd) */
-                env->regs[R_EAX] = do_openbsd_syscall(env,
-                                                      env->regs[R_EAX],
-                                                      env->regs[R_EBX],
-                                                      env->regs[R_ECX],
-                                                      env->regs[R_EDX],
-                                                      env->regs[R_ESI],
-                                                      env->regs[R_EDI],
-                                                      env->regs[R_EBP]);
-            }
-            if (((abi_ulong)env->regs[R_EAX]) >= (abi_ulong)(-515)) {
-                env->regs[R_EAX] = -env->regs[R_EAX];
-                env->eflags |= CC_C;
-            } else {
-                env->eflags &= ~CC_C;
-            }
-            break;
-#ifndef TARGET_ABI32
-        case EXCP_SYSCALL:
-            /* syscall from syscall instruction */
-            if (bsd_type == target_freebsd) {
-                env->regs[R_EAX] = do_freebsd_syscall(env,
-                                                      env->regs[R_EAX],
-                                                      env->regs[R_EDI],
-                                                      env->regs[R_ESI],
-                                                      env->regs[R_EDX],
-                                                      env->regs[R_ECX],
-                                                      env->regs[8],
-                                                      env->regs[9], 0, 0);
-            } else { /* if (bsd_type == target_openbsd) */
-                env->regs[R_EAX] = do_openbsd_syscall(env,
-                                                      env->regs[R_EAX],
-                                                      env->regs[R_EDI],
-                                                      env->regs[R_ESI],
-                                                      env->regs[R_EDX],
-                                                      env->regs[10],
-                                                      env->regs[8],
-                                                      env->regs[9]);
-            }
-            env->eip = env->exception_next_eip;
-            if (((abi_ulong)env->regs[R_EAX]) >= (abi_ulong)(-515)) {
-                env->regs[R_EAX] = -env->regs[R_EAX];
-                env->eflags |= CC_C;
-            } else {
-                env->eflags &= ~CC_C;
-            }
-            break;
-#endif
-        case EXCP_INTERRUPT:
-            /* just indicate that signals should be handled asap */
-            break;
-        default:
-            pc = env->segs[R_CS].base + env->eip;
-            fprintf(stderr,
-                    "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n",
-                    (long)pc, trapnr);
-            abort();
-        }
-        process_pending_signals(env);
-    }
+    target_cpu_loop(env);
 }
 #endif
 
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 26/48] bsd-user: move sparc cpu_loop into target_arch_cpu.h as target_cpu_loop
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (24 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 25/48] bsd-user: move x86 (i386 and x86_64) cpu_loop to target_arch_cpu.h imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:45   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 27/48] bsd-user: style tweak: space pedantry imp
                   ` (22 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh, Stacey Son

From: Warner Losh <imp@bsdimp.com>

Move the sparc cpu_loop out of main.c and into target_arch_cpu.h and
rename it from cpu_loop to target_cpu_loop. Remove the #ifdef around
the catch-all cpu_loop.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/main.c                  | 270 -------------------------------
 bsd-user/sparc/target_arch_cpu.h | 267 +++++++++++++++++++++++++++++-
 2 files changed, 266 insertions(+), 271 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 43c578c760..af4eae2e8b 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -88,280 +88,10 @@ void fork_end(int child)
     }
 }
 
-#ifdef TARGET_I386 /* stopgap ifdef */
 void cpu_loop(CPUArchState *env)
 {
     target_cpu_loop(env);
 }
-#endif
-
-#ifdef TARGET_SPARC
-#define SPARC64_STACK_BIAS 2047
-
-/* #define DEBUG_WIN */
-/*
- * WARNING: dealing with register windows _is_ complicated. More info
- * can be found at http://www.sics.se/~psm/sparcstack.html
- */
-static inline int get_reg_index(CPUSPARCState *env, int cwp, int index)
-{
-    index = (index + cwp * 16) % (16 * env->nwindows);
-    /*
-     * wrap handling : if cwp is on the last window, then we use the
-     * registers 'after' the end
-     */
-    if (index < 8 && env->cwp == env->nwindows - 1) {
-        index += 16 * env->nwindows;
-    }
-    return index;
-}
-
-/* save the register window 'cwp1' */
-static inline void save_window_offset(CPUSPARCState *env, int cwp1)
-{
-    unsigned int i;
-    abi_ulong sp_ptr;
-
-    sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
-#ifdef TARGET_SPARC64
-    if (sp_ptr & 3) {
-        sp_ptr += SPARC64_STACK_BIAS;
-    }
-#endif
-#if defined(DEBUG_WIN)
-    printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx " save_cwp=%d\n",
-           sp_ptr, cwp1);
-#endif
-    for (i = 0; i < 16; i++) {
-        /* FIXME - what to do if put_user() fails? */
-        put_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
-        sp_ptr += sizeof(abi_ulong);
-    }
-}
-
-static void save_window(CPUSPARCState *env)
-{
-#ifndef TARGET_SPARC64
-    unsigned int new_wim;
-    new_wim = ((env->wim >> 1) | (env->wim << (env->nwindows - 1))) &
-        ((1LL << env->nwindows) - 1);
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
-    env->wim = new_wim;
-#else
-    /*
-     * cansave is zero if the spill trap handler is triggered by `save` and
-     * nonzero if triggered by a `flushw`
-     */
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
-    env->cansave++;
-    env->canrestore--;
-#endif
-}
-
-static void restore_window(CPUSPARCState *env)
-{
-#ifndef TARGET_SPARC64
-    unsigned int new_wim;
-#endif
-    unsigned int i, cwp1;
-    abi_ulong sp_ptr;
-
-#ifndef TARGET_SPARC64
-    new_wim = ((env->wim << 1) | (env->wim >> (env->nwindows - 1))) &
-        ((1LL << env->nwindows) - 1);
-#endif
-
-    /* restore the invalid window */
-    cwp1 = cpu_cwp_inc(env, env->cwp + 1);
-    sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
-#ifdef TARGET_SPARC64
-    if (sp_ptr & 3) {
-        sp_ptr += SPARC64_STACK_BIAS;
-    }
-#endif
-#if defined(DEBUG_WIN)
-    printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx " load_cwp=%d\n",
-           sp_ptr, cwp1);
-#endif
-    for (i = 0; i < 16; i++) {
-        /* FIXME - what to do if get_user() fails? */
-        get_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
-        sp_ptr += sizeof(abi_ulong);
-    }
-#ifdef TARGET_SPARC64
-    env->canrestore++;
-    if (env->cleanwin < env->nwindows - 1) {
-        env->cleanwin++;
-    }
-    env->cansave--;
-#else
-    env->wim = new_wim;
-#endif
-}
-
-static void flush_windows(CPUSPARCState *env)
-{
-    int offset, cwp1;
-
-    offset = 1;
-    for (;;) {
-        /* if restore would invoke restore_window(), then we can stop */
-        cwp1 = cpu_cwp_inc(env, env->cwp + offset);
-#ifndef TARGET_SPARC64
-        if (env->wim & (1 << cwp1)) {
-            break;
-        }
-#else
-        if (env->canrestore == 0) {
-            break;
-        }
-        env->cansave++;
-        env->canrestore--;
-#endif
-        save_window_offset(env, cwp1);
-        offset++;
-    }
-    cwp1 = cpu_cwp_inc(env, env->cwp + 1);
-#ifndef TARGET_SPARC64
-    /* set wim so that restore will reload the registers */
-    env->wim = 1 << cwp1;
-#endif
-#if defined(DEBUG_WIN)
-    printf("flush_windows: nb=%d\n", offset - 1);
-#endif
-}
-
-void cpu_loop(CPUSPARCState *env)
-{
-    CPUState *cs = env_cpu(env);
-    int trapnr, ret, syscall_nr;
-    /* target_siginfo_t info; */
-
-    while (1) {
-        cpu_exec_start(cs);
-        trapnr = cpu_exec(cs);
-        cpu_exec_end(cs);
-        process_queued_cpu_work(cs);
-
-        switch (trapnr) {
-#ifndef TARGET_SPARC64
-        case 0x80:
-#else
-        /* FreeBSD uses 0x141 for syscalls too */
-        case 0x141:
-            if (bsd_type != target_freebsd) {
-                goto badtrap;
-            }
-            /* fallthrough */
-        case 0x100:
-#endif
-            syscall_nr = env->gregs[1];
-            if (bsd_type == target_freebsd)
-                ret = do_freebsd_syscall(env, syscall_nr,
-                                         env->regwptr[0], env->regwptr[1],
-                                         env->regwptr[2], env->regwptr[3],
-                                         env->regwptr[4], env->regwptr[5],
-                                         0, 0);
-            else if (bsd_type == target_netbsd)
-                ret = do_netbsd_syscall(env, syscall_nr,
-                                        env->regwptr[0], env->regwptr[1],
-                                        env->regwptr[2], env->regwptr[3],
-                                        env->regwptr[4], env->regwptr[5]);
-            else { /* if (bsd_type == target_openbsd) */
-#if defined(TARGET_SPARC64)
-                syscall_nr &= ~(TARGET_OPENBSD_SYSCALL_G7RFLAG |
-                                TARGET_OPENBSD_SYSCALL_G2RFLAG);
-#endif
-                ret = do_openbsd_syscall(env, syscall_nr,
-                                         env->regwptr[0], env->regwptr[1],
-                                         env->regwptr[2], env->regwptr[3],
-                                         env->regwptr[4], env->regwptr[5]);
-            }
-            if ((unsigned int)ret >= (unsigned int)(-515)) {
-                ret = -ret;
-#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
-                env->xcc |= PSR_CARRY;
-#else
-                env->psr |= PSR_CARRY;
-#endif
-            } else {
-#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
-                env->xcc &= ~PSR_CARRY;
-#else
-                env->psr &= ~PSR_CARRY;
-#endif
-            }
-            env->regwptr[0] = ret;
-            /* next instruction */
-#if defined(TARGET_SPARC64)
-            if (bsd_type == target_openbsd &&
-                env->gregs[1] & TARGET_OPENBSD_SYSCALL_G2RFLAG) {
-                env->pc = env->gregs[2];
-                env->npc = env->pc + 4;
-            } else if (bsd_type == target_openbsd &&
-                       env->gregs[1] & TARGET_OPENBSD_SYSCALL_G7RFLAG) {
-                env->pc = env->gregs[7];
-                env->npc = env->pc + 4;
-            } else {
-                env->pc = env->npc;
-                env->npc = env->npc + 4;
-            }
-#else
-            env->pc = env->npc;
-            env->npc = env->npc + 4;
-#endif
-            break;
-        case 0x83: /* flush windows */
-#ifdef TARGET_ABI32
-        case 0x103:
-#endif
-            flush_windows(env);
-            /* next instruction */
-            env->pc = env->npc;
-            env->npc = env->npc + 4;
-            break;
-#ifndef TARGET_SPARC64
-        case TT_WIN_OVF: /* window overflow */
-            save_window(env);
-            break;
-        case TT_WIN_UNF: /* window underflow */
-            restore_window(env);
-            break;
-        case TT_TFAULT:
-        case TT_DFAULT:
-            break;
-#else
-        case TT_SPILL: /* window overflow */
-            save_window(env);
-            break;
-        case TT_FILL: /* window underflow */
-            restore_window(env);
-            break;
-        case TT_TFAULT:
-        case TT_DFAULT:
-            break;
-#endif
-        case EXCP_INTERRUPT:
-            /* just indicate that signals should be handled asap */
-            break;
-        case EXCP_DEBUG:
-            {
-                gdb_handlesig(cs, TARGET_SIGTRAP);
-            }
-            break;
-        default:
-#ifdef TARGET_SPARC64
-        badtrap:
-#endif
-            printf("Unhandled trap: 0x%x\n", trapnr);
-            cpu_dump_state(cs, stderr, 0);
-            exit(1);
-        }
-        process_pending_signals(env);
-    }
-}
-
-#endif
 
 static void usage(void)
 {
diff --git a/bsd-user/sparc/target_arch_cpu.h b/bsd-user/sparc/target_arch_cpu.h
index dcf7694cba..5e3ecbed5c 100644
--- a/bsd-user/sparc/target_arch_cpu.h
+++ b/bsd-user/sparc/target_arch_cpu.h
@@ -19,4 +19,269 @@
 #ifndef _TARGET_ARCH_CPU_H_
 #define _TARGET_ARCH_CPU_H_
 
-#endif /* ! _TARGET_ARCH_CPU_H_ */
+#define SPARC64_STACK_BIAS 2047
+
+/* #define DEBUG_WIN */
+/*
+ * WARNING: dealing with register windows _is_ complicated. More info
+ * can be found at http://www.sics.se/~psm/sparcstack.html
+ */
+static inline int get_reg_index(CPUSPARCState *env, int cwp, int index)
+{
+    index = (index + cwp * 16) % (16 * env->nwindows);
+    /*
+     * wrap handling : if cwp is on the last window, then we use the
+     * registers 'after' the end
+     */
+    if (index < 8 && env->cwp == env->nwindows - 1) {
+        index += 16 * env->nwindows;
+    }
+    return index;
+}
+
+/* save the register window 'cwp1' */
+static inline void save_window_offset(CPUSPARCState *env, int cwp1)
+{
+    unsigned int i;
+    abi_ulong sp_ptr;
+
+    sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
+#ifdef TARGET_SPARC64
+    if (sp_ptr & 3) {
+        sp_ptr += SPARC64_STACK_BIAS;
+    }
+#endif
+#if defined(DEBUG_WIN)
+    printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx " save_cwp=%d\n",
+           sp_ptr, cwp1);
+#endif
+    for (i = 0; i < 16; i++) {
+        /* FIXME - what to do if put_user() fails? */
+        put_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
+        sp_ptr += sizeof(abi_ulong);
+    }
+}
+
+static void save_window(CPUSPARCState *env)
+{
+#ifndef TARGET_SPARC64
+    unsigned int new_wim;
+    new_wim = ((env->wim >> 1) | (env->wim << (env->nwindows - 1))) &
+        ((1LL << env->nwindows) - 1);
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+    env->wim = new_wim;
+#else
+    /*
+     * cansave is zero if the spill trap handler is triggered by `save` and
+     * nonzero if triggered by a `flushw`
+     */
+    save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
+    env->cansave++;
+    env->canrestore--;
+#endif
+}
+
+static void restore_window(CPUSPARCState *env)
+{
+#ifndef TARGET_SPARC64
+    unsigned int new_wim;
+#endif
+    unsigned int i, cwp1;
+    abi_ulong sp_ptr;
+
+#ifndef TARGET_SPARC64
+    new_wim = ((env->wim << 1) | (env->wim >> (env->nwindows - 1))) &
+        ((1LL << env->nwindows) - 1);
+#endif
+
+    /* restore the invalid window */
+    cwp1 = cpu_cwp_inc(env, env->cwp + 1);
+    sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
+#ifdef TARGET_SPARC64
+    if (sp_ptr & 3) {
+        sp_ptr += SPARC64_STACK_BIAS;
+    }
+#endif
+#if defined(DEBUG_WIN)
+    printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx " load_cwp=%d\n",
+           sp_ptr, cwp1);
+#endif
+    for (i = 0; i < 16; i++) {
+        /* FIXME - what to do if get_user() fails? */
+        get_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
+        sp_ptr += sizeof(abi_ulong);
+    }
+#ifdef TARGET_SPARC64
+    env->canrestore++;
+    if (env->cleanwin < env->nwindows - 1) {
+        env->cleanwin++;
+    }
+    env->cansave--;
+#else
+    env->wim = new_wim;
+#endif
+}
+
+static void flush_windows(CPUSPARCState *env)
+{
+    int offset, cwp1;
+
+    offset = 1;
+    for (;;) {
+        /* if restore would invoke restore_window(), then we can stop */
+        cwp1 = cpu_cwp_inc(env, env->cwp + offset);
+#ifndef TARGET_SPARC64
+        if (env->wim & (1 << cwp1)) {
+            break;
+        }
+#else
+        if (env->canrestore == 0) {
+            break;
+        }
+        env->cansave++;
+        env->canrestore--;
+#endif
+        save_window_offset(env, cwp1);
+        offset++;
+    }
+    cwp1 = cpu_cwp_inc(env, env->cwp + 1);
+#ifndef TARGET_SPARC64
+    /* set wim so that restore will reload the registers */
+    env->wim = 1 << cwp1;
+#endif
+#if defined(DEBUG_WIN)
+    printf("flush_windows: nb=%d\n", offset - 1);
+#endif
+}
+
+static void target_cpu_loop(CPUSPARCState *env)
+{
+    CPUState *cs = env_cpu(env);
+    int trapnr, ret, syscall_nr;
+    /* target_siginfo_t info; */
+
+    while (1) {
+        cpu_exec_start(cs);
+        trapnr = cpu_exec(cs);
+        cpu_exec_end(cs);
+        process_queued_cpu_work(cs);
+
+        switch (trapnr) {
+#ifndef TARGET_SPARC64
+        case 0x80:
+#else
+        /* FreeBSD uses 0x141 for syscalls too */
+        case 0x141:
+            if (bsd_type != target_freebsd) {
+                goto badtrap;
+            }
+            /* fallthrough */
+        case 0x100:
+#endif
+            syscall_nr = env->gregs[1];
+            if (bsd_type == target_freebsd)
+                ret = do_freebsd_syscall(env, syscall_nr,
+                                         env->regwptr[0], env->regwptr[1],
+                                         env->regwptr[2], env->regwptr[3],
+                                         env->regwptr[4], env->regwptr[5],
+                                         0, 0);
+            else if (bsd_type == target_netbsd)
+                ret = do_netbsd_syscall(env, syscall_nr,
+                                        env->regwptr[0], env->regwptr[1],
+                                        env->regwptr[2], env->regwptr[3],
+                                        env->regwptr[4], env->regwptr[5]);
+            else { /* if (bsd_type == target_openbsd) */
+#if defined(TARGET_SPARC64)
+                syscall_nr &= ~(TARGET_OPENBSD_SYSCALL_G7RFLAG |
+                                TARGET_OPENBSD_SYSCALL_G2RFLAG);
+#endif
+                ret = do_openbsd_syscall(env, syscall_nr,
+                                         env->regwptr[0], env->regwptr[1],
+                                         env->regwptr[2], env->regwptr[3],
+                                         env->regwptr[4], env->regwptr[5]);
+            }
+            if ((unsigned int)ret >= (unsigned int)(-515)) {
+                ret = -ret;
+#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
+                env->xcc |= PSR_CARRY;
+#else
+                env->psr |= PSR_CARRY;
+#endif
+            } else {
+#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
+                env->xcc &= ~PSR_CARRY;
+#else
+                env->psr &= ~PSR_CARRY;
+#endif
+            }
+            env->regwptr[0] = ret;
+            /* next instruction */
+#if defined(TARGET_SPARC64)
+            if (bsd_type == target_openbsd &&
+                env->gregs[1] & TARGET_OPENBSD_SYSCALL_G2RFLAG) {
+                env->pc = env->gregs[2];
+                env->npc = env->pc + 4;
+            } else if (bsd_type == target_openbsd &&
+                       env->gregs[1] & TARGET_OPENBSD_SYSCALL_G7RFLAG) {
+                env->pc = env->gregs[7];
+                env->npc = env->pc + 4;
+            } else {
+                env->pc = env->npc;
+                env->npc = env->npc + 4;
+            }
+#else
+            env->pc = env->npc;
+            env->npc = env->npc + 4;
+#endif
+            break;
+        case 0x83: /* flush windows */
+#ifdef TARGET_ABI32
+        case 0x103:
+#endif
+            flush_windows(env);
+            /* next instruction */
+            env->pc = env->npc;
+            env->npc = env->npc + 4;
+            break;
+#ifndef TARGET_SPARC64
+        case TT_WIN_OVF: /* window overflow */
+            save_window(env);
+            break;
+        case TT_WIN_UNF: /* window underflow */
+            restore_window(env);
+            break;
+        case TT_TFAULT:
+        case TT_DFAULT:
+            break;
+#else
+        case TT_SPILL: /* window overflow */
+            save_window(env);
+            break;
+        case TT_FILL: /* window underflow */
+            restore_window(env);
+            break;
+        case TT_TFAULT:
+        case TT_DFAULT:
+            break;
+#endif
+        case EXCP_INTERRUPT:
+            /* just indicate that signals should be handled asap */
+            break;
+        case EXCP_DEBUG:
+            {
+                gdb_handlesig(cs, TARGET_SIGTRAP);
+            }
+            break;
+        default:
+#ifdef TARGET_SPARC64
+        badtrap:
+#endif
+            printf("Unhandled trap: 0x%x\n", trapnr);
+            cpu_dump_state(cs, stderr, 0);
+            exit(1);
+        }
+        process_pending_signals(env);
+    }
+}
+
+#endif /* _TARGET_ARCH_CPU_H_ */
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 27/48] bsd-user: style tweak: space pedantry
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (25 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 26/48] bsd-user: move sparc cpu_loop into target_arch_cpu.h as target_cpu_loop imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:46   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 28/48] bsd-user: style tweak: comments imp
                   ` (21 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/elfload.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index 243a5a5048..f455a3812a 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -756,7 +756,7 @@ static void padzero(abi_ulong elf_bss, abi_ulong last_bss)
 
 
 static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
-                                   struct elfhdr * exec,
+                                   struct elfhdr *exec,
                                    abi_ulong load_addr,
                                    abi_ulong load_bias,
                                    abi_ulong interp_load_addr, int ibcs,
@@ -891,12 +891,12 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,
     if (retval < 0) {
         perror("load_elf_interp");
         exit(-1);
-        free (elf_phdata);
+        free(elf_phdata);
         return retval;
     }
 #ifdef BSWAP_NEEDED
     eppnt = elf_phdata;
-    for (i = 0; i<interp_elf_ex->e_phnum; i++, eppnt++) {
+    for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
         bswap_phdr(eppnt);
     }
 #endif
@@ -1155,11 +1155,11 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
     unsigned int interpreter_type = INTERPRETER_NONE;
     unsigned char ibcs2_interpreter;
     int i;
-    struct elf_phdr * elf_ppnt;
+    struct elf_phdr *elf_ppnt;
     struct elf_phdr *elf_phdata;
     abi_ulong elf_bss, k, elf_brk;
     int retval;
-    char * elf_interpreter;
+    char *elf_interpreter;
     abi_ulong elf_entry, interp_load_addr = 0;
     abi_ulong start_code, end_code, start_data, end_data;
     abi_ulong reloc_func_desc = 0;
@@ -1183,14 +1183,14 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
     }
 
     bprm->p = copy_elf_strings(1, &bprm->filename, bprm->page, bprm->p);
-    bprm->p = copy_elf_strings(bprm->envc, bprm->envp, bprm->page,bprm->p);
-    bprm->p = copy_elf_strings(bprm->argc, bprm->argv, bprm->page,bprm->p);
+    bprm->p = copy_elf_strings(bprm->envc, bprm->envp, bprm->page, bprm->p);
+    bprm->p = copy_elf_strings(bprm->argc, bprm->argv, bprm->page, bprm->p);
     if (!bprm->p) {
         retval = -E2BIG;
     }
 
     /* Now read in all of the header information */
-    elf_phdata = (struct elf_phdr *)malloc(elf_ex.e_phentsize*elf_ex.e_phnum);
+    elf_phdata = (struct elf_phdr *)malloc(elf_ex.e_phentsize * elf_ex.e_phnum);
     if (elf_phdata == NULL) {
         return -ENOMEM;
     }
@@ -1223,11 +1223,11 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
     elf_interpreter = NULL;
     start_code = ~((abi_ulong)0UL);
     end_code = 0;
-    start_data = 0;
+    start_data =n 0;
     end_data = 0;
     interp_ex.a_info = 0;
 
-    for (i = 0;i < elf_ex.e_phnum; i++) {
+    for (i = 0; i < elf_ex.e_phnum; i++) {
         if (elf_ppnt->p_type == PT_INTERP) {
             if (elf_interpreter != NULL)
             {
@@ -1267,7 +1267,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
 
             if (strcmp(elf_interpreter, "/usr/lib/libc.so.1") == 0 ||
                 strcmp(elf_interpreter, "/usr/lib/ld.so.1") == 0) {
-              ibcs2_interpreter = 1;
+                ibcs2_interpreter = 1;
             }
 
             if (retval >= 0) {
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 28/48] bsd-user: style tweak: comments
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (26 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 27/48] bsd-user: style tweak: space pedantry imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:51   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 29/48] bsd-user: style tweak: use {} correctly imp
                   ` (20 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Use the preferred block comment style, move comments as needed for line length
restrictions, delete some dead code that looked like a comment, break some lines
> 80 columns at the same time since there are many associated with comments.

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/elfload.c | 216 ++++++++++++++++++++++++++-------------------
 1 file changed, 123 insertions(+), 93 deletions(-)

diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
index f455a3812a..75ccc06719 100644
--- a/bsd-user/elfload.c
+++ b/bsd-user/elfload.c
@@ -23,10 +23,10 @@
  * These occupy the top three bytes.
  */
 enum {
-        ADDR_NO_RANDOMIZE =     0x0040000,      /* disable randomization of VA space */
-        FDPIC_FUNCPTRS =        0x0080000,      /* userspace function ptrs point to descriptors
-                                                 * (signal handling)
-                                                 */
+            /* disable randomization of VA space */
+        ADDR_NO_RANDOMIZE =     0x0040000,
+            /* userspace function ptrs point to descriptors (signal handling) */
+        FDPIC_FUNCPTRS =        0x0080000,
         MMAP_PAGE_ZERO =        0x0100000,
         ADDR_COMPAT_LAYOUT =    0x0200000,
         READ_IMPLIES_EXEC =     0x0400000,
@@ -117,7 +117,8 @@ static uint32_t get_elf_hwcap(void)
 #define ELF_DATA       ELFDATA2LSB
 #define ELF_ARCH       EM_X86_64
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+                               struct image_info *infop)
 {
     regs->rax = 0;
     regs->rsp = infop->start_stack;
@@ -143,18 +144,21 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #define ELF_DATA        ELFDATA2LSB
 #define ELF_ARCH        EM_386
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+                               struct image_info *infop)
 {
     regs->esp = infop->start_stack;
     regs->eip = infop->entry;
 
-    /* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program
-       starts %edx contains a pointer to a function which might be
-       registered using `atexit'.  This provides a mean for the
-       dynamic linker to call DT_FINI functions for shared libraries
-       that have been loaded before the code runs.
-
-       A value of 0 tells we have no such handler.  */
+    /*
+     * SVR4/i386 ABI (pages 3-31, 3-32) says that when the program starts %edx
+     * contains a pointer to a function which might be registered using
+     * `atexit'.  This provides a mean for the dynamic linker to call DT_FINI
+     * functions for shared libraries that have been loaded before the code
+     * runs.
+     *
+     * A value of 0 tells we have no such handler.
+     */
     regs->edx = 0;
 }
 #endif
@@ -178,7 +182,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #endif
 #define ELF_ARCH        EM_ARM
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+                               struct image_info *infop)
 {
     abi_long stack = infop->start_stack;
     memset(regs, 0, sizeof(*regs));
@@ -235,7 +240,8 @@ enum
 
 #define STACK_BIAS              2047
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+                               struct image_info *infop)
 {
 #ifndef TARGET_ABI32
     regs->tstate = 0;
@@ -267,7 +273,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #define ELF_DATA    ELFDATA2MSB
 #define ELF_ARCH    EM_SPARC
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+                               struct image_info *infop)
 {
     regs->psr = 0;
     regs->pc = infop->entry;
@@ -321,6 +328,7 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
  *   AT_IGNOREPPC is used for that.
  * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
  *   even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
+ * - Handle glibc compatibility with last two...
  */
 #define DLINFO_ARCH_ITEMS       5
 #define ARCH_DLINFO                                                     \
@@ -328,14 +336,12 @@ do {                                                                    \
         NEW_AUX_ENT(AT_DCACHEBSIZE, 0x20);                              \
         NEW_AUX_ENT(AT_ICACHEBSIZE, 0x20);                              \
         NEW_AUX_ENT(AT_UCACHEBSIZE, 0);                                 \
-        /*                                                              \
-         * Now handle glibc compatibility.                              \
-         */                                                             \
         NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);                        \
         NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);                        \
  } while (0)
 
-static inline void init_thread(struct target_pt_regs *_regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *_regs,
+                               struct image_info *infop)
 {
     abi_ulong pos = infop->start_stack;
     abi_ulong tmp;
@@ -353,11 +359,12 @@ static inline void init_thread(struct target_pt_regs *_regs, struct image_info *
     infop->entry = entry;
 #endif
     _regs->nip = infop->entry;
-    /* Note that isn't exactly what regular kernel does
+    /*
+     * Note that isn't exactly what regular kernel does
      * but this is what the ABI wants and is needed to allow
      * execution of PPC BSD programs.
+     * FIXME - what to for failure of get_user()?
      */
-    /* FIXME - what to for failure of get_user()? */
     get_user_ual(_regs->gpr[3], pos);
     pos += sizeof(abi_ulong);
     _regs->gpr[4] = pos;
@@ -390,7 +397,8 @@ static inline void init_thread(struct target_pt_regs *_regs, struct image_info *
 #endif
 #define ELF_ARCH    EM_MIPS
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+                               struct image_info *infop)
 {
     regs->cp0_status = 2 << CP0St_KSU;
     regs->cp0_epc = infop->entry;
@@ -412,11 +420,12 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #define ELF_DATA  ELFDATA2LSB
 #define ELF_ARCH  EM_SH
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+                               struct image_info *infop)
 {
-  /* Check other registers XXXXX */
-  regs->pc = infop->entry;
-  regs->regs[15] = infop->start_stack;
+    /* Check other registers XXXXX */
+    regs->pc = infop->entry;
+    regs->regs[15] = infop->start_stack;
 }
 
 #define USE_ELF_CORE_DUMP
@@ -434,9 +443,10 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #define ELF_DATA  ELFDATA2LSB
 #define ELF_ARCH  EM_CRIS
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+                               struct image_info *infop)
 {
-  regs->erp = infop->entry;
+    regs->erp = infop->entry;
 }
 
 #define USE_ELF_CORE_DUMP
@@ -454,10 +464,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #define ELF_DATA        ELFDATA2MSB
 #define ELF_ARCH        EM_68K
 
-/* ??? Does this need to do anything?
-#define ELF_PLAT_INIT(_r) */
-
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+                               struct image_info *infop)
 {
     regs->usp = infop->start_stack;
     regs->sr = 0;
@@ -479,7 +487,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 #define ELF_DATA       ELFDATA2MSB
 #define ELF_ARCH       EM_ALPHA
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
+static inline void init_thread(struct target_pt_regs *regs,
+                               struct image_info *infop)
 {
     regs->pc = infop->entry;
     regs->ps = 8;
@@ -538,8 +547,10 @@ struct exec
 
 /* Necessary parameters */
 #define TARGET_ELF_EXEC_PAGESIZE TARGET_PAGE_SIZE
-#define TARGET_ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE - 1))
-#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1))
+#define TARGET_ELF_PAGESTART(_v) \
+    ((_v) & ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE - 1))
+#define TARGET_ELF_PAGEOFFSET(_v) \
+    ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1))
 
 #define INTERPRETER_NONE 0
 #define INTERPRETER_AOUT 1
@@ -557,7 +568,7 @@ static int load_aout_interp(void *exptr, int interp_fd);
 #ifdef BSWAP_NEEDED
 static void bswap_ehdr(struct elfhdr *ehdr)
 {
-    bswap16s(&ehdr->e_type);                    /* Object file type */
+    bswap16s(&ehdr->e_type);            /* Object file type */
     bswap16s(&ehdr->e_machine);         /* Architecture */
     bswap32s(&ehdr->e_version);         /* Object file version */
     bswaptls(&ehdr->e_entry);           /* Entry point virtual address */
@@ -565,16 +576,16 @@ static void bswap_ehdr(struct elfhdr *ehdr)
     bswaptls(&ehdr->e_shoff);           /* Section header table file offset */
     bswap32s(&ehdr->e_flags);           /* Processor-specific flags */
     bswap16s(&ehdr->e_ehsize);          /* ELF header size in bytes */
-    bswap16s(&ehdr->e_phentsize);               /* Program header table entry size */
+    bswap16s(&ehdr->e_phentsize);       /* Program header table entry size */
     bswap16s(&ehdr->e_phnum);           /* Program header table entry count */
-    bswap16s(&ehdr->e_shentsize);               /* Section header table entry size */
+    bswap16s(&ehdr->e_shentsize);       /* Section header table entry size */
     bswap16s(&ehdr->e_shnum);           /* Section header table entry count */
-    bswap16s(&ehdr->e_shstrndx);                /* Section header string table index */
+    bswap16s(&ehdr->e_shstrndx);        /* Section header string table index */
 }
 
 static void bswap_phdr(struct elf_phdr *phdr)
 {
-    bswap32s(&phdr->p_type);                    /* Segment type */
+    bswap32s(&phdr->p_type);            /* Segment type */
     bswaptls(&phdr->p_offset);          /* Segment file offset */
     bswaptls(&phdr->p_vaddr);           /* Segment virtual address */
     bswaptls(&phdr->p_paddr);           /* Segment physical address */
@@ -668,8 +679,9 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct linux_binprm *bprm,
     abi_ulong stack_base, size, error;
     int i;
 
-    /* Create enough stack to hold everything.  If we don't use
-     * it for args, we'll use it for something else...
+    /*
+     * Create enough stack to hold everything.  If we don't use it for args,
+     * we'll use it for something else...
      */
     size = x86_stack_size;
     if (size < MAX_ARG_PAGES * TARGET_PAGE_SIZE)
@@ -717,9 +729,11 @@ static void set_brk(abi_ulong start, abi_ulong end)
 }
 
 
-/* We need to explicitly zero any fractional pages after the data
-   section (i.e. bss).  This would contain the junk from the file that
-   should not be in memory. */
+/*
+ * We need to explicitly zero any fractional pages after the data section
+ * (i.e. bss).  This would contain the junk from the file that should not be in
+ * memory.
+ */
 static void padzero(abi_ulong elf_bss, abi_ulong last_bss)
 {
         abi_ulong nbyte;
@@ -727,11 +741,12 @@ static void padzero(abi_ulong elf_bss, abi_ulong last_bss)
         if (elf_bss >= last_bss)
                 return;
 
-        /* XXX: this is really a hack : if the real host page size is
-           smaller than the target page size, some pages after the end
-           of the file may not be mapped. A better fix would be to
-           patch target_mmap(), but it is more complicated as the file
-           size must be known */
+        /*
+         * XXX: this is really a hack : if the real host page size is smaller
+         * than the target page size, some pages after the end f the file may
+         * not be mapped. A better fix would be to patch target_mmap(), but it
+         * is more complicated as the file size must be known.
+         */
         if (qemu_real_host_page_size < qemu_host_page_size) {
             abi_ulong end_addr, end_addr1;
             end_addr1 = REAL_HOST_PAGE_ALIGN(elf_bss);
@@ -794,7 +809,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
         if (size & 15)
                 sp -= 16 - (size & 15);
 
-        /* This is correct because Linux defines
+        /*
+         * This is correct because Linux defines
          * elf_addr_t as Elf32_Off / Elf64_Off
          */
 #define NEW_AUX_ENT(id, val) do {               \
@@ -902,8 +918,10 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,
 #endif
 
     if (interp_elf_ex->e_type == ET_DYN) {
-        /* in order to avoid hardcoding the interpreter load
-           address in qemu, we allocate a big enough memory zone */
+        /*
+         * in order to avoid hardcoding the interpreter load address in qemu, we
+         * allocate a big enough memory zone
+         */
         error = target_mmap(0, INTERP_MAP_SIZE,
                             PROT_NONE, MAP_PRIVATE | MAP_ANON,
                             -1, 0);
@@ -931,11 +949,11 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,
                 vaddr = eppnt->p_vaddr;
             }
             error = target_mmap(load_addr + TARGET_ELF_PAGESTART(vaddr),
-                                eppnt->p_filesz + TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr),
-                                elf_prot,
-                                elf_type,
-                                interpreter_fd,
-                                eppnt->p_offset - TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr));
+                eppnt->p_filesz + TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr),
+                elf_prot,
+                elf_type,
+                interpreter_fd,
+                eppnt->p_offset - TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr));
 
             if (error == -1) {
                 /* Real error */
@@ -975,7 +993,8 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,
      * bss page.
      */
     padzero(elf_bss, last_bss);
-    elf_bss = TARGET_ELF_PAGESTART(elf_bss + qemu_host_page_size - 1); /* What we have mapped so far */
+    /* What we have mapped so far */
+    elf_bss = TARGET_ELF_PAGESTART(elf_bss + qemu_host_page_size - 1);
 
     /* Map the last of the bss segment */
     if (last_bss > elf_bss) {
@@ -1109,10 +1128,12 @@ static void load_symbols(struct elfhdr *hdr, int fd)
         i++;
     }
 
-     /* Attempt to free the storage associated with the local symbols
-        that we threw away.  Whether or not this has any effect on the
-        memory allocation depends on the malloc implementation and how
-        many symbols we managed to discard. */
+     /*
+      * Attempt to free the storage associated with the local symbols that we
+      * threw away.  Whether or not this has any effect on the memory allocation
+      * depends on the malloc implementation and how many symbols we managed to
+      * discard.
+      */
     new_syms = realloc(syms, nsyms * sizeof(*syms));
     if (new_syms == NULL) {
         free(s);
@@ -1237,9 +1258,9 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
                 return -EINVAL;
             }
 
-            /* This is the program interpreter used for
-             * shared libraries - for now assume that this
-             * is an a.out format binary
+            /*
+             * This is the program interpreter used for shared libraries - for
+             * now assume that this is an a.out format binary
              */
 
             elf_interpreter = (char *)malloc(elf_ppnt->p_filesz);
@@ -1259,9 +1280,10 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
                 exit(-1);
             }
 
-            /* If the program interpreter is one of these two,
-               then assume an iBCS2 image. Otherwise assume
-               a native linux image. */
+            /*
+             * If the program interpreter is one of these two, then assume an
+             * iBCS2 image. Otherwise assume a native linux image.
+             */
 
             /* JRP - Need to add X86 lib dir stuff here... */
 
@@ -1278,7 +1300,6 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
                 else {
                     perror(elf_interpreter);
                     exit(-1);
-                    /* retval = -errno; */
                 }
             }
 
@@ -1289,8 +1310,8 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
                 }
             }
             if (retval >= 0) {
-                interp_ex = *((struct exec *) bprm->buf); /* aout exec-header */
-                interp_elf_ex = *((struct elfhdr *) bprm->buf); /* elf exec-header */
+                interp_ex = *((struct exec *) bprm->buf); /* aout */
+                interp_elf_ex = *((struct elfhdr *) bprm->buf); /* elf */
             }
             if (retval < 0) {
                 perror("load_elf_binary3");
@@ -1327,8 +1348,10 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
         }
     }
 
-    /* OK, we are done with that, now set up the arg stuff,
-       and then start this sucker up */
+    /*
+     * OK, we are done with that, now set up the arg stuff, and then start this
+     * sucker up
+     */
 
     {
         char *passed_p;
@@ -1378,18 +1401,19 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
         }
     }
 
-    /* Do this so that we can load the interpreter, if need be.  We will
-       change some of these later */
+    /*
+     * Do this so that we can load the interpreter, if need be.  We will change
+     * some of these later
+     */
     info->rss = 0;
     bprm->p = setup_arg_pages(bprm->p, bprm, info);
     info->start_stack = bprm->p;
 
-    /* Now we do a little grungy work by mmaping the ELF image into
-     * the correct location in memory.  At this point, we assume that
-     * the image should be loaded at fixed address, not at a variable
-     * address.
+    /*
+     * Now we do a little grungy work by mmaping the ELF image into the correct
+     * location in memory.  At this point, we assume that the image should be
+     * loaded at fixed address, not at a variable address.
      */
-
     for (i = 0, elf_ppnt = elf_phdata; i < elf_ex.e_phnum; i++, elf_ppnt++) {
         int elf_prot = 0;
         int elf_flags = 0;
@@ -1405,11 +1429,13 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
         if (elf_ex.e_type == ET_EXEC || load_addr_set) {
             elf_flags |= MAP_FIXED;
         } else if (elf_ex.e_type == ET_DYN) {
-            /* Try and get dynamic programs out of the way of the default mmap
-               base, as well as whatever program they might try to exec.  This
-               is because the brk will follow the loader, and is not movable.  */
-            /* NOTE: for qemu, we do a big mmap to get enough space
-               without hardcoding any address */
+            /*
+             * Try and get dynamic programs out of the way of the default mmap
+             * base, as well as whatever program they might try to exec.  This
+             * is because the brk will follow the loader, and is not movable.
+             * NOTE: for qemu, we do a big mmap to get enough space without
+             * hardcoding any address
+             */
             error = target_mmap(0, ET_DYN_MAP_SIZE,
                                 PROT_NONE, MAP_PRIVATE | MAP_ANON,
                                 -1, 0);
@@ -1520,18 +1546,22 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
     info->end_data = end_data;
     info->start_stack = bprm->p;
 
-    /* Calling set_brk effectively mmaps the pages that we need for the bss and break
-       sections */
+    /*
+     * Calling set_brk effectively mmaps the pages that we need for the bss and
+     * break sections
+     */
     set_brk(elf_bss, elf_brk);
 
     padzero(elf_bss, elf_brk);
 
     if (info->personality == PER_SVR4)
     {
-            /* Why this, you ask???  Well SVr4 maps page 0 as read-only,
-               and some applications "depend" upon this behavior.
-               Since we do not have the power to recompile these, we
-               emulate the SVr4 behavior.  Sigh.  */
+            /*
+             * Why this, you ask???  Well SVr4 maps page 0 as read-only, and
+             * some applications "depend" upon this behavior.  Since we do not
+             * have the power to recompile these, we emulate the SVr4 behavior.
+             * Sigh.
+             */
             target_mmap(0, qemu_host_page_size, PROT_READ | PROT_EXEC,
                                       MAP_FIXED | MAP_PRIVATE, -1, 0);
     }
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 29/48] bsd-user: style tweak: use {} correctly
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (27 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 28/48] bsd-user: style tweak: comments imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:55   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 30/48] bsd-user: style tweak: fix block comments imp
                   ` (19 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Format if/for/while statements with {} always, on a separate line
and fix a couple indentations issues for singletons.

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 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[] = "i386";
     int family = object_property_get_int(OBJECT(thread_cpu), "family", NULL);
-    if (family > 6)
+    if (family > 6) {
         family = 6;
-    if (family >= 3)
+    }
+    if (family >= 3) {
         elf_platform[1] = '0' + family;
+    }
     return elf_platform;
 }
 
@@ -188,8 +190,9 @@ static inline void init_thread(struct target_pt_regs *regs,
     abi_long stack = infop->start_stack;
     memset(regs, 0, sizeof(*regs));
     regs->ARM_cpsr = 0x10;
-    if (infop->entry & 1)
+    if (infop->entry & 1) {
         regs->ARM_cpsr |= CPSR_T;
+    }
     regs->ARM_pc = infop->entry & 0xfffffffe;
     regs->ARM_sp = infop->start_stack;
     /* FIXME - what to for failure of get_user()? */
@@ -205,8 +208,7 @@ static inline void init_thread(struct target_pt_regs *regs,
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
-enum
-{
+enum {
   ARM_HWCAP_ARM_SWP       = 1 << 0,
   ARM_HWCAP_ARM_HALF      = 1 << 1,
   ARM_HWCAP_ARM_THUMB     = 1 << 2,
@@ -252,9 +254,9 @@ static inline void init_thread(struct target_pt_regs *regs,
 #ifdef TARGET_ABI32
     regs->u_regs[14] = infop->start_stack - 16 * 4;
 #else
-    if (personality(infop->personality) == PER_LINUX32)
+    if (personality(infop->personality) == PER_LINUX32) {
         regs->u_regs[14] = infop->start_stack - 16 * 4;
-    else {
+    } else {
         regs->u_regs[14] = infop->start_stack - 16 * 8 - STACK_BIAS;
         if (bsd_type == target_freebsd) {
             regs->u_regs[8] = infop->start_stack;
@@ -520,8 +522,7 @@ static inline void init_thread(struct target_pt_regs *regs,
 
 #include "elf.h"
 
-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 = tmp;
-        while (*tmp++);
+        while (*tmp++) {
+            continue;
+        }
         len = 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 **argv, void **page,
                 if (!pag) {
                     pag = g_try_malloc0(TARGET_PAGE_SIZE);
                     page[p / TARGET_PAGE_SIZE] = pag;
-                    if (!pag)
+                    if (!pag) {
                         return 0;
+                    }
                 }
             }
             if (len == 0 || offset == 0) {
                 *(pag + offset) = *tmp;
-            }
-            else {
+            } else {
               int bytes_to_copy = (len > offset) ? offset : len;
               tmp -= bytes_to_copy;
               p -= bytes_to_copy;
@@ -684,8 +687,9 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct linux_binprm *bprm,
      * we'll use it for something else...
      */
     size = x86_stack_size;
-    if (size < MAX_ARG_PAGES * TARGET_PAGE_SIZE)
+    if (size < MAX_ARG_PAGES * TARGET_PAGE_SIZE) {
         size = MAX_ARG_PAGES * TARGET_PAGE_SIZE;
+    }
     error = 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 = HOST_PAGE_ALIGN(start);
         end = HOST_PAGE_ALIGN(end);
-        if (end <= start)
+        if (end <= start) {
                 return;
+        }
         if (target_mmap(start, end - start,
                        PROT_READ | PROT_WRITE | PROT_EXEC,
                        MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) == -1) {
@@ -738,8 +743,9 @@ static void padzero(abi_ulong elf_bss, abi_ulong last_bss)
 {
         abi_ulong nbyte;
 
-        if (elf_bss >= last_bss)
-                return;
+        if (elf_bss >= last_bss) {
+            return;
+        }
 
         /*
          * XXX: this is really a hack : if the real host page size is smaller
@@ -798,16 +804,18 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
          */
         sp = sp & ~(abi_ulong)15;
         size = (DLINFO_ITEMS + 1) * 2;
-        if (k_platform)
-                size += 2;
+        if (k_platform) {
+            size += 2;
+        }
 #ifdef DLINFO_ARCH_ITEMS
         size += DLINFO_ARCH_ITEMS * 2;
 #endif
         size += envc + argc + 2;
         size += (!ibcs ? 3 : 1);        /* argc itself */
         size *= n;
-        if (size & 15)
-                sp -= 16 - (size & 15);
+        if (size & 15) {
+            sp -= 16 - (size & 15);
+        }
 
         /*
          * This is correct because Linux defines
@@ -834,8 +842,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, 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 *interp_elf_ex,
 
 
     /* Now read in all of the header information */
-
-    if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZE)
+    if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZE) {
         return ~(abi_ulong)0UL;
+    }
 
     elf_phdata =  (struct elf_phdr *)
         malloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum);
 
-    if (!elf_phdata)
+    if (!elf_phdata) {
         return ~((abi_ulong)0UL);
+    }
 
     /*
      * If the size of this structure has changed, then punt, since
@@ -934,16 +944,22 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,
     }
 
     eppnt = elf_phdata;
-    for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++)
+    for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
         if (eppnt->p_type == PT_LOAD) {
             int elf_type = MAP_PRIVATE | MAP_DENYWRITE;
             int elf_prot = 0;
             abi_ulong vaddr = 0;
             abi_ulong k;
 
-            if (eppnt->p_flags & PF_R) elf_prot =  PROT_READ;
-            if (eppnt->p_flags & PF_W) elf_prot |= PROT_WRITE;
-            if (eppnt->p_flags & PF_X) elf_prot |= PROT_EXEC;
+            if (eppnt->p_flags & PF_R) {
+                elf_prot =  PROT_READ;
+            }
+            if (eppnt->p_flags & PF_W) {
+                elf_prot |= PROT_WRITE;
+            }
+            if (eppnt->p_flags & PF_X) {
+                elf_prot |= PROT_EXEC;
+            }
             if (interp_elf_ex->e_type == ET_EXEC || load_addr_set) {
                 elf_type |= MAP_FIXED;
                 vaddr = eppnt->p_vaddr;
@@ -972,15 +988,20 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,
              * track of the largest address we see for this.
              */
             k = load_addr + eppnt->p_vaddr + eppnt->p_filesz;
-            if (k > elf_bss) elf_bss = k;
+            if (k > elf_bss) {
+                elf_bss = k;
+            }
 
             /*
              * Do the same thing for the memory mapping - between
              * elf_bss and last_bss is the bss section.
              */
             k = load_addr + eppnt->p_memsz + eppnt->p_vaddr;
-            if (k > last_bss) last_bss = k;
+            if (k > last_bss) {
+                last_bss = k;
+            }
         }
+    }
 
     /* Now use mmap to map the library into memory. */
 
@@ -1061,8 +1082,9 @@ static void load_symbols(struct elfhdr *hdr, int fd)
 
     lseek(fd, hdr->e_shoff, SEEK_SET);
     for (i = 0; i < hdr->e_shnum; i++) {
-        if (read(fd, &sechdr, sizeof(sechdr)) != sizeof(sechdr))
+        if (read(fd, &sechdr, sizeof(sechdr)) != sizeof(sechdr)) {
             return;
+        }
 #ifdef BSWAP_NEEDED
         bswap_shdr(&sechdr);
 #endif
@@ -1244,14 +1266,13 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
     elf_interpreter = NULL;
     start_code = ~((abi_ulong)0UL);
     end_code = 0;
-    start_data =n 0;
+    start_data = 0;
     end_data = 0;
     interp_ex.a_info = 0;
 
     for (i = 0; i < elf_ex.e_phnum; i++) {
         if (elf_ppnt->p_type == PT_INTERP) {
-            if (elf_interpreter != NULL)
-            {
+            if (elf_interpreter != 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 = open(path(elf_interpreter), O_RDONLY);
                 if (retval >= 0) {
                     interpreter_fd = 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 = 0, elf_ppnt = elf_phdata; i < elf_ex.e_phnum;
             i++, elf_ppnt++) {
-            if (elf_ppnt->p_type != PT_LOAD)
+            if (elf_ppnt->p_type != PT_LOAD) {
                 continue;
+            }
             if (HOST_PAGE_ALIGN(elf_ppnt->p_vaddr) < mmap_min_addr) {
                 guest_base = HOST_PAGE_ALIGN(mmap_min_addr);
                 break;
@@ -1419,12 +1440,19 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
         int elf_flags = 0;
         abi_ulong error;
 
-        if (elf_ppnt->p_type != PT_LOAD)
+        if (elf_ppnt->p_type != PT_LOAD) {
             continue;
+        }
 
-        if (elf_ppnt->p_flags & PF_R) elf_prot |= PROT_READ;
-        if (elf_ppnt->p_flags & PF_W) elf_prot |= PROT_WRITE;
-        if (elf_ppnt->p_flags & PF_X) elf_prot |= PROT_EXEC;
+        if (elf_ppnt->p_flags & PF_R) {
+            elf_prot |= PROT_READ;
+        }
+        if (elf_ppnt->p_flags & PF_W) {
+            elf_prot |= PROT_WRITE;
+        }
+        if (elf_ppnt->p_flags & PF_X) {
+            elf_prot |= PROT_EXEC;
+        }
         elf_flags = MAP_PRIVATE | MAP_DENYWRITE;
         if (elf_ex.e_type == ET_EXEC || load_addr_set) {
             elf_flags |= MAP_FIXED;
@@ -1460,8 +1488,9 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
         }
 
 #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 = TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr);
+        }
 #endif
 
         if (!load_addr_set) {
@@ -1475,19 +1504,26 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
             }
         }
         k = elf_ppnt->p_vaddr;
-        if (k < start_code)
+        if (k < start_code) {
             start_code = k;
-        if (start_data < k)
+        }
+        if (start_data < k) {
             start_data = k;
+        }
         k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz;
-        if (k > elf_bss)
+        if (k > elf_bss) {
             elf_bss = k;
-        if ((elf_ppnt->p_flags & PF_X) && end_code <  k)
+        }
+        if ((elf_ppnt->p_flags & PF_X) && end_code <  k) {
             end_code = k;
-        if (end_data < k)
+        }
+        if (end_data < k) {
             end_data = k;
+        }
         k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz;
-        if (k > elf_brk) elf_brk = k;
+        if (k > elf_brk) {
+            elf_brk = k;
+        }
     }
 
     elf_entry += 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 = load_aout_interp(&interp_ex, interpreter_fd);
-        }
-        else if (interpreter_type & 2) {
+        } else if (interpreter_type & 2) {
             elf_entry = load_elf_interp(&interp_elf_ex, interpreter_fd,
                                             &interp_load_addr);
         }
@@ -1521,10 +1556,13 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
 
     free(elf_phdata);
 
-    if (qemu_log_enabled())
+    if (qemu_log_enabled()) {
         load_symbols(&elf_ex, bprm->fd);
+    }
 
-    if (interpreter_type != INTERPRETER_AOUT) close(bprm->fd);
+    if (interpreter_type != INTERPRETER_AOUT) {
+        close(bprm->fd);
+    }
     info->personality = (ibcs2_interpreter ? PER_SVR4 : PER_LINUX);
 
 #ifdef LOW_ELF_STACK
@@ -1554,8 +1592,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
 
     padzero(elf_bss, elf_brk);
 
-    if (info->personality == PER_SVR4)
-    {
+    if (info->personality == PER_SVR4) {
             /*
              * Why this, you ask???  Well SVr4 maps page 0 as read-only, and
              * some applications "depend" upon this behavior.  Since we do not
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 30/48] bsd-user: style tweak: fix block comments
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (28 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 29/48] bsd-user: style tweak: use {} correctly imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 17:59   ` Richard Henderson
  2021-04-24 15:59 ` [PATCH v2 31/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
                   ` (18 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/mmap.c | 51 ++++++++++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 22 deletions(-)

diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index 0ac1b92706..0ff06d7349 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -23,8 +23,6 @@
 #include "bsd-mman.h"
 #include "exec/exec-all.h"
 
-//#define DEBUG_MMAP
-
 static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
 static __thread int mmap_lock_count;
 
@@ -165,8 +163,10 @@ static int mmap_frag(abi_ulong real_start,
 
     prot_new = prot | prot1;
     if (!(flags & MAP_ANON)) {
-        /* msync() won't work here, so we return an error if write is
-           possible while it is a shared mapping */
+        /*
+         * msync() won't work here, so we return an error if write is possible
+         * while it is a shared mapping
+         */
         if ((flags & TARGET_BSD_MAP_FLAGMASK) == MAP_SHARED &&
             (prot & PROT_WRITE))
             return -1;
@@ -194,12 +194,13 @@ static abi_ulong mmap_next_start = 0x40000000;
 
 unsigned long last_brk;
 
-/* find a free memory area of size 'size'. The search starts at
-   'start'. If 'start' == 0, then a default start address is used.
-   Return -1 if error.
-*/
-/* page_init() marks pages used by the host as reserved to be sure not
-   to use them. */
+/*
+ * find a free memory area of size 'size'. The search starts at 'start'. If
+ * 'start' == 0, then a default start address is used.  Return -1 if error.
+ *
+ * page_init() marks pages used by the host as reserved to be sure not to use
+ * them.
+ */
 static abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size)
 {
     abi_ulong addr, addr1, addr_start;
@@ -208,11 +209,12 @@ static abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size)
 
     new_brk = (unsigned long)sbrk(0);
     if (last_brk && last_brk < new_brk && last_brk == (target_ulong)last_brk) {
-        /* This is a hack to catch the host allocating memory with brk().
-           If it uses mmap then we loose.
-           FIXME: We really want to avoid the host allocating memory in
-           the first place, and maybe leave some slack to avoid switching
-           to mmap.  */
+        /*
+         * This is a hack to catch the host allocating memory with brk().  If it
+         * uses mmap then we loose.
+         * FIXME: We really want to avoid the host allocating memory in the
+         * first place, and maybe leave some slack to avoid switching to mmap.
+         */
         page_set_flags(last_brk & TARGET_PAGE_MASK,
                        TARGET_PAGE_ALIGN(new_brk),
                        PAGE_RESERVED);
@@ -298,9 +300,10 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
             errno = ENOMEM;
             goto fail;
         }
-        /* Note: we prefer to control the mapping address. It is
-           especially important if qemu_host_page_size >
-           qemu_real_host_page_size */
+        /*
+         * Note: we prefer to control the mapping address. It is specially
+         * important if qemu_host_page_size > qemu_real_host_page_size
+         */
         p = mmap(g2h_untagged(mmap_start),
                  host_len, prot, flags | MAP_FIXED, fd, host_offset);
         if (p == MAP_FAILED)
@@ -329,12 +332,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
             }
         }
 
-        /* worst case: we cannot map the file because the offset is not
-           aligned, so we read it */
+        /*
+         * worst case: we cannot map the file because the offset is not aligned,
+         * so we read it
+         */
         if (!(flags & MAP_ANON) &&
             (offset & ~qemu_host_page_mask) != (start & ~qemu_host_page_mask)) {
-            /* msync() won't work here, so we return an error if write is
-               possible while it is a shared mapping */
+            /*
+             * msync() won't work here, so we return an error if write is
+             * possible while it is a shared mapping
+             */
             if ((flags & TARGET_BSD_MAP_FLAGMASK) == MAP_SHARED &&
                 (prot & PROT_WRITE)) {
                 errno = EINVAL;
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 31/48] bsd-user: style tweak: use {} for all if statements, format else correctly
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (29 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 30/48] bsd-user: style tweak: fix block comments imp
@ 2021-04-24 15:59 ` imp
  2021-04-24 18:01   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 32/48] bsd-user: style tweak: remove spacing after '*' and add after } imp
                   ` (17 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 15:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/mmap.c | 112 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 74 insertions(+), 38 deletions(-)

diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
index 0ff06d7349..1aec1916c0 100644
--- a/bsd-user/mmap.c
+++ b/bsd-user/mmap.c
@@ -48,17 +48,19 @@ bool have_mmap_lock(void)
 /* Grab lock to make sure things are in a consistent state after fork().  */
 void mmap_fork_start(void)
 {
-    if (mmap_lock_count)
+    if (mmap_lock_count) {
         abort();
+    }
     pthread_mutex_lock(&mmap_mutex);
 }
 
 void mmap_fork_end(int child)
 {
-    if (child)
+    if (child) {
         pthread_mutex_init(&mmap_mutex, NULL);
-    else
+    } else {
         pthread_mutex_unlock(&mmap_mutex);
+    }
 }
 
 /* NOTE: all the constants are the HOST ones, but addresses are target. */
@@ -75,15 +77,18 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
            prot & PROT_EXEC ? 'x' : '-');
 #endif
 
-    if ((start & ~TARGET_PAGE_MASK) != 0)
+    if ((start & ~TARGET_PAGE_MASK) != 0) {
         return -EINVAL;
+    }
     len = TARGET_PAGE_ALIGN(len);
     end = start + len;
-    if (end < start)
+    if (end < start) {
         return -EINVAL;
+    }
     prot &= PROT_READ | PROT_WRITE | PROT_EXEC;
-    if (len == 0)
+    if (len == 0) {
         return 0;
+    }
 
     mmap_lock();
     host_start = start & qemu_host_page_mask;
@@ -102,8 +107,9 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
         }
         ret = mprotect(g2h_untagged(host_start),
                        qemu_host_page_size, prot1 & PAGE_BITS);
-        if (ret != 0)
+        if (ret != 0) {
             goto error;
+        }
         host_start += qemu_host_page_size;
     }
     if (end < host_end) {
@@ -113,16 +119,18 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
         }
         ret = mprotect(g2h_untagged(host_end - qemu_host_page_size),
                        qemu_host_page_size, prot1 & PAGE_BITS);
-        if (ret != 0)
+        if (ret != 0) {
             goto error;
+        }
         host_end -= qemu_host_page_size;
     }
 
     /* handle the pages in the middle */
     if (host_start < host_end) {
         ret = mprotect(g2h_untagged(host_start), host_end - host_start, prot);
-        if (ret != 0)
+        if (ret != 0) {
             goto error;
+        }
     }
     page_set_flags(start, start + len, prot | PAGE_VALID);
     mmap_unlock();
@@ -147,16 +155,18 @@ static int mmap_frag(abi_ulong real_start,
     /* get the protection of the target pages outside the mapping */
     prot1 = 0;
     for (addr = real_start; addr < real_end; addr++) {
-        if (addr < start || addr >= end)
+        if (addr < start || addr >= end) {
             prot1 |= page_get_flags(addr);
+        }
     }
 
     if (prot1 == 0) {
         /* no page was there, so we allocate one */
         void *p = mmap(host_start, qemu_host_page_size, prot,
                        flags | MAP_ANON, -1, 0);
-        if (p == MAP_FAILED)
+        if (p == MAP_FAILED) {
             return -1;
+        }
         prot1 = prot;
     }
     prot1 &= PAGE_BITS;
@@ -168,19 +178,22 @@ static int mmap_frag(abi_ulong real_start,
          * while it is a shared mapping
          */
         if ((flags & TARGET_BSD_MAP_FLAGMASK) == MAP_SHARED &&
-            (prot & PROT_WRITE))
+            (prot & PROT_WRITE)) {
             return -1;
+        }
 
         /* adjust protection to be able to read */
-        if (!(prot1 & PROT_WRITE))
+        if (!(prot1 & PROT_WRITE)) {
             mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE);
+        }
 
         /* read the corresponding file data */
         pread(fd, g2h_untagged(start), end - start, offset);
 
         /* put final protection */
-        if (prot_new != (prot1 | PROT_WRITE))
+        if (prot_new != (prot1 | PROT_WRITE)) {
             mprotect(host_start, qemu_host_page_size, prot_new);
+        }
     } else {
         /* just update the protection */
         if (prot_new != prot1) {
@@ -224,23 +237,27 @@ static abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size)
     size = HOST_PAGE_ALIGN(size);
     start = start & qemu_host_page_mask;
     addr = start;
-    if (addr == 0)
+    if (addr == 0) {
         addr = mmap_next_start;
+    }
     addr_start = addr;
     for (;;) {
         prot = 0;
         for (addr1 = addr; addr1 < (addr + size); addr1 += TARGET_PAGE_SIZE) {
             prot |= page_get_flags(addr1);
         }
-        if (prot == 0)
+        if (prot == 0) {
             break;
+        }
         addr += qemu_host_page_size;
         /* we found nothing */
-        if (addr == addr_start)
+        if (addr == addr_start) {
             return (abi_ulong)-1;
+        }
     }
-    if (start == 0)
+    if (start == 0) {
         mmap_next_start = addr + size;
+    }
     return addr;
 }
 
@@ -260,10 +277,12 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
                prot & PROT_READ ? 'r' : '-',
                prot & PROT_WRITE ? 'w' : '-',
                prot & PROT_EXEC ? 'x' : '-');
-        if (flags & MAP_FIXED)
+        if (flags & MAP_FIXED) {
             printf("MAP_FIXED ");
-        if (flags & MAP_ANON)
+        }
+        if (flags & MAP_ANON) {
             printf("MAP_ANON ");
+        }
         switch (flags & TARGET_BSD_MAP_FLAGMASK) {
         case MAP_PRIVATE:
             printf("MAP_PRIVATE ");
@@ -285,8 +304,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
     }
 
     len = TARGET_PAGE_ALIGN(len);
-    if (len == 0)
+    if (len == 0) {
         goto the_end;
+    }
     real_start = start & qemu_host_page_mask;
 
     if (!(flags & MAP_FIXED)) {
@@ -306,12 +326,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
          */
         p = mmap(g2h_untagged(mmap_start),
                  host_len, prot, flags | MAP_FIXED, fd, host_offset);
-        if (p == MAP_FAILED)
+        if (p == MAP_FAILED) {
             goto fail;
+        }
         /* update start so that it points to the file position at 'offset' */
         host_start = (unsigned long)p;
-        if (!(flags & MAP_ANON))
+        if (!(flags & MAP_ANON)) {
             host_start += offset - host_offset;
+        }
         start = h2g(host_start);
     } else {
         int flg;
@@ -350,8 +372,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
             retaddr = target_mmap(start, len, prot | PROT_WRITE,
                                   MAP_FIXED | MAP_PRIVATE | MAP_ANON,
                                   -1, 0);
-            if (retaddr == -1)
+            if (retaddr == -1) {
                 goto fail;
+            }
             pread(fd, g2h_untagged(start), len, offset);
             if (!(prot & PROT_WRITE)) {
                 ret = target_mprotect(start, len, prot);
@@ -369,14 +392,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
                 /* one single host page */
                 ret = mmap_frag(real_start, start, end,
                                 prot, flags, fd, offset);
-                if (ret == -1)
+                if (ret == -1) {
                     goto fail;
+                }
                 goto the_end1;
             }
             ret = mmap_frag(real_start, start, real_start + qemu_host_page_size,
                             prot, flags, fd, offset);
-            if (ret == -1)
+            if (ret == -1) {
                 goto fail;
+            }
             real_start += qemu_host_page_size;
         }
         /* handle the end of the mapping */
@@ -385,8 +410,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
                             real_end - qemu_host_page_size, real_end,
                             prot, flags, fd,
                             offset + real_end - qemu_host_page_size - start);
-            if (ret == -1)
+            if (ret == -1) {
                 goto fail;
+            }
             real_end -= qemu_host_page_size;
         }
 
@@ -394,14 +420,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
         if (real_start < real_end) {
             void *p;
             unsigned long offset1;
-            if (flags & MAP_ANON)
+            if (flags & MAP_ANON) {
                 offset1 = 0;
-            else
+            } else {
                 offset1 = offset + real_start - start;
+            }
             p = mmap(g2h_untagged(real_start), real_end - real_start,
                      prot, flags, fd, offset1);
-            if (p == MAP_FAILED)
+            if (p == MAP_FAILED) {
                 goto fail;
+            }
         }
     }
  the_end1:
@@ -427,11 +455,13 @@ int target_munmap(abi_ulong start, abi_ulong len)
 #ifdef DEBUG_MMAP
     printf("munmap: start=0x%lx len=0x%lx\n", start, len);
 #endif
-    if (start & ~TARGET_PAGE_MASK)
+    if (start & ~TARGET_PAGE_MASK) {
         return -EINVAL;
+    }
     len = TARGET_PAGE_ALIGN(len);
-    if (len == 0)
+    if (len == 0) {
         return -EINVAL;
+    }
     mmap_lock();
     end = start + len;
     real_start = start & qemu_host_page_mask;
@@ -449,16 +479,18 @@ int target_munmap(abi_ulong start, abi_ulong len)
             }
             end = real_end;
         }
-        if (prot != 0)
+        if (prot != 0) {
             real_start += qemu_host_page_size;
+        }
     }
     if (end < real_end) {
         prot = 0;
         for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) {
             prot |= page_get_flags(addr);
         }
-        if (prot != 0)
+        if (prot != 0) {
             real_end -= qemu_host_page_size;
+        }
     }
 
     ret = 0;
@@ -467,8 +499,9 @@ int target_munmap(abi_ulong start, abi_ulong len)
         ret = munmap(g2h_untagged(real_start), real_end - real_start);
     }
 
-    if (ret == 0)
+    if (ret == 0) {
         page_set_flags(start, start + len, 0);
+    }
     mmap_unlock();
     return ret;
 }
@@ -477,14 +510,17 @@ int target_msync(abi_ulong start, abi_ulong len, int flags)
 {
     abi_ulong end;
 
-    if (start & ~TARGET_PAGE_MASK)
+    if (start & ~TARGET_PAGE_MASK) {
         return -EINVAL;
+    }
     len = TARGET_PAGE_ALIGN(len);
     end = start + len;
-    if (end < start)
+    if (end < start) {
         return -EINVAL;
-    if (end == start)
+    }
+    if (end == start) {
         return 0;
+    }
 
     start &= qemu_host_page_mask;
     return msync(g2h_untagged(start), end - start, flags);
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 32/48] bsd-user: style tweak: remove spacing after '*' and add after }
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (30 preceding siblings ...)
  2021-04-24 15:59 ` [PATCH v2 31/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:03   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 33/48] bsd-user: style tweak: Use preferred block comments imp
                   ` (16 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/qemu.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index 5a82722281..de20e8329a 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -124,19 +124,19 @@ struct linux_binprm {
         int argc, envc;
         char **argv;
         char **envp;
-        char * filename;        /* Name of binary */
+        char *filename;         /* Name of binary */
 };
 
 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);
 abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
                               abi_ulong stringp, int push_ptr);
-int loader_exec(const char * filename, char ** argv, char ** envp,
-             struct target_pt_regs * regs, struct image_info *infop);
+int loader_exec(const char *filename, char **argv, char **envp,
+             struct target_pt_regs *regs, struct image_info *infop);
 
-int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
-                    struct image_info * info);
-int load_flt_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
-                    struct image_info * info);
+int load_elf_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
+                    struct image_info *info);
+int load_flt_binary(struct linux_binprm *bprm, struct target_pt_regs *regs,
+                    struct image_info *info);
 
 abi_long memcpy_to_target(abi_ulong dest, const void *src,
                           unsigned long len);
@@ -246,7 +246,7 @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
         break;\
     default:\
         abort();\
-    }\
+    } \
     0;\
 })
 
@@ -270,7 +270,7 @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
         /* avoid warning */\
         x = 0;\
         abort();\
-    }\
+    } \
     0;\
 })
 
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 33/48] bsd-user: style tweak: Use preferred block comments
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (31 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 32/48] bsd-user: style tweak: remove spacing after '*' and add after } imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:07   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 34/48] bsd-user: style tweak: don't assign in if statements imp
                   ` (15 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/qemu.h | 74 ++++++++++++++++++++++++++++---------------------
 1 file changed, 43 insertions(+), 31 deletions(-)

diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index de20e8329a..7f3cfa68aa 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -47,9 +47,10 @@ extern enum BSDType bsd_type;
 #define THREAD
 #endif
 
-/* This struct is used to hold certain information about the image.
- * Basically, it replicates in user space what would be certain
- * task_struct fields in the kernel
+/*
+ * This struct is used to hold certain information about the image.  Basically,
+ * it replicates in user space what would be certain task_struct fields in the
+ * kernel
  */
 struct image_info {
     abi_ulong load_addr;
@@ -78,12 +79,13 @@ struct sigqueue {
 struct emulated_sigtable {
     int pending; /* true if signal is pending */
     struct sigqueue *first;
-    struct sigqueue info; /* in order to always have memory for the
-                             first signal, we put it here */
+    /* in order to always have memory for the first signal, we put it here */
+    struct sigqueue info;
 };
 
-/* NOTE: we force a big alignment so that the stack stored after is
-   aligned too */
+/*
+ * NOTE: we force a big alignment so that the stack stored after is aligned too
+ */
 typedef struct TaskState {
     pid_t ts_tid;     /* tid (or pid) of this task */
 
@@ -103,7 +105,6 @@ void init_task_state(TaskState *ts);
 extern const char *qemu_uname_release;
 extern unsigned long mmap_min_addr;
 
-/* ??? See if we can avoid exposing so much of the loader internals.  */
 /*
  * MAX_ARG_PAGES defines the number of pages allocated for arguments
  * and envelope for the new program. 32 should suffice, this gives
@@ -224,9 +225,11 @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
     return page_check_range((target_ulong)addr, size, type) == 0;
 }
 
-/* NOTE __get_user and __put_user use host pointers and don't check access. */
-/* These are usually used to access struct data members once the
- * struct has been locked - usually with lock_user_struct().
+/*
+ * NOTE __get_user and __put_user use host pointers and don't check access.
+ *
+ * These are usually used to access struct data members once the struct has been
+ * locked - usually with lock_user_struct().
  */
 #define __put_user(x, hptr)\
 ({\
@@ -267,17 +270,18 @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
         x = (typeof(*hptr))tswap64(*(uint64_t *)(hptr));\
         break;\
     default:\
-        /* avoid warning */\
         x = 0;\
         abort();\
     } \
     0;\
 })
 
-/* put_user()/get_user() take a guest address and check access */
-/* These are usually used to access an atomic data type, such as an int,
- * that has been passed by address.  These internally perform locking
- * and unlocking on the data type.
+/*
+ * put_user()/get_user() take a guest address and check access
+ *
+ * These are usually used to access an atomic data type, such as an int, that
+ * has been passed by address.  These internally perform locking and unlocking
+ * on the data type.
  */
 #define put_user(x, gaddr, target_type)                                 \
 ({                                                                      \
@@ -301,7 +305,6 @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
         __ret = __get_user((x), __hptr);                                \
         unlock_user(__hptr, __gaddr, 0);                                \
     } else {                                                            \
-        /* avoid warning */                                             \
         (x) = 0;                                                        \
         __ret = -TARGET_EFAULT;                                         \
     }                                                                   \
@@ -330,22 +333,28 @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
 #define get_user_u8(x, gaddr)  get_user((x), (gaddr), uint8_t)
 #define get_user_s8(x, gaddr)  get_user((x), (gaddr), int8_t)
 
-/* copy_from_user() and copy_to_user() are usually used to copy data
+/*
+ * copy_from_user() and copy_to_user() are usually used to copy data
  * buffers between the target and host.  These internally perform
  * locking/unlocking of the memory.
  */
 abi_long copy_from_user(void *hptr, abi_ulong gaddr, size_t len);
 abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len);
 
-/* Functions for accessing guest memory.  The tget and tput functions
-   read/write single values, byteswapping as necessary.  The lock_user function
-   gets a pointer to a contiguous area of guest memory, but does not perform
-   any byteswapping.  lock_user may return either a pointer to the guest
-   memory, or a temporary buffer.  */
+/*
+ * Functions for accessing guest memory.  The tget and tput functions
+ * read/write single values, byteswapping as necessary.  The lock_user function
+ * gets a pointer to a contiguous area of guest memory, but does not perform
+ * any byteswapping.  lock_user may return either a pointer to the guest
+ * memory, or a temporary buffer.
+ */
 
-/* Lock an area of guest memory into the host.  If copy is true then the
-   host area will have the same contents as the guest.  */
-static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy)
+/*
+ * Lock an area of guest memory into the host.  If copy is true then the
+ * host area will have the same contents as the guest.
+ */
+static inline void *lock_user(int type, abi_ulong guest_addr, long len,
+                              int copy)
 {
     if (!access_ok(type, guest_addr, len))
         return NULL;
@@ -364,9 +373,10 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy
 #endif
 }
 
-/* Unlock an area of guest memory.  The first LEN bytes must be
-   flushed back to guest memory. host_ptr = NULL is explicitly
-   allowed and does nothing. */
+/*
+ * Unlock an area of guest memory.  The first LEN bytes must be flushed back to
+ * guest memory. host_ptr = NULL is explicitly allowed and does nothing.
+ */
 static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
                                long len)
 {
@@ -382,8 +392,10 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
 #endif
 }
 
-/* Return the length of a string in target memory or -TARGET_EFAULT if
-   access error. */
+/*
+ * Return the length of a string in target memory or -TARGET_EFAULT if access
+ * error.
+ */
 abi_long target_strlen(abi_ulong gaddr);
 
 /* Like lock_user but for null terminated strings.  */
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 34/48] bsd-user: style tweak: don't assign in if statements
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (32 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 33/48] bsd-user: style tweak: Use preferred block comments imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:09   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 35/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
                   ` (14 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/qemu.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index 7f3cfa68aa..2494d9209d 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -288,7 +288,8 @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
     abi_ulong __gaddr = (gaddr);                                        \
     target_type *__hptr;                                                \
     abi_long __ret;                                                     \
-    if ((__hptr = lock_user(VERIFY_WRITE, __gaddr, sizeof(target_type), 0))) { \
+    __hptr = lock_user(VERIFY_WRITE, __gaddr, sizeof(target_type), 0);  \
+    if (__hptr) {                                                       \
         __ret = __put_user((x), __hptr);                                \
         unlock_user(__hptr, __gaddr, sizeof(target_type));              \
     } else                                                              \
@@ -301,7 +302,8 @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
     abi_ulong __gaddr = (gaddr);                                        \
     target_type *__hptr;                                                \
     abi_long __ret;                                                     \
-    if ((__hptr = lock_user(VERIFY_READ, __gaddr, sizeof(target_type), 1))) { \
+    __hptr = lock_user(VERIFY_READ, __gaddr, sizeof(target_type), 1);   \
+    if (__hptr) {                                                       \
         __ret = __get_user((x), __hptr);                                \
         unlock_user(__hptr, __gaddr, 0);                                \
     } else {                                                            \
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 35/48] bsd-user: style tweak: use {} for all if statements, format else correctly
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (33 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 34/48] bsd-user: style tweak: don't assign in if statements imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:12   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 36/48] bsd-user: style tweak: Use preferred block comments imp
                   ` (13 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/qemu.h | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index 2494d9209d..8d3767964d 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -358,16 +358,18 @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len);
 static inline void *lock_user(int type, abi_ulong guest_addr, long len,
                               int copy)
 {
-    if (!access_ok(type, guest_addr, len))
+    if (!access_ok(type, guest_addr, len)) {
         return NULL;
+    }
 #ifdef DEBUG_REMAP
     {
         void *addr;
         addr = g_malloc(len);
-        if (copy)
+        if (copy) {
             memcpy(addr, g2h_untagged(guest_addr), len);
-        else
+        } else {
             memset(addr, 0, len);
+        }
         return addr;
     }
 #else
@@ -384,12 +386,15 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
 {
 
 #ifdef DEBUG_REMAP
-    if (!host_ptr)
+    if (!host_ptr) {
         return;
-    if (host_ptr == g2h_untagged(guest_addr))
+    }
+    if (host_ptr == g2h_untagged(guest_addr)) {
         return;
-    if (len > 0)
+    }
+    if (len > 0) {
         memcpy(g2h_untagged(guest_addr), host_ptr, len);
+    }
     g_free(host_ptr);
 #endif
 }
@@ -405,8 +410,9 @@ static inline void *lock_user_string(abi_ulong guest_addr)
 {
     abi_long len;
     len = target_strlen(guest_addr);
-    if (len < 0)
+    if (len < 0) {
         return NULL;
+    }
     return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1);
 }
 
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 36/48] bsd-user: style tweak: Use preferred block comments
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (34 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 35/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:13   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 37/48] bsd-user: style tweak: don't assign in if statements imp
                   ` (12 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/uaccess.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/bsd-user/uaccess.c b/bsd-user/uaccess.c
index 89163257f4..7eb4546fed 100644
--- a/bsd-user/uaccess.c
+++ b/bsd-user/uaccess.c
@@ -4,9 +4,10 @@
 
 #include "qemu.h"
 
-/* copy_from_user() and copy_to_user() are usually used to copy data
- * buffers between the target and host.  These internally perform
- * locking/unlocking of the memory.
+/*
+ * copy_from_user() and copy_to_user() are usually used to copy data buffers
+ * between the target and host.  These internally perform locking/unlocking of
+ * the memory.
  */
 abi_long copy_from_user(void *hptr, abi_ulong gaddr, size_t len)
 {
@@ -37,8 +38,10 @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len)
     return ret;
 }
 
-/* Return the length of a string in target memory or -TARGET_EFAULT if
-   access error  */
+/*
+ * Return the length of a string in target memory or -TARGET_EFAULT if access
+ * error
+ */
 abi_long target_strlen(abi_ulong guest_addr1)
 {
     uint8_t *ptr;
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 37/48] bsd-user: style tweak: don't assign in if statements
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (35 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 36/48] bsd-user: style tweak: Use preferred block comments imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:14   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 38/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
                   ` (11 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/uaccess.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/bsd-user/uaccess.c b/bsd-user/uaccess.c
index 7eb4546fed..aab5e995a9 100644
--- a/bsd-user/uaccess.c
+++ b/bsd-user/uaccess.c
@@ -14,7 +14,8 @@ abi_long copy_from_user(void *hptr, abi_ulong gaddr, size_t len)
     abi_long ret = 0;
     void *ghptr;
 
-    if ((ghptr = lock_user(VERIFY_READ, gaddr, len, 1))) {
+    ghptr = lock_user(VERIFY_READ, gaddr, len, 1);
+    if (ghptr) {
         memcpy(hptr, ghptr, len);
         unlock_user(ghptr, gaddr, 0);
     } else
@@ -29,7 +30,8 @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len)
     abi_long ret = 0;
     void *ghptr;
 
-    if ((ghptr = lock_user(VERIFY_WRITE, gaddr, len, 0))) {
+    ghptr = lock_user(VERIFY_WRITE, gaddr, len, 0);
+    if (ghptr) {
         memcpy(ghptr, hptr, len);
         unlock_user(ghptr, gaddr, len);
     } else
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 38/48] bsd-user: style tweak: use {} for all if statements, format else correctly
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (36 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 37/48] bsd-user: style tweak: don't assign in if statements imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:15   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 39/48] bsd-user: style tweak: spaces around =, remove stray space imp
                   ` (10 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/uaccess.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/bsd-user/uaccess.c b/bsd-user/uaccess.c
index aab5e995a9..2e8ad2982f 100644
--- a/bsd-user/uaccess.c
+++ b/bsd-user/uaccess.c
@@ -54,8 +54,9 @@ abi_long target_strlen(abi_ulong guest_addr1)
     for (;;) {
         max_len = TARGET_PAGE_SIZE - (guest_addr & ~TARGET_PAGE_MASK);
         ptr = lock_user(VERIFY_READ, guest_addr, max_len, 1);
-        if (!ptr)
+        if (!ptr) {
             return -TARGET_EFAULT;
+        }
         len = qemu_strnlen((const char *)ptr, max_len);
         unlock_user(ptr, guest_addr, 0);
         guest_addr += len;
@@ -63,8 +64,9 @@ abi_long target_strlen(abi_ulong guest_addr1)
         if (guest_addr == 0 ||
             (guest_addr - guest_addr1) > 0x7fffffff)
             return -TARGET_EFAULT;
-        if (len != max_len)
+        if (len != max_len) {
             break;
+        }
     }
     return guest_addr - guest_addr1;
 }
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 39/48] bsd-user: style tweak: spaces around =, remove stray space
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (37 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 38/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:16   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 40/48] bsd-user: style tweak: Use preferred block comments imp
                   ` (9 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/strace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bsd-user/strace.c b/bsd-user/strace.c
index be40b8a20c..e4153fd0a1 100644
--- a/bsd-user/strace.c
+++ b/bsd-user/strace.c
@@ -147,11 +147,11 @@ static void print_syscall(int num, const struct syscallname *scnames,
         abi_long arg4, abi_long arg5, abi_long arg6)
 {
     unsigned int i;
-    const char *format="%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
+    const char *format = "%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
         TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
         TARGET_ABI_FMT_ld ")";
 
-    gemu_log("%d ", getpid() );
+    gemu_log("%d ", getpid());
 
     for (i = 0; i < nscnames; i++) {
         if (scnames[i].nr == num) {
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 40/48] bsd-user: style tweak: Use preferred block comments
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (38 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 39/48] bsd-user: style tweak: spaces around =, remove stray space imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:16   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 41/48] bsd-user: style tweak: don't assign in if statements imp
                   ` (8 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/strace.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/bsd-user/strace.c b/bsd-user/strace.c
index e4153fd0a1..aa4ab8cee7 100644
--- a/bsd-user/strace.c
+++ b/bsd-user/strace.c
@@ -159,8 +159,10 @@ static void print_syscall(int num, const struct syscallname *scnames,
                 scnames[i].call(&scnames[i], arg1, arg2, arg3, arg4, arg5,
                         arg6);
             } else {
-                /* XXX: this format system is broken because it uses
-                   host types and host pointers for strings */
+                /*
+                 * XXX: this format system is broken because it uses host types
+                 * and host pointers for strings
+                 */
                 if (scnames[i].format != NULL) {
                     format = scnames[i].format;
                 }
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 41/48] bsd-user: style tweak: don't assign in if statements
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (39 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 40/48] bsd-user: style tweak: Use preferred block comments imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:17   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 42/48] bsd-user: style tweak: spaces around operators and commas imp
                   ` (7 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/strace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bsd-user/strace.c b/bsd-user/strace.c
index aa4ab8cee7..94f2b59565 100644
--- a/bsd-user/strace.c
+++ b/bsd-user/strace.c
@@ -80,7 +80,8 @@ static void print_execve(const struct syscallname *name, abi_long arg1,
         if (!arg_addr) {
             break;
         }
-        if ((s = lock_user_string(arg_addr))) {
+        s = lock_user_string(arg_addr);
+        if (s) {
             gemu_log("\"%s\",", s);
             unlock_user(s, arg_addr, 0);
         }
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 42/48] bsd-user: style tweak: spaces around operators and commas
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (40 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 41/48] bsd-user: style tweak: don't assign in if statements imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:18   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 43/48] bsd-user: style tweak: fold long lines imp
                   ` (6 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/syscall.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c
index 3352735c68..5e033e8bf4 100644
--- a/bsd-user/syscall.c
+++ b/bsd-user/syscall.c
@@ -77,8 +77,8 @@ static abi_long do_obreak(abi_ulong new_brk)
     /* We need to allocate more memory after the brk... */
     new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page + 1);
     mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size,
-                                        PROT_READ|PROT_WRITE,
-                                        MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0));
+                                        PROT_READ | PROT_WRITE,
+                                        MAP_ANON | MAP_FIXED | MAP_PRIVATE, -1, 0));
 
     if (!is_error(mapped_addr))
         target_brk = new_brk;
@@ -158,7 +158,7 @@ static abi_long do_freebsd_sysarch(void *env, int op, abi_ulong parms)
 static int
 oidfmt(int *oid, int len, char *fmt, uint32_t *kind)
 {
-    int qoid[CTL_MAXNAME+2];
+    int qoid[CTL_MAXNAME + 2];
     uint8_t buf[BUFSIZ];
     int i;
     size_t j;
@@ -241,7 +241,7 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
         return -TARGET_EFAULT;
     holdlen = oldlen;
     for (p = hnamep, q = snamep, i = 0; i < namelen; p++, i++)
-       *q++ = tswap32(*p);
+        *q++ = tswap32(*p);
     oidfmt(snamep, namelen, NULL, &kind);
     /* XXX swap hnewp */
     ret = get_errno(sysctl(snamep, namelen, holdp, &holdlen, hnewp, newlen));
@@ -271,7 +271,7 @@ static abi_long lock_iovec(int type, struct iovec *vec, abi_ulong target_addr,
     target_vec = lock_user(VERIFY_READ, target_addr, count * sizeof(struct target_iovec), 1);
     if (!target_vec)
         return -TARGET_EFAULT;
-    for (i = 0;i < count; i++) {
+    for (i = 0; i < count; i++) {
         base = tswapl(target_vec[i].iov_base);
         vec[i].iov_len = tswapl(target_vec[i].iov_len);
         if (vec[i].iov_len != 0) {
@@ -283,7 +283,7 @@ static abi_long lock_iovec(int type, struct iovec *vec, abi_ulong target_addr,
             vec[i].iov_base = NULL;
         }
     }
-    unlock_user (target_vec, target_addr, 0);
+    unlock_user(target_vec, target_addr, 0);
     return 0;
 }
 
@@ -297,13 +297,13 @@ static abi_long unlock_iovec(struct iovec *vec, abi_ulong target_addr,
     target_vec = lock_user(VERIFY_READ, target_addr, count * sizeof(struct target_iovec), 1);
     if (!target_vec)
         return -TARGET_EFAULT;
-    for (i = 0;i < count; i++) {
+    for (i = 0; i < count; i++) {
         if (target_vec[i].iov_base) {
             base = tswapl(target_vec[i].iov_base);
             unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0);
         }
     }
-    unlock_user (target_vec, target_addr, 0);
+    unlock_user(target_vec, target_addr, 0);
 
     return 0;
 }
@@ -393,7 +393,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_FREEBSD_NR_syscall:
     case TARGET_FREEBSD_NR___syscall:
-        ret = do_freebsd_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,arg7,arg8,0);
+        ret = do_freebsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 0);
         break;
     default:
         ret = get_errno(syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8));
@@ -472,7 +472,7 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_NETBSD_NR_syscall:
     case TARGET_NETBSD_NR___syscall:
-        ret = do_netbsd_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0);
+        ret = do_netbsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, arg6, 0);
         break;
     default:
         ret = syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -551,7 +551,7 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_OPENBSD_NR_syscall:
     case TARGET_OPENBSD_NR___syscall:
-        ret = do_openbsd_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0);
+        ret = do_openbsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, arg6, 0);
         break;
     default:
         ret = syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 43/48] bsd-user: style tweak: fold long lines
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (41 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 42/48] bsd-user: style tweak: spaces around operators and commas imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:18   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 44/48] bsd-user: style tweak: use preferred block comments imp
                   ` (5 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/syscall.c | 40 +++++++++++++++++++++++++---------------
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c
index 5e033e8bf4..46c0e29841 100644
--- a/bsd-user/syscall.c
+++ b/bsd-user/syscall.c
@@ -28,8 +28,6 @@
 #include "qemu-common.h"
 #include "user/syscall-trace.h"
 
-//#define DEBUG
-
 static abi_ulong target_brk;
 static abi_ulong target_original_brk;
 
@@ -78,7 +76,8 @@ static abi_long do_obreak(abi_ulong new_brk)
     new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page + 1);
     mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size,
                                         PROT_READ | PROT_WRITE,
-                                        MAP_ANON | MAP_FIXED | MAP_PRIVATE, -1, 0));
+                                        MAP_ANON | MAP_FIXED | MAP_PRIVATE,
+                                        -1, 0));
 
     if (!is_error(mapped_addr))
         target_brk = new_brk;
@@ -221,8 +220,9 @@ static int sysctl_oldcvt(void *holdp, size_t holdlen, uint32_t kind)
 }
 
 /* XXX this needs to be emulated on non-FreeBSD hosts... */
-static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong oldp,
-                          abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen)
+static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen,
+                                  abi_ulong oldp, abi_ulong oldlenp,
+                                  abi_ulong newp, abi_ulong newlen)
 {
     abi_long ret;
     void *hnamep, *holdp, *hnewp = NULL;
@@ -268,7 +268,8 @@ static abi_long lock_iovec(int type, struct iovec *vec, abi_ulong target_addr,
     abi_ulong base;
     int i;
 
-    target_vec = lock_user(VERIFY_READ, target_addr, count * sizeof(struct target_iovec), 1);
+    target_vec = lock_user(VERIFY_READ, target_addr,
+                           count * sizeof(struct target_iovec), 1);
     if (!target_vec)
         return -TARGET_EFAULT;
     for (i = 0; i < count; i++) {
@@ -294,7 +295,8 @@ static abi_long unlock_iovec(struct iovec *vec, abi_ulong target_addr,
     abi_ulong base;
     int i;
 
-    target_vec = lock_user(VERIFY_READ, target_addr, count * sizeof(struct target_iovec), 1);
+    target_vec = lock_user(VERIFY_READ, target_addr,
+                           count * sizeof(struct target_iovec), 1);
     if (!target_vec)
         return -TARGET_EFAULT;
     for (i = 0; i < count; i++) {
@@ -373,7 +375,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_FREEBSD_NR_mmap:
         ret = get_errno(target_mmap(arg1, arg2, arg3,
-                                    target_to_host_bitmask(arg4, mmap_flags_tbl),
+                                    target_to_host_bitmask(arg4,
+                                                           mmap_flags_tbl),
                                     arg5,
                                     arg6));
         break;
@@ -393,10 +396,12 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_FREEBSD_NR_syscall:
     case TARGET_FREEBSD_NR___syscall:
-        ret = do_freebsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 0);
+        ret = do_freebsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4,
+                                 arg5, arg6, arg7, arg8, 0);
         break;
     default:
-        ret = get_errno(syscall(num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8));
+        ret = get_errno(syscall(num, arg1, arg2, arg3, arg4, arg5, arg6,
+                                arg7, arg8));
         break;
     }
  fail:
@@ -463,7 +468,8 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_NETBSD_NR_mmap:
         ret = get_errno(target_mmap(arg1, arg2, arg3,
-                                    target_to_host_bitmask(arg4, mmap_flags_tbl),
+                                    target_to_host_bitmask(arg4,
+                                                           mmap_flags_tbl),
                                     arg5,
                                     arg6));
         break;
@@ -472,7 +478,8 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_NETBSD_NR_syscall:
     case TARGET_NETBSD_NR___syscall:
-        ret = do_netbsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, arg6, 0);
+        ret = do_netbsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5,
+                                arg6, 0);
         break;
     default:
         ret = syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -536,13 +543,15 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(open(path(p),
-                             target_to_host_bitmask(arg2, fcntl_flags_tbl),
+                             target_to_host_bitmask(arg2,
+                                                    fcntl_flags_tbl),
                              arg3));
         unlock_user(p, arg1, 0);
         break;
     case TARGET_OPENBSD_NR_mmap:
         ret = get_errno(target_mmap(arg1, arg2, arg3,
-                                    target_to_host_bitmask(arg4, mmap_flags_tbl),
+                                    target_to_host_bitmask(arg4,
+                                                           mmap_flags_tbl),
                                     arg5,
                                     arg6));
         break;
@@ -551,7 +560,8 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_OPENBSD_NR_syscall:
     case TARGET_OPENBSD_NR___syscall:
-        ret = do_openbsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, arg6, 0);
+        ret = do_openbsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4,
+                                 arg5, arg6, 0);
         break;
     default:
         ret = syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 44/48] bsd-user: style tweak: use preferred block comments
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (42 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 43/48] bsd-user: style tweak: fold long lines imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:19   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 45/48] bsd-user: style tweak: Use preferred {} in if/else statements imp
                   ` (4 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/syscall.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c
index 46c0e29841..fbe3b3b2fe 100644
--- a/bsd-user/syscall.c
+++ b/bsd-user/syscall.c
@@ -140,8 +140,8 @@ static abi_long do_freebsd_sysarch(CPUX86State *env, int op, abi_ulong parms)
 #ifdef TARGET_SPARC
 static abi_long do_freebsd_sysarch(void *env, int op, abi_ulong parms)
 {
-    /* XXX handle
-     * TARGET_FREEBSD_SPARC_UTRAP_INSTALL,
+    /*
+     * XXX handle TARGET_FREEBSD_SPARC_UTRAP_INSTALL,
      * TARGET_FREEBSD_SPARC_SIGTRAMP_INSTALL
      */
     return -TARGET_EINVAL;
@@ -257,7 +257,8 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen,
 }
 #endif
 
-/* FIXME
+/*
+ * FIXME
  * lock_iovec()/unlock_iovec() have a return code of 0 for success where
  * other lock functions have a return code of 0 for failure.
  */
@@ -277,8 +278,10 @@ static abi_long lock_iovec(int type, struct iovec *vec, abi_ulong target_addr,
         vec[i].iov_len = tswapl(target_vec[i].iov_len);
         if (vec[i].iov_len != 0) {
             vec[i].iov_base = lock_user(type, base, vec[i].iov_len, copy);
-            /* Don't check lock_user return value. We must call writev even
-               if a element has invalid base address. */
+            /*
+             * Don't check lock_user return value. We must call writev even if a
+             * element has invalid base address.
+             */
         } else {
             /* zero length pointer is ignored */
             vec[i].iov_base = NULL;
@@ -310,9 +313,11 @@ static abi_long unlock_iovec(struct iovec *vec, abi_ulong target_addr,
     return 0;
 }
 
-/* do_syscall() should always have a single exit point at the end so
-   that actions, such as logging of syscall results, can be performed.
-   All errnos that do_syscall() returns must be -TARGET_<errcode>. */
+/*
+ * do_syscall() should always have a single exit point at the end so that
+ * actions, such as logging of syscall results, can be performed.  All errnos
+ * that do_syscall() returns must be -TARGET_<errcode>.
+ */
 abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
                             abi_long arg2, abi_long arg3, abi_long arg4,
                             abi_long arg5, abi_long arg6, abi_long arg7,
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 45/48] bsd-user: style tweak: Use preferred {} in if/else statements.
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (43 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 44/48] bsd-user: style tweak: use preferred block comments imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:21   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 46/48] bsd-user: style tweak: Return is not a function call imp
                   ` (3 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/syscall.c | 120 +++++++++++++++++++++++++++++----------------
 1 file changed, 78 insertions(+), 42 deletions(-)

diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c
index fbe3b3b2fe..36ffa6a880 100644
--- a/bsd-user/syscall.c
+++ b/bsd-user/syscall.c
@@ -33,11 +33,12 @@ static abi_ulong target_original_brk;
 
 static inline abi_long get_errno(abi_long ret)
 {
-    if (ret == -1)
+    if (ret == -1) {
         /* XXX need to translate host -> target errnos here */
         return -(errno);
-    else
+    } else {
         return ret;
+    }
 }
 
 #define target_to_host_bitmask(x, tbl) (x)
@@ -59,10 +60,12 @@ static abi_long do_obreak(abi_ulong new_brk)
     abi_long mapped_addr;
     int new_alloc_size;
 
-    if (!new_brk)
+    if (!new_brk) {
         return 0;
-    if (new_brk < target_original_brk)
+    }
+    if (new_brk < target_original_brk) {
         return -TARGET_EINVAL;
+    }
 
     brk_page = HOST_PAGE_ALIGN(target_brk);
 
@@ -79,10 +82,11 @@ static abi_long do_obreak(abi_ulong new_brk)
                                         MAP_ANON | MAP_FIXED | MAP_PRIVATE,
                                         -1, 0));
 
-    if (!is_error(mapped_addr))
+    if (!is_error(mapped_addr)) {
         target_brk = new_brk;
-    else
+    } else {
         return mapped_addr;
+    }
 
     return 0;
 }
@@ -98,35 +102,39 @@ static abi_long do_freebsd_sysarch(CPUX86State *env, int op, abi_ulong parms)
 #ifdef TARGET_ABI32
     case TARGET_FREEBSD_I386_SET_GSBASE:
     case TARGET_FREEBSD_I386_SET_FSBASE:
-        if (op == TARGET_FREEBSD_I386_SET_GSBASE)
+        if (op == TARGET_FREEBSD_I386_SET_GSBASE) {
 #else
     case TARGET_FREEBSD_AMD64_SET_GSBASE:
     case TARGET_FREEBSD_AMD64_SET_FSBASE:
-        if (op == TARGET_FREEBSD_AMD64_SET_GSBASE)
+        if (op == TARGET_FREEBSD_AMD64_SET_GSBASE) {
 #endif
             idx = R_GS;
-        else
+        } else {
             idx = R_FS;
-        if (get_user(val, parms, abi_ulong))
+        }
+        if (get_user(val, parms, abi_ulong)) {
             return -TARGET_EFAULT;
+        }
         cpu_x86_load_seg(env, idx, 0);
         env->segs[idx].base = val;
         break;
 #ifdef TARGET_ABI32
     case TARGET_FREEBSD_I386_GET_GSBASE:
     case TARGET_FREEBSD_I386_GET_FSBASE:
-        if (op == TARGET_FREEBSD_I386_GET_GSBASE)
+        if (op == TARGET_FREEBSD_I386_GET_GSBASE) {
 #else
     case TARGET_FREEBSD_AMD64_GET_GSBASE:
     case TARGET_FREEBSD_AMD64_GET_FSBASE:
-        if (op == TARGET_FREEBSD_AMD64_GET_GSBASE)
+        if (op == TARGET_FREEBSD_AMD64_GET_GSBASE) {
 #endif
             idx = R_GS;
-        else
+        } else {
             idx = R_FS;
+        }
         val = env->segs[idx].base;
-        if (put_user(val, parms, abi_ulong))
+        if (put_user(val, parms, abi_ulong)) {
             return -TARGET_EFAULT;
+        }
         break;
     /* XXX handle the others... */
     default:
@@ -168,14 +176,17 @@ oidfmt(int *oid, int len, char *fmt, uint32_t *kind)
 
     j = sizeof(buf);
     i = sysctl(qoid, len + 2, buf, &j, 0, 0);
-    if (i)
+    if (i) {
         return i;
+    }
 
-    if (kind)
+    if (kind) {
         *kind = *(uint32_t *)buf;
+    }
 
-    if (fmt)
+    if (fmt) {
         strcpy(fmt, (char *)(buf + sizeof(uint32_t)));
+    }
     return (0);
 }
 
@@ -231,27 +242,34 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen,
     int32_t *snamep = g_malloc(sizeof(int32_t) * namelen), *p, *q, i;
     uint32_t kind = 0;
 
-    if (oldlenp)
+    if (oldlenp) {
         get_user_ual(oldlen, oldlenp);
-    if (!(hnamep = lock_user(VERIFY_READ, namep, namelen, 1)))
+    }
+    if (!(hnamep = lock_user(VERIFY_READ, namep, namelen, 1))) {
         return -TARGET_EFAULT;
-    if (newp && !(hnewp = lock_user(VERIFY_READ, newp, newlen, 1)))
+    }
+    if (newp && !(hnewp = lock_user(VERIFY_READ, newp, newlen, 1))) {
         return -TARGET_EFAULT;
-    if (!(holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0)))
+    }
+    if (!(holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0))) {
         return -TARGET_EFAULT;
+    }
     holdlen = oldlen;
-    for (p = hnamep, q = snamep, i = 0; i < namelen; p++, i++)
+    for (p = hnamep, q = snamep, i = 0; i < namelen; p++, i++) {
         *q++ = tswap32(*p);
+    }
     oidfmt(snamep, namelen, NULL, &kind);
     /* XXX swap hnewp */
     ret = get_errno(sysctl(snamep, namelen, holdp, &holdlen, hnewp, newlen));
-    if (!ret)
+    if (!ret) {
         sysctl_oldcvt(holdp, holdlen, kind);
+    }
     put_user_ual(holdlen, oldlenp);
     unlock_user(hnamep, namep, 0);
     unlock_user(holdp, oldp, holdlen);
-    if (hnewp)
+    if (hnewp) {
         unlock_user(hnewp, newp, 0);
+    }
     g_free(snamep);
     return ret;
 }
@@ -271,8 +289,9 @@ static abi_long lock_iovec(int type, struct iovec *vec, abi_ulong target_addr,
 
     target_vec = lock_user(VERIFY_READ, target_addr,
                            count * sizeof(struct target_iovec), 1);
-    if (!target_vec)
+    if (!target_vec) {
         return -TARGET_EFAULT;
+    }
     for (i = 0; i < count; i++) {
         base = tswapl(target_vec[i].iov_base);
         vec[i].iov_len = tswapl(target_vec[i].iov_len);
@@ -300,8 +319,9 @@ static abi_long unlock_iovec(struct iovec *vec, abi_ulong target_addr,
 
     target_vec = lock_user(VERIFY_READ, target_addr,
                            count * sizeof(struct target_iovec), 1);
-    if (!target_vec)
+    if (!target_vec) {
         return -TARGET_EFAULT;
+    }
     for (i = 0; i < count; i++) {
         if (target_vec[i].iov_base) {
             base = tswapl(target_vec[i].iov_base);
@@ -332,8 +352,9 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
 #endif
     record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
 
-    if (do_strace)
+    if (do_strace) {
         print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
+    }
 
     switch (num) {
     case TARGET_FREEBSD_NR_exit:
@@ -347,14 +368,16 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = 0; /* avoid warning */
         break;
     case TARGET_FREEBSD_NR_read:
-        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
+        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) {
             goto efault;
+        }
         ret = get_errno(read(arg1, p, arg3));
         unlock_user(p, arg2, ret);
         break;
     case TARGET_FREEBSD_NR_write:
-        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
+        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) {
             goto efault;
+        }
         ret = get_errno(write(arg1, p, arg3));
         unlock_user(p, arg2, 0);
         break;
@@ -364,15 +387,17 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
             struct iovec *vec;
 
             vec = alloca(count * sizeof(struct iovec));
-            if (lock_iovec(VERIFY_READ, vec, arg2, count, 1) < 0)
+            if (lock_iovec(VERIFY_READ, vec, arg2, count, 1) < 0) {
                 goto efault;
+            }
             ret = get_errno(writev(arg1, vec, count));
             unlock_iovec(vec, arg2, count, 0);
         }
         break;
     case TARGET_FREEBSD_NR_open:
-        if (!(p = lock_user_string(arg1)))
+        if (!(p = lock_user_string(arg1))) {
             goto efault;
+        }
         ret = get_errno(open(path(p),
                              target_to_host_bitmask(arg2, fcntl_flags_tbl),
                              arg3));
@@ -413,8 +438,9 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
 #ifdef DEBUG
     gemu_log(" = %ld\n", ret);
 #endif
-    if (do_strace)
+    if (do_strace) {
         print_freebsd_syscall_ret(num, ret);
+    }
 
     record_syscall_return(cpu, num, ret);
     return ret;
@@ -437,8 +463,9 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
 
     record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
 
-    if (do_strace)
+    if (do_strace) {
         print_netbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
+    }
 
     switch (num) {
     case TARGET_NETBSD_NR_exit:
@@ -452,20 +479,23 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = 0; /* avoid warning */
         break;
     case TARGET_NETBSD_NR_read:
-        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
+        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) {
             goto efault;
+        }
         ret = get_errno(read(arg1, p, arg3));
         unlock_user(p, arg2, ret);
         break;
     case TARGET_NETBSD_NR_write:
-        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
+        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) {
             goto efault;
+        }
         ret = get_errno(write(arg1, p, arg3));
         unlock_user(p, arg2, 0);
         break;
     case TARGET_NETBSD_NR_open:
-        if (!(p = lock_user_string(arg1)))
+        if (!(p = lock_user_string(arg1))) {
             goto efault;
+        }
         ret = get_errno(open(path(p),
                              target_to_host_bitmask(arg2, fcntl_flags_tbl),
                              arg3));
@@ -494,8 +524,9 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
 #ifdef DEBUG
     gemu_log(" = %ld\n", ret);
 #endif
-    if (do_strace)
+    if (do_strace) {
         print_netbsd_syscall_ret(num, ret);
+    }
 
     record_syscall_return(cpu, num, ret);
     return ret;
@@ -518,8 +549,9 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
 
     record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
 
-    if (do_strace)
+    if (do_strace) {
         print_openbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
+    }
 
     switch (num) {
     case TARGET_OPENBSD_NR_exit:
@@ -533,20 +565,23 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = 0; /* avoid warning */
         break;
     case TARGET_OPENBSD_NR_read:
-        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
+        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) {
             goto efault;
+        }
         ret = get_errno(read(arg1, p, arg3));
         unlock_user(p, arg2, ret);
         break;
     case TARGET_OPENBSD_NR_write:
-        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
+        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) {
             goto efault;
+        }
         ret = get_errno(write(arg1, p, arg3));
         unlock_user(p, arg2, 0);
         break;
     case TARGET_OPENBSD_NR_open:
-        if (!(p = lock_user_string(arg1)))
+        if (!(p = lock_user_string(arg1))) {
             goto efault;
+        }
         ret = get_errno(open(path(p),
                              target_to_host_bitmask(arg2,
                                                     fcntl_flags_tbl),
@@ -576,8 +611,9 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
 #ifdef DEBUG
     gemu_log(" = %ld\n", ret);
 #endif
-    if (do_strace)
+    if (do_strace) {
         print_openbsd_syscall_ret(num, ret);
+    }
 
     record_syscall_return(cpu, num, ret);
     return ret;
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 46/48] bsd-user: style tweak: Return is not a function call.
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (44 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 45/48] bsd-user: style tweak: Use preferred {} in if/else statements imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:21   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 47/48] bsd-user: style tweak: don't assign in if statement imp
                   ` (2 subsequent siblings)
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c
index 36ffa6a880..1f6b93923c 100644
--- a/bsd-user/syscall.c
+++ b/bsd-user/syscall.c
@@ -187,7 +187,7 @@ oidfmt(int *oid, int len, char *fmt, uint32_t *kind)
     if (fmt) {
         strcpy(fmt, (char *)(buf + sizeof(uint32_t)));
     }
-    return (0);
+    return 0;
 }
 
 /*
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 47/48] bsd-user: style tweak: don't assign in if statement.
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (45 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 46/48] bsd-user: style tweak: Return is not a function call imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:21   ` Richard Henderson
  2021-04-24 16:00 ` [PATCH v2 48/48] bsd-user: put back a break; that had gone missing imp
  2021-04-24 16:55 ` [PATCH v2 00/48] bsd-user style and reorg patches no-reply
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/syscall.c | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c
index 1f6b93923c..1851311acd 100644
--- a/bsd-user/syscall.c
+++ b/bsd-user/syscall.c
@@ -245,13 +245,18 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen,
     if (oldlenp) {
         get_user_ual(oldlen, oldlenp);
     }
-    if (!(hnamep = lock_user(VERIFY_READ, namep, namelen, 1))) {
+    hnamep = lock_user(VERIFY_READ, namep, namelen, 1);
+    if (!hnamep) {
         return -TARGET_EFAULT;
     }
-    if (newp && !(hnewp = lock_user(VERIFY_READ, newp, newlen, 1))) {
-        return -TARGET_EFAULT;
+    if (newp) {
+        hnewp = lock_user(VERIFY_READ, newp, newlen, 1);
+        if (!hnewp) {
+            return -TARGET_EFAULT;
+        }
     }
-    if (!(holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0))) {
+    holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0);
+    if (!holdp) {
         return -TARGET_EFAULT;
     }
     holdlen = oldlen;
@@ -368,14 +373,16 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = 0; /* avoid warning */
         break;
     case TARGET_FREEBSD_NR_read:
-        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) {
+        p = lock_user(VERIFY_WRITE, arg2, arg3, 0);
+        if (!p) {
             goto efault;
         }
         ret = get_errno(read(arg1, p, arg3));
         unlock_user(p, arg2, ret);
         break;
     case TARGET_FREEBSD_NR_write:
-        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) {
+        p = lock_user(VERIFY_READ, arg2, arg3, 1);
+        if (!p) {
             goto efault;
         }
         ret = get_errno(write(arg1, p, arg3));
@@ -395,7 +402,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
     case TARGET_FREEBSD_NR_open:
-        if (!(p = lock_user_string(arg1))) {
+        p = lock_user_string(arg1);
+        if (!p) {
             goto efault;
         }
         ret = get_errno(open(path(p),
@@ -479,21 +487,24 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = 0; /* avoid warning */
         break;
     case TARGET_NETBSD_NR_read:
-        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) {
+        p = lock_user(VERIFY_WRITE, arg2, arg3, 0);
+        if (!p) {
             goto efault;
         }
         ret = get_errno(read(arg1, p, arg3));
         unlock_user(p, arg2, ret);
         break;
     case TARGET_NETBSD_NR_write:
-        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) {
+        p = lock_user(VERIFY_READ, arg2, arg3, 1);
+        if (!p) {
             goto efault;
         }
         ret = get_errno(write(arg1, p, arg3));
         unlock_user(p, arg2, 0);
         break;
     case TARGET_NETBSD_NR_open:
-        if (!(p = lock_user_string(arg1))) {
+        p = lock_user_string(arg1);
+        if (!p) {
             goto efault;
         }
         ret = get_errno(open(path(p),
@@ -565,21 +576,24 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = 0; /* avoid warning */
         break;
     case TARGET_OPENBSD_NR_read:
-        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) {
+        p = lock_user(VERIFY_WRITE, arg2, arg3, 0);
+        if (!p) {
             goto efault;
         }
         ret = get_errno(read(arg1, p, arg3));
         unlock_user(p, arg2, ret);
         break;
     case TARGET_OPENBSD_NR_write:
-        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) {
+        p = lock_user(VERIFY_READ, arg2, arg3, 1);
+        if (!p) {
             goto efault;
         }
         ret = get_errno(write(arg1, p, arg3));
         unlock_user(p, arg2, 0);
         break;
     case TARGET_OPENBSD_NR_open:
-        if (!(p = lock_user_string(arg1))) {
+        p = lock_user_string(arg1);
+        if (!p) {
             goto efault;
         }
         ret = get_errno(open(path(p),
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* [PATCH v2 48/48] bsd-user: put back a break; that had gone missing...
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (46 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 47/48] bsd-user: style tweak: don't assign in if statement imp
@ 2021-04-24 16:00 ` imp
  2021-04-24 18:22   ` Richard Henderson
  2021-04-24 16:55 ` [PATCH v2 00/48] bsd-user style and reorg patches no-reply
  48 siblings, 1 reply; 84+ messages in thread
From: imp @ 2021-04-24 16:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: kevans, arichardson, Warner Losh

From: Warner Losh <imp@bsdimp.com>

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/syscall.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c
index 1851311acd..d5c3168a6d 100644
--- a/bsd-user/syscall.c
+++ b/bsd-user/syscall.c
@@ -209,6 +209,7 @@ static int sysctl_oldcvt(void *holdp, size_t holdlen, uint32_t kind)
 #else
     case CTLTYPE_LONG:
         *(uint64_t *)holdp = tswap64(*(long *)holdp);
+        break;
     case CTLTYPE_ULONG:
         *(uint64_t *)holdp = tswap64(*(unsigned long *)holdp);
         break;
-- 
2.22.1



^ permalink raw reply related	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 00/48] bsd-user style and reorg patches
  2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
                   ` (47 preceding siblings ...)
  2021-04-24 16:00 ` [PATCH v2 48/48] bsd-user: put back a break; that had gone missing imp
@ 2021-04-24 16:55 ` no-reply
  2021-04-24 17:00   ` Warner Losh
  48 siblings, 1 reply; 84+ messages in thread
From: no-reply @ 2021-04-24 16:55 UTC (permalink / raw)
  To: imp; +Cc: kevans, arichardson, qemu-devel, imp

Patchew URL: https://patchew.org/QEMU/20210424160016.15200-1-imp@bsdimp.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20210424160016.15200-1-imp@bsdimp.com
Subject: [PATCH v2 00/48] bsd-user style and reorg patches

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]         patchew/20210424160016.15200-1-imp@bsdimp.com -> patchew/20210424160016.15200-1-imp@bsdimp.com
Switched to a new branch 'test'
be1f8df bsd-user: put back a break; that had gone missing...
19b2708 bsd-user: style tweak: don't assign in if statement.
1bf13fe bsd-user: style tweak: Return is not a function call.
de239a3 bsd-user: style tweak: Use preferred {} in if/else statements.
cf2e30f bsd-user: style tweak: use preferred block comments
1a93628 bsd-user: style tweak: fold long lines
1448c0f bsd-user: style tweak: spaces around operators and commas
11e0aae bsd-user: style tweak: don't assign in if statements
2c53346 bsd-user: style tweak: Use preferred block comments
8946d14 bsd-user: style tweak: spaces around =, remove stray space
ab7c026 bsd-user: style tweak: use {} for all if statements, format else correctly
3a3b578 bsd-user: style tweak: don't assign in if statements
d32211e bsd-user: style tweak: Use preferred block comments
695b534 bsd-user: style tweak: use {} for all if statements, format else correctly
eca311e bsd-user: style tweak: don't assign in if statements
45bfe91 bsd-user: style tweak: Use preferred block comments
d00c21e bsd-user: style tweak: remove spacing after '*' and add after }
780e9f4 bsd-user: style tweak: use {} for all if statements, format else correctly
e92240f bsd-user: style tweak: fix block comments
cb3234a bsd-user: style tweak: use {} correctly
522e458 bsd-user: style tweak: comments
e7e00a4 bsd-user: style tweak: space pedantry
55da1fd bsd-user: move sparc cpu_loop into target_arch_cpu.h as target_cpu_loop
c546aa9 bsd-user: move x86 (i386 and x86_64) cpu_loop to target_arch_cpu.h
f19b57e bsd-user: create target_arch_cpu.h
7ed989c bsd-user: introduce host_os.h for bsd-specific code and defaults
9cb365d bsd-user: use qemu_strtoul in preference to strtol
4454689 bsd-user: style nits: return is not a function
0c748d0 bsd-user: style tweak: use {} consistently in for / if / else statements
3ce10b8 bsd-user: style tweak: move extern to header file
3aa06bf bsd-user: style tweak: Use preferred block comments
2e4fcda bsd-user: style tweak: Fix commentary issues
4416126 bsd-user: style tweak: Put {} around all if/else/for statements
dc7ae60 bsd-user: style tweak: return is not a function, eliminate ()
b84160d bsd-user: style tweak: Remove #if 0'd code
df39a25 bsd-user: style tweak: Remove #if 0'd code
9d92841 bsd-user: style tweak: Remove #if 0'd code
7ef0035 bsd-user: style tweak: Remove #if 0'd code
00a0b5e bsd-user: Remove commented out code
c87209f bsd-user: style tweak: use C not C++ comments
1284f86 bsd-user: style tweak: use C not C++ comments
afedaf7 bsd-user: style tweak: keyword space (
d903536 bsd-user: style tweak: keyword space (
a9aa3e4 bsd-user: style tweak: keyword space (
64b81a2 bsd-user: style tweak: keyword space (
1c1ed78 bsd-user: whitespace changes
3d281e8 bsd-user: whitespace changes
6f7ee37 bsd-user: whitespace changes

=== OUTPUT BEGIN ===
1/48 Checking commit 6f7ee37e5c9f (bsd-user: whitespace changes)
2/48 Checking commit 3d281e896a43 (bsd-user: whitespace changes)
WARNING: line over 80 characters
#149: FILE: bsd-user/elfload.c:541:
+#define TARGET_ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE - 1))

ERROR: braces {} are necessary for all arms of this statement
#331: FILE: bsd-user/elfload.c:867:
+    if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZE)
[...]

ERROR: braces {} are necessary for all arms of this statement
#341: FILE: bsd-user/elfload.c:873:
+    if (!elf_phdata)
[...]

ERROR: space prohibited between function name and open parenthesis '('
#382: FILE: bsd-user/elfload.c:894:
+        free (elf_phdata);

ERROR: spaces required around that '<' (ctx:VxV)
#391: FILE: bsd-user/elfload.c:899:
+    for (i = 0; i<interp_elf_ex->e_phnum; i++, eppnt++) {
                  ^

WARNING: Block comments use a leading /* on a separate line
#409: FILE: bsd-user/elfload.c:905:
+        /* in order to avoid hardcoding the interpreter load

WARNING: Block comments use * on subsequent lines
#410: FILE: bsd-user/elfload.c:906:
+        /* in order to avoid hardcoding the interpreter load
+           address in qemu, we allocate a big enough memory zone */

WARNING: Block comments use a trailing */ on a separate line
#410: FILE: bsd-user/elfload.c:906:
+           address in qemu, we allocate a big enough memory zone */

WARNING: line over 80 characters
#442: FILE: bsd-user/elfload.c:934:
+                                eppnt->p_filesz + TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr),

WARNING: line over 80 characters
#446: FILE: bsd-user/elfload.c:938:
+                                eppnt->p_offset - TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr));

ERROR: line over 90 characters
#507: FILE: bsd-user/elfload.c:978:
+    elf_bss = TARGET_ELF_PAGESTART(elf_bss + qemu_host_page_size - 1); /* What we have mapped so far */

ERROR: space required after that ',' (ctx:VxV)
#554: FILE: bsd-user/elfload.c:1186:
+    bprm->p = copy_elf_strings(bprm->envc, bprm->envp, bprm->page,bprm->p);
                                                                  ^

ERROR: space required after that ',' (ctx:VxV)
#555: FILE: bsd-user/elfload.c:1187:
+    bprm->p = copy_elf_strings(bprm->argc, bprm->argv, bprm->page,bprm->p);
                                                                  ^

ERROR: space required after that ';' (ctx:VxV)
#590: FILE: bsd-user/elfload.c:1230:
+    for (i = 0;i < elf_ex.e_phnum; i++) {
               ^

ERROR: suspect code indent for conditional statements (12, 14)
#626: FILE: bsd-user/elfload.c:1268:
+            if (strcmp(elf_interpreter, "/usr/lib/libc.so.1") == 0 ||
[...]
               ibcs2_interpreter = 1;

total: 9 errors, 6 warnings, 666 lines checked

Patch 2/48 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

3/48 Checking commit 1c1ed7831e8a (bsd-user: whitespace changes)
ERROR: consider using qemu_strtol in preference to strtol
#102: FILE: bsd-user/main.c:835:
+            guest_base = strtol(argv[optind++], NULL, 0);

ERROR: braces {} are necessary for all arms of this statement
#143: FILE: bsd-user/main.c:1126:
+        for (i = 0; i < 8; i++)
[...]

ERROR: braces {} are necessary for all arms of this statement
#146: FILE: bsd-user/main.c:1128:
+        for (i = 0; i < 8; i++)
[...]

total: 3 errors, 0 warnings, 119 lines checked

Patch 3/48 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

4/48 Checking commit 64b81a2f81d0 (bsd-user: style tweak: keyword space ()
5/48 Checking commit a9aa3e409bd8 (bsd-user: style tweak: keyword space ()
6/48 Checking commit d903536bcaa8 (bsd-user: style tweak: keyword space ()
ERROR: space required after that ';' (ctx:VxV)
#32: FILE: bsd-user/syscall.c:274:
+    for (i = 0;i < count; i++) {
               ^

ERROR: space required after that ';' (ctx:VxV)
#41: FILE: bsd-user/syscall.c:300:
+    for (i = 0;i < count; i++) {
               ^

total: 2 errors, 0 warnings, 60 lines checked

Patch 6/48 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

7/48 Checking commit afedaf7c29e2 (bsd-user: style tweak: keyword space ()
8/48 Checking commit 1284f86e9b7b (bsd-user: style tweak: use C not C++ comments)
9/48 Checking commit c87209f1f0f9 (bsd-user: style tweak: use C not C++ comments)
10/48 Checking commit 00a0b5ee4157 (bsd-user: Remove commented out code)
11/48 Checking commit 7ef00352a15f (bsd-user: style tweak: Remove #if 0'd code)
12/48 Checking commit 9d92841f7d3a (bsd-user: style tweak: Remove #if 0'd code)
13/48 Checking commit df39a2547ed7 (bsd-user: style tweak: Remove #if 0'd code)
14/48 Checking commit b84160d0a3db (bsd-user: style tweak: Remove #if 0'd code)
15/48 Checking commit dc7ae6073667 (bsd-user: style tweak: return is not a function, eliminate ())
16/48 Checking commit 4416126bd67b (bsd-user: style tweak: Put {} around all if/else/for statements)
17/48 Checking commit 2e4fcdafda97 (bsd-user: style tweak: Fix commentary issues)
18/48 Checking commit 3aa06bf4a169 (bsd-user: style tweak: Use preferred block comments)
19/48 Checking commit 3ce10b8d1073 (bsd-user: style tweak: move extern to header file)
20/48 Checking commit 0c748d0a6ea1 (bsd-user: style tweak: use {} consistently in for / if / else statements)
21/48 Checking commit 4454689b7dff (bsd-user: style nits: return is not a function)
22/48 Checking commit 9cb365d13f71 (bsd-user: use qemu_strtoul in preference to strtol)
23/48 Checking commit 7ed989c1d383 (bsd-user: introduce host_os.h for bsd-specific code and defaults)
Use of uninitialized value $acpi_testexpected in string eq at ./scripts/checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#24: 
new file mode 100644

WARNING: architecture specific defines should be avoided
#48: FILE: bsd-user/freebsd/host_os.h:20:
+#ifndef __HOST_OS_H_

WARNING: architecture specific defines should be avoided
#101: FILE: bsd-user/netbsd/host_os.h:20:
+#ifndef __HOST_OS_H_

WARNING: architecture specific defines should be avoided
#132: FILE: bsd-user/openbsd/host_os.h:20:
+#ifndef __HOST_OS_H_

total: 0 errors, 4 warnings, 91 lines checked

Patch 23/48 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
24/48 Checking commit f19b57e6a271 (bsd-user: create target_arch_cpu.h)
Use of uninitialized value $acpi_testexpected in string eq at ./scripts/checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#31: 
new file mode 100644

total: 0 errors, 1 warnings, 111 lines checked

Patch 24/48 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
25/48 Checking commit c546aa906cbe (bsd-user: move x86 (i386 and x86_64) cpu_loop to target_arch_cpu.h)
26/48 Checking commit 55da1fd9d9a3 (bsd-user: move sparc cpu_loop into target_arch_cpu.h as target_cpu_loop)
27/48 Checking commit e7e00a4308a1 (bsd-user: style tweak: space pedantry)
ERROR: spaces required around that '=' (ctx:WxV)
#78: FILE: bsd-user/elfload.c:1226:
+    start_data =n 0;
                ^

total: 1 errors, 0 warnings, 73 lines checked

Patch 27/48 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

28/48 Checking commit 522e4589fc17 (bsd-user: style tweak: comments)
29/48 Checking commit cb3234ad892f (bsd-user: style tweak: use {} correctly)
30/48 Checking commit e92240f03f40 (bsd-user: style tweak: fix block comments)
31/48 Checking commit 780e9f44ba8b (bsd-user: style tweak: use {} for all if statements, format else correctly)
32/48 Checking commit d00c21e0a91a (bsd-user: style tweak: remove spacing after '*' and add after })
33/48 Checking commit 45bfe917b433 (bsd-user: style tweak: Use preferred block comments)
34/48 Checking commit eca311e2127b (bsd-user: style tweak: don't assign in if statements)
35/48 Checking commit 695b53466022 (bsd-user: style tweak: use {} for all if statements, format else correctly)
36/48 Checking commit d32211e78858 (bsd-user: style tweak: Use preferred block comments)
37/48 Checking commit 3a3b578aff7b (bsd-user: style tweak: don't assign in if statements)
38/48 Checking commit ab7c026d39c0 (bsd-user: style tweak: use {} for all if statements, format else correctly)
39/48 Checking commit 8946d1425629 (bsd-user: style tweak: spaces around =, remove stray space)
40/48 Checking commit 2c5334681060 (bsd-user: style tweak: Use preferred block comments)
41/48 Checking commit 11e0aae47a39 (bsd-user: style tweak: don't assign in if statements)
42/48 Checking commit 1448c0f5067c (bsd-user: style tweak: spaces around operators and commas)
WARNING: line over 80 characters
#24: FILE: bsd-user/syscall.c:81:
+                                        MAP_ANON | MAP_FIXED | MAP_PRIVATE, -1, 0));

ERROR: line over 90 characters
#85: FILE: bsd-user/syscall.c:396:
+        ret = do_freebsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 0);

WARNING: line over 80 characters
#94: FILE: bsd-user/syscall.c:475:
+        ret = do_netbsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, arg6, 0);

WARNING: line over 80 characters
#103: FILE: bsd-user/syscall.c:554:
+        ret = do_openbsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, arg6, 0);

total: 1 errors, 3 warnings, 81 lines checked

Patch 42/48 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

43/48 Checking commit 1a936284fa25 (bsd-user: style tweak: fold long lines)
44/48 Checking commit cf2e30fc41ca (bsd-user: style tweak: use preferred block comments)
45/48 Checking commit de239a3b68bb (bsd-user: style tweak: Use preferred {} in if/else statements.)
ERROR: do not use assignment in if condition
#139: FILE: bsd-user/syscall.c:248:
+    if (!(hnamep = lock_user(VERIFY_READ, namep, namelen, 1))) {

ERROR: do not use assignment in if condition
#143: FILE: bsd-user/syscall.c:251:
+    if (newp && !(hnewp = lock_user(VERIFY_READ, newp, newlen, 1))) {

ERROR: do not use assignment in if condition
#147: FILE: bsd-user/syscall.c:254:
+    if (!(holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0))) {

ERROR: do not use assignment in if condition
#210: FILE: bsd-user/syscall.c:371:
+        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) {

ERROR: do not use assignment in if condition
#218: FILE: bsd-user/syscall.c:378:
+        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) {

ERROR: do not use assignment in if condition
#238: FILE: bsd-user/syscall.c:398:
+        if (!(p = lock_user_string(arg1))) {

ERROR: do not use assignment in if condition
#271: FILE: bsd-user/syscall.c:482:
+        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) {

ERROR: do not use assignment in if condition
#279: FILE: bsd-user/syscall.c:489:
+        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) {

ERROR: do not use assignment in if condition
#287: FILE: bsd-user/syscall.c:496:
+        if (!(p = lock_user_string(arg1))) {

ERROR: do not use assignment in if condition
#320: FILE: bsd-user/syscall.c:568:
+        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) {

ERROR: do not use assignment in if condition
#328: FILE: bsd-user/syscall.c:575:
+        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) {

ERROR: do not use assignment in if condition
#336: FILE: bsd-user/syscall.c:582:
+        if (!(p = lock_user_string(arg1))) {

total: 12 errors, 0 warnings, 318 lines checked

Patch 45/48 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

46/48 Checking commit 1bf13fe0ac6b (bsd-user: style tweak: Return is not a function call.)
47/48 Checking commit 19b2708a0763 (bsd-user: style tweak: don't assign in if statement.)
48/48 Checking commit be1f8df08151 (bsd-user: put back a break; that had gone missing...)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20210424160016.15200-1-imp@bsdimp.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 00/48] bsd-user style and reorg patches
  2021-04-24 16:55 ` [PATCH v2 00/48] bsd-user style and reorg patches no-reply
@ 2021-04-24 17:00   ` Warner Losh
  0 siblings, 0 replies; 84+ messages in thread
From: Warner Losh @ 2021-04-24 17:00 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Kyle Evans, Alex Richardson

[-- Attachment #1: Type: text/plain, Size: 17927 bytes --]

This is a false positive. The files were wrong before, so it's detecting
residual wrongness in the incremental changes.

The cumulative diff of all 48 patches passes with only warnings:

Use of uninitialized value $acpi_testexpected in string eq at ../scripts/
checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#2:
new file mode 100644

WARNING: architecture specific defines should be avoided
#1641: FILE: bsd-user/freebsd/host_os.h:20:
+#ifndef __HOST_OS_H_

WARNING: architecture specific defines should be avoided
#3123: FILE: bsd-user/netbsd/host_os.h:20:
+#ifndef __HOST_OS_H_

WARNING: architecture specific defines should be avoided
#3154: FILE: bsd-user/openbsd/host_os.h:20:
+#ifndef __HOST_OS_H_

total: 0 errors, 4 warnings, 4264 lines checked

Warner

On Sat, Apr 24, 2021 at 10:55 AM <no-reply@patchew.org> wrote:

> Patchew URL:
> https://patchew.org/QEMU/20210424160016.15200-1-imp@bsdimp.com/
>
>
>
> Hi,
>
> This series seems to have some coding style problems. See output below for
> more information:
>
> Type: series
> Message-id: 20210424160016.15200-1-imp@bsdimp.com
> Subject: [PATCH v2 00/48] bsd-user style and reorg patches
>
> === TEST SCRIPT BEGIN ===
> #!/bin/bash
> git rev-parse base > /dev/null || exit 0
> git config --local diff.renamelimit 0
> git config --local diff.renames True
> git config --local diff.algorithm histogram
> ./scripts/checkpatch.pl --mailback base..
> === TEST SCRIPT END ===
>
> Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
> From https://github.com/patchew-project/qemu
>  * [new tag]         patchew/20210424160016.15200-1-imp@bsdimp.com ->
> patchew/20210424160016.15200-1-imp@bsdimp.com
> Switched to a new branch 'test'
> be1f8df bsd-user: put back a break; that had gone missing...
> 19b2708 bsd-user: style tweak: don't assign in if statement.
> 1bf13fe bsd-user: style tweak: Return is not a function call.
> de239a3 bsd-user: style tweak: Use preferred {} in if/else statements.
> cf2e30f bsd-user: style tweak: use preferred block comments
> 1a93628 bsd-user: style tweak: fold long lines
> 1448c0f bsd-user: style tweak: spaces around operators and commas
> 11e0aae bsd-user: style tweak: don't assign in if statements
> 2c53346 bsd-user: style tweak: Use preferred block comments
> 8946d14 bsd-user: style tweak: spaces around =, remove stray space
> ab7c026 bsd-user: style tweak: use {} for all if statements, format else
> correctly
> 3a3b578 bsd-user: style tweak: don't assign in if statements
> d32211e bsd-user: style tweak: Use preferred block comments
> 695b534 bsd-user: style tweak: use {} for all if statements, format else
> correctly
> eca311e bsd-user: style tweak: don't assign in if statements
> 45bfe91 bsd-user: style tweak: Use preferred block comments
> d00c21e bsd-user: style tweak: remove spacing after '*' and add after }
> 780e9f4 bsd-user: style tweak: use {} for all if statements, format else
> correctly
> e92240f bsd-user: style tweak: fix block comments
> cb3234a bsd-user: style tweak: use {} correctly
> 522e458 bsd-user: style tweak: comments
> e7e00a4 bsd-user: style tweak: space pedantry
> 55da1fd bsd-user: move sparc cpu_loop into target_arch_cpu.h as
> target_cpu_loop
> c546aa9 bsd-user: move x86 (i386 and x86_64) cpu_loop to target_arch_cpu.h
> f19b57e bsd-user: create target_arch_cpu.h
> 7ed989c bsd-user: introduce host_os.h for bsd-specific code and defaults
> 9cb365d bsd-user: use qemu_strtoul in preference to strtol
> 4454689 bsd-user: style nits: return is not a function
> 0c748d0 bsd-user: style tweak: use {} consistently in for / if / else
> statements
> 3ce10b8 bsd-user: style tweak: move extern to header file
> 3aa06bf bsd-user: style tweak: Use preferred block comments
> 2e4fcda bsd-user: style tweak: Fix commentary issues
> 4416126 bsd-user: style tweak: Put {} around all if/else/for statements
> dc7ae60 bsd-user: style tweak: return is not a function, eliminate ()
> b84160d bsd-user: style tweak: Remove #if 0'd code
> df39a25 bsd-user: style tweak: Remove #if 0'd code
> 9d92841 bsd-user: style tweak: Remove #if 0'd code
> 7ef0035 bsd-user: style tweak: Remove #if 0'd code
> 00a0b5e bsd-user: Remove commented out code
> c87209f bsd-user: style tweak: use C not C++ comments
> 1284f86 bsd-user: style tweak: use C not C++ comments
> afedaf7 bsd-user: style tweak: keyword space (
> d903536 bsd-user: style tweak: keyword space (
> a9aa3e4 bsd-user: style tweak: keyword space (
> 64b81a2 bsd-user: style tweak: keyword space (
> 1c1ed78 bsd-user: whitespace changes
> 3d281e8 bsd-user: whitespace changes
> 6f7ee37 bsd-user: whitespace changes
>
> === OUTPUT BEGIN ===
> 1/48 Checking commit 6f7ee37e5c9f (bsd-user: whitespace changes)
> 2/48 Checking commit 3d281e896a43 (bsd-user: whitespace changes)
> WARNING: line over 80 characters
> #149: FILE: bsd-user/elfload.c:541:
> +#define TARGET_ELF_PAGESTART(_v) ((_v) & ~(unsigned
> long)(TARGET_ELF_EXEC_PAGESIZE - 1))
>
> ERROR: braces {} are necessary for all arms of this statement
> #331: FILE: bsd-user/elfload.c:867:
> +    if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum >
> TARGET_PAGE_SIZE)
> [...]
>
> ERROR: braces {} are necessary for all arms of this statement
> #341: FILE: bsd-user/elfload.c:873:
> +    if (!elf_phdata)
> [...]
>
> ERROR: space prohibited between function name and open parenthesis '('
> #382: FILE: bsd-user/elfload.c:894:
> +        free (elf_phdata);
>
> ERROR: spaces required around that '<' (ctx:VxV)
> #391: FILE: bsd-user/elfload.c:899:
> +    for (i = 0; i<interp_elf_ex->e_phnum; i++, eppnt++) {
>                   ^
>
> WARNING: Block comments use a leading /* on a separate line
> #409: FILE: bsd-user/elfload.c:905:
> +        /* in order to avoid hardcoding the interpreter load
>
> WARNING: Block comments use * on subsequent lines
> #410: FILE: bsd-user/elfload.c:906:
> +        /* in order to avoid hardcoding the interpreter load
> +           address in qemu, we allocate a big enough memory zone */
>
> WARNING: Block comments use a trailing */ on a separate line
> #410: FILE: bsd-user/elfload.c:906:
> +           address in qemu, we allocate a big enough memory zone */
>
> WARNING: line over 80 characters
> #442: FILE: bsd-user/elfload.c:934:
> +                                eppnt->p_filesz +
> TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr),
>
> WARNING: line over 80 characters
> #446: FILE: bsd-user/elfload.c:938:
> +                                eppnt->p_offset -
> TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr));
>
> ERROR: line over 90 characters
> #507: FILE: bsd-user/elfload.c:978:
> +    elf_bss = TARGET_ELF_PAGESTART(elf_bss + qemu_host_page_size - 1); /*
> What we have mapped so far */
>
> ERROR: space required after that ',' (ctx:VxV)
> #554: FILE: bsd-user/elfload.c:1186:
> +    bprm->p = copy_elf_strings(bprm->envc, bprm->envp,
> bprm->page,bprm->p);
>                                                                   ^
>
> ERROR: space required after that ',' (ctx:VxV)
> #555: FILE: bsd-user/elfload.c:1187:
> +    bprm->p = copy_elf_strings(bprm->argc, bprm->argv,
> bprm->page,bprm->p);
>                                                                   ^
>
> ERROR: space required after that ';' (ctx:VxV)
> #590: FILE: bsd-user/elfload.c:1230:
> +    for (i = 0;i < elf_ex.e_phnum; i++) {
>                ^
>
> ERROR: suspect code indent for conditional statements (12, 14)
> #626: FILE: bsd-user/elfload.c:1268:
> +            if (strcmp(elf_interpreter, "/usr/lib/libc.so.1") == 0 ||
> [...]
>                ibcs2_interpreter = 1;
>
> total: 9 errors, 6 warnings, 666 lines checked
>
> Patch 2/48 has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.
>
> 3/48 Checking commit 1c1ed7831e8a (bsd-user: whitespace changes)
> ERROR: consider using qemu_strtol in preference to strtol
> #102: FILE: bsd-user/main.c:835:
> +            guest_base = strtol(argv[optind++], NULL, 0);
>
> ERROR: braces {} are necessary for all arms of this statement
> #143: FILE: bsd-user/main.c:1126:
> +        for (i = 0; i < 8; i++)
> [...]
>
> ERROR: braces {} are necessary for all arms of this statement
> #146: FILE: bsd-user/main.c:1128:
> +        for (i = 0; i < 8; i++)
> [...]
>
> total: 3 errors, 0 warnings, 119 lines checked
>
> Patch 3/48 has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.
>
> 4/48 Checking commit 64b81a2f81d0 (bsd-user: style tweak: keyword space ()
> 5/48 Checking commit a9aa3e409bd8 (bsd-user: style tweak: keyword space ()
> 6/48 Checking commit d903536bcaa8 (bsd-user: style tweak: keyword space ()
> ERROR: space required after that ';' (ctx:VxV)
> #32: FILE: bsd-user/syscall.c:274:
> +    for (i = 0;i < count; i++) {
>                ^
>
> ERROR: space required after that ';' (ctx:VxV)
> #41: FILE: bsd-user/syscall.c:300:
> +    for (i = 0;i < count; i++) {
>                ^
>
> total: 2 errors, 0 warnings, 60 lines checked
>
> Patch 6/48 has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.
>
> 7/48 Checking commit afedaf7c29e2 (bsd-user: style tweak: keyword space ()
> 8/48 Checking commit 1284f86e9b7b (bsd-user: style tweak: use C not C++
> comments)
> 9/48 Checking commit c87209f1f0f9 (bsd-user: style tweak: use C not C++
> comments)
> 10/48 Checking commit 00a0b5ee4157 (bsd-user: Remove commented out code)
> 11/48 Checking commit 7ef00352a15f (bsd-user: style tweak: Remove #if 0'd
> code)
> 12/48 Checking commit 9d92841f7d3a (bsd-user: style tweak: Remove #if 0'd
> code)
> 13/48 Checking commit df39a2547ed7 (bsd-user: style tweak: Remove #if 0'd
> code)
> 14/48 Checking commit b84160d0a3db (bsd-user: style tweak: Remove #if 0'd
> code)
> 15/48 Checking commit dc7ae6073667 (bsd-user: style tweak: return is not a
> function, eliminate ())
> 16/48 Checking commit 4416126bd67b (bsd-user: style tweak: Put {} around
> all if/else/for statements)
> 17/48 Checking commit 2e4fcdafda97 (bsd-user: style tweak: Fix commentary
> issues)
> 18/48 Checking commit 3aa06bf4a169 (bsd-user: style tweak: Use preferred
> block comments)
> 19/48 Checking commit 3ce10b8d1073 (bsd-user: style tweak: move extern to
> header file)
> 20/48 Checking commit 0c748d0a6ea1 (bsd-user: style tweak: use {}
> consistently in for / if / else statements)
> 21/48 Checking commit 4454689b7dff (bsd-user: style nits: return is not a
> function)
> 22/48 Checking commit 9cb365d13f71 (bsd-user: use qemu_strtoul in
> preference to strtol)
> 23/48 Checking commit 7ed989c1d383 (bsd-user: introduce host_os.h for
> bsd-specific code and defaults)
> Use of uninitialized value $acpi_testexpected in string eq at ./scripts/
> checkpatch.pl line 1529.
> WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
> #24:
> new file mode 100644
>
> WARNING: architecture specific defines should be avoided
> #48: FILE: bsd-user/freebsd/host_os.h:20:
> +#ifndef __HOST_OS_H_
>
> WARNING: architecture specific defines should be avoided
> #101: FILE: bsd-user/netbsd/host_os.h:20:
> +#ifndef __HOST_OS_H_
>
> WARNING: architecture specific defines should be avoided
> #132: FILE: bsd-user/openbsd/host_os.h:20:
> +#ifndef __HOST_OS_H_
>
> total: 0 errors, 4 warnings, 91 lines checked
>
> Patch 23/48 has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.
> 24/48 Checking commit f19b57e6a271 (bsd-user: create target_arch_cpu.h)
> Use of uninitialized value $acpi_testexpected in string eq at ./scripts/
> checkpatch.pl line 1529.
> WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
> #31:
> new file mode 100644
>
> total: 0 errors, 1 warnings, 111 lines checked
>
> Patch 24/48 has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.
> 25/48 Checking commit c546aa906cbe (bsd-user: move x86 (i386 and x86_64)
> cpu_loop to target_arch_cpu.h)
> 26/48 Checking commit 55da1fd9d9a3 (bsd-user: move sparc cpu_loop into
> target_arch_cpu.h as target_cpu_loop)
> 27/48 Checking commit e7e00a4308a1 (bsd-user: style tweak: space pedantry)
> ERROR: spaces required around that '=' (ctx:WxV)
> #78: FILE: bsd-user/elfload.c:1226:
> +    start_data =n 0;
>                 ^
>
> total: 1 errors, 0 warnings, 73 lines checked
>
> Patch 27/48 has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.
>
> 28/48 Checking commit 522e4589fc17 (bsd-user: style tweak: comments)
> 29/48 Checking commit cb3234ad892f (bsd-user: style tweak: use {}
> correctly)
> 30/48 Checking commit e92240f03f40 (bsd-user: style tweak: fix block
> comments)
> 31/48 Checking commit 780e9f44ba8b (bsd-user: style tweak: use {} for all
> if statements, format else correctly)
> 32/48 Checking commit d00c21e0a91a (bsd-user: style tweak: remove spacing
> after '*' and add after })
> 33/48 Checking commit 45bfe917b433 (bsd-user: style tweak: Use preferred
> block comments)
> 34/48 Checking commit eca311e2127b (bsd-user: style tweak: don't assign in
> if statements)
> 35/48 Checking commit 695b53466022 (bsd-user: style tweak: use {} for all
> if statements, format else correctly)
> 36/48 Checking commit d32211e78858 (bsd-user: style tweak: Use preferred
> block comments)
> 37/48 Checking commit 3a3b578aff7b (bsd-user: style tweak: don't assign in
> if statements)
> 38/48 Checking commit ab7c026d39c0 (bsd-user: style tweak: use {} for all
> if statements, format else correctly)
> 39/48 Checking commit 8946d1425629 (bsd-user: style tweak: spaces around
> =, remove stray space)
> 40/48 Checking commit 2c5334681060 (bsd-user: style tweak: Use preferred
> block comments)
> 41/48 Checking commit 11e0aae47a39 (bsd-user: style tweak: don't assign in
> if statements)
> 42/48 Checking commit 1448c0f5067c (bsd-user: style tweak: spaces around
> operators and commas)
> WARNING: line over 80 characters
> #24: FILE: bsd-user/syscall.c:81:
> +                                        MAP_ANON | MAP_FIXED |
> MAP_PRIVATE, -1, 0));
>
> ERROR: line over 90 characters
> #85: FILE: bsd-user/syscall.c:396:
> +        ret = do_freebsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3,
> arg4, arg5, arg6, arg7, arg8, 0);
>
> WARNING: line over 80 characters
> #94: FILE: bsd-user/syscall.c:475:
> +        ret = do_netbsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4,
> arg5, arg6, 0);
>
> WARNING: line over 80 characters
> #103: FILE: bsd-user/syscall.c:554:
> +        ret = do_openbsd_syscall(cpu_env, arg1 & 0xffff, arg2, arg3,
> arg4, arg5, arg6, 0);
>
> total: 1 errors, 3 warnings, 81 lines checked
>
> Patch 42/48 has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.
>
> 43/48 Checking commit 1a936284fa25 (bsd-user: style tweak: fold long lines)
> 44/48 Checking commit cf2e30fc41ca (bsd-user: style tweak: use preferred
> block comments)
> 45/48 Checking commit de239a3b68bb (bsd-user: style tweak: Use preferred
> {} in if/else statements.)
> ERROR: do not use assignment in if condition
> #139: FILE: bsd-user/syscall.c:248:
> +    if (!(hnamep = lock_user(VERIFY_READ, namep, namelen, 1))) {
>
> ERROR: do not use assignment in if condition
> #143: FILE: bsd-user/syscall.c:251:
> +    if (newp && !(hnewp = lock_user(VERIFY_READ, newp, newlen, 1))) {
>
> ERROR: do not use assignment in if condition
> #147: FILE: bsd-user/syscall.c:254:
> +    if (!(holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0))) {
>
> ERROR: do not use assignment in if condition
> #210: FILE: bsd-user/syscall.c:371:
> +        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) {
>
> ERROR: do not use assignment in if condition
> #218: FILE: bsd-user/syscall.c:378:
> +        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) {
>
> ERROR: do not use assignment in if condition
> #238: FILE: bsd-user/syscall.c:398:
> +        if (!(p = lock_user_string(arg1))) {
>
> ERROR: do not use assignment in if condition
> #271: FILE: bsd-user/syscall.c:482:
> +        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) {
>
> ERROR: do not use assignment in if condition
> #279: FILE: bsd-user/syscall.c:489:
> +        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) {
>
> ERROR: do not use assignment in if condition
> #287: FILE: bsd-user/syscall.c:496:
> +        if (!(p = lock_user_string(arg1))) {
>
> ERROR: do not use assignment in if condition
> #320: FILE: bsd-user/syscall.c:568:
> +        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) {
>
> ERROR: do not use assignment in if condition
> #328: FILE: bsd-user/syscall.c:575:
> +        if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) {
>
> ERROR: do not use assignment in if condition
> #336: FILE: bsd-user/syscall.c:582:
> +        if (!(p = lock_user_string(arg1))) {
>
> total: 12 errors, 0 warnings, 318 lines checked
>
> Patch 45/48 has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.
>
> 46/48 Checking commit 1bf13fe0ac6b (bsd-user: style tweak: Return is not a
> function call.)
> 47/48 Checking commit 19b2708a0763 (bsd-user: style tweak: don't assign in
> if statement.)
> 48/48 Checking commit be1f8df08151 (bsd-user: put back a break; that had
> gone missing...)
> === OUTPUT END ===
>
> Test command exited with code: 1
>
>
> The full log is available at
>
> http://patchew.org/logs/20210424160016.15200-1-imp@bsdimp.com/testing.checkpatch/?type=message
> .
> ---
> Email generated automatically by Patchew [https://patchew.org/].
> Please send your feedback to patchew-devel@redhat.com

[-- Attachment #2: Type: text/html, Size: 20885 bytes --]

^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 10/48] bsd-user: Remove commented out code
  2021-04-24 15:59 ` [PATCH v2 10/48] bsd-user: Remove commented out code imp
@ 2021-04-24 17:19   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:19 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Remove dead code that's been commented out forever.
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/qemu.h | 4 ----
>   1 file changed, 4 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 11/48] bsd-user: style tweak: Remove #if 0'd code
  2021-04-24 15:59 ` [PATCH v2 11/48] bsd-user: style tweak: Remove #if 0'd code imp
@ 2021-04-24 17:21   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:21 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/elfload.c | 12 ------------
>   1 file changed, 12 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 12/48] bsd-user: style tweak: Remove #if 0'd code
  2021-04-24 15:59 ` [PATCH v2 12/48] " imp
@ 2021-04-24 17:23   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:23 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/main.c | 143 ------------------------------------------------
>   1 file changed, 143 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 13/48] bsd-user: style tweak: Remove #if 0'd code
  2021-04-24 15:59 ` [PATCH v2 13/48] " imp
@ 2021-04-24 17:23   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:23 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/strace.c | 8 --------
>   1 file changed, 8 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 14/48] bsd-user: style tweak: Remove #if 0'd code
  2021-04-24 15:59 ` [PATCH v2 14/48] " imp
@ 2021-04-24 17:24   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:24 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/x86_64/target_syscall.h | 15 ---------------
>   1 file changed, 15 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 15/48] bsd-user: style tweak: return is not a function,  eliminate ()
  2021-04-24 15:59 ` [PATCH v2 15/48] bsd-user: style tweak: return is not a function, eliminate () imp
@ 2021-04-24 17:24   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:24 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/bsdload.c | 13 ++++++-------
>   1 file changed, 6 insertions(+), 7 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 16/48] bsd-user: style tweak: Put {} around all if/else/for statements
  2021-04-24 15:59 ` [PATCH v2 16/48] bsd-user: style tweak: Put {} around all if/else/for statements imp
@ 2021-04-24 17:25   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:25 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/bsdload.c | 12 +++++++-----
>   1 file changed, 7 insertions(+), 5 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 21/48] bsd-user: style nits: return is not a function
  2021-04-24 15:59 ` [PATCH v2 21/48] bsd-user: style nits: return is not a function imp
@ 2021-04-24 17:27   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:27 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/elfload.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 22/48] bsd-user: use qemu_strtoul in preference to strtol
  2021-04-24 15:59 ` [PATCH v2 22/48] bsd-user: use qemu_strtoul in preference to strtol imp
@ 2021-04-24 17:34   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:34 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/main.c | 12 ++++++++----
>   1 file changed, 8 insertions(+), 4 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 25/48] bsd-user: move x86 (i386 and x86_64) cpu_loop to target_arch_cpu.h
  2021-04-24 15:59 ` [PATCH v2 25/48] bsd-user: move x86 (i386 and x86_64) cpu_loop to target_arch_cpu.h imp
@ 2021-04-24 17:43   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:43 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson, Stacey Son

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Move the x86 version of the cpu_loop to target_arch_cpu.h as
> target_cpu_loop. Create a cpu_loop that calls the target_cpu_loop function, but
> only for x86 for now. This is code-movement only commit.
> 
> Signed-off-by: Stacey Son<sson@FreeBSD.org>
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/i386/target_arch_cpu.h | 177 +++++++++++++++++++++++++++++++-
>   bsd-user/main.c                 | 176 +------------------------------
>   2 files changed, 179 insertions(+), 174 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 26/48] bsd-user: move sparc cpu_loop into target_arch_cpu.h as target_cpu_loop
  2021-04-24 15:59 ` [PATCH v2 26/48] bsd-user: move sparc cpu_loop into target_arch_cpu.h as target_cpu_loop imp
@ 2021-04-24 17:45   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:45 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson, Stacey Son

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Move the sparc cpu_loop out of main.c and into target_arch_cpu.h and
> rename it from cpu_loop to target_cpu_loop. Remove the #ifdef around
> the catch-all cpu_loop.
> 
> Signed-off-by: Stacey Son<sson@FreeBSD.org>
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/main.c                  | 270 -------------------------------
>   bsd-user/sparc/target_arch_cpu.h | 267 +++++++++++++++++++++++++++++-
>   2 files changed, 266 insertions(+), 271 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 27/48] bsd-user: style tweak: space pedantry
  2021-04-24 15:59 ` [PATCH v2 27/48] bsd-user: style tweak: space pedantry imp
@ 2021-04-24 17:46   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:46 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> -    start_data = 0;
> +    start_data =n 0;

Typo.  Is this inside an ifdef or such?

Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 28/48] bsd-user: style tweak: comments
  2021-04-24 15:59 ` [PATCH v2 28/48] bsd-user: style tweak: comments imp
@ 2021-04-24 17:51   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:51 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Use the preferred block comment style, move comments as needed for line length
> restrictions, delete some dead code that looked like a comment, break some lines
>> 80 columns at the same time since there are many associated with comments.
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/elfload.c | 216 ++++++++++++++++++++++++++-------------------
>   1 file changed, 123 insertions(+), 93 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 29/48] bsd-user: style tweak: use {} correctly
  2021-04-24 15:59 ` [PATCH v2 29/48] bsd-user: style tweak: use {} correctly imp
@ 2021-04-24 17:55   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:55 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Format if/for/while statements with {} always, on a separate line
> and fix a couple indentations issues for singletons.
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/elfload.c | 147 ++++++++++++++++++++++++++++-----------------
>   1 file changed, 92 insertions(+), 55 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


> -    start_data =n 0;
> +    start_data = 0;

Ah, I see it got fixed.  Anyway, squashing this back into the previous is the 
right thing to do.


r~


^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 30/48] bsd-user: style tweak: fix block comments
  2021-04-24 15:59 ` [PATCH v2 30/48] bsd-user: style tweak: fix block comments imp
@ 2021-04-24 17:59   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 17:59 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/mmap.c | 51 ++++++++++++++++++++++++++++---------------------
>   1 file changed, 29 insertions(+), 22 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 31/48] bsd-user: style tweak: use {} for all if statements, format else correctly
  2021-04-24 15:59 ` [PATCH v2 31/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
@ 2021-04-24 18:01   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:01 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 8:59 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/mmap.c | 112 ++++++++++++++++++++++++++++++++----------------
>   1 file changed, 74 insertions(+), 38 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 32/48] bsd-user: style tweak: remove spacing after '*' and add after }
  2021-04-24 16:00 ` [PATCH v2 32/48] bsd-user: style tweak: remove spacing after '*' and add after } imp
@ 2021-04-24 18:03   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:03 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/qemu.h | 18 +++++++++---------
>   1 file changed, 9 insertions(+), 9 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 33/48] bsd-user: style tweak: Use preferred block comments
  2021-04-24 16:00 ` [PATCH v2 33/48] bsd-user: style tweak: Use preferred block comments imp
@ 2021-04-24 18:07   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:07 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/qemu.h | 74 ++++++++++++++++++++++++++++---------------------
>   1 file changed, 43 insertions(+), 31 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 34/48] bsd-user: style tweak: don't assign in if statements
  2021-04-24 16:00 ` [PATCH v2 34/48] bsd-user: style tweak: don't assign in if statements imp
@ 2021-04-24 18:09   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:09 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/qemu.h | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 35/48] bsd-user: style tweak: use {} for all if statements, format else correctly
  2021-04-24 16:00 ` [PATCH v2 35/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
@ 2021-04-24 18:12   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:12 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/qemu.h | 20 +++++++++++++-------
>   1 file changed, 13 insertions(+), 7 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 36/48] bsd-user: style tweak: Use preferred block comments
  2021-04-24 16:00 ` [PATCH v2 36/48] bsd-user: style tweak: Use preferred block comments imp
@ 2021-04-24 18:13   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:13 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/uaccess.c | 13 ++++++++-----
>   1 file changed, 8 insertions(+), 5 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 37/48] bsd-user: style tweak: don't assign in if statements
  2021-04-24 16:00 ` [PATCH v2 37/48] bsd-user: style tweak: don't assign in if statements imp
@ 2021-04-24 18:14   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:14 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/uaccess.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 38/48] bsd-user: style tweak: use {} for all if statements, format else correctly
  2021-04-24 16:00 ` [PATCH v2 38/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
@ 2021-04-24 18:15   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:15 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/uaccess.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 39/48] bsd-user: style tweak: spaces around =, remove stray space
  2021-04-24 16:00 ` [PATCH v2 39/48] bsd-user: style tweak: spaces around =, remove stray space imp
@ 2021-04-24 18:16   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:16 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/strace.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 40/48] bsd-user: style tweak: Use preferred block comments
  2021-04-24 16:00 ` [PATCH v2 40/48] bsd-user: style tweak: Use preferred block comments imp
@ 2021-04-24 18:16   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:16 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/strace.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 41/48] bsd-user: style tweak: don't assign in if statements
  2021-04-24 16:00 ` [PATCH v2 41/48] bsd-user: style tweak: don't assign in if statements imp
@ 2021-04-24 18:17   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:17 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/strace.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 42/48] bsd-user: style tweak: spaces around operators and commas
  2021-04-24 16:00 ` [PATCH v2 42/48] bsd-user: style tweak: spaces around operators and commas imp
@ 2021-04-24 18:18   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:18 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/syscall.c | 22 +++++++++++-----------
>   1 file changed, 11 insertions(+), 11 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 43/48] bsd-user: style tweak: fold long lines
  2021-04-24 16:00 ` [PATCH v2 43/48] bsd-user: style tweak: fold long lines imp
@ 2021-04-24 18:18   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:18 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/syscall.c | 40 +++++++++++++++++++++++++---------------
>   1 file changed, 25 insertions(+), 15 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 44/48] bsd-user: style tweak: use preferred block comments
  2021-04-24 16:00 ` [PATCH v2 44/48] bsd-user: style tweak: use preferred block comments imp
@ 2021-04-24 18:19   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:19 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/syscall.c | 21 +++++++++++++--------
>   1 file changed, 13 insertions(+), 8 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 45/48] bsd-user: style tweak: Use preferred {} in if/else statements.
  2021-04-24 16:00 ` [PATCH v2 45/48] bsd-user: style tweak: Use preferred {} in if/else statements imp
@ 2021-04-24 18:21   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:21 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/syscall.c | 120 +++++++++++++++++++++++++++++----------------
>   1 file changed, 78 insertions(+), 42 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 46/48] bsd-user: style tweak: Return is not a function call.
  2021-04-24 16:00 ` [PATCH v2 46/48] bsd-user: style tweak: Return is not a function call imp
@ 2021-04-24 18:21   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:21 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/syscall.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 47/48] bsd-user: style tweak: don't assign in if statement.
  2021-04-24 16:00 ` [PATCH v2 47/48] bsd-user: style tweak: don't assign in if statement imp
@ 2021-04-24 18:21   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:21 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/syscall.c | 40 +++++++++++++++++++++++++++-------------
>   1 file changed, 27 insertions(+), 13 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

* Re: [PATCH v2 48/48] bsd-user: put back a break; that had gone missing...
  2021-04-24 16:00 ` [PATCH v2 48/48] bsd-user: put back a break; that had gone missing imp
@ 2021-04-24 18:22   ` Richard Henderson
  0 siblings, 0 replies; 84+ messages in thread
From: Richard Henderson @ 2021-04-24 18:22 UTC (permalink / raw)
  To: imp, qemu-devel; +Cc: kevans, arichardson

On 4/24/21 9:00 AM, imp@bsdimp.com wrote:
> From: Warner Losh<imp@bsdimp.com>
> 
> Signed-off-by: Warner Losh<imp@bsdimp.com>
> ---
>   bsd-user/syscall.c | 1 +
>   1 file changed, 1 insertion(+)
> 

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~



^ permalink raw reply	[flat|nested] 84+ messages in thread

end of thread, other threads:[~2021-04-24 18:32 UTC | newest]

Thread overview: 84+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-24 15:59 [PATCH v2 00/48] bsd-user style and reorg patches imp
2021-04-24 15:59 ` [PATCH v2 01/48] bsd-user: whitespace changes imp
2021-04-24 15:59 ` [PATCH v2 02/48] " imp
2021-04-24 15:59 ` [PATCH v2 03/48] " imp
2021-04-24 15:59 ` [PATCH v2 04/48] bsd-user: style tweak: keyword space ( imp
2021-04-24 15:59 ` [PATCH v2 05/48] " imp
2021-04-24 15:59 ` [PATCH v2 06/48] " imp
2021-04-24 15:59 ` [PATCH v2 07/48] " imp
2021-04-24 15:59 ` [PATCH v2 08/48] bsd-user: style tweak: use C not C++ comments imp
2021-04-24 15:59 ` [PATCH v2 09/48] " imp
2021-04-24 15:59 ` [PATCH v2 10/48] bsd-user: Remove commented out code imp
2021-04-24 17:19   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 11/48] bsd-user: style tweak: Remove #if 0'd code imp
2021-04-24 17:21   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 12/48] " imp
2021-04-24 17:23   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 13/48] " imp
2021-04-24 17:23   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 14/48] " imp
2021-04-24 17:24   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 15/48] bsd-user: style tweak: return is not a function, eliminate () imp
2021-04-24 17:24   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 16/48] bsd-user: style tweak: Put {} around all if/else/for statements imp
2021-04-24 17:25   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 17/48] bsd-user: style tweak: Fix commentary issues imp
2021-04-24 15:59 ` [PATCH v2 18/48] bsd-user: style tweak: Use preferred block comments imp
2021-04-24 15:59 ` [PATCH v2 19/48] bsd-user: style tweak: move extern to header file imp
2021-04-24 15:59 ` [PATCH v2 20/48] bsd-user: style tweak: use {} consistently in for / if / else statements imp
2021-04-24 15:59 ` [PATCH v2 21/48] bsd-user: style nits: return is not a function imp
2021-04-24 17:27   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 22/48] bsd-user: use qemu_strtoul in preference to strtol imp
2021-04-24 17:34   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 23/48] bsd-user: introduce host_os.h for bsd-specific code and defaults imp
2021-04-24 15:59 ` [PATCH v2 24/48] bsd-user: create target_arch_cpu.h imp
2021-04-24 15:59 ` [PATCH v2 25/48] bsd-user: move x86 (i386 and x86_64) cpu_loop to target_arch_cpu.h imp
2021-04-24 17:43   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 26/48] bsd-user: move sparc cpu_loop into target_arch_cpu.h as target_cpu_loop imp
2021-04-24 17:45   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 27/48] bsd-user: style tweak: space pedantry imp
2021-04-24 17:46   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 28/48] bsd-user: style tweak: comments imp
2021-04-24 17:51   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 29/48] bsd-user: style tweak: use {} correctly imp
2021-04-24 17:55   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 30/48] bsd-user: style tweak: fix block comments imp
2021-04-24 17:59   ` Richard Henderson
2021-04-24 15:59 ` [PATCH v2 31/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
2021-04-24 18:01   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 32/48] bsd-user: style tweak: remove spacing after '*' and add after } imp
2021-04-24 18:03   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 33/48] bsd-user: style tweak: Use preferred block comments imp
2021-04-24 18:07   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 34/48] bsd-user: style tweak: don't assign in if statements imp
2021-04-24 18:09   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 35/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
2021-04-24 18:12   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 36/48] bsd-user: style tweak: Use preferred block comments imp
2021-04-24 18:13   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 37/48] bsd-user: style tweak: don't assign in if statements imp
2021-04-24 18:14   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 38/48] bsd-user: style tweak: use {} for all if statements, format else correctly imp
2021-04-24 18:15   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 39/48] bsd-user: style tweak: spaces around =, remove stray space imp
2021-04-24 18:16   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 40/48] bsd-user: style tweak: Use preferred block comments imp
2021-04-24 18:16   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 41/48] bsd-user: style tweak: don't assign in if statements imp
2021-04-24 18:17   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 42/48] bsd-user: style tweak: spaces around operators and commas imp
2021-04-24 18:18   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 43/48] bsd-user: style tweak: fold long lines imp
2021-04-24 18:18   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 44/48] bsd-user: style tweak: use preferred block comments imp
2021-04-24 18:19   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 45/48] bsd-user: style tweak: Use preferred {} in if/else statements imp
2021-04-24 18:21   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 46/48] bsd-user: style tweak: Return is not a function call imp
2021-04-24 18:21   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 47/48] bsd-user: style tweak: don't assign in if statement imp
2021-04-24 18:21   ` Richard Henderson
2021-04-24 16:00 ` [PATCH v2 48/48] bsd-user: put back a break; that had gone missing imp
2021-04-24 18:22   ` Richard Henderson
2021-04-24 16:55 ` [PATCH v2 00/48] bsd-user style and reorg patches no-reply
2021-04-24 17:00   ` Warner Losh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).