diff --git a/include/haproxy/tools.h b/include/haproxy/tools.h index fbd8a59c4..fc1b576f3 100644 --- a/include/haproxy/tools.h +++ b/include/haproxy/tools.h @@ -1201,5 +1201,6 @@ int openssl_compare_current_name(const char *name); /* vma helpers */ void vma_set_name(void *addr, size_t size, const char *type, const char *name); +void vma_set_name_id(void *addr, size_t size, const char *type, const char *name, unsigned int id); #endif /* _HAPROXY_TOOLS_H */ diff --git a/src/tools.c b/src/tools.c index a8e01fe43..7608e7e6d 100644 --- a/src/tools.c +++ b/src/tools.c @@ -6477,11 +6477,13 @@ int openssl_compare_current_name(const char *name) * heap as much as possible below that. * * and are mandatory + * is optional, if != ~0, will be used to append an id after the name + * in order to differentiate 2 entries set using the same and * * The function does nothing if naming API is not available, and naming errors * are ignored. */ -void vma_set_name(void *addr, size_t size, const char *type, const char *name) +void vma_set_name_id(void *addr, size_t size, const char *type, const char *name, unsigned int id) { long pagesize = sysconf(_SC_PAGESIZE); void *aligned_addr; @@ -6515,15 +6517,18 @@ void vma_set_name(void *addr, size_t size, const char *type, const char *name) * except [, ], \, $ and '. * As a result, when looking for /proc//maps, we can see the anonymous range * as follow : - * `7364c4fff000-736508000000 rw-s 00000000 00:01 3540 [anon_shmem:scope:name]` + * `7364c4fff000-736508000000 rw-s 00000000 00:01 3540 [anon_shmem:scope:name{-id}]` * (MAP_SHARED) - * `7364c4fff000-736508000000 rw-s 00000000 00:01 3540 [anon:scope:name]` + * `7364c4fff000-736508000000 rw-s 00000000 00:01 3540 [anon:scope:name{-id}]` * (MAP_PRIVATE) */ char fullname[80]; int rn; - rn = snprintf(fullname, sizeof(fullname), "%s:%s", type, name); + if (id != ~0) + rn = snprintf(fullname, sizeof(fullname), "%s:%s-%u", type, name, id); + else + rn = snprintf(fullname, sizeof(fullname), "%s:%s", type, name); if (rn >= 0) { /* Give a name to the map by setting PR_SET_VMA_ANON_NAME attribute @@ -6541,6 +6546,12 @@ void vma_set_name(void *addr, size_t size, const char *type, const char *name) #endif } +/* wrapper for vma_set_name_id() but without id */ +void vma_set_name(void *addr, size_t size, const char *type, const char *name) +{ + vma_set_name_id(addr, size, type, name, ~0); +} + #if defined(RTLD_DEFAULT) || defined(RTLD_NEXT) /* redefine dlopen() so that we can detect unexpected replacement of some * critical symbols, typically init/alloc/free functions coming from alternate