machine.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "util.h"
  6. #include "machine.h"
  7. #include "api/fs/fs.h"
  8. #include "debug.h"
  9. #include "symbol.h"
  10. int arch__fix_module_text_start(u64 *start, u64 *size, const char *name)
  11. {
  12. u64 m_start = *start;
  13. char path[PATH_MAX];
  14. snprintf(path, PATH_MAX, "module/%.*s/sections/.text",
  15. (int)strlen(name) - 2, name + 1);
  16. if (sysfs__read_ull(path, (unsigned long long *)start) < 0) {
  17. pr_debug2("Using module %s start:%#lx\n", path, m_start);
  18. *start = m_start;
  19. } else {
  20. /* Successful read of the modules segment text start address.
  21. * Calculate difference between module start address
  22. * in memory and module text segment start address.
  23. * For example module load address is 0x3ff8011b000
  24. * (from /proc/modules) and module text segment start
  25. * address is 0x3ff8011b870 (from file above).
  26. *
  27. * Adjust the module size and subtract the GOT table
  28. * size located at the beginning of the module.
  29. */
  30. *size -= (*start - m_start);
  31. }
  32. return 0;
  33. }
  34. /* On s390 kernel text segment start is located at very low memory addresses,
  35. * for example 0x10000. Modules are located at very high memory addresses,
  36. * for example 0x3ff xxxx xxxx. The gap between end of kernel text segment
  37. * and beginning of first module's text segment is very big.
  38. * Therefore do not fill this gap and do not assign it to the kernel dso map.
  39. */
  40. void arch__symbols__fixup_end(struct symbol *p, struct symbol *c)
  41. {
  42. if (strchr(p->name, '[') == NULL && strchr(c->name, '['))
  43. /* Last kernel symbol mapped to end of page */
  44. p->end = roundup(p->end, page_size);
  45. else
  46. p->end = c->start;
  47. pr_debug4("%s sym:%s end:%#lx\n", __func__, p->name, p->end);
  48. }