Re: posix_madvise(2) should fail with ENOMEM for invalid adresses range

2014-11-24 Thread Alan Barrett

On Sun, 23 Nov 2014, Nicolas Joly wrote:
According the OpenGroup online document for posix_madvise[1], it 
should fail with ENOMEM for invalid addresses ranges : [...] But 
we currently fail with EINVAL (returned value from range_check() 
function).


In general, when POSIX doesn't make sense, NetBSD should not need 
to follow what POSIX says.  In this case, it probably doesn't 
matter much.


--apb (Alan Barrett)


Re: posix_madvise(2) should fail with ENOMEM for invalid adresses range

2014-11-23 Thread Justin Cormack
On Sun, Nov 23, 2014 at 4:37 PM, Nicolas Joly  wrote:
>
> Hi,
>
> According the OpenGroup online document for posix_madvise[1], it
> should fail with ENOMEM for invalid addresses ranges :
>
> [ENOMEM]
> Addresses in the range starting at addr and continuing for len
> bytes are partly or completely outside the range allowed for the
> address space of the calling process.
>
> But we currently fail with EINVAL (returned value from range_check()
> function).
>
> Ok to apply the attached patch to fix posix_madvise/madvise ?
>
> Thanks.
>
> [1] 
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_madvise.html

There was some discussion on PR 48910

http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=48910

Which was slightly inconclusive.

Justin


posix_madvise(2) should fail with ENOMEM for invalid adresses range

2014-11-23 Thread Nicolas Joly

Hi,

According the OpenGroup online document for posix_madvise[1], it
should fail with ENOMEM for invalid addresses ranges :

[ENOMEM]
Addresses in the range starting at addr and continuing for len
bytes are partly or completely outside the range allowed for the
address space of the calling process.

But we currently fail with EINVAL (returned value from range_check()
function).

Ok to apply the attached patch to fix posix_madvise/madvise ?

Thanks.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_madvise.html

-- 
Nicolas Joly

Biology IT Center
Institut Pasteur, Paris.
Index: sys/uvm/uvm_mmap.c
===
RCS file: /cvsroot/src/sys/uvm/uvm_mmap.c,v
retrieving revision 1.149
diff -u -p -r1.149 uvm_mmap.c
--- sys/uvm/uvm_mmap.c  5 Sep 2014 09:24:48 -   1.149
+++ sys/uvm/uvm_mmap.c  11 Nov 2014 11:21:23 -
@@ -843,7 +843,7 @@ sys_madvise(struct lwp *l, const struct 
 
error = range_test(addr, size, false);
if (error)
-   return error;
+   return ENOMEM;
 
switch (advice) {
case MADV_NORMAL:
Index: lib/libc/sys/madvise.2
===
RCS file: /cvsroot/src/lib/libc/sys/madvise.2,v
retrieving revision 1.28
diff -u -p -r1.28 madvise.2
--- lib/libc/sys/madvise.2  19 Jul 2014 19:26:47 -  1.28
+++ lib/libc/sys/madvise.2  11 Nov 2014 11:21:23 -
@@ -105,6 +105,13 @@ will fail if:
 .Bl -tag -width Er
 .It Bq Er EINVAL
 Invalid parameters were provided.
+.It Bq Er ENOMEM
+Addresses in the range starting at
+.Fa addr
+and continuing for
+.Fa len
+bytes are partly or completely outside the range allowed for the address
+space of the calling process.
 .El
 .Sh SEE ALSO
 .Xr mincore 2 ,