1// SPDX-License-Identifier: GPL-2.0 2#include <unistd.h> 3#include <stdio.h> 4#include <string.h> 5#include <internal/lib.h> // page_size 6#include "machine.h" 7#include "api/fs/fs.h" 8#include "debug.h" 9#include "symbol.h" 10 11int arch__fix_module_text_start(u64 *start, u64 *size, const char *name) 12{ 13 u64 m_start = *start; 14 char path[PATH_MAX]; 15 16 snprintf(path, PATH_MAX, "module/%.*s/sections/.text", 17 (int)strlen(name) - 2, name + 1); 18 if (sysfs__read_ull(path, (unsigned long long *)start) < 0) { 19 pr_debug2("Using module %s start:%#lx\n", path, m_start); 20 *start = m_start; 21 } else { 22 /* Successful read of the modules segment text start address. 23 * Calculate difference between module start address 24 * in memory and module text segment start address. 25 * For example module load address is 0x3ff8011b000 26 * (from /proc/modules) and module text segment start 27 * address is 0x3ff8011b870 (from file above). 28 * 29 * Adjust the module size and subtract the GOT table 30 * size located at the beginning of the module. 31 */ 32 *size -= (*start - m_start); 33 } 34 35 return 0; 36} 37