lkml.org 
[lkml]   [2023]   [Jul]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v5 14/14] selftests/nolibc: add mmap and munmap test cases
Hi Zhangjin,

On Wed, Jun 28, 2023 at 09:51:57PM +0800, Zhangjin Wu wrote:
> Three mmap/munmap related test cases are added:
>
> - mmap_bad: the length argument must be greater than 0, otherwise, fail
> with -EINVAL.
>
> - munmap_bad: invalid (void *)-1 address fail with -EINVAL.
>
> - mmap_munmap_good: mmap() a file with good offset and then munmap().
>
> Note, it is not easy to find a unique file for mmap() in different
> scenes, so, a file list is used to search the right one:
>
> - /proc/1/exe, for 'run' and 'run-user' target
> 'run-user' can not find '/proc/self/exe'
>
> - /proc/self/exe, for 'libc-test' target
> normal program 'libc-test' has no permission to access '/proc/1/exe'

Strictly speaking, if your executable is not readable (e.g. chmod 111
due to a restrictive umask) it will also fail that one.

> - the others, for kernel without procfs
> let it pass even with 'worst case' kernel configs

You should include /dev/zero, which is commonly used to allocate anonymous
memory and is more likely present and readable than any of the other files.
And another file of choice is obviously argv[0] ;-) In this case you don't
need any of the other extra ones. Thus I could suggest that you try in this
order:

/dev/zero, /proc/self/exe, /proc/1/exe, argv[0]

and be done with it. That doesn't prevent one from extending the list if
really needed later, but I doubt it would be needed. Also, it's already
arranged in a read-write, then read-only fallbacks mode, so if we later
need to add more complex tests involving writes, the writable /dev/zero
will have precedence.

Willy

\
 
 \ /
  Last update: 2023-07-02 21:33    [W:0.171 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site