Question about mmap syscall and POSIX standard on mips arch

From: Hongzhi, Song
Date: Wed Oct 17 2018 - 23:26:16 EST


Hi all,

Ltp has a POSIX teatcase about mmap, 24-2.c.

https://github.com/linux-test-project/ltp/blob/e816127e5d8efbff5ae53e9c2292fae22f36838b/testcases/open_posix_testsuite/conformance/interfaces/mmap/24-2.c#L94

-----part of code-----

ÂÂÂ pa = mmap(addr, len, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, fd,
0);
ÂÂÂ if (pa == MAP_FAILED && errno == ENOMEM) {
ÂÂÂÂÂÂÂ printf("Got ENOMEM: %s\nTest PASSED\n", strerror(errno));
exit(PTS_PASS);
ÂÂÂ }

-----end----------------


Under POSIX standard, the expected errno should be ENOMEM

when the specific [addr+len] exceeds the bound of memory.


But mips returns EINVAL.

https://github.com/torvalds/linux/blob/bab5c80b211035739997ebd361a679fa85b39465/arch/mips/mm/mmap.c#L69

-------part of code-------

ÂÂÂ if (flags & MAP_FIXED) {
ÂÂÂÂÂÂÂ /* Even MAP_FIXED mappings must reside within TASK_SIZE */
ÂÂÂÂÂÂÂ if (TASK_SIZE - len < addr)
ÂÂÂÂÂÂÂÂÂÂÂ return -EINVAL;

-------end------------------


So, can we change EINVAL to ENOMEM to follow POSIX standard?


--Hongzhi