[LTP] [PATCH 03/13] lib: Add tst_mapping_in_range()

Petr Vorel pvorel@suse.cz
Fri Dec 27 11:25:40 CET 2024


> This moves the range_is_mapped() function from
> testcases/kernel/mem/lib/mem.c to a top level library and renames the
> function to a better fitting name.

+1

> +/**
> + * tst_mapping_in_range()
> + *
> + * @low A lower address inside of the processe address space.
> + * @high A higher address inside of the processe address space.
nit: missing ':' causes "undefined" instead of the documentation.
Please fix that before merge.

> + *
> + * @return Returns true if there is a mapping between low and high addresses in
> + *         the process address space.
> + */
> +int tst_mapping_in_range(unsigned long low, unsigned long high);
> +
>  #endif /* TST_MEMUTILS_H__ */
> diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
> index e33f19d29..e49684ba1 100644
> --- a/lib/tst_memutils.c
> +++ b/lib/tst_memutils.c
> @@ -14,6 +14,7 @@
>  #include "tst_test.h"
>  #include "tst_memutils.h"
>  #include "tst_capability.h"
> +#include "tst_safe_stdio.h"
>  #include "lapi/syscalls.h"

>  #define BLOCKSIZE (16 * 1024 * 1024)
> @@ -184,3 +185,33 @@ void tst_disable_oom_protection(pid_t pid)
>  {
>  	set_oom_score_adj(pid, 0);
>  }
> +
> +int tst_mapping_in_range(unsigned long low, unsigned long high)
> +{
> +	FILE *fp;
> +
> +	fp = SAFE_FOPEN("/proc/self/maps", "r");

nit: it might be better to have const char *file, const int lineno params
and have TST_MAPPING_IN_RANGE(). But I'm OK to keep it this way.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr


More information about the ltp mailing list