libroot: Name mmap areas by the name of the image that allocated them.

This adds an average overhead of 10-15 us, which seems acceptable
(without the previous patch it adds 200-250 us, which is less so),
and it makes "listarea" output much more enlightening for applications
like app_server or WebKit which use a lot of them.

Change-Id: I48a4148e6e9fb0d1a8bbf67294deeafad9372f44
Reviewed-on: https://review.haiku-os.org/c/1462
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Augustin Cavalier
2019-05-18 18:09:43 +00:00
committed by waddlesplash
parent dee722ce4f
commit ba390da3b4
+14 -1
View File
@@ -8,11 +8,13 @@
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <OS.h>
#include <runtime_loader/runtime_loader.h>
#include <errno_private.h>
#include <syscall_utils.h>
#include <syscalls.h>
@@ -130,8 +132,19 @@ mmap(void* address, size_t length, int protection, int flags, int fd,
if ((protection & PROT_EXEC) != 0)
areaProtection |= B_EXECUTE_AREA;
// create a name for this area based on calling image
void* addr = __builtin_return_address(0);
char* imageName;
char areaName[B_OS_NAME_LENGTH];
status_t status = __gRuntimeLoader->get_nearest_symbol_at_address(
addr, NULL, NULL, &imageName, NULL, NULL, NULL, NULL);
if (status == B_OK)
snprintf(areaName, sizeof(areaName), "%s mmap area", imageName);
else
strlcpy(areaName, "mmap area", sizeof(areaName));
// ask the kernel to map
area_id area = _kern_map_file("mmap area", &address, addressSpec,
area_id area = _kern_map_file(areaName, &address, addressSpec,
length, areaProtection, mapping, true, fd, offset);
if (area < 0) {
__set_errno(area);