Messages in this thread | | | Date | Fri, 29 May 1998 13:54:57 -0400 | From | Natarajan Krishnaswami <> | Subject | Re: mmap bug? |
| |
>>>>> "Matthew" == Matthew Kirkwood <weejock@ferret.lmh.ox.ac.uk> writes:
[someone] wrote: >> It seems that attempts to mmap a region of size zero causes >> mmap to return zero. Is this a bug? >> >> Since it doesn't return -1, it looks like success, but of >> course dereferencing this NULL pointer causes a crash.
Zero is a multiple of the page size, so there is no partial page mapped: the map is empty. Returning a pointer which may not be dereferenced seems reasonable. However, mmap is explicitly forbidden from returning 0, and SIGBUS would probably be the correct signal to deliver if an address in a 0-length map were dereferenced.
Matthew> I was just curious as to whether Unix98 or similar Matthew> specifies any behaviour;
The zero-length case is not specifically treated.
Matthew> FWIW, Solaris (x86 and Sparc) returns -1 and sets errno Matthew> to EINVAL. Digital Unix returns -1 and ENXIO.
EINVAL should not be returned unless MAP_FIXED is set and the address argument is invalid. ENXIO might work, since it can occur if: SUS2> Addresses in the range [off, off + len) are invalid for the SUS2> object specified by fildes.
N.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu
| |