Skip to content

Commit 6b36d2f

Browse files
authored
Merge pull request #50 from struct/add_name_zone
add new iso_alloc_name_zone interface
2 parents 30b8a25 + d8b485d commit 6b36d2f

5 files changed

Lines changed: 24 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,5 @@ If all else fails please file an issue on the [github project](https://github.co
177177
`void iso_verify_zones()` - Verifies the state of all zones. Will abort if inconsistencies are found.
178178

179179
`void iso_verify_zone(iso_alloc_zone_handle *zone)` - Verifies the state of specified zone. Will abort if inconsistencies are found.
180+
181+
`int32_t iso_alloc_name_zone(iso_alloc_zone_handle *zone, char *name)` - Allows naming of custom zones via prctl on Android

include/iso_alloc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ EXTERNAL_API uint64_t iso_alloc_zone_mem_usage(iso_alloc_zone_handle *zone);
3737
EXTERNAL_API uint64_t iso_alloc_mem_usage();
3838
EXTERNAL_API void iso_verify_zones();
3939
EXTERNAL_API void iso_verify_zone(iso_alloc_zone_handle *zone);
40+
EXTERNAL_API int32_t iso_alloc_name_zone(iso_alloc_zone_handle *zone, char *name);
4041

4142
#if EXPERIMENTAL
4243
EXTERNAL_API void iso_alloc_search_stack(void *p);

include/iso_alloc_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ INTERNAL_HIDDEN uint64_t rand_uint64(void);
571571
INTERNAL_HIDDEN size_t _iso_alloc_print_stats();
572572
INTERNAL_HIDDEN size_t _iso_chunk_size(void *p);
573573
INTERNAL_HIDDEN int64_t check_canary_no_abort(iso_alloc_zone *zone, void *p);
574+
INTERNAL_HIDDEN int32_t name_zone(iso_alloc_zone *zone, char *name);
574575
INTERNAL_HIDDEN int32_t name_mapping(void *p, size_t sz, const char *name);
575576
INTERNAL_HIDDEN int8_t *_fmt(uint64_t n, uint32_t base);
576577
INTERNAL_HIDDEN void _iso_alloc_printf(int32_t fd, const char *f, ...);

src/iso_alloc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,20 @@ __attribute__((destructor(LAST_DTOR))) void iso_alloc_dtor(void) {
577577
UNLOCK_ROOT();
578578
}
579579

580+
INTERNAL_HIDDEN int32_t name_zone(iso_alloc_zone *zone, char *name) {
581+
#if NAMED_MAPPINGS && __ANDROID__
582+
return name_mapping(zone->user_pages_start, ZONE_USER_SIZE, (const char *) name);
583+
#else
584+
return 0;
585+
#endif
586+
}
587+
580588
INTERNAL_HIDDEN int32_t name_mapping(void *p, size_t sz, const char *name) {
581589
#if NAMED_MAPPINGS && __ANDROID__
582590
return prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, p, sz, name);
583-
#endif
591+
#else
584592
return 0;
593+
#endif
585594
}
586595

587596
INTERNAL_HIDDEN iso_alloc_zone *iso_new_zone(size_t size, bool internal) {

src/iso_alloc_interfaces.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ EXTERNAL_API NO_DISCARD iso_alloc_zone_handle *iso_alloc_new_zone(size_t size) {
135135
return zone;
136136
}
137137

138+
EXTERNAL_API int32_t iso_alloc_name_zone(iso_alloc_zone_handle *zone, char *name) {
139+
if(zone == NULL) {
140+
return 0;
141+
} else {
142+
zone = (iso_alloc_zone_handle *) ((uintptr_t) zone ^ (uintptr_t) _root->zone_handle_mask);
143+
}
144+
145+
return name_zone(zone, name);
146+
}
147+
138148
EXTERNAL_API void iso_alloc_protect_root() {
139149
_iso_alloc_protect_root();
140150
}

0 commit comments

Comments
 (0)