Skip to content

Commit

Permalink
utils/task: find_vma_span_area(): Add MIN_ULP_START_VMA_ADDR
Browse files Browse the repository at this point in the history
Finish: commit 8500222 ("utils/task: find_vma_span_area(): Add first var")
Signed-off-by: Rong Tao <[email protected]>
  • Loading branch information
Rtoax committed Apr 17, 2024
1 parent 8500222 commit 8cd1f73
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/patch/patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ static int create_mmap_vma_file(struct task_struct *task, struct load_info *info
* 0xFFFFFFFFUL, maybe i should use jmp_table, see arch_jmp_table_jmp()
* or, maybe we could use jmp/bl to register.
*
* The base address on aarch64 is bigger than 4bytes length, such as:
* Such ad base address on ASLR process address space(PIC ELF) is
* bigger than 4 bytes, Such as:
* $ cat /proc/$(pidof hello)/maps
* 5583490000-5583491000 r-xp 00000000 b3:02 1061933 /hello
*/
Expand Down
10 changes: 9 additions & 1 deletion src/utils/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,18 @@ struct vm_area_struct *next_vma(struct task_struct *task, struct vm_area_struct

unsigned long find_vma_span_area(struct task_struct *task, size_t size)
{
struct vm_area_struct *ivma;
struct vm_area_struct *ivma, *first_vma;
struct rb_node *first, *rnode;

first = rb_first(&task->vmas_rb);
first_vma = rb_entry(first, struct vm_area_struct, node_rb);

/**
* Return the minimal address if the space is enough to store 'size'.
*/
if (first_vma->vm_start > MIN_ULP_START_VMA_ADDR &&
first_vma->vm_start - MIN_ULP_START_VMA_ADDR >= size)
return MIN_ULP_START_VMA_ADDR;

for (rnode = first; rnode; rnode = rb_next(rnode)) {
ivma = rb_entry(rnode, struct vm_area_struct, node_rb);
Expand Down
1 change: 1 addition & 0 deletions src/utils/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct vma_ulp {
/* This is ELF */
void *elf_mem;

#define MIN_ULP_START_VMA_ADDR 0x400000U
/* Belongs to */
struct vm_area_struct *vma;

Expand Down

1 comment on commit 8cd1f73

@Rtoax
Copy link
Owner Author

@Rtoax Rtoax commented on 8cd1f73 Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #5

Please sign in to comment.