From: Halesh <halesh.s@india.com>
To: linux-kernel@vger.kernel.org
Subject: mlock() return value issue in kernel 2.6.23.17
Date: Thu, 31 Jul 2008 10:15:10 +0000 (UTC) [thread overview]
Message-ID: <loom.20080731T100441-892@post.gmane.org> (raw)
Hi all,
Please find the below testcase provide to test mlock.
Test Case :
===========================
#include <sys/resource.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
int main(void)
{
int fd,ret, i = 0;
char *addr, *addr1 = NULL;
unsigned int page_size;
struct rlimit rlim;
if (0 != geteuid())
{
printf("Execute this pgm as root\n");
exit(1);
}
/* create a file */
if ((fd = open("mmap_test.c",O_RDWR|O_CREAT,0755)) == -1)
{
printf("cant create test file\n");
exit(1);
}
page_size = sysconf(_SC_PAGE_SIZE);
/* set the MEMLOCK limit */
rlim.rlim_cur = 2000;
rlim.rlim_max = 2000;
if ((ret = setrlimit(RLIMIT_MEMLOCK,&rlim)) != 0)
{
printf("Cant change limit values\n");
exit(1);
}
addr = 0;
while (1)
{
/* map a page into memory each time*/
if ((addr = (char *) mmap(addr,page_size, PROT_READ |
PROT_WRITE,MAP_SHARED,fd,0)) == MAP_FAILED)
{
printf("cant do mmap on file\n");
exit(1);
}
if (0 == i)
addr1 = addr;
i++;
errno = 0;
/* lock the mapped memory pagewise*/
if ((ret = mlock((char *)addr, 1500)) == -1)
{
printf("errno value is %d\n", errno);
printf("cant lock maped region\n");
exit(1);
}
addr = addr + page_size;
}
}
======================================================
This testcase results with mlock failure with errno 14 that is EFAULT, but this
has been no where reported that mlock will give EFAULT, When i tested the same
on older kernel like 2.6.18, I got the correct result i.e errno 12 (ENOMEM).
I think in source code mlock(2), setting errno ENOMEM has been missed in
do_mlock() , on mlock_fixup() failure.
Let me know if my understanding is wrong!
Thanks,
Halesh
next reply other threads:[~2008-07-31 10:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-31 10:15 Halesh [this message]
2008-07-31 12:50 ` mlock() return value issue in kernel 2.6.23.17 KOSAKI Motohiro
2008-07-31 21:30 ` Andrew Morton
2008-08-01 7:23 ` KOSAKI Motohiro
-- strict thread matches above, loose matches on Subject: below --
2008-08-01 8:30 Halesh S
2008-08-01 8:56 ` KOSAKI Motohiro
2008-08-01 10:06 Halesh S
2008-10-07 22:24 Yanping Du
2008-10-08 0:59 ` KOSAKI Motohiro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=loom.20080731T100441-892@post.gmane.org \
--to=halesh.s@india.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox