Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
/devicetable-offsets.h
/elfconfig.h
/mk_elfconfig
/modpost
+27
View File
@@ -0,0 +1,27 @@
# SPDX-License-Identifier: GPL-2.0
CFLAGS_REMOVE_empty.o += $(CC_FLAGS_LTO)
hostprogs-always-y += modpost mk_elfconfig
always-y += empty.o
modpost-objs := modpost.o file2alias.o sumversion.o symsearch.o
devicetable-offsets-file := devicetable-offsets.h
$(obj)/$(devicetable-offsets-file): $(obj)/devicetable-offsets.s FORCE
$(call filechk,offsets,__DEVICETABLE_OFFSETS_H__)
targets += $(devicetable-offsets-file) devicetable-offsets.s
# dependencies on generated files need to be listed explicitly
$(obj)/modpost.o $(obj)/file2alias.o $(obj)/sumversion.o $(obj)/symsearch.o: $(obj)/elfconfig.h
$(obj)/file2alias.o: $(obj)/$(devicetable-offsets-file)
quiet_cmd_elfconfig = MKELF $@
cmd_elfconfig = $(obj)/mk_elfconfig < $< > $@
$(obj)/elfconfig.h: $(obj)/empty.o $(obj)/mk_elfconfig FORCE
$(call if_changed,elfconfig)
targets += elfconfig.h
@@ -0,0 +1,288 @@
// SPDX-License-Identifier: GPL-2.0
#define COMPILE_OFFSETS
#include <linux/kbuild.h>
#include <linux/mod_devicetable.h>
#define DEVID(devid) DEFINE(SIZE_##devid, sizeof(struct devid))
#define DEVID_FIELD(devid, field) \
DEFINE(OFF_##devid##_##field, offsetof(struct devid, field))
int main(void)
{
DEVID(usb_device_id);
DEVID_FIELD(usb_device_id, match_flags);
DEVID_FIELD(usb_device_id, idVendor);
DEVID_FIELD(usb_device_id, idProduct);
DEVID_FIELD(usb_device_id, bcdDevice_lo);
DEVID_FIELD(usb_device_id, bcdDevice_hi);
DEVID_FIELD(usb_device_id, bDeviceClass);
DEVID_FIELD(usb_device_id, bDeviceSubClass);
DEVID_FIELD(usb_device_id, bDeviceProtocol);
DEVID_FIELD(usb_device_id, bInterfaceClass);
DEVID_FIELD(usb_device_id, bInterfaceSubClass);
DEVID_FIELD(usb_device_id, bInterfaceProtocol);
DEVID_FIELD(usb_device_id, bInterfaceNumber);
DEVID(hid_device_id);
DEVID_FIELD(hid_device_id, bus);
DEVID_FIELD(hid_device_id, group);
DEVID_FIELD(hid_device_id, vendor);
DEVID_FIELD(hid_device_id, product);
DEVID(ieee1394_device_id);
DEVID_FIELD(ieee1394_device_id, match_flags);
DEVID_FIELD(ieee1394_device_id, vendor_id);
DEVID_FIELD(ieee1394_device_id, model_id);
DEVID_FIELD(ieee1394_device_id, specifier_id);
DEVID_FIELD(ieee1394_device_id, version);
DEVID(pci_device_id);
DEVID_FIELD(pci_device_id, vendor);
DEVID_FIELD(pci_device_id, device);
DEVID_FIELD(pci_device_id, subvendor);
DEVID_FIELD(pci_device_id, subdevice);
DEVID_FIELD(pci_device_id, class);
DEVID_FIELD(pci_device_id, class_mask);
DEVID_FIELD(pci_device_id, override_only);
DEVID(ccw_device_id);
DEVID_FIELD(ccw_device_id, match_flags);
DEVID_FIELD(ccw_device_id, cu_type);
DEVID_FIELD(ccw_device_id, cu_model);
DEVID_FIELD(ccw_device_id, dev_type);
DEVID_FIELD(ccw_device_id, dev_model);
DEVID(ap_device_id);
DEVID_FIELD(ap_device_id, dev_type);
DEVID(css_device_id);
DEVID_FIELD(css_device_id, type);
DEVID(serio_device_id);
DEVID_FIELD(serio_device_id, type);
DEVID_FIELD(serio_device_id, proto);
DEVID_FIELD(serio_device_id, id);
DEVID_FIELD(serio_device_id, extra);
DEVID(acpi_device_id);
DEVID_FIELD(acpi_device_id, id);
DEVID_FIELD(acpi_device_id, cls);
DEVID_FIELD(acpi_device_id, cls_msk);
DEVID(pnp_device_id);
DEVID_FIELD(pnp_device_id, id);
DEVID(pnp_card_device_id);
DEVID_FIELD(pnp_card_device_id, devs);
DEVID(pcmcia_device_id);
DEVID_FIELD(pcmcia_device_id, match_flags);
DEVID_FIELD(pcmcia_device_id, manf_id);
DEVID_FIELD(pcmcia_device_id, card_id);
DEVID_FIELD(pcmcia_device_id, func_id);
DEVID_FIELD(pcmcia_device_id, function);
DEVID_FIELD(pcmcia_device_id, device_no);
DEVID_FIELD(pcmcia_device_id, prod_id_hash);
DEVID(of_device_id);
DEVID_FIELD(of_device_id, name);
DEVID_FIELD(of_device_id, type);
DEVID_FIELD(of_device_id, compatible);
DEVID(vio_device_id);
DEVID_FIELD(vio_device_id, type);
DEVID_FIELD(vio_device_id, compat);
DEVID(input_device_id);
DEVID_FIELD(input_device_id, flags);
DEVID_FIELD(input_device_id, bustype);
DEVID_FIELD(input_device_id, vendor);
DEVID_FIELD(input_device_id, product);
DEVID_FIELD(input_device_id, version);
DEVID_FIELD(input_device_id, evbit);
DEVID_FIELD(input_device_id, keybit);
DEVID_FIELD(input_device_id, relbit);
DEVID_FIELD(input_device_id, absbit);
DEVID_FIELD(input_device_id, mscbit);
DEVID_FIELD(input_device_id, ledbit);
DEVID_FIELD(input_device_id, sndbit);
DEVID_FIELD(input_device_id, ffbit);
DEVID_FIELD(input_device_id, swbit);
DEVID(eisa_device_id);
DEVID_FIELD(eisa_device_id, sig);
DEVID(parisc_device_id);
DEVID_FIELD(parisc_device_id, hw_type);
DEVID_FIELD(parisc_device_id, hversion);
DEVID_FIELD(parisc_device_id, hversion_rev);
DEVID_FIELD(parisc_device_id, sversion);
DEVID(sdio_device_id);
DEVID_FIELD(sdio_device_id, class);
DEVID_FIELD(sdio_device_id, vendor);
DEVID_FIELD(sdio_device_id, device);
DEVID(ssb_device_id);
DEVID_FIELD(ssb_device_id, vendor);
DEVID_FIELD(ssb_device_id, coreid);
DEVID_FIELD(ssb_device_id, revision);
DEVID(bcma_device_id);
DEVID_FIELD(bcma_device_id, manuf);
DEVID_FIELD(bcma_device_id, id);
DEVID_FIELD(bcma_device_id, rev);
DEVID_FIELD(bcma_device_id, class);
DEVID(virtio_device_id);
DEVID_FIELD(virtio_device_id, device);
DEVID_FIELD(virtio_device_id, vendor);
DEVID(hv_vmbus_device_id);
DEVID_FIELD(hv_vmbus_device_id, guid);
DEVID(rpmsg_device_id);
DEVID_FIELD(rpmsg_device_id, name);
DEVID(i2c_device_id);
DEVID_FIELD(i2c_device_id, name);
DEVID(i3c_device_id);
DEVID_FIELD(i3c_device_id, match_flags);
DEVID_FIELD(i3c_device_id, dcr);
DEVID_FIELD(i3c_device_id, manuf_id);
DEVID_FIELD(i3c_device_id, part_id);
DEVID_FIELD(i3c_device_id, extra_info);
DEVID(slim_device_id);
DEVID_FIELD(slim_device_id, manf_id);
DEVID_FIELD(slim_device_id, prod_code);
DEVID(spi_device_id);
DEVID_FIELD(spi_device_id, name);
DEVID(dmi_system_id);
DEVID_FIELD(dmi_system_id, matches);
DEVID(platform_device_id);
DEVID_FIELD(platform_device_id, name);
DEVID(mdio_device_id);
DEVID_FIELD(mdio_device_id, phy_id);
DEVID_FIELD(mdio_device_id, phy_id_mask);
DEVID(zorro_device_id);
DEVID_FIELD(zorro_device_id, id);
DEVID(isapnp_device_id);
DEVID_FIELD(isapnp_device_id, vendor);
DEVID_FIELD(isapnp_device_id, function);
DEVID(ipack_device_id);
DEVID_FIELD(ipack_device_id, format);
DEVID_FIELD(ipack_device_id, vendor);
DEVID_FIELD(ipack_device_id, device);
DEVID(amba_id);
DEVID_FIELD(amba_id, id);
DEVID_FIELD(amba_id, mask);
DEVID(mips_cdmm_device_id);
DEVID_FIELD(mips_cdmm_device_id, type);
DEVID(x86_cpu_id);
DEVID_FIELD(x86_cpu_id, feature);
DEVID_FIELD(x86_cpu_id, family);
DEVID_FIELD(x86_cpu_id, model);
DEVID_FIELD(x86_cpu_id, vendor);
DEVID(cpu_feature);
DEVID_FIELD(cpu_feature, feature);
DEVID(mcb_device_id);
DEVID_FIELD(mcb_device_id, device);
DEVID(mei_cl_device_id);
DEVID_FIELD(mei_cl_device_id, name);
DEVID_FIELD(mei_cl_device_id, uuid);
DEVID_FIELD(mei_cl_device_id, version);
DEVID(rio_device_id);
DEVID_FIELD(rio_device_id, did);
DEVID_FIELD(rio_device_id, vid);
DEVID_FIELD(rio_device_id, asm_did);
DEVID_FIELD(rio_device_id, asm_vid);
DEVID(ulpi_device_id);
DEVID_FIELD(ulpi_device_id, vendor);
DEVID_FIELD(ulpi_device_id, product);
DEVID(hda_device_id);
DEVID_FIELD(hda_device_id, vendor_id);
DEVID_FIELD(hda_device_id, rev_id);
DEVID_FIELD(hda_device_id, api_version);
DEVID(sdw_device_id);
DEVID_FIELD(sdw_device_id, mfg_id);
DEVID_FIELD(sdw_device_id, part_id);
DEVID_FIELD(sdw_device_id, sdw_version);
DEVID_FIELD(sdw_device_id, class_id);
DEVID(fsl_mc_device_id);
DEVID_FIELD(fsl_mc_device_id, vendor);
DEVID_FIELD(fsl_mc_device_id, obj_type);
DEVID(tb_service_id);
DEVID_FIELD(tb_service_id, match_flags);
DEVID_FIELD(tb_service_id, protocol_key);
DEVID_FIELD(tb_service_id, protocol_id);
DEVID_FIELD(tb_service_id, protocol_version);
DEVID_FIELD(tb_service_id, protocol_revision);
DEVID(typec_device_id);
DEVID_FIELD(typec_device_id, svid);
DEVID(tee_client_device_id);
DEVID_FIELD(tee_client_device_id, uuid);
DEVID(wmi_device_id);
DEVID_FIELD(wmi_device_id, guid_string);
DEVID(mhi_device_id);
DEVID_FIELD(mhi_device_id, chan);
DEVID(auxiliary_device_id);
DEVID_FIELD(auxiliary_device_id, name);
DEVID(ssam_device_id);
DEVID_FIELD(ssam_device_id, match_flags);
DEVID_FIELD(ssam_device_id, domain);
DEVID_FIELD(ssam_device_id, category);
DEVID_FIELD(ssam_device_id, target);
DEVID_FIELD(ssam_device_id, instance);
DEVID_FIELD(ssam_device_id, function);
DEVID(dfl_device_id);
DEVID_FIELD(dfl_device_id, type);
DEVID_FIELD(dfl_device_id, feature_id);
DEVID(ishtp_device_id);
DEVID_FIELD(ishtp_device_id, guid);
DEVID(cdx_device_id);
DEVID_FIELD(cdx_device_id, vendor);
DEVID_FIELD(cdx_device_id, device);
DEVID_FIELD(cdx_device_id, subvendor);
DEVID_FIELD(cdx_device_id, subdevice);
DEVID_FIELD(cdx_device_id, class);
DEVID_FIELD(cdx_device_id, class_mask);
DEVID_FIELD(cdx_device_id, override_only);
DEVID(vchiq_device_id);
DEVID_FIELD(vchiq_device_id, name);
DEVID(coreboot_device_id);
DEVID_FIELD(coreboot_device_id, tag);
return 0;
}
+1
View File
@@ -0,0 +1 @@
/* empty file to figure out endianness / word size */
File diff suppressed because it is too large Load Diff
+32
View File
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: GPL-2.0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <elf.h>
int
main(int argc, char **argv)
{
unsigned char ei[EI_NIDENT];
if (fread(ei, 1, EI_NIDENT, stdin) != EI_NIDENT) {
fprintf(stderr, "Error: input truncated\n");
return 1;
}
if (memcmp(ei, ELFMAG, SELFMAG) != 0) {
fprintf(stderr, "Error: not ELF\n");
return 1;
}
switch (ei[EI_CLASS]) {
case ELFCLASS32:
printf("#define KERNEL_ELFCLASS ELFCLASS32\n");
break;
case ELFCLASS64:
printf("#define KERNEL_ELFCLASS ELFCLASS64\n");
break;
default:
exit(1);
}
return 0;
}
File diff suppressed because it is too large Load Diff
+244
View File
@@ -0,0 +1,244 @@
/* SPDX-License-Identifier: GPL-2.0 */
#include <byteswap.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <elf.h>
#include "../../include/linux/module_symbol.h"
#include <list_types.h>
#include "elfconfig.h"
/* On BSD-alike OSes elf.h defines these according to host's word size */
#undef ELF_ST_BIND
#undef ELF_ST_TYPE
#undef ELF_R_SYM
#undef ELF_R_TYPE
#if KERNEL_ELFCLASS == ELFCLASS32
#define Elf_Ehdr Elf32_Ehdr
#define Elf_Shdr Elf32_Shdr
#define Elf_Sym Elf32_Sym
#define Elf_Addr Elf32_Addr
#define Elf_Section Elf32_Half
#define ELF_ST_BIND ELF32_ST_BIND
#define ELF_ST_TYPE ELF32_ST_TYPE
#define Elf_Rel Elf32_Rel
#define Elf_Rela Elf32_Rela
#define ELF_R_SYM ELF32_R_SYM
#define ELF_R_TYPE ELF32_R_TYPE
#else
#define Elf_Ehdr Elf64_Ehdr
#define Elf_Shdr Elf64_Shdr
#define Elf_Sym Elf64_Sym
#define Elf_Addr Elf64_Addr
#define Elf_Section Elf64_Half
#define ELF_ST_BIND ELF64_ST_BIND
#define ELF_ST_TYPE ELF64_ST_TYPE
#define Elf_Rel Elf64_Rel
#define Elf_Rela Elf64_Rela
#define ELF_R_SYM ELF64_R_SYM
#define ELF_R_TYPE ELF64_R_TYPE
#endif
#define bswap(x) \
({ \
_Static_assert(sizeof(x) == 1 || sizeof(x) == 2 || \
sizeof(x) == 4 || sizeof(x) == 8, "bug"); \
(typeof(x))(sizeof(x) == 2 ? bswap_16(x) : \
sizeof(x) == 4 ? bswap_32(x) : \
sizeof(x) == 8 ? bswap_64(x) : \
x); \
})
#define TO_NATIVE(x) \
(target_is_big_endian == host_is_big_endian ? x : bswap(x))
#define __get_unaligned_t(type, ptr) ({ \
const struct { type x; } __attribute__((__packed__)) *__pptr = \
(typeof(__pptr))(ptr); \
__pptr->x; \
})
#define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr))
#define get_unaligned_native(ptr) \
({ \
typeof(*(ptr)) _val = get_unaligned(ptr); \
TO_NATIVE(_val); \
})
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)
struct buffer {
char *p;
int pos;
int size;
};
void __attribute__((format(printf, 2, 3)))
buf_printf(struct buffer *buf, const char *fmt, ...);
void
buf_write(struct buffer *buf, const char *s, int len);
/**
* struct module_alias - auto-generated MODULE_ALIAS()
*
* @node: linked to module::aliases
* @modname: name of the builtin module (only for vmlinux)
* @str: a string for MODULE_ALIAS()
*/
struct module_alias {
struct list_head node;
char *builtin_modname;
char str[];
};
/**
* struct module - represent a module (vmlinux or *.ko)
*
* @dump_file: path to the .symvers file if loaded from a file
* @aliases: list head for module_aliases
* @no_trim_symbol: .no_trim_symbol section data
* @no_trim_symbol_len: length of the .no_trim_symbol section
*/
struct module {
struct list_head list;
struct list_head exported_symbols;
struct list_head unresolved_symbols;
const char *dump_file;
bool is_gpl_compatible;
bool is_vmlinux;
bool seen;
bool has_init;
bool has_cleanup;
char srcversion[25];
// Missing namespace dependencies
struct list_head missing_namespaces;
// Actual imported namespaces
struct list_head imported_namespaces;
struct list_head aliases;
char *no_trim_symbol;
unsigned int no_trim_symbol_len;
char name[];
};
struct elf_info {
size_t size;
Elf_Ehdr *hdr;
Elf_Shdr *sechdrs;
Elf_Sym *symtab_start;
Elf_Sym *symtab_stop;
unsigned int export_symbol_secndx; /* .export_symbol section */
char *strtab;
char *modinfo;
unsigned int modinfo_len;
char *no_trim_symbol;
unsigned int no_trim_symbol_len;
/* support for 32bit section numbers */
unsigned int num_sections; /* max_secindex + 1 */
unsigned int secindex_strings;
/* if Nth symbol table entry has .st_shndx = SHN_XINDEX,
* take shndx from symtab_shndx_start[N] instead */
Elf32_Word *symtab_shndx_start;
Elf32_Word *symtab_shndx_stop;
struct symsearch *symsearch;
};
/* Accessor for sym->st_shndx, hides ugliness of "64k sections" */
static inline unsigned int get_secindex(const struct elf_info *info,
const Elf_Sym *sym)
{
unsigned int index = sym->st_shndx;
/*
* Elf{32,64}_Sym::st_shndx is 2 byte. Big section numbers are available
* in the .symtab_shndx section.
*/
if (index == SHN_XINDEX)
return info->symtab_shndx_start[sym - info->symtab_start];
/*
* Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of
* the way to UINT_MAX-255..UINT_MAX, to avoid conflicting with real
* section indices.
*/
if (index >= SHN_LORESERVE && index <= SHN_HIRESERVE)
return index - SHN_HIRESERVE - 1;
return index;
}
/*
* If there's no name there, ignore it; likewise, ignore it if it's
* one of the magic symbols emitted used by current tools.
*
* Internal symbols created by tools should be ignored by modpost.
*/
static inline bool is_valid_name(struct elf_info *elf, Elf_Sym *sym)
{
const char *name = elf->strtab + sym->st_name;
if (!name || !strlen(name))
return false;
return !is_mapping_symbol(name);
}
/* symsearch.c */
void symsearch_init(struct elf_info *elf);
void symsearch_finish(struct elf_info *elf);
Elf_Sym *symsearch_find_nearest(struct elf_info *elf, Elf_Addr addr,
unsigned int secndx, bool allow_negative,
Elf_Addr min_distance);
/* file2alias.c */
void handle_moddevtable(struct module *mod, struct elf_info *info,
Elf_Sym *sym, const char *symname);
/* sumversion.c */
void get_src_version(const char *modname, char sum[], unsigned sumlen);
/* from modpost.c */
extern bool target_is_big_endian;
extern bool host_is_big_endian;
const char *get_basename(const char *path);
char *read_text_file(const char *filename);
char *get_line(char **stringp);
void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym);
void __attribute__((format(printf, 2, 3)))
modpost_log(bool is_error, const char *fmt, ...);
/*
* warn - show the given message, then let modpost continue running, still
* allowing modpost to exit successfully. This should be used when
* we still allow to generate vmlinux and modules.
*
* error - show the given message, then let modpost continue running, but fail
* in the end. This should be used when we should stop building vmlinux
* or modules, but we can continue running modpost to catch as many
* issues as possible.
*
* fatal - show the given message, and bail out immediately. This should be
* used when there is no point to continue running modpost.
*/
#define warn(fmt, args...) modpost_log(false, fmt, ##args)
#define error(fmt, args...) modpost_log(true, fmt, ##args)
#define fatal(fmt, args...) do { error(fmt, ##args); exit(1); } while (1)
+413
View File
@@ -0,0 +1,413 @@
#include <netinet/in.h>
#ifdef __sun__
#include <inttypes.h>
#else
#include <stdint.h>
#endif
#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#include <xalloc.h>
#include "modpost.h"
/*
* Stolen form Cryptographic API.
*
* MD4 Message Digest Algorithm (RFC1320).
*
* Implementation derived from Andrew Tridgell and Steve French's
* CIFS MD4 implementation, and the cryptoapi implementation
* originally based on the public domain implementation written
* by Colin Plumb in 1993.
*
* Copyright (c) Andrew Tridgell 1997-1998.
* Modified by Steve French (sfrench@us.ibm.com) 2002
* Copyright (c) Cryptoapi developers.
* Copyright (c) 2002 David S. Miller (davem@redhat.com)
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
*
* 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.
*
*/
#define MD4_DIGEST_SIZE 16
#define MD4_HMAC_BLOCK_SIZE 64
#define MD4_BLOCK_WORDS 16
#define MD4_HASH_WORDS 4
struct md4_ctx {
uint32_t hash[MD4_HASH_WORDS];
uint32_t block[MD4_BLOCK_WORDS];
uint64_t byte_count;
};
static inline uint32_t lshift(uint32_t x, unsigned int s)
{
x &= 0xFFFFFFFF;
return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s));
}
static inline uint32_t F(uint32_t x, uint32_t y, uint32_t z)
{
return (x & y) | ((~x) & z);
}
static inline uint32_t G(uint32_t x, uint32_t y, uint32_t z)
{
return (x & y) | (x & z) | (y & z);
}
static inline uint32_t H(uint32_t x, uint32_t y, uint32_t z)
{
return x ^ y ^ z;
}
#define ROUND1(a,b,c,d,k,s) (a = lshift(a + F(b,c,d) + k, s))
#define ROUND2(a,b,c,d,k,s) (a = lshift(a + G(b,c,d) + k + (uint32_t)0x5A827999,s))
#define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (uint32_t)0x6ED9EBA1,s))
/* XXX: this stuff can be optimized */
static inline void le32_to_cpu_array(uint32_t *buf, unsigned int words)
{
while (words--) {
*buf = ntohl(*buf);
buf++;
}
}
static inline void cpu_to_le32_array(uint32_t *buf, unsigned int words)
{
while (words--) {
*buf = htonl(*buf);
buf++;
}
}
static void md4_transform(uint32_t *hash, uint32_t const *in)
{
uint32_t a, b, c, d;
a = hash[0];
b = hash[1];
c = hash[2];
d = hash[3];
ROUND1(a, b, c, d, in[0], 3);
ROUND1(d, a, b, c, in[1], 7);
ROUND1(c, d, a, b, in[2], 11);
ROUND1(b, c, d, a, in[3], 19);
ROUND1(a, b, c, d, in[4], 3);
ROUND1(d, a, b, c, in[5], 7);
ROUND1(c, d, a, b, in[6], 11);
ROUND1(b, c, d, a, in[7], 19);
ROUND1(a, b, c, d, in[8], 3);
ROUND1(d, a, b, c, in[9], 7);
ROUND1(c, d, a, b, in[10], 11);
ROUND1(b, c, d, a, in[11], 19);
ROUND1(a, b, c, d, in[12], 3);
ROUND1(d, a, b, c, in[13], 7);
ROUND1(c, d, a, b, in[14], 11);
ROUND1(b, c, d, a, in[15], 19);
ROUND2(a, b, c, d,in[ 0], 3);
ROUND2(d, a, b, c, in[4], 5);
ROUND2(c, d, a, b, in[8], 9);
ROUND2(b, c, d, a, in[12], 13);
ROUND2(a, b, c, d, in[1], 3);
ROUND2(d, a, b, c, in[5], 5);
ROUND2(c, d, a, b, in[9], 9);
ROUND2(b, c, d, a, in[13], 13);
ROUND2(a, b, c, d, in[2], 3);
ROUND2(d, a, b, c, in[6], 5);
ROUND2(c, d, a, b, in[10], 9);
ROUND2(b, c, d, a, in[14], 13);
ROUND2(a, b, c, d, in[3], 3);
ROUND2(d, a, b, c, in[7], 5);
ROUND2(c, d, a, b, in[11], 9);
ROUND2(b, c, d, a, in[15], 13);
ROUND3(a, b, c, d,in[ 0], 3);
ROUND3(d, a, b, c, in[8], 9);
ROUND3(c, d, a, b, in[4], 11);
ROUND3(b, c, d, a, in[12], 15);
ROUND3(a, b, c, d, in[2], 3);
ROUND3(d, a, b, c, in[10], 9);
ROUND3(c, d, a, b, in[6], 11);
ROUND3(b, c, d, a, in[14], 15);
ROUND3(a, b, c, d, in[1], 3);
ROUND3(d, a, b, c, in[9], 9);
ROUND3(c, d, a, b, in[5], 11);
ROUND3(b, c, d, a, in[13], 15);
ROUND3(a, b, c, d, in[3], 3);
ROUND3(d, a, b, c, in[11], 9);
ROUND3(c, d, a, b, in[7], 11);
ROUND3(b, c, d, a, in[15], 15);
hash[0] += a;
hash[1] += b;
hash[2] += c;
hash[3] += d;
}
static inline void md4_transform_helper(struct md4_ctx *ctx)
{
le32_to_cpu_array(ctx->block, ARRAY_SIZE(ctx->block));
md4_transform(ctx->hash, ctx->block);
}
static void md4_init(struct md4_ctx *mctx)
{
mctx->hash[0] = 0x67452301;
mctx->hash[1] = 0xefcdab89;
mctx->hash[2] = 0x98badcfe;
mctx->hash[3] = 0x10325476;
mctx->byte_count = 0;
}
static void md4_update(struct md4_ctx *mctx,
const unsigned char *data, unsigned int len)
{
const uint32_t avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
mctx->byte_count += len;
if (avail > len) {
memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
data, len);
return;
}
memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
data, avail);
md4_transform_helper(mctx);
data += avail;
len -= avail;
while (len >= sizeof(mctx->block)) {
memcpy(mctx->block, data, sizeof(mctx->block));
md4_transform_helper(mctx);
data += sizeof(mctx->block);
len -= sizeof(mctx->block);
}
memcpy(mctx->block, data, len);
}
static void md4_final_ascii(struct md4_ctx *mctx, char *out, unsigned int len)
{
const unsigned int offset = mctx->byte_count & 0x3f;
char *p = (char *)mctx->block + offset;
int padding = 56 - (offset + 1);
*p++ = 0x80;
if (padding < 0) {
memset(p, 0x00, padding + sizeof (uint64_t));
md4_transform_helper(mctx);
p = (char *)mctx->block;
padding = 56;
}
memset(p, 0, padding);
mctx->block[14] = mctx->byte_count << 3;
mctx->block[15] = mctx->byte_count >> 29;
le32_to_cpu_array(mctx->block, (sizeof(mctx->block) -
sizeof(uint64_t)) / sizeof(uint32_t));
md4_transform(mctx->hash, mctx->block);
cpu_to_le32_array(mctx->hash, ARRAY_SIZE(mctx->hash));
snprintf(out, len, "%08X%08X%08X%08X",
mctx->hash[0], mctx->hash[1], mctx->hash[2], mctx->hash[3]);
}
static inline void add_char(unsigned char c, struct md4_ctx *md)
{
md4_update(md, &c, 1);
}
static int parse_string(const char *file, unsigned long len,
struct md4_ctx *md)
{
unsigned long i;
add_char(file[0], md);
for (i = 1; i < len; i++) {
add_char(file[i], md);
if (file[i] == '"' && file[i-1] != '\\')
break;
}
return i;
}
static int parse_comment(const char *file, unsigned long len)
{
unsigned long i;
for (i = 2; i < len; i++) {
if (file[i-1] == '*' && file[i] == '/')
break;
}
return i;
}
/* FIXME: Handle .s files differently (eg. # starts comments) --RR */
static int parse_file(const char *fname, struct md4_ctx *md)
{
char *file;
unsigned long i, len;
file = read_text_file(fname);
len = strlen(file);
for (i = 0; i < len; i++) {
/* Collapse and ignore \ and CR. */
if (file[i] == '\\' && (i+1 < len) && file[i+1] == '\n') {
i++;
continue;
}
/* Ignore whitespace */
if (isspace(file[i]))
continue;
/* Handle strings as whole units */
if (file[i] == '"') {
i += parse_string(file+i, len - i, md);
continue;
}
/* Comments: ignore */
if (file[i] == '/' && file[i+1] == '*') {
i += parse_comment(file+i, len - i);
continue;
}
add_char(file[i], md);
}
free(file);
return 1;
}
/* Check whether the file is a static library or not */
static bool is_static_library(const char *objfile)
{
int len = strlen(objfile);
return objfile[len - 2] == '.' && objfile[len - 1] == 'a';
}
/* We have dir/file.o. Open dir/.file.o.cmd, look for source_ and deps_ line
* to figure out source files. */
static int parse_source_files(const char *objfile, struct md4_ctx *md)
{
char *cmd, *file, *line, *dir, *pos;
const char *base;
int dirlen, ret = 0, check_files = 0;
cmd = xmalloc(strlen(objfile) + sizeof("..cmd"));
base = get_basename(objfile);
dirlen = base - objfile;
sprintf(cmd, "%.*s.%s.cmd", dirlen, objfile, base);
dir = xmalloc(dirlen + 1);
strncpy(dir, objfile, dirlen);
dir[dirlen] = '\0';
file = read_text_file(cmd);
pos = file;
/* Sum all files in the same dir or subdirs. */
while ((line = get_line(&pos))) {
char* p;
/* trim the leading spaces away */
while (isspace(*line))
line++;
p = line;
if (strstarts(line, "source_")) {
p = strrchr(line, ' ');
if (!p) {
warn("malformed line: %s\n", line);
goto out_file;
}
p++;
if (!parse_file(p, md)) {
warn("could not open %s: %s\n",
p, strerror(errno));
goto out_file;
}
continue;
}
if (strstarts(line, "deps_")) {
check_files = 1;
continue;
}
if (!check_files)
continue;
/* Continue until line does not end with '\' */
if ( *(p + strlen(p)-1) != '\\')
break;
/* Terminate line at first space, to get rid of final ' \' */
while (*p) {
if (isspace(*p)) {
*p = '\0';
break;
}
p++;
}
/* Check if this file is in same dir as objfile */
if ((strstr(line, dir)+strlen(dir)-1) == strrchr(line, '/')) {
if (!parse_file(line, md)) {
warn("could not open %s: %s\n",
line, strerror(errno));
goto out_file;
}
}
}
/* Everyone parsed OK */
ret = 1;
out_file:
free(file);
free(dir);
free(cmd);
return ret;
}
/* Calc and record src checksum. */
void get_src_version(const char *modname, char sum[], unsigned sumlen)
{
char *buf, *pos;
struct md4_ctx md;
char *fname;
char filelist[PATH_MAX + 1];
/* objects for a module are listed in the first line of *.mod file. */
snprintf(filelist, sizeof(filelist), "%s.mod", modname);
buf = read_text_file(filelist);
pos = buf;
md4_init(&md);
while ((fname = strsep(&pos, "\n"))) {
if (!*fname)
continue;
if (!(is_static_library(fname)) &&
!parse_source_files(fname, &md))
goto free;
}
md4_final_ascii(&md, sum, sumlen);
free:
free(buf);
}
+199
View File
@@ -0,0 +1,199 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Helper functions for finding the symbol in an ELF which is "nearest"
* to a given address.
*/
#include <xalloc.h>
#include "modpost.h"
struct syminfo {
unsigned int symbol_index;
unsigned int section_index;
Elf_Addr addr;
};
/*
* Container used to hold an entire binary search table.
* Entries in table are ascending, sorted first by section_index,
* then by addr, and last by symbol_index. The sorting by
* symbol_index is used to ensure predictable behavior when
* multiple symbols are present with the same address; all
* symbols past the first are effectively ignored, by eliding
* them in symsearch_fixup().
*/
struct symsearch {
unsigned int table_size;
struct syminfo table[];
};
static int syminfo_compare(const void *s1, const void *s2)
{
const struct syminfo *sym1 = s1;
const struct syminfo *sym2 = s2;
if (sym1->section_index > sym2->section_index)
return 1;
if (sym1->section_index < sym2->section_index)
return -1;
if (sym1->addr > sym2->addr)
return 1;
if (sym1->addr < sym2->addr)
return -1;
if (sym1->symbol_index > sym2->symbol_index)
return 1;
if (sym1->symbol_index < sym2->symbol_index)
return -1;
return 0;
}
static unsigned int symbol_count(struct elf_info *elf)
{
unsigned int result = 0;
for (Elf_Sym *sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
if (is_valid_name(elf, sym))
result++;
}
return result;
}
/*
* Populate the search array that we just allocated.
* Be slightly paranoid here. The ELF file is mmap'd and could
* conceivably change between symbol_count() and symsearch_populate().
* If we notice any difference, bail out rather than potentially
* propagating errors or crashing.
*/
static void symsearch_populate(struct elf_info *elf,
struct syminfo *table,
unsigned int table_size)
{
bool is_arm = (elf->hdr->e_machine == EM_ARM);
for (Elf_Sym *sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
if (is_valid_name(elf, sym)) {
if (table_size-- == 0)
fatal("%s: size mismatch\n", __func__);
table->symbol_index = sym - elf->symtab_start;
table->section_index = get_secindex(elf, sym);
table->addr = sym->st_value;
/*
* For ARM Thumb instruction, the bit 0 of st_value is
* set if the symbol is STT_FUNC type. Mask it to get
* the address.
*/
if (is_arm && ELF_ST_TYPE(sym->st_info) == STT_FUNC)
table->addr &= ~1;
table++;
}
}
if (table_size != 0)
fatal("%s: size mismatch\n", __func__);
}
/*
* Do any fixups on the table after sorting.
* For now, this just finds adjacent entries which have
* the same section_index and addr, and it propagates
* the first symbol_index over the subsequent entries,
* so that only one symbol_index is seen for any given
* section_index and addr. This ensures that whether
* we're looking at an address from "above" or "below"
* that we see the same symbol_index.
* This does leave some duplicate entries in the table;
* in practice, these are a small fraction of the
* total number of entries, and they are harmless to
* the binary search algorithm other than a few occasional
* unnecessary comparisons.
*/
static void symsearch_fixup(struct syminfo *table, unsigned int table_size)
{
/* Don't look at index 0, it will never change. */
for (unsigned int i = 1; i < table_size; i++) {
if (table[i].addr == table[i - 1].addr &&
table[i].section_index == table[i - 1].section_index) {
table[i].symbol_index = table[i - 1].symbol_index;
}
}
}
void symsearch_init(struct elf_info *elf)
{
unsigned int table_size = symbol_count(elf);
elf->symsearch = xmalloc(sizeof(struct symsearch) +
sizeof(struct syminfo) * table_size);
elf->symsearch->table_size = table_size;
symsearch_populate(elf, elf->symsearch->table, table_size);
qsort(elf->symsearch->table, table_size,
sizeof(struct syminfo), syminfo_compare);
symsearch_fixup(elf->symsearch->table, table_size);
}
void symsearch_finish(struct elf_info *elf)
{
free(elf->symsearch);
elf->symsearch = NULL;
}
/*
* Find the syminfo which is in secndx and "nearest" to addr.
* allow_negative: allow returning a symbol whose address is > addr.
* min_distance: ignore symbols which are further away than this.
*
* Returns a pointer into the symbol table for success.
* Returns NULL if no legal symbol is found within the requested range.
*/
Elf_Sym *symsearch_find_nearest(struct elf_info *elf, Elf_Addr addr,
unsigned int secndx, bool allow_negative,
Elf_Addr min_distance)
{
unsigned int hi = elf->symsearch->table_size;
unsigned int lo = 0;
struct syminfo *table = elf->symsearch->table;
struct syminfo target;
target.addr = addr;
target.section_index = secndx;
target.symbol_index = ~0; /* compares greater than any actual index */
while (hi > lo) {
unsigned int mid = lo + (hi - lo) / 2; /* Avoids overflow */
if (syminfo_compare(&table[mid], &target) > 0)
hi = mid;
else
lo = mid + 1;
}
/*
* table[hi], if it exists, is the first entry in the array which
* lies beyond target. table[hi - 1], if it exists, is the last
* entry in the array which comes before target, including the
* case where it perfectly matches the section and the address.
*
* Note -- if the address we're looking up falls perfectly
* in the middle of two symbols, this is written to always
* prefer the symbol with the lower address.
*/
Elf_Sym *result = NULL;
if (allow_negative &&
hi < elf->symsearch->table_size &&
table[hi].section_index == secndx &&
table[hi].addr - addr <= min_distance) {
min_distance = table[hi].addr - addr;
result = &elf->symtab_start[table[hi].symbol_index];
}
if (hi > 0 &&
table[hi - 1].section_index == secndx &&
addr - table[hi - 1].addr <= min_distance) {
result = &elf->symtab_start[table[hi - 1].symbol_index];
}
return result;
}