tools/perf/util/map.c
Source file repositories/reference/linux-study-clean/tools/perf/util/map.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/map.c- Extension
.c- Size
- 15913 bytes
- Lines
- 651
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
inttypes.hlimits.hstdio.hstdlib.hstring.hlinux/string.hlinux/zalloc.huapi/linux/mman.hdebug.hdso.hmap.hnamespaces.hsrcline.hsymbol.hthread.hvdso.h
Detected Declarations
function is_android_libfunction replace_android_libfunction map__initfunction modulesfunction __map__is_kernelfunction __map__is_extra_kernel_mapfunction __map__is_bpf_progfunction __map__is_bpf_imagefunction __map__is_oolfunction map__has_symbolsfunction map__exitfunction map__deletefunction map__putfunction map__fixup_startfunction map__fixup_endfunction map__loadfunction map__fprintffunction prefer_dso_long_namefunction __map__fprintf_dsonamefunction map__fprintf_dsonamefunction map__fprintf_dsoname_dsofffunction map__fprintf_srclinefunction srccode_state_freefunction map__rip_2objdumpfunction map__rip_2objdumpfunction map__objdump_2ripfunction map__contains_symbol
Annotated Snippet
if (apk_path) {
new_length += strlen(apk_path) + 1;
if (new_length > PATH_MAX)
return false;
snprintf(newfilename, new_length,
"%s/libs/%s/%s", apk_path, app_abi, libname);
} else {
if (new_length > PATH_MAX)
return false;
snprintf(newfilename, new_length,
"libs/%s/%s", app_abi, libname);
}
return true;
}
if (strstarts(filename, "/system/lib/")) {
char *ndk, *app;
const char *arch;
int ndk_length, app_length;
ndk = getenv("NDK_ROOT");
app = getenv("APP_PLATFORM");
if (!(ndk && app))
return false;
ndk_length = strlen(ndk);
app_length = strlen(app);
if (!(ndk_length && app_length && app_abi_length))
return false;
arch = !strncmp(app_abi, "arm", 3) ? "arm" :
!strncmp(app_abi, "mips", 4) ? "mips" :
!strncmp(app_abi, "x86", 3) ? "x86" : NULL;
if (!arch)
return false;
new_length = 27 + ndk_length +
app_length + lib_length
+ strlen(arch);
if (new_length > PATH_MAX)
return false;
snprintf(newfilename, new_length,
"%.*s/platforms/%.*s/arch-%s/usr/lib/%s",
ndk_length, ndk, app_length, app, arch, libname);
return true;
}
return false;
}
static void map__init(struct map *map, u64 start, u64 end, u64 pgoff,
struct dso *dso, u32 prot, u32 flags)
{
map__set_start(map, start);
map__set_end(map, end);
map__set_pgoff(map, pgoff);
assert(map__reloc(map) == 0);
map__set_dso(map, dso__get(dso));
refcount_set(map__refcnt(map), 1);
RC_CHK_ACCESS(map)->prot = prot;
RC_CHK_ACCESS(map)->flags = flags;
map__set_mapping_type(map, MAPPING_TYPE__DSO);
assert(map__erange_warned(map) == false);
assert(map__priv(map) == false);
assert(map__hit(map) == false);
}
struct map *map__new(struct machine *machine, u64 start, u64 len,
u64 pgoff, const struct dso_id *id,
u32 prot, u32 flags,
char *filename, struct thread *thread)
{
struct map *result;
RC_STRUCT(map) *map;
struct nsinfo *nsi = NULL;
struct nsinfo *nnsi;
map = zalloc(sizeof(*map));
if (ADD_RC_CHK(result, map)) {
char newfilename[PATH_MAX];
struct dso *dso;
int anon, no_dso, vdso, android;
android = is_android_lib(filename);
anon = is_anon_memory(filename) || flags & MAP_HUGETLB;
vdso = is_vdso_map(filename);
Annotation
- Immediate include surface: `inttypes.h`, `limits.h`, `stdio.h`, `stdlib.h`, `string.h`, `linux/string.h`, `linux/zalloc.h`, `uapi/linux/mman.h`.
- Detected declarations: `function is_android_lib`, `function replace_android_lib`, `function map__init`, `function modules`, `function __map__is_kernel`, `function __map__is_extra_kernel_map`, `function __map__is_bpf_prog`, `function __map__is_bpf_image`, `function __map__is_ool`, `function map__has_symbols`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.