Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retreiving heap-allocated objects using internal pointers #1833

Open
uditagarwal97 opened this issue Apr 26, 2020 · 0 comments
Open

Retreiving heap-allocated objects using internal pointers #1833

uditagarwal97 opened this issue Apr 26, 2020 · 0 comments

Comments

@uditagarwal97
Copy link

Hello,
Currently, jemalloc stores the object pointer and the size of the allocation in R-tree and, by using sallocx(obj_pointer), I can retrieve the size of the allocation. However, I want to retrieve the object_pointer and the size of allocation using an internal pointer. What I meant by an internal pointer is that: a pointer that points anywhere in the body of the heap-allocated object i.e.
object_pointer( or base_pointer) < internal_pointer < (object_pointer + size_of_allocation). For instance,

typedef struct FOO{
	char a;
	int arr[20];
} foo;
void *obj_ptr = malloc(sizeof(foo)); //Object or base pointer
void *internal_ptr = (obj_ptr + 2); // Internal pointer
assert( (obj_ptr < internal_ptr) && (internal_ptr < (obj_ptr + sizeof(foo))) ); // condition for a valid internal ptr

Now, if I have any valid internal pointer, I need to get its corresponding object pointer and size of allocation. Since jemalloc already stores all the necessary information, instead of maintaining a saperate data structure, I was thinking to add some new functions for querying the R-Tree; Something similar to rtree_leaf_elm_lookup and rtree_leaf_elm_lookup_hard but with a minor change that during tree lookup instead of if (leaf->key == input_key) it should be if(leaf->key < input_key && input_key < (leaf->key + leaf->size) ). But I'm not sure if these changes will suffice and would really appreciate any insights on this method or any alternative ways of achieving the above objective.

Thanks and Regards,
Udit Agarwal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant