• KOSAKI Motohiro's avatar
    mlock() fix return values · a477097d
    KOSAKI Motohiro authored
    Halesh says:
    
    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_REA...
    a477097d
mlock.c 5.56 KB