I have built busybox with CONFIG_LFS=y, this problem still exists.

mmap is defined in glibc as below:
void *mmap(void *addr, size_t len, int prot , int flags , int fd, off_t offset);
The type of last parameter offset is off_ t, so using mmap will still cause 
truncation problems.

The mmap64() function is identical to the mmap() function except that it can be 
used to map memory from files that are larger than 2 gigabytes into the process 
memory.


Strace log :
arm32_for_busybox_devmem / # strace devmem 0x280000000
execve("/sbin/devmem", ["devmem", "0x280000000"], 0xbed2bd24 /* 21 vars */) = 0
.......
.......
.......
mmap2(NULL, 4096, PROT_READ, MAP_SHARED, 3, 0x80000000) = 0xb6f36000
.......
.......
.......
exit_group(0)                           = ?
+++ exited with 0 +++

-----邮件原件-----
发件人: Denys Vlasenko [mailto:[email protected]] 
发送时间: 2021年10月7日 23:35
收件人: xiechengliang <[email protected]>
抄送: [email protected]
主题: Re: devmem: use mmap64 replace mmap

This should be solvable by building with CONFIG_LFS=y
- this makes off_t 64-bit and makes all operations on files 64-bit aware.

Can you try that?



On Mon, Sep 27, 2021 at 4:06 PM xiechengliang <[email protected]> wrote:
>
> Subject: [PATCH] devmem: The type of the physical address to be 
> accessed by
>
> devmem is off_t, when the 32-bit Linux kernel support lpae, the 
> physical
>
> address can exceed 4G, and accessing or modifying the  address 
> exceeding 4G
>
> will cause truncation.
>
>
>
> function                        old     new   delta
>
> do_cmd                        127     127      +0
>
>
>
> Signed-off-by: xiechengliang <[email protected]>
>
> ---
>
> miscutils/devmem.c | 6 +++---
>
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
>
>
> diff --git a/miscutils/devmem.c b/miscutils/devmem.c
>
> index f9f0276bc..594bb440c 100644
>
> --- a/miscutils/devmem.c
>
> +++ b/miscutils/devmem.c
>
> @@ -30,7 +30,7 @@ int devmem_main(int argc UNUSED_PARAM, char **argv)
>
>        void *map_base, *virt_addr;
>
>        uint64_t read_result;
>
>        uint64_t writeval = writeval; /* for compiler */
>
> -        off_t target;
>
> +       uint64_t target;
>
>        unsigned page_size, mapped_size, offset_in_page;
>
>        int fd;
>
>        unsigned width = 8 * sizeof(int);
>
> @@ -82,12 +82,12 @@ int devmem_main(int argc UNUSED_PARAM, char 
> **argv)
>
>                  * Must map two pages to make it possible: */
>
>                 mapped_size *= 2;
>
>        }
>
> -        map_base = mmap(NULL,
>
> +       map_base = mmap64(NULL,
>
>                           mapped_size,
>
>                           argv[3] ? (PROT_READ | PROT_WRITE) : 
> PROT_READ,
>
>                           MAP_SHARED,
>
>                           fd,
>
> -                           target & ~(off_t)(page_size - 1));
>
> +                          target & ~(uint64_t)(page_size - 1));
>
>        if (map_base == MAP_FAILED)
>
>                 bb_simple_perror_msg_and_die("mmap");
>
>
>
> --
>
> 2.12.3
>
>
>
> _______________________________________________
> busybox mailing list
> [email protected]
> http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to