2003-07-07 20:42:11

by Richard B. Johnson

[permalink] [raw]
Subject: syscall __NR_mmap2


Is anybody using __NR_mmap2 function call? It doesn't work in Linux
2.4.20. It returns nice values, but the address returned does not
have any relationship to what's really there!!

write(1, "Addr = 000b8000\n", 16) = 16
open("/dev/mem", O_RDWR) = 3
mmap2(0xb8000, 8192, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, 3, 0xb8000) = 0xb8000
write(1, "000B8000 FF FF FF FF FF FF FF F"..., 77) = 77
write(1, "000B8010 FF FF FF FF FF FF FF F"..., 77) = 77
write(1, "000B8020 FF FF FF FF FF FF FF F"..., 77) = 77
close(3) = 0
munmap(0xb8000, 8192) = 0
This should be displaying screen memory (it doesn't).

Does anybody care? Isn't this supposed to replace old_mmap() using
__NR_mmap? `strace` seems to think I have the right values in
the right registers. The returned value is correct, but as a
caddr_t, it doesn't point to what it's supposed to point to.


Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.


2003-07-07 21:18:29

by Ulrich Drepper

[permalink] [raw]
Subject: Re: syscall __NR_mmap2

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Richard B. Johnson wrote:

> write(1, "Addr = 000b8000\n", 16) = 16
> open("/dev/mem", O_RDWR) = 3
> mmap2(0xb8000, 8192, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, 3, 0xb8000) = 0xb8000

mmap64() (and if you compile glibc with an adequate minimal kernel
requirement mmap as well) is implemented using mmap2. It works nicely.
Admittedly, I haven't used the stock 2.4 kernel. And I also haven't
used /dev/mem. But at least for the first part I would expect to see
problem reports since the code is used and glibc wouldn't work.

In your code, assuming this is x86, do you really want to read the
memory starting at address 0xb8000000? This is what your code does. I
don't know enough about the kernel memory layout to say whether
something is supposed to be there or not.

- --
- --------------. ,-. 444 Castro Street
Ulrich Drepper \ ,-----------------' \ Mountain View, CA 94041 USA
Red Hat `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/Cebv2ijCOnn/RHQRAukcAKCbI3cTMvmAsHxRWX2ralSqUlcp8ACfTBRU
PNoh4p0/XrWFWXk9JnbnNyk=
=DQ6S
-----END PGP SIGNATURE-----

2003-07-08 00:22:28

by Jamie Lokier

[permalink] [raw]
Subject: Re: syscall __NR_mmap2

Richard B. Johnson wrote:
> mmap2(0xb8000, 8192, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, 3, 0xb8000) = 0xb8000

You meant to write:

mmap2(0xb8000, 8192, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_FIXED, 3, 0xb8000 >> 12);

The offset argument to mmap2 is divided by PAGE_SIZE.
That is the whole point of mmap2 :)

-- Jamie

2003-07-08 11:38:19

by Richard B. Johnson

[permalink] [raw]
Subject: Re: syscall __NR_mmap2

On Tue, 8 Jul 2003, Jamie Lokier wrote:

> Richard B. Johnson wrote:
> > mmap2(0xb8000, 8192, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, 3, 0xb8000) = 0xb8000
>
> You meant to write:
>
> mmap2(0xb8000, 8192, PROT_READ|PROT_WRITE,
> MAP_SHARED|MAP_FIXED, 3, 0xb8000 >> 12);
>
> The offset argument to mmap2 is divided by PAGE_SIZE.
> That is the whole point of mmap2 :)
>
> -- Jamie

Okay. Do you know where that's documented? Nothing in linux/Documentation,
and nothing in any headers. Do you have to read the code to find out?

So, the address is now the offset in PAGES, not bytes. Seems logical,
but there is no clue in any documentation.


Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.

2003-07-08 11:40:44

by Richard B. Johnson

[permalink] [raw]
Subject: Re: syscall __NR_mmap2

On Mon, 7 Jul 2003, Ulrich Drepper wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Richard B. Johnson wrote:
>
> > write(1, "Addr = 000b8000\n", 16) = 16
> > open("/dev/mem", O_RDWR) = 3
> > mmap2(0xb8000, 8192, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, 3, 0xb8000) = 0xb8000
>
> mmap64() (and if you compile glibc with an adequate minimal kernel
> requirement mmap as well) is implemented using mmap2. It works nicely.
> Admittedly, I haven't used the stock 2.4 kernel. And I also haven't
> used /dev/mem. But at least for the first part I would expect to see
> problem reports since the code is used and glibc wouldn't work.
>
> In your code, assuming this is x86, do you really want to read the
> memory starting at address 0xb8000000? This is what your code does. I
> don't know enough about the kernel memory layout to say whether
> something is supposed to be there or not.
>

Yes. Thanks. There is no known documentation that states that
the address to the function is in PAGES. Certainly, this will
work once I use pages instead of bytes.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.

2003-07-08 13:44:32

by Kurt Wall

[permalink] [raw]
Subject: Re: syscall __NR_mmap2

Quoth Richard B. Johnson:
> On Tue, 8 Jul 2003, Jamie Lokier wrote:
>
> > Richard B. Johnson wrote:
> > > mmap2(0xb8000, 8192, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, 3, 0xb8000) = 0xb8000
> >
> > You meant to write:
> >
> > mmap2(0xb8000, 8192, PROT_READ|PROT_WRITE,
> > MAP_SHARED|MAP_FIXED, 3, 0xb8000 >> 12);
> >
> > The offset argument to mmap2 is divided by PAGE_SIZE.
> > That is the whole point of mmap2 :)
> >
> > -- Jamie
>
> Okay. Do you know where that's documented? Nothing in linux/Documentation,
> and nothing in any headers. Do you have to read the code to find out?
>
> So, the address is now the offset in PAGES, not bytes. Seems logical,
> but there is no clue in any documentation.

With the possible exception of the man mmap2 ;-)

DESCRIPTION
The function mmap2 operates in exactly the same way as
mmap(2), except that the final argument specifies the off?
set into the file in units of the system page size
(instead of bytes). This enables applications that use a


--
"I have a very firm grasp on reality! I can reach out and strangle it
any time!"

2003-07-08 13:51:26

by Jamie Lokier

[permalink] [raw]
Subject: Re: syscall __NR_mmap2

Richard B. Johnson wrote:
> > The offset argument to mmap2 is divided by PAGE_SIZE.
> > That is the whole point of mmap2 :)
>
> Okay. Do you know where that's documented? Nothing in linux/Documentation,
> and nothing in any headers. Do you have to read the code to find out?
>
> So, the address is now the offset in PAGES, not bytes. Seems logical,
> but there is no clue in any documentation.

I found this great command which really helps. Only 1337 kernel
gnurus know about it, now u can be 1 2 :)

$ man mmap2
[...]
The function mmap2 operates in exactly the same way as mmap(2), except
that the final argument specifies the offset into the file in units of
the system page size (instead of bytes).

-- Jamie

2003-07-08 14:25:39

by Richard B. Johnson

[permalink] [raw]
Subject: Re: syscall __NR_mmap2

On Tue, 8 Jul 2003, Jamie Lokier wrote:

> Richard B. Johnson wrote:
> > > The offset argument to mmap2 is divided by PAGE_SIZE.
> > > That is the whole point of mmap2 :)
> >
> > Okay. Do you know where that's documented? Nothing in linux/Documentation,
> > and nothing in any headers. Do you have to read the code to find out?
> >
> > So, the address is now the offset in PAGES, not bytes. Seems logical,
> > but there is no clue in any documentation.
>
> I found this great command which really helps. Only 1337 kernel
> gnurus know about it, now u can be 1 2 :)
>
> $ man mmap2
> [...]
> The function mmap2 operates in exactly the same way as mmap(2), except
> that the final argument specifies the offset into the file in units of
> the system page size (instead of bytes).
>
> -- Jamie
>

Yeah? So the Linux kernel now requires a specific vendor distribution?
Since when?

So, to get the proper documentation of the Linux Kernel, I now
need to purchase a vendor's distribution??? I think not. I think
the sys-calls need to be documented and I think that I have established
proof of that supposition.

Script started on Tue Jul 8 10:35:05 2003
# man mmap2
No manual entry for mmap2
# mmap
# man map

MMAP(2) Linux Programmer's Manual MMAP(2)

NAME
mmap, munmap - map or unmap files or devices into memory

SYNOPSIS
#include <sys/types.h>
#include <sys/mman.h>

caddr_t mmap(caddr_t addr, size_t len, int prot , int
flags, int fd, off_t offset );
int munmap(caddr_t addr, size_t len);

DESCRIPTION
WARNING: This is a BSD man page. Linux 0.99.11 can't map
files, and can't do other things documented here.

The mmap function causes the pages starting at addr and
continuing for at most len bytes to be mapped from the
object described by fd, starting at byte offset offset.
If offset or len is not a multiple of the pagesize, the
mapped region may extend past the specified range.

line 1
#
#
# exit
exit

Script done on Tue Jul 8 10:35:29 2003

Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.

2003-07-08 14:37:55

by Kurt Wall

[permalink] [raw]
Subject: Re: syscall __NR_mmap2

Quoth Richard B. Johnson:

[...]

> Yeah? So the Linux kernel now requires a specific vendor distribution?
> Since when?

I don't think this vendor specific. The mmap2() man page I have comes
from the man pages package maintained by Andries Brouwer (release 1.56).
The LSM file says you can get them at
ftp://ftp.win.tue.nl/pub/linux-local/manpages


> So, to get the proper documentation of the Linux Kernel, I now
> need to purchase a vendor's distribution??? I think not. I think

No.

> the sys-calls need to be documented and I think that I have established
> proof of that supposition.
>
> Script started on Tue Jul 8 10:35:05 2003
> # man mmap2
> No manual entry for mmap2
> # mmap
> # man map
>
> MMAP(2) Linux Programmer's Manual MMAP(2)
>
> NAME
> mmap, munmap - map or unmap files or devices into memory
>
> SYNOPSIS
> #include <sys/types.h>
> #include <sys/mman.h>
>
> caddr_t mmap(caddr_t addr, size_t len, int prot , int
> flags, int fd, off_t offset );
> int munmap(caddr_t addr, size_t len);
>
> DESCRIPTION
> WARNING: This is a BSD man page. Linux 0.99.11 can't map
> files, and can't do other things documented here.

I'd say your man pages are woefully out of date.

Kurt
--
Do infants have as much fun in infancy as adults do in adultery?

2003-07-08 14:36:23

by Randy.Dunlap

[permalink] [raw]
Subject: Re: syscall __NR_mmap2

On Tue, 8 Jul 2003 10:40:15 -0400 (EDT) "Richard B. Johnson" <[email protected]> wrote:

| On Tue, 8 Jul 2003, Jamie Lokier wrote:
|
| > Richard B. Johnson wrote:
| > > > The offset argument to mmap2 is divided by PAGE_SIZE.
| > > > That is the whole point of mmap2 :)
| > >
| > > Okay. Do you know where that's documented? Nothing in linux/Documentation,
| > > and nothing in any headers. Do you have to read the code to find out?
| > >
| > > So, the address is now the offset in PAGES, not bytes. Seems logical,
| > > but there is no clue in any documentation.
| >
| > I found this great command which really helps. Only 1337 kernel
| > gnurus know about it, now u can be 1 2 :)
| >
| > $ man mmap2
| > [...]
| > The function mmap2 operates in exactly the same way as mmap(2), except
| > that the final argument specifies the offset into the file in units of
| > the system page size (instead of bytes).
| >
| > -- Jamie
| >
|
| Yeah? So the Linux kernel now requires a specific vendor distribution?
| Since when?
|
| So, to get the proper documentation of the Linux Kernel, I now
| need to purchase a vendor's distribution??? I think not. I think
| the sys-calls need to be documented and I think that I have established
| proof of that supposition.

I can read that mmap2 man page by downloading the latest tarball
from http://www.kernel.org/pub/linux/docs/manpages/ ,
regardless of my distro.

And if what you want/need isn't there, aeb accepts contributions
to it as well.

--
~Randy
| http://developer.osdl.org/rddunlap/ | http://www.xenotime.net/linux/ |