WIP FPC-III support
[linux/fpc-iii.git] / tools / perf / arch / s390 / util / machine.c
blob724efb2d842d72aa2d0b853fd7fd1e6775a576ce
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"
11 int arch__fix_module_text_start(u64 *start, u64 *size, const char *name)
13 u64 m_start = *start;
14 char path[PATH_MAX];
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).
29 * Adjust the module size and subtract the GOT table
30 * size located at the beginning of the module.
32 *size -= (*start - m_start);
35 return 0;
38 /* On s390 kernel text segment start is located at very low memory addresses,
39 * for example 0x10000. Modules are located at very high memory addresses,
40 * for example 0x3ff xxxx xxxx. The gap between end of kernel text segment
41 * and beginning of first module's text segment is very big.
42 * Therefore do not fill this gap and do not assign it to the kernel dso map.
44 void arch__symbols__fixup_end(struct symbol *p, struct symbol *c)
46 if (strchr(p->name, '[') == NULL && strchr(c->name, '['))
47 /* Last kernel symbol mapped to end of page */
48 p->end = roundup(p->end, page_size);
49 else
50 p->end = c->start;
51 pr_debug4("%s sym:%s end:%#lx\n", __func__, p->name, p->end);