Skip to content

Commit

Permalink
pmm: add address-in-section helper routines (#70)
Browse files Browse the repository at this point in the history
Add a few helper routines checking if given address belongs to a
section or a section group: in_text_section() in_init_section()
in_user_section() in_kernel_section().

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>

Co-authored-by: Bjoern Doebel <[email protected]>
  • Loading branch information
wipawel and bjoernd authored Aug 24, 2020
1 parent 51cc44c commit d259b22
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions include/mm/pmm.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ static inline bool mfn_invalid(mfn_t mfn) { return paddr_invalid(mfn_to_paddr(mf

static inline mfn_t get_free_frame(void) { return get_free_frames(PAGE_ORDER_4K); }

static inline bool in_text_section(const void *addr) {
return (addr >= _ptr(__start_text) && addr < _ptr(__end_text)) ||
(addr >= _ptr(__start_text_init) && addr < _ptr(__end_text_init));
}

static inline bool in_init_section(const void *addr) {
return (addr >= _ptr(__start_text_init) && addr < _ptr(__end_text_init)) ||
(addr >= _ptr(__start_data_init) && addr < _ptr(__end_data_init)) ||
(addr >= _ptr(__start_bss_init) && addr < _ptr(__end_bss_init));
}

static inline bool in_user_section(const void *addr) {
return (addr >= _ptr(__start_text_user) && addr < _ptr(__end_text_user)) ||
(addr >= _ptr(__start_data_user) && addr < _ptr(__end_data_user)) ||
(addr >= _ptr(__start_bss_user) && addr < _ptr(__end_bss_user));
}

static inline bool in_kernel_section(const void *addr) {
return (addr >= _ptr(__start_text) && addr < _ptr(__end_text)) ||
(addr >= _ptr(__start_data) && addr < _ptr(__end_data)) ||
(addr >= _ptr(__start_bss) && addr < _ptr(__end_bss)) ||
(addr >= _ptr(__start_rodata) && addr < _ptr(__end_rodata));
}

#endif /* __ASSEMBLY__ */

#endif /* KTF_PMM_H */

0 comments on commit d259b22

Please sign in to comment.