linux(4): Deduplicate linux_trans_osrel().

MFC after:		1 week
This commit is contained in:
Dmitry Chagin 2023-02-02 17:58:07 +03:00
parent 6039e966ff
commit 95b8603427
6 changed files with 31 additions and 106 deletions

View File

@ -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
};

View File

@ -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 = {

View File

@ -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,

View File

@ -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);
}

View File

@ -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

View File

@ -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 */