Skip to content

Comments

Rename RzBinMap->paddr and RzBinSection->paddr to offset.#5018

Closed
Rot127 wants to merge 2 commits intorizinorg:devfrom
Rot127:paddr-rename
Closed

Rename RzBinMap->paddr and RzBinSection->paddr to offset.#5018
Rot127 wants to merge 2 commits intorizinorg:devfrom
Rot127:paddr-rename

Conversation

@Rot127
Copy link
Member

@Rot127 Rot127 commented Mar 20, 2025

Do not squash

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository.
  • I made sure to follow the project's coding style.
  • I've documented every RZ_API function and struct this PR changes.
  • I've added tests that prove my changes are effective (required for changes to RZ_API).
  • I've updated the Rizin book with the relevant information (if needed).

Detailed description

This name change is an attempt to be more precise what the member actually does.

The paddr member was effectively used as an offset into the binary file.
It holds the offset where the map starts.

The name "paddr" is commonly used for "physical address" though.
But a file offset is not the same as a physical address in most contexts.

A physical address commonly refers to a memory space which has some kind of address
translation unit, which manages the memory space by giving out virtual addresses to
memory users.
The physical address refers then to the actual offset into the memory space
(while the virtual addresses don't need fixed to the same physical memory location).

In the context of RzBinMap the paddr is an offset into the binary file.
Not into a memory space. One could argue that the binary file itself is a "physical memory space",
but this is a rather uncommon interpretation.

More so, if RzBinMap is used in context of binary formats which have the concept of mapping (ELF, PE etc)
this naming can be a source of confusion. Because physical address in those binary formats refers to
actual physical addresses as described above. And offsets into files are referred as offset.
For example ELF has for program headers: p_paddr, p_vaddr and p_offset.
For sections only: sh_offset, sh_addr (sh_addr is virtual or physical depending what the machine supports).

The name change from paddr to offset attempts to fix this potential source of confusion.

Test plan

All green

Closing issues

...

Rot127 added 2 commits March 20, 2025 06:54
…mon binary formats.

This name change is an attempt to be more precise what the member actually does.

The paddr member was effectively used as an offset into the binary file.
It holds the offset where the map starts.

The name "paddr" is commonly used for "physical address" though.
But a file offset is not the same as a physical address in most contexts.

A physical address commonly refers to a memory space which has some kind of address
translation unit, which manages the memory space by giving out virtual addresses to
memory users.
The physical address refers then to the actual offset into the memory space
(while the virtual addresses don't need fixed to the same physical memory location).

In the context of RzBinMap the paddr is an offset into the binary file.
Not into a memory space. One could argue that the binary file itself is a "physical memory space",
but this is a rather uncommon interpretation.

More so, if RzBinMap is used in context of binary formats which have the concept of mapping (ELF, PE etc)
this naming can be a source of confusion. Because physical address in those binary formats refers to
actual physical addresses as described above. And offsets into files are referred as offset.
For example ELF has for program headers: p_paddr, p_vaddr and p_offset.
For sections only: sh_offset, sh_addr (sh_addr is virtual or physical depending what the machine supports).

The name change from paddr to offset attempts to fix this potential source of confusion.
… common binary formats.

The reason for this change is the same as in a87f37a
(see commit messsage for details).

TLDR justification:

The most common binary formats make a distinction between physical addresses
and file offsets.
For sections specifically there are no physical addresses defined.
Only file offsets ad addresses (if those are virtual or physical depend on
the MMU of the machine, if it has any).

Naming the member nonetheless paddr (short for physical address)
can easily lead to confusion about its usage.
@notxvilka
Copy link
Contributor

Not sure about it. paddr has a nice symmetry to vaddr. I think, it's just better to address with documenting instead.
But if you go with renaming, offset might become ambiguous too, something like source_offset or fileoffset might be more on point probably.

@Rot127
Copy link
Member Author

Rot127 commented Mar 20, 2025

Not sure about it. paddr has a nice symmetry to vaddr. I think, it's just better to address with documenting instead.

Would wait for the comment from @thestr4ng3r and then probably close this. As @wargio already said in Mattermost, it is a general design flaw of the IO not being specific on what address abstraction level it works (OS, MMU, file offsets).

@Rot127
Copy link
Member Author

Rot127 commented Mar 22, 2025

Superseded by #5024

@Rot127 Rot127 closed this Mar 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants