mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-05-29 10:37:04 +00:00
We got the sane_ctype.h headers from git and kept using it so far, but since that code originally came from the kernel sources to the git sources, perhaps its better to just use the one in the kernel, so that we can leverage tools/perf/check_headers.sh to be notified when our copy gets out of sync, i.e. when fixes or goodies are added to the code we've copied. This will help with things like tools/lib/string.c where we want to have more things in common with the kernel, such as strim(), skip_spaces(), etc so as to go on removing the things that we have in tools/perf/util/ and instead using the code in the kernel, indirectly and removing things like EXPORT_SYMBOL(), etc, getting notified when fixes and improvements are made to the original code. Hopefully this also should help with reducing the difference of code hosted in tools/ to the one in the kernel proper. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Link: https://lkml.kernel.org/n/tip-7k9868l713wqtgo01xxygn12@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
104 lines
2.2 KiB
C
104 lines
2.2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/types.h>
|
|
#include <linux/string.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "../../util/util.h"
|
|
#include "../../util/machine.h"
|
|
#include "../../util/map.h"
|
|
#include "../../util/symbol.h"
|
|
#include <linux/ctype.h>
|
|
|
|
#include <symbol/kallsyms.h>
|
|
|
|
#if defined(__x86_64__)
|
|
|
|
struct extra_kernel_map_info {
|
|
int cnt;
|
|
int max_cnt;
|
|
struct extra_kernel_map *maps;
|
|
bool get_entry_trampolines;
|
|
u64 entry_trampoline;
|
|
};
|
|
|
|
static int add_extra_kernel_map(struct extra_kernel_map_info *mi, u64 start,
|
|
u64 end, u64 pgoff, const char *name)
|
|
{
|
|
if (mi->cnt >= mi->max_cnt) {
|
|
void *buf;
|
|
size_t sz;
|
|
|
|
mi->max_cnt = mi->max_cnt ? mi->max_cnt * 2 : 32;
|
|
sz = sizeof(struct extra_kernel_map) * mi->max_cnt;
|
|
buf = realloc(mi->maps, sz);
|
|
if (!buf)
|
|
return -1;
|
|
mi->maps = buf;
|
|
}
|
|
|
|
mi->maps[mi->cnt].start = start;
|
|
mi->maps[mi->cnt].end = end;
|
|
mi->maps[mi->cnt].pgoff = pgoff;
|
|
strlcpy(mi->maps[mi->cnt].name, name, KMAP_NAME_LEN);
|
|
|
|
mi->cnt += 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int find_extra_kernel_maps(void *arg, const char *name, char type,
|
|
u64 start)
|
|
{
|
|
struct extra_kernel_map_info *mi = arg;
|
|
|
|
if (!mi->entry_trampoline && kallsyms2elf_binding(type) == STB_GLOBAL &&
|
|
!strcmp(name, "_entry_trampoline")) {
|
|
mi->entry_trampoline = start;
|
|
return 0;
|
|
}
|
|
|
|
if (is_entry_trampoline(name)) {
|
|
u64 end = start + page_size;
|
|
|
|
return add_extra_kernel_map(mi, start, end, 0, name);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int machine__create_extra_kernel_maps(struct machine *machine,
|
|
struct dso *kernel)
|
|
{
|
|
struct extra_kernel_map_info mi = { .cnt = 0, };
|
|
char filename[PATH_MAX];
|
|
int ret;
|
|
int i;
|
|
|
|
machine__get_kallsyms_filename(machine, filename, PATH_MAX);
|
|
|
|
if (symbol__restricted_filename(filename, "/proc/kallsyms"))
|
|
return 0;
|
|
|
|
ret = kallsyms__parse(filename, &mi, find_extra_kernel_maps);
|
|
if (ret)
|
|
goto out_free;
|
|
|
|
if (!mi.entry_trampoline)
|
|
goto out_free;
|
|
|
|
for (i = 0; i < mi.cnt; i++) {
|
|
struct extra_kernel_map *xm = &mi.maps[i];
|
|
|
|
xm->pgoff = mi.entry_trampoline;
|
|
ret = machine__create_extra_kernel_map(machine, kernel, xm);
|
|
if (ret)
|
|
goto out_free;
|
|
}
|
|
|
|
machine->trampolines_mapped = mi.cnt;
|
|
out_free:
|
|
free(mi.maps);
|
|
return ret;
|
|
}
|
|
|
|
#endif
|