The branch main has been updated by dchagin:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=95b8603427d5759c5d6090ffaacfaf7f3b8fb926

commit 95b8603427d5759c5d6090ffaacfaf7f3b8fb926
Author:     Dmitry Chagin <dcha...@freebsd.org>
AuthorDate: 2023-02-02 14:58:07 +0000
Commit:     Dmitry Chagin <dcha...@freebsd.org>
CommitDate: 2023-02-02 14:58:07 +0000

    linux(4): Deduplicate linux_trans_osrel().
    
    MFC after:              1 week
---
 sys/amd64/linux/linux_sysvec.c     | 31 ++-----------------------------
 sys/amd64/linux32/linux32_sysvec.c | 29 +----------------------------
 sys/arm64/linux/linux_sysvec.c     | 22 ----------------------
 sys/compat/linux/linux_elf.c       | 23 +++++++++++++++++++++++
 sys/compat/linux/linux_elf.h       |  5 +++++
 sys/i386/linux/linux_sysvec.c      | 27 ---------------------------
 6 files changed, 31 insertions(+), 106 deletions(-)

diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c
index b42c90abc07d..96cdf5e5c818 100644
--- a/sys/amd64/linux/linux_sysvec.c
+++ b/sys/amd64/linux/linux_sysvec.c
@@ -115,7 +115,6 @@ extern const char *linux_syscallnames[];
 
 SET_DECLARE(linux_ioctl_handler_set, struct linux_ioctl_handler);
 
-static bool    linux_trans_osrel(const Elf_Note *note, int32_t *osrel);
 static void    linux_vdso_install(const void *param);
 static void    linux_vdso_deinstall(const void *param);
 static void    linux_vdso_reloc(char *mapping, Elf_Addr offset);
@@ -737,37 +736,11 @@ linux_vdso_reloc(char *mapping, Elf_Addr offset)
        }
 }
 
-static char GNULINUX_ABI_VENDOR[] = "GNU";
-static int GNULINUX_ABI_DESC = 0;
-
-static bool
-linux_trans_osrel(const Elf_Note *note, int32_t *osrel)
-{
-       const Elf32_Word *desc;
-       uintptr_t p;
-
-       p = (uintptr_t)(note + 1);
-       p += roundup2(note->n_namesz, sizeof(Elf32_Addr));
-
-       desc = (const Elf32_Word *)p;
-       if (desc[0] != GNULINUX_ABI_DESC)
-               return (false);
-
-       /*
-        * For Linux we encode osrel using the Linux convention of
-        *      (version << 16) | (major << 8) | (minor)
-        * See macro in linux_mib.h
-        */
-       *osrel = LINUX_KERNVER(desc[1], desc[2], desc[3]);
-
-       return (true);
-}
-
 static Elf_Brandnote linux64_brandnote = {
-       .hdr.n_namesz   = sizeof(GNULINUX_ABI_VENDOR),
+       .hdr.n_namesz   = sizeof(GNU_ABI_VENDOR),
        .hdr.n_descsz   = 16,
        .hdr.n_type     = 1,
-       .vendor         = GNULINUX_ABI_VENDOR,
+       .vendor         = GNU_ABI_VENDOR,
        .flags          = BN_TRANSLATE_OSREL,
        .trans_osrel    = linux_trans_osrel
 };
diff --git a/sys/amd64/linux32/linux32_sysvec.c 
b/sys/amd64/linux32/linux32_sysvec.c
index c28f1c396d36..6e40a6a82a39 100644
--- a/sys/amd64/linux32/linux32_sysvec.c
+++ b/sys/amd64/linux32/linux32_sysvec.c
@@ -127,7 +127,6 @@ static void linux_exec_sysvec_init(void *param);
 static int     linux_on_exec_vmspace(struct proc *p,
                    struct image_params *imgp);
 static void    linux32_fixlimit(struct rlimit *rl, int which);
-static bool    linux32_trans_osrel(const Elf_Note *note, int32_t *osrel);
 static void    linux_vdso_install(const void *param);
 static void    linux_vdso_deinstall(const void *param);
 static void    linux_vdso_reloc(char *mapping, Elf_Addr offset);
@@ -1016,39 +1015,13 @@ linux_vdso_reloc(char *mapping, Elf_Addr offset)
        }
 }
 
-static char GNU_ABI_VENDOR[] = "GNU";
-static int GNULINUX_ABI_DESC = 0;
-
-static bool
-linux32_trans_osrel(const Elf_Note *note, int32_t *osrel)
-{
-       const Elf32_Word *desc;
-       uintptr_t p;
-
-       p = (uintptr_t)(note + 1);
-       p += roundup2(note->n_namesz, sizeof(Elf32_Addr));
-
-       desc = (const Elf32_Word *)p;
-       if (desc[0] != GNULINUX_ABI_DESC)
-               return (false);
-
-       /*
-        * For Linux we encode osrel using the Linux convention of
-        *      (version << 16) | (major << 8) | (minor)
-        * See macro in linux_mib.h
-        */
-       *osrel = LINUX_KERNVER(desc[1], desc[2], desc[3]);
-
-       return (true);
-}
-
 static Elf_Brandnote linux32_brandnote = {
        .hdr.n_namesz   = sizeof(GNU_ABI_VENDOR),
        .hdr.n_descsz   = 16,   /* XXX at least 16 */
        .hdr.n_type     = 1,
        .vendor         = GNU_ABI_VENDOR,
        .flags          = BN_TRANSLATE_OSREL,
-       .trans_osrel    = linux32_trans_osrel
+       .trans_osrel    = linux_trans_osrel
 };
 
 static Elf32_Brandinfo linux_brand = {
diff --git a/sys/arm64/linux/linux_sysvec.c b/sys/arm64/linux/linux_sysvec.c
index 169dafe26ed2..48b4305c5fe4 100644
--- a/sys/arm64/linux/linux_sysvec.c
+++ b/sys/arm64/linux/linux_sysvec.c
@@ -105,7 +105,6 @@ extern const char *linux_syscallnames[];
 
 SET_DECLARE(linux_ioctl_handler_set, struct linux_ioctl_handler);
 
-static bool    linux_trans_osrel(const Elf_Note *note, int32_t *osrel);
 static void    linux_vdso_install(const void *param);
 static void    linux_vdso_deinstall(const void *param);
 static void    linux_vdso_reloc(char *mapping, Elf_Addr offset);
@@ -571,27 +570,6 @@ linux_vdso_reloc(char *mapping, Elf_Addr offset)
        }
 }
 
-static char GNU_ABI_VENDOR[] = "GNU";
-static int GNU_ABI_LINUX = 0;
-
-/* LINUXTODO: deduplicate */
-static bool
-linux_trans_osrel(const Elf_Note *note, int32_t *osrel)
-{
-       const Elf32_Word *desc;
-       uintptr_t p;
-
-       p = (uintptr_t)(note + 1);
-       p += roundup2(note->n_namesz, sizeof(Elf32_Addr));
-
-       desc = (const Elf32_Word *)p;
-       if (desc[0] != GNU_ABI_LINUX)
-               return (false);
-
-       *osrel = LINUX_KERNVER(desc[1], desc[2], desc[3]);
-       return (true);
-}
-
 static Elf_Brandnote linux64_brandnote = {
        .hdr.n_namesz   = sizeof(GNU_ABI_VENDOR),
        .hdr.n_descsz   = 16,
diff --git a/sys/compat/linux/linux_elf.c b/sys/compat/linux/linux_elf.c
index 3e0582e2b8c3..43df9508d470 100644
--- a/sys/compat/linux/linux_elf.c
+++ b/sys/compat/linux/linux_elf.c
@@ -67,6 +67,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/../linux/linux.h>
 #endif
 #include <compat/linux/linux_elf.h>
+#include <compat/linux/linux_mib.h>
 #include <compat/linux/linux_misc.h>
 
 struct l_elf_siginfo {
@@ -465,3 +466,25 @@ __linuxN(copyout_strings)(struct image_params *imgp, 
uintptr_t *stack_base)
 
        return (0);
 }
+
+bool
+linux_trans_osrel(const Elf_Note *note, int32_t *osrel)
+{
+       const Elf32_Word *desc;
+       uintptr_t p;
+
+       p = (uintptr_t)(note + 1);
+       p += roundup2(note->n_namesz, sizeof(Elf32_Addr));
+
+       desc = (const Elf32_Word *)p;
+       if (desc[0] != GNU_ABI_LINUX)
+               return (false);
+       /*
+        * For Linux we encode osrel using the Linux convention of
+        *      (version << 16) | (major << 8) | (minor)
+        * See macro in linux_mib.h
+        */
+       *osrel = LINUX_KERNVER(desc[1], desc[2], desc[3]);
+
+       return (true);
+}
diff --git a/sys/compat/linux/linux_elf.h b/sys/compat/linux/linux_elf.h
index e0905983070b..87b21c4a14b2 100644
--- a/sys/compat/linux/linux_elf.h
+++ b/sys/compat/linux/linux_elf.h
@@ -33,11 +33,16 @@ struct note_info_list;
 /* Linux core notes are labeled "CORE" */
 #define        LINUX_ABI_VENDOR        "CORE"
 
+/* Elf notes */
+#define        GNU_ABI_VENDOR          "GNU"
+#define        GNU_ABI_LINUX           0
+
 /* This adds "linux32_" and "linux64_" prefixes. */
 #define        __linuxN(x)     
__CONCAT(__CONCAT(__CONCAT(linux,__ELF_WORD_SIZE),_),x)
 
 void   __linuxN(prepare_notes)(struct thread *, struct note_info_list *,
            size_t *);
 int    __linuxN(copyout_strings)(struct image_params *, uintptr_t *);
+bool   linux_trans_osrel(const Elf_Note *note, int32_t *osrel);
 
 #endif
diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c
index aaf52b873258..9e2939ee4213 100644
--- a/sys/i386/linux/linux_sysvec.c
+++ b/sys/i386/linux/linux_sysvec.c
@@ -112,7 +112,6 @@ static void linux_exec_sysvec_init(void *param);
 static int     linux_on_exec_vmspace(struct proc *p,
                    struct image_params *imgp);
 static void    linux_set_fork_retval(struct thread *td);
-static bool    linux_trans_osrel(const Elf_Note *note, int32_t *osrel);
 static void    linux_vdso_install(const void *param);
 static void    linux_vdso_deinstall(const void *param);
 static void    linux_vdso_reloc(char *mapping, Elf_Addr offset);
@@ -840,32 +839,6 @@ linux_vdso_reloc(char *mapping, Elf_Addr offset)
        }
 }
 
-static char GNU_ABI_VENDOR[] = "GNU";
-static int GNULINUX_ABI_DESC = 0;
-
-static bool
-linux_trans_osrel(const Elf_Note *note, int32_t *osrel)
-{
-       const Elf32_Word *desc;
-       uintptr_t p;
-
-       p = (uintptr_t)(note + 1);
-       p += roundup2(note->n_namesz, sizeof(Elf32_Addr));
-
-       desc = (const Elf32_Word *)p;
-       if (desc[0] != GNULINUX_ABI_DESC)
-               return (false);
-
-       /*
-        * For Linux we encode osrel using the Linux convention of
-        *      (version << 16) | (major << 8) | (minor)
-        * See macro in linux_mib.h
-        */
-       *osrel = LINUX_KERNVER(desc[1], desc[2], desc[3]);
-
-       return (true);
-}
-
 static Elf_Brandnote linux_brandnote = {
        .hdr.n_namesz   = sizeof(GNU_ABI_VENDOR),
        .hdr.n_descsz   = 16,   /* XXX at least 16 */

Reply via email to