* Re: do_mmap
2002-05-31 17:30 ` do_mmap Linus Torvalds
@ 2002-05-31 17:46 ` Thomas 'Dent' Mirlacher
2002-05-31 17:56 ` do_mmap Linus Torvalds
2002-05-31 18:10 ` do_mmap Richard B. Johnson
2002-05-31 18:59 ` do_mmap Alan Cox
2002-06-01 11:12 ` do_mmap Kai Henningsen
2 siblings, 2 replies; 17+ messages in thread
From: Thomas 'Dent' Mirlacher @ 2002-05-31 17:46 UTC (permalink / raw)
To: Linus Torvalds; +Cc: linux-kernel
--snip/snip
> >> is it possible to have 0 as a valid address? - if not, this should
> >> be the return on errors.
> >
> >SuS explicitly says that 0 is not a valid mmap return address.
>
> But if so, SuS is _very_ _very_ wrong.
>
> The fact is, if you use something like vm86 mode, you absolutely _need_
> to be able to explicitly mmap at address 0.
>
> So it is correct (and in fact there is no other sane way to do it) to
> say
>
> addr = mmap(NULL, 1024*1024,
> PROT_READ | PROT_WRITE ,
> MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED,
> -1, 0);
>
> and if SuS says that mmap must not return NULL for this case, then SuS
> is so full of sh*t that it's not worth worrying about.
>
> In short, under Linux 0 _is_, and will always be (at least on x86) a
> perfectly valid return address from mmap() and friends. It's only going
> to be returned when you explicitly ask for it with MAP_FIXED, but it
> absolutely is a valid return.
ok. so 0 or (NULL) is not an option, and also unnneccessary once someone
know how the error retun is used. - wouldn't it be much more cleaner
to convert this _ugly_ unsigned long vals into void * wherever these vals
are carrying an address? (well at least for do_mmap*) and use ERR_PTR
for returning, and IS_ERR for checking for an error?
btw, is err should (according to alans explaination be):
return (unsigned long)ptr > (unsigned long)-1024UL;
tm
--
in some way i do, and in some way i don't.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: do_mmap
2002-05-31 17:46 ` do_mmap Thomas 'Dent' Mirlacher
@ 2002-05-31 17:56 ` Linus Torvalds
2002-05-31 18:10 ` do_mmap Richard B. Johnson
1 sibling, 0 replies; 17+ messages in thread
From: Linus Torvalds @ 2002-05-31 17:56 UTC (permalink / raw)
To: Thomas 'Dent' Mirlacher; +Cc: linux-kernel
On Fri, 31 May 2002, Thomas 'Dent' Mirlacher wrote:
>
> ok. so 0 or (NULL) is not an option, and also unnneccessary once someone
> know how the error retun is used. - wouldn't it be much more cleaner
> to convert this _ugly_ unsigned long vals into void * wherever these vals
> are carrying an address? (well at least for do_mmap*) and use ERR_PTR
> for returning, and IS_ERR for checking for an error?
Using ERR_PTR/PTR_ERR/IS_ERR is probably the correct thing to do, but
that codebase predates the "error pointer" macros by about 9 years ;)
> btw, is err should (according to alans explaination be):
>
> return (unsigned long)ptr > (unsigned long)-1024UL;
The 1000 vs 1024 thing is just another "random number". I don't know what
the right number is myself, it may be worth trying to pick one that is
uniformly easy to test against, for example. Many architectures are better
at some constants than others.
Linus
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: do_mmap
2002-05-31 17:46 ` do_mmap Thomas 'Dent' Mirlacher
2002-05-31 17:56 ` do_mmap Linus Torvalds
@ 2002-05-31 18:10 ` Richard B. Johnson
2002-05-31 18:21 ` do_mmap Thomas 'Dent' Mirlacher
1 sibling, 1 reply; 17+ messages in thread
From: Richard B. Johnson @ 2002-05-31 18:10 UTC (permalink / raw)
To: Thomas 'Dent' Mirlacher; +Cc: Linus Torvalds, linux-kernel
On Fri, 31 May 2002, Thomas 'Dent' Mirlacher wrote:
> --snip/snip
>
> > >> is it possible to have 0 as a valid address? - if not, this should
> > >> be the return on errors.
> > >
> > >SuS explicitly says that 0 is not a valid mmap return address.
> >
> > But if so, SuS is _very_ _very_ wrong.
> >
> > The fact is, if you use something like vm86 mode, you absolutely _need_
> > to be able to explicitly mmap at address 0.
> >
> > So it is correct (and in fact there is no other sane way to do it) to
> > say
> >
> > addr = mmap(NULL, 1024*1024,
> > PROT_READ | PROT_WRITE ,
> > MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED,
> > -1, 0);
> >
> > and if SuS says that mmap must not return NULL for this case, then SuS
> > is so full of sh*t that it's not worth worrying about.
> >
> > In short, under Linux 0 _is_, and will always be (at least on x86) a
> > perfectly valid return address from mmap() and friends. It's only going
> > to be returned when you explicitly ask for it with MAP_FIXED, but it
> > absolutely is a valid return.
>
> ok. so 0 or (NULL) is not an option, and also unnneccessary once someone
> know how the error retun is used. - wouldn't it be much more cleaner
> to convert this _ugly_ unsigned long vals into void * wherever these vals
> are carrying an address? (well at least for do_mmap*) and use ERR_PTR
> for returning, and IS_ERR for checking for an error?
>
> btw, is err should (according to alans explaination be):
>
> return (unsigned long)ptr > (unsigned long)-1024UL;
>
> tm
>
At the user-mode API, we get to (void *) -1, defined in sys/mman.h
(actually (__ptr_t) -1); so whatever you do, the 'C' runtime library
has to 'know' about your return values if this propagates to
sys-calls.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Windows-2000/Professional isn't.
^ permalink raw reply [flat|nested] 17+ messages in thread* Re: do_mmap
2002-05-31 18:10 ` do_mmap Richard B. Johnson
@ 2002-05-31 18:21 ` Thomas 'Dent' Mirlacher
2002-05-31 18:38 ` do_mmap Richard B. Johnson
0 siblings, 1 reply; 17+ messages in thread
From: Thomas 'Dent' Mirlacher @ 2002-05-31 18:21 UTC (permalink / raw)
To: Richard B. Johnson; +Cc: Linus Torvalds, linux-kernel
Dick,
--snip/snip
> > btw, is err should (according to alans explaination be):
> >
> > return (unsigned long)ptr > (unsigned long)-1024UL;
> >
> > tm
> >
>
> At the user-mode API, we get to (void *) -1, defined in sys/mman.h
> (actually (__ptr_t) -1); so whatever you do, the 'C' runtime library
> has to 'know' about your return values if this propagates to
> sys-calls.
the code right now, will pass all the errors through to the user
space in any case (beside a handful internal kernel-functions).
by changing unsigned long to void * everything should stay the same
(at least for todays architectures) - well if i'm wrong, please
enlighten me :)
also using IS_ERR is essentially the same as the other approaches
to check for errors (beside the check for == 0).
this means by "cleaning up" the internal functions, _nothing_ should
me impacted, even if the changes are step by step, function by function,
beside some gcc warnings (the well known: "assignment makes pointer from
integer without a cast").
cheers,
tm
--
in some way i do, and in some way i don't.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: do_mmap
2002-05-31 18:21 ` do_mmap Thomas 'Dent' Mirlacher
@ 2002-05-31 18:38 ` Richard B. Johnson
0 siblings, 0 replies; 17+ messages in thread
From: Richard B. Johnson @ 2002-05-31 18:38 UTC (permalink / raw)
To: Thomas 'Dent' Mirlacher; +Cc: Linus Torvalds, linux-kernel
On Fri, 31 May 2002, Thomas 'Dent' Mirlacher wrote:
> Dick,
>
> --snip/snip
>
>
> > > btw, is err should (according to alans explaination be):
> > >
> > > return (unsigned long)ptr > (unsigned long)-1024UL;
> > >
> > > tm
> > >
> >
> > At the user-mode API, we get to (void *) -1, defined in sys/mman.h
> > (actually (__ptr_t) -1); so whatever you do, the 'C' runtime library
> > has to 'know' about your return values if this propagates to
> > sys-calls.
>
> the code right now, will pass all the errors through to the user
> space in any case (beside a handful internal kernel-functions).
>
> by changing unsigned long to void * everything should stay the same
> (at least for todays architectures) - well if i'm wrong, please
> enlighten me :)
>
> also using IS_ERR is essentially the same as the other approaches
> to check for errors (beside the check for == 0).
>
> this means by "cleaning up" the internal functions, _nothing_ should
> me impacted, even if the changes are step by step, function by function,
> beside some gcc warnings (the well known: "assignment makes pointer from
> integer without a cast").
>
> cheers,
>
> tm
>
Good. It was just a 'sanity-check' as these things caught my
eye. Because I have to fix a lot of junk code that others have
written (here at work), as they become Peter-principled to
higher-level positions, I get sensitized to these things.
No complaint -- I like fixing junk code!
The previously line was written for Network Security Administrators
(Hello Thor).
Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Windows-2000/Professional isn't.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: do_mmap
2002-05-31 17:30 ` do_mmap Linus Torvalds
2002-05-31 17:46 ` do_mmap Thomas 'Dent' Mirlacher
@ 2002-05-31 18:59 ` Alan Cox
2002-06-01 11:12 ` do_mmap Kai Henningsen
2 siblings, 0 replies; 17+ messages in thread
From: Alan Cox @ 2002-05-31 18:59 UTC (permalink / raw)
To: Linus Torvalds; +Cc: linux-kernel
On Fri, 2002-05-31 at 18:30, Linus Torvalds wrote:
> >> is it possible to have 0 as a valid address? - if not, this should
> >> be the return on errors.
> >
> >SuS explicitly says that 0 is not a valid mmap return address.
>
> But if so, SuS is _very_ _very_ wrong.
>
> The fact is, if you use something like vm86 mode, you absolutely _need_
> to be able to explicitly mmap at address 0.
>
> So it is correct (and in fact there is no other sane way to do it) to
> say
>
> addr = mmap(NULL, 1024*1024,
> PROT_READ | PROT_WRITE ,
> MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED,
> -1, 0);
>
> and if SuS says that mmap must not return NULL for this case, then SuS
> is so full of sh*t that it's not worth worrying about.
SuS doesn't have this requirement in the case of MAP_FIXED.
For normal maps it says
"When the implementation selects a value for pa, it never places a mapping
at address 0, nor does it replace any extant mapping."
For MAP_FIXED it says the return value shal be that of pa (first
argument) exactly
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: do_mmap
2002-05-31 17:30 ` do_mmap Linus Torvalds
2002-05-31 17:46 ` do_mmap Thomas 'Dent' Mirlacher
2002-05-31 18:59 ` do_mmap Alan Cox
@ 2002-06-01 11:12 ` Kai Henningsen
2 siblings, 0 replies; 17+ messages in thread
From: Kai Henningsen @ 2002-06-01 11:12 UTC (permalink / raw)
To: torvalds; +Cc: linux-kernel
torvalds@transmeta.com (Linus Torvalds) wrote on 31.05.02 in <ad8bvv$3tr$1@penguin.transmeta.com>:
> In article <1022855243.12888.410.camel@irongate.swansea.linux.org.uk>,
> Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> >On Fri, 2002-05-31 at 14:00, Thomas 'Dent' Mirlacher wrote:
> >> and the checks in various places are really strange. - well some
> >> places check for:
> >> o != NULL
> >> o > -1024UL
> >
> >"Not an error". Its relying as some other bits of code do actually that
> >the top mappable user address is never in the top 1K of the address
> >space
> >
> >> is it possible to have 0 as a valid address? - if not, this should
> >> be the return on errors.
> >
> >SuS explicitly says that 0 is not a valid mmap return address.
>
> But if so, SuS is _very_ _very_ wrong.
[...]
> and if SuS says that mmap must not return NULL for this case, then SuS
> is so full of sh*t that it's not worth worrying about.
Actually, at least SuSv3 does not say any such thing. *What* it says is
that the return is either MAP_FAILED or the correct address, and that if
it is called *without* MAP_FIXED, then the argument 0 has special meaning,
and it won't map something at 0 (and thus return 0) - which, AFAICT, is
exactly what we want it to say. Specifically, NULL is *never* an error
return value for mmap.
At least, unless we define MAP_FAILED to be NULL - traditionally, it's
(void *)-1 probably exactly so it is possible to return an address of 0.
See <http://www.opengroup.org/onlinepubs/007904975/functions/mmap.html>.
MfG Kai
^ permalink raw reply [flat|nested] 17+ messages in thread