Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <inttypes.h>
0003 #include <unistd.h>
0004 #include <stdio.h>
0005 #include <string.h>
0006 #include <internal/lib.h> // page_size
0007 #include "machine.h"
0008 #include "api/fs/fs.h"
0009 #include "debug.h"
0010 #include "symbol.h"
0011 
0012 int arch__fix_module_text_start(u64 *start, u64 *size, const char *name)
0013 {
0014     u64 m_start = *start;
0015     char path[PATH_MAX];
0016 
0017     snprintf(path, PATH_MAX, "module/%.*s/sections/.text",
0018                 (int)strlen(name) - 2, name + 1);
0019     if (sysfs__read_ull(path, (unsigned long long *)start) < 0) {
0020         pr_debug2("Using module %s start:%#lx\n", path, m_start);
0021         *start = m_start;
0022     } else {
0023         /* Successful read of the modules segment text start address.
0024          * Calculate difference between module start address
0025          * in memory and module text segment start address.
0026          * For example module load address is 0x3ff8011b000
0027          * (from /proc/modules) and module text segment start
0028          * address is 0x3ff8011b870 (from file above).
0029          *
0030          * Adjust the module size and subtract the GOT table
0031          * size located at the beginning of the module.
0032          */
0033         *size -= (*start - m_start);
0034     }
0035 
0036     return 0;
0037 }