Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Apr 2017 20:57:16 -0700
From:      "Christopher R. Bowman" <crb@chrisbowman.com>
To:        Fabian Keil <freebsd-listen@fabiankeil.de>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Dtrace oddity
Message-ID:  <15DF9D2C-40A4-4341-AE7E-E8A776ED3F09@ChrisBowman.com>
In-Reply-To: <20170411151426.3b760182@fabiankeil.de>
References:  <CD5E9B03-6147-4E4D-BED6-6C45022051E3@chrisbowman.com> <20170411151426.3b760182@fabiankeil.de>

next in thread | previous in thread | raw e-mail | index | archive | help
Fabian,
	That was hugely helpful.  I should have known about the extra =
mmap sys calls, but sometimes your mind only sees what it expects to =
see.  Checking for negative values on open is also the right thing to do =
(I had mis-read the man page to imply that zero indicated a failure to =
open).  But the real help was putting one of the flags for mmap.  I =
don=E2=80=99t think FreeBSD used to check for that as I have a vague =
recollection that this code used to work on a pervious version.
Thanks SO SO much for the help!
Christopher

--------
Christopher R. Bowman
email: crb@ChrisBowman.com
World Wide GSM cell: +1 (408) 476-2299

> On Apr 11, 2017, at 6:14 AM, Fabian Keil =
<freebsd-listen@fabiankeil.de> wrote:
>=20
> Christopher Bowman <crb@chrisbowman.com> wrote:
>=20
>> The man page lists a bunch of reasons for EINVAL so I want to
>> investigate this and I don=E2=80=99t quite know good strategies to =
debug the
>> kernel (yet) so I thought I=E2=80=99d experiment with Dtrace a bit.  =
Here is the
>> oddity: when I run Dtrace and then run my test program I get the
>> following output from Dtrace:
>>=20
>> crb@retread:60> dtrace -n 'syscall:freebsd:mmap:entry /execname =3D=3D =
"test"/ {}'
>> dtrace: description 'syscall:freebsd:mmap:entry ' matched 1
>> probe CPU     ID                    FUNCTION:NAME
>>  0  63401                       mmap:entry=20
>>  0  63401                       mmap:entry=20
>>  0  63401                       mmap:entry=20
>>  0  63401                       mmap:entry=20
>>  0  63401                       mmap:entry=20
>>  0  63401                       mmap:entry=20
>>  0  63401                       mmap:entry=20
>>  0  63401                       mmap:entry=20
>>  0  63401                       mmap:entry=20
>>  0  63401                       mmap:entry=20
>>  0  63401                       mmap:entry=20
>>  0  63401                       mmap:entry=20
>>=20
>> I think Dtrace is indicating that the mmap syscall was called 12 =
times
>> by my test program yet I can see how the program below would have =
done
>> that.
>=20
> A bunch of mmap syscalls occur before main is even entered.
> Try running your program with truss to see what's going on.
>=20
>> Here is my program:
> [...]
>> 	printf("opening device %s\n", argv[1]);
>> 	int device =3D open (argv[1], O_RDWR);
>> 	if (device =3D=3D 0) {
>=20
> You should check for -1 here.
>=20
>> 	void *pa =3D mmap (0, 4095, PROT_READ | PROT_WRITE, 0, device, =
0);
>=20
> No flags? =46rom the mmap man page:
>=20
> |     [EINVAL]           None of MAP_ANON, MAP_PRIVATE, MAP_SHARED, or
> |                        MAP_STACK was specified.  At least one of =
these flags
> |                        must be included.
>=20
> Fabian




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?15DF9D2C-40A4-4341-AE7E-E8A776ED3F09>