* Fixed more incorrect occurrences of the pid_t == int assumption.

* Automatic whitespace cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36090 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2010-04-08 17:32:09 +00:00
parent d7754ff079
commit e99d1fd16f
9 changed files with 274 additions and 274 deletions

View File

@ -1,19 +1,19 @@
/*
/*
* Copyright (c) 2002, Intel Corporation. All rights reserved.
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* of this license, see the COPYING file at the top level of this
* source tree.
* The mmap( ) function shall fail if:
* [ENOMEM] MAP_FIXED was specified,
* [ENOMEM] MAP_FIXED was specified,
* and the range [addr,addr+len) exceeds that allowed
* for the address space of a process; or, if MAP_FIXED was not specified and
* there is insufficient room in the address space to effect the mapping.
*
*
* Test Step:
* 1. Map a shared memory object, with size exceeding the value get from
* rlim_cur of resource RLIMIT_AS, setting MAP_FIXED;
* 3. Should get ENOMEM.
* 3. Should get ENOMEM.
*/
#define _XOPEN_SOURCE 600
@ -29,7 +29,7 @@
#include <string.h>
#include <errno.h>
#include "posixtest.h"
#define TNAME "mmap/24-2.c"
int main()
@ -37,23 +37,23 @@ int main()
char tmpfname[256];
int shm_fd;
void *pa = NULL;
void *pa = NULL;
void *addr = NULL;
size_t len;
int prot = PROT_READ | PROT_WRITE;
int flag = MAP_SHARED;
int fd;
off_t off = 0;
/* Size of the shared memory object */
size_t shm_size;
struct rlimit rlim;
unsigned long page_size = sysconf(_SC_PAGE_SIZE);
shm_size = 2 * page_size;
snprintf(tmpfname, sizeof(tmpfname), "pts_mmap_24_2_%d",
getpid());
snprintf(tmpfname, sizeof(tmpfname), "pts_mmap_24_2_%ld",
(long)getpid());
/* Create shared object */
shm_unlink(tmpfname);
shm_fd = shm_open(tmpfname, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
@ -62,7 +62,7 @@ int main()
printf(TNAME " Error at shm_open(): %s\n", strerror(errno));
return PTS_UNRESOLVED;
}
shm_unlink(tmpfname);
shm_unlink(tmpfname);
if(ftruncate(shm_fd, shm_size) == -1) {
printf(TNAME " Error at ftruncate(): %s\n", strerror(errno));
return PTS_UNRESOLVED;
@ -74,25 +74,25 @@ int main()
printf(TNAME " Error at getrlimit(): %s\n", strerror(errno));
return PTS_UNRESOLVED;
}
printf("available memory: %lu\n", rlim.rlim_cur);
/* First mmap, just to get a legal addr for second mmap */
fd = shm_fd;
len = shm_size;
printf("available memory: %lu\n", rlim.rlim_cur);
/* First mmap, just to get a legal addr for second mmap */
fd = shm_fd;
len = shm_size;
pa = mmap (addr, len, prot, flag, fd, off);
if (pa == MAP_FAILED)
{
printf ("Test Fail: " TNAME " Error at first mmap(): %s\n",
strerror(errno));
printf ("Test Fail: " TNAME " Error at first mmap(): %s\n",
strerror(errno));
exit(PTS_FAIL);
}
fd = shm_fd;
fd = shm_fd;
len = rlim.rlim_cur;
flag = MAP_FIXED | MAP_SHARED;
addr = pa;
printf("addr: %lx, len: %lx\n", (unsigned long)addr,
(unsigned long)len);
printf("addr: %lx, len: %lx\n", (unsigned long)addr,
(unsigned long)len);
/* Make sure addr and len is aligned to page size */
if ((unsigned long)addr % page_size)
{
@ -104,17 +104,17 @@ int main()
{
/* Lower boundary */
len &= ~(page_size - 1);
}
printf("addr: %lx, len: %lx\n", (unsigned long)addr,
(unsigned long)len);
}
printf("addr: %lx, len: %lx\n", (unsigned long)addr,
(unsigned long)len);
pa = mmap (addr, len, prot, flag, fd, off);
if (pa == MAP_FAILED && errno == ENOMEM)
{
printf ("Test Pass: " TNAME " Get ENOMEM: %s\n",
strerror(errno));
printf ("Test Pass: " TNAME " Get ENOMEM: %s\n",
strerror(errno));
exit(PTS_PASS);
}
if (pa == MAP_FAILED)
perror("Error at mmap()");
else

View File

@ -1,24 +1,24 @@
/*
/*
* Copyright (c) 2002, Intel Corporation. All rights reserved.
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* of this license, see the COPYING file at the top level of this
* source tree.
*
* MPR An implementation may permit accesses other than those specified by prot;
* however, if the Memory Protection option is supported, the implementation
* shall not permit a write to succeed where PROT_WRITE has not been set or
* shall not permit any access where PROT_NONE alone has been set.
* MPR An implementation may permit accesses other than those specified by prot;
* however, if the Memory Protection option is supported, the implementation
* shall not permit a write to succeed where PROT_WRITE has not been set or
* shall not permit any access where PROT_NONE alone has been set.
* The implementation shall support at least the following values of prot:
* PROT_NONE, PROT_READ, PROT_WRITE, and the bitwise-inclusive OR of PROT_READ and
* PROT_WRITE.
* PROT_WRITE.
*
* Test Step:
*
* If Memory Protection option is supported:
* 1. Spawn a child process.
* 2. The child process mmap a memory region setting prot as PROT_READ.
* 3. Try to write the mapped memory.
* 4. If the writing triger SIGSEGV, the PASS.
* 3. Try to write the mapped memory.
* 4. If the writing triger SIGSEGV, the PASS.
*
* Please refer to IEEE_1003.1-2001. 2.8.3.3 Memory Protection.
*/
@ -35,16 +35,16 @@
#include <string.h>
#include <errno.h>
#include "posixtest.h"
#define TNAME "mmap/6-1.c"
int main()
{
#ifdef _POSIX_MEMORY_PROTECTION
char tmpfname[256];
int total_size = 1024;
int total_size = 1024;
void *pa = NULL;
void *pa = NULL;
void *addr = NULL;
size_t size = total_size;
int flag = MAP_SHARED;
@ -58,39 +58,39 @@ int main()
int status;
int sig_num;
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_6_1_%d",
getpid());
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_6_1_%ld",
(long)getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
unlink(tmpfname);
child = fork();
if (child == 0)
{
if(ftruncate(fd, total_size) == -1)
{
printf(TNAME "Error at ftruncate(): %s\n",
strerror(errno));
printf(TNAME "Error at ftruncate(): %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
prot = PROT_READ;
pa = mmap(addr, size, prot, flag, fd, off);
if (pa == MAP_FAILED)
{
printf("Test Fail: " TNAME " Error at mmap: %s\n",
strerror(errno));
printf("Test Fail: " TNAME " Error at mmap: %s\n",
strerror(errno));
exit(PTS_FAIL);
}
ch = pa;
*ch = 'b';
@ -103,10 +103,10 @@ int main()
if (WIFSTOPPED(status))
{
sig_num = WSTOPSIG(status);
printf("Child process stopped by signal %d\n", sig_num);
printf("Child process stopped by signal %d\n", sig_num);
if (sig_num == SIGSEGV)
{
printf("Test Pass: " TNAME
printf("Test Pass: " TNAME
" Got SIGSEGV when writing to the mapped memory, "
"without setting PROT_WRITE\n");
return PTS_PASS;
@ -115,10 +115,10 @@ int main()
if (WIFSIGNALED(status))
{
sig_num = WTERMSIG(status);
printf("Child process terminated by signal %d\n", sig_num);
printf("Child process terminated by signal %d\n", sig_num);
if (sig_num == SIGSEGV)
{
printf ("Test Pass: " TNAME
printf ("Test Pass: " TNAME
" Got SIGSEGV when writing to the mapped memory, "
"without setting PROT_WRITE\n");
return PTS_PASS;
@ -128,7 +128,7 @@ int main()
{
if (WEXITSTATUS(status) == 0)
{
printf ("Test FAIL: " TNAME
printf ("Test FAIL: " TNAME
" Did not got SIGSEGV when writing to the mapped memory,"
" without setting PROT_WRITE\n");
return PTS_FAIL;
@ -139,9 +139,9 @@ int main()
}
#else
printf ("Test Unresolved: " TNAME
" _POSIX_MEMORY_PROTECTION not defined\n");
printf ("Test Unresolved: " TNAME
" _POSIX_MEMORY_PROTECTION not defined\n");
return PTS_UNRESOLVED;
#endif
}

View File

@ -1,25 +1,25 @@
/*
/*
* Copyright (c) 2002, Intel Corporation. All rights reserved.
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* of this license, see the COPYING file at the top level of this
* source tree.
*
* MPR An implementation may permit accesses other than those specified by prot;
* however, if the Memory Protection option is supported, the implementation
* shall not permit a write to succeed where PROT_WRITE has not been set or
* shall not permit any access where PROT_NONE alone has been set.
* MPR An implementation may permit accesses other than those specified by prot;
* however, if the Memory Protection option is supported, the implementation
* shall not permit a write to succeed where PROT_WRITE has not been set or
* shall not permit any access where PROT_NONE alone has been set.
* The implementation shall support at least the following values of prot:
* PROT_NONE, PROT_READ, PROT_WRITE, and the bitwise-inclusive OR of PROT_READ and
* PROT_WRITE.
*
* PROT_WRITE.
*
* Test Step:
*
* If the Memory Protection option is supported:
*
* 1. Spawn a child process.
* 2. The child process mmap a memory region setting prot as PROT_NONE.
* 3. Try to read the mapped memory.
* 4. If the read will triger SIGSEGV, the PASS.
* 3. Try to read the mapped memory.
* 4. If the read will triger SIGSEGV, the PASS.
*
* Please refer to IEEE_1003.1-2001. 2.8.3.3 Memory Protection.
*/
@ -38,7 +38,7 @@
#include <string.h>
#include <errno.h>
#include "posixtest.h"
#define TNAME "mmap/6-2.c"
int main()
@ -47,9 +47,9 @@ int main()
#ifdef _POSIX_MEMORY_PROTECTION
char tmpfname[256];
char* data;
int total_size = 1024;
void *pa = NULL;
int total_size = 1024;
void *pa = NULL;
void *addr = NULL;
size_t size = total_size;
int flag = MAP_SHARED;
@ -63,49 +63,49 @@ int main()
int status;
int sig_num;
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_6_2_%d",
getpid());
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_6_2_%ld",
(long)getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
unlink(tmpfname);
child = fork();
if (child == 0)
{
fflush (NULL);
data = (char *) malloc(total_size);
fflush (NULL);
data = (char *) malloc(total_size);
memset(data, 'a', total_size);
if (write(fd, data, total_size) != total_size)
{
printf(TNAME "Error at write(): %s\n",
strerror(errno));
printf(TNAME "Error at write(): %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
free(data);
prot = PROT_NONE;
pa = mmap(addr, size, prot, flag, fd, off);
if (pa == MAP_FAILED)
{
printf("Test Fail: " TNAME " Error at mmap: %s\n",
strerror(errno));
printf("Test Fail: " TNAME " Error at mmap: %s\n",
strerror(errno));
exit(PTS_FAIL);
}
ch = pa;
/* Read acess */
if(*ch != 'a')
{
printf ("Test Fail: " TNAME
" The file did not mapped to memory\n");
printf ("Test Fail: " TNAME
" The file did not mapped to memory\n");
exit(PTS_FAIL);
}
exit(0);
@ -119,44 +119,44 @@ int main()
sig_num = WSTOPSIG(status);
if (sig_num == SIGSEGV)
{
printf("Test Pass: " TNAME
printf("Test Pass: " TNAME
" Got SIGSEGV when reading the mapped memory, "
"setting PROT_NONE\n");
return PTS_PASS;
}
printf("Child process stopped by signal %d\n", sig_num);
printf("Child process stopped by signal %d\n", sig_num);
}
if (WIFSIGNALED(status))
{
sig_num = WTERMSIG(status);
if (sig_num == SIGSEGV)
{
printf ("Test Pass: " TNAME
printf ("Test Pass: " TNAME
" Got SIGSEGV when reading the mapped memory, "
" setting PROT_NOTE\n");
return PTS_PASS;
}
printf("Child process terminated by signal %d\n", sig_num);
printf("Child process terminated by signal %d\n", sig_num);
}
if (WIFEXITED(status))
{
if (WEXITSTATUS(status) == 0)
{
printf ("Test FAIL: " TNAME
printf ("Test FAIL: " TNAME
" Did not got SIGSEGV when reading the mapped memory,"
" setting PROT_NOTE\n");
return PTS_FAIL;
}
}
printf ("Test Unresolved\n");
return PTS_UNRESOLVED;
}
#else
printf ("Test Unresolved: " TNAME
" _POSIX_MEMORY_PROTECTION not defined\n");
printf ("Test Unresolved: " TNAME
" _POSIX_MEMORY_PROTECTION not defined\n");
return PTS_UNRESOLVED;
#endif
}

View File

@ -1,23 +1,23 @@
/*
/*
* Copyright (c) 2002, Intel Corporation. All rights reserved.
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* of this license, see the COPYING file at the top level of this
* source tree.
*
* MPR An implementation may permit accesses other than those specified by prot;
* however, if the Memory Protection option is supported, the implementation
* shall not permit a write to succeed where PROT_WRITE has not been set or
* shall not permit any access where PROT_NONE alone has been set.
* MPR An implementation may permit accesses other than those specified by prot;
* however, if the Memory Protection option is supported, the implementation
* shall not permit a write to succeed where PROT_WRITE has not been set or
* shall not permit any access where PROT_NONE alone has been set.
* The implementation shall support at least the following values of prot:
* PROT_NONE, PROT_READ, PROT_WRITE, and the bitwise-inclusive OR of PROT_READ and
* PROT_WRITE.
*
* PROT_WRITE.
*
* Test Step:
* If Memory Protection option is suppored:
* 1. Spawn a child process.
* 2. The child process mmap a memory region setting prot as PROT_NONE.
* 3. Try to write the mapped memory.
* 4. If the write will triger SIGSEGV, the PASS.
* 3. Try to write the mapped memory.
* 4. If the write will triger SIGSEGV, the PASS.
*
* Please refer to IEEE_1003.1-2001. 2.8.3.3 Memory Protection.
*/
@ -36,7 +36,7 @@
#include <string.h>
#include <errno.h>
#include "posixtest.h"
#define TNAME "mmap/6-3.c"
int main()
@ -44,9 +44,9 @@ int main()
#ifdef _POSIX_MEMORY_PROTECTION
char tmpfname[256];
int total_size = 1024;
void *pa = NULL;
int total_size = 1024;
void *pa = NULL;
void *addr = NULL;
size_t size = total_size;
int flag = MAP_SHARED;
@ -60,40 +60,40 @@ int main()
int status;
int sig_num;
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_6_3_%d",
getpid());
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_6_3_%ld",
(long)getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
unlink(tmpfname);
child = fork();
if (child == 0)
{
fflush (NULL);
fflush (NULL);
if (ftruncate(fd, total_size) == -1)
{
printf(TNAME "Error at ftruncate(): %s\n",
strerror(errno));
printf(TNAME "Error at ftruncate(): %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
prot = PROT_NONE;
pa = mmap(addr, size, prot, flag, fd, off);
if (pa == MAP_FAILED)
{
printf("Test Fail: " TNAME " Error at mmap: %s\n",
strerror(errno));
printf("Test Fail: " TNAME " Error at mmap: %s\n",
strerror(errno));
exit(PTS_FAIL);
}
ch = pa;
/* Write acess */
@ -109,43 +109,43 @@ int main()
sig_num = WSTOPSIG(status);
if (sig_num == SIGSEGV)
{
printf("Test Pass: " TNAME
printf("Test Pass: " TNAME
" Got SIGSEGV when writing the mapped memory, "
"setting PROT_NONE\n");
return PTS_PASS;
}
printf("Child process stopped by signal %d\n", sig_num);
printf("Child process stopped by signal %d\n", sig_num);
}
if (WIFSIGNALED(status))
{
sig_num = WTERMSIG(status);
if (sig_num == SIGSEGV)
{
printf ("Test Pass: " TNAME
printf ("Test Pass: " TNAME
" Got SIGSEGV when writing the mapped memory, "
" setting PROT_NOTE\n");
return PTS_PASS;
}
printf("Child process terminated by signal %d\n", sig_num);
printf("Child process terminated by signal %d\n", sig_num);
}
if (WIFEXITED(status))
{
if (WEXITSTATUS(status) == 0)
{
printf ("Test FAIL: " TNAME
printf ("Test FAIL: " TNAME
" Did not got SIGSEGV when writing the mapped memory,"
" setting PROT_NOTE\n");
return PTS_FAIL;
}
}
printf ("Test Unresolved\n");
return PTS_UNRESOLVED;
}
#else
printf ("Test Unresolved: " TNAME
" _POSIX_MEMORY_PROTECTION not defined\n");
printf ("Test Unresolved: " TNAME
" _POSIX_MEMORY_PROTECTION not defined\n");
return PTS_UNRESOLVED;
#endif
}

View File

@ -1,14 +1,14 @@
/*
/*
* Copyright (c) 2002, Intel Corporation. All rights reserved.
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* of this license, see the COPYING file at the top level of this
* source tree.
*
* The munmap( ) function shall remove any mappings for those
* entire pages containing any part of the address space of
* the process starting at addr and continuing for len bytes.
* Further references to these pages shall result in the
* generation of a SIGSEGV signal to the process.
* The munmap( ) function shall remove any mappings for those
* entire pages containing any part of the address space of
* the process starting at addr and continuing for len bytes.
* Further references to these pages shall result in the
* generation of a SIGSEGV signal to the process.
*
* Test Step:
* 1. map a file into memory;
@ -31,7 +31,7 @@
#include <string.h>
#include <errno.h>
#include "posixtest.h"
#define TNAME "munmap/1-1.c"
void sigsegv_handler(int signum)
@ -44,9 +44,9 @@ void sigsegv_handler(int signum)
int main()
{
char tmpfname[256];
long file_size;
long file_size;
void *pa = NULL;
void *pa = NULL;
void *addr = NULL;
size_t len;
int flag;
@ -55,66 +55,66 @@ int main()
int prot;
int page_size;
char *ch1;
struct sigaction sa;
sigfillset(&sa.sa_mask);
sa.sa_handler = sigsegv_handler;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGSEGV, &sa, NULL);
page_size = sysconf(_SC_PAGE_SIZE);
file_size = 2 * page_size;
/* We hope to map 2 pages */
len = page_size + 1;
/* Create tmp file */
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_munmap_1_1_%d",
getpid());
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_munmap_1_1_%ld",
(long)getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
unlink(tmpfname);
if (ftruncate (fd, file_size) == -1)
{
printf("Error at ftruncate: %s\n", strerror(errno));
exit(PTS_UNRESOLVED);
}
}
flag = MAP_SHARED;
prot = PROT_READ | PROT_WRITE;
pa = mmap(addr, len, prot, flag, fd, off);
if (pa == MAP_FAILED)
{
printf ("Test UNRESOLVED: " TNAME " Error at mmap: %s\n",
strerror(errno));
printf ("Test UNRESOLVED: " TNAME " Error at mmap: %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
/* ch1 is outside the mapped object, but in the mapped file */
ch1 = pa + len + 1;
*ch1 = 'b';
close (fd);
if (munmap (pa, len) == -1)
{
printf ("Test FAILED: " TNAME " Error at munmap: %s\n",
strerror(errno));
printf ("Test FAILED: " TNAME " Error at munmap: %s\n",
strerror(errno));
exit(PTS_FAIL);
}
/* Try to reference the unmapped area, should trigger SIGSEGV */
/* Try to reference the unmapped area, should trigger SIGSEGV */
*ch1 = 'a';
/* If reach this point, test fail */
printf ("Test FAILED: Did not trigger SIGSEGV\n");
return PTS_FAIL;

View File

@ -1,19 +1,19 @@
/*
/*
* Copyright (c) 2002, Intel Corporation. All rights reserved.
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* of this license, see the COPYING file at the top level of this
* source tree.
*
* The munmap( ) function shall remove any mappings for those
* entire pages containing any part of the address space of
* the process starting at addr and continuing for len bytes.
* Further references to these pages shall result in the
* generation of a SIGSEGV signal to the process.
* The munmap( ) function shall remove any mappings for those
* entire pages containing any part of the address space of
* the process starting at addr and continuing for len bytes.
* Further references to these pages shall result in the
* generation of a SIGSEGV signal to the process.
*
* Test Step:
* 1. map a file into memory;
* 2. unmap;
* 3. Try to reference the unmapped memory, test whether SIGSEGV
* 3. Try to reference the unmapped memory, test whether SIGSEGV
* is triggered.
*/
@ -31,7 +31,7 @@
#include <string.h>
#include <errno.h>
#include "posixtest.h"
#define TNAME "munmap/1-2.c"
void sigsegv_handler(int signum)
@ -44,9 +44,9 @@ void sigsegv_handler(int signum)
int main()
{
char tmpfname[256];
long file_size;
long file_size;
void *pa = NULL;
void *pa = NULL;
void *addr = NULL;
size_t len;
int flag;
@ -55,60 +55,60 @@ int main()
int prot;
int page_size;
char *ch;
struct sigaction sa;
sigfillset(&sa.sa_mask);
sa.sa_handler = sigsegv_handler;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGSEGV, &sa, NULL);
page_size = sysconf(_SC_PAGE_SIZE);
file_size = 2 * page_size;
/* We hope to map 2 pages */
len = page_size + 1;
/* Create tmp file */
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_munmap_1_1_%d",
getpid());
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_munmap_1_1_%ld",
(long)getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
unlink(tmpfname);
if (ftruncate (fd, file_size) == -1)
{
printf("Error at ftruncate: %s\n", strerror(errno));
exit(PTS_UNRESOLVED);
}
}
flag = MAP_SHARED;
prot = PROT_READ | PROT_WRITE;
pa = mmap(addr, len, prot, flag, fd, off);
if (pa == MAP_FAILED)
{
printf ("Test UNRESOLVED: " TNAME " Error at mmap: %s\n",
strerror(errno));
printf ("Test UNRESOLVED: " TNAME " Error at mmap: %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
ch = pa;
*ch = 'b';
close (fd);
munmap (pa, len);
/* Should trigger SIGSEGV here */
/* Should trigger SIGSEGV here */
*ch = 'a';
printf ("Test FAILED: Did not trigger SIGSEGV\n");
return PTS_FAIL;
}

View File

@ -1,12 +1,12 @@
/*
/*
* Copyright (c) 2002, Intel Corporation. All rights reserved.
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* of this license, see the COPYING file at the top level of this
* source tree.
*
* The implementation shall require that addr be a multiple
* The implementation shall require that addr be a multiple
* of the page size {PAGESIZE}.
*
*
* Test step:
* Try to call unmap, with addr NOT a multiple of page size.
* Should get EINVAL.
@ -26,15 +26,15 @@
#include <string.h>
#include <errno.h>
#include "posixtest.h"
#define TNAME "munmap/3-1.c"
int main()
{
char tmpfname[256];
long file_size;
long file_size;
void *pa = NULL;
void *pa = NULL;
void *addr = NULL;
size_t len;
int flag;
@ -43,43 +43,43 @@ int main()
int prot;
int page_size;
char *pa2;
page_size = sysconf(_SC_PAGE_SIZE);
file_size = 2 * page_size;
/* We hope to map 2 pages */
len = page_size + 1;
/* Create tmp file */
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_munmap_1_1_%d",
getpid());
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_munmap_1_1_%ld",
(long)getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
unlink(tmpfname);
if (ftruncate (fd, file_size) == -1)
{
printf("Error at ftruncate: %s\n", strerror(errno));
exit(PTS_UNRESOLVED);
}
}
flag = MAP_SHARED;
prot = PROT_READ | PROT_WRITE;
pa = mmap(addr, len, prot, flag, fd, off);
if (pa == MAP_FAILED)
{
printf ("Test Unresolved: " TNAME " Error at mmap: %s\n",
strerror(errno));
printf ("Test Unresolved: " TNAME " Error at mmap: %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
@ -88,18 +88,18 @@ int main()
while (((unsigned long)pa2 % page_size) == 0)
pa2++;
close (fd);
if (munmap (pa2, len) == -1 && errno == EINVAL)
{
printf ("Got EINVAL\n");
printf ("Test PASSED\n");
printf ("Got EINVAL\n");
printf ("Test PASSED\n");
exit(PTS_PASS);
}
else
{
printf ("Test FAILED: " TNAME " munmap returns: %s\n",
strerror(errno));
printf ("Test FAILED: " TNAME " munmap returns: %s\n",
strerror(errno));
exit(PTS_FAIL);
}
}

View File

@ -1,11 +1,11 @@
/*
/*
* Copyright (c) 2002, Intel Corporation. All rights reserved.
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* of this license, see the COPYING file at the top level of this
* source tree.
*
*
* If a mapping to be removed was private, any modifications
* If a mapping to be removed was private, any modifications
* made in this address range shall be discarded.
*
* Test Step:
@ -14,7 +14,7 @@
* the file;
* 3. munmap the mapped memory;
* 4. mmap the same file again into memory;
* 5. If the modification in step 2 appears in the mapped memory, then fail,
* 5. If the modification in step 2 appears in the mapped memory, then fail,
* otherwise pass.
*/
@ -32,18 +32,18 @@
#include <string.h>
#include <errno.h>
#include "posixtest.h"
#define TNAME "munmap/4-1.c"
int main()
{
int rc;
char tmpfname[256];
char* data;
int total_size = 1024;
int total_size = 1024;
void *pa = NULL;
void *pa = NULL;
void *addr = NULL;
size_t size = total_size;
int flag;
@ -53,39 +53,39 @@ int main()
char * ch;
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_munmap_4_1_%d",
getpid());
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_munmap_4_1_%ld",
(long)getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
unlink(tmpfname);
data = (char *) malloc(total_size);
data = (char *) malloc(total_size);
memset(data, 'a', total_size);
if (write(fd, data, total_size) != total_size)
{
printf(TNAME "Error at write(): %s\n",
strerror(errno));
printf(TNAME "Error at write(): %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
free(data);
prot = PROT_READ | PROT_WRITE;
flag = MAP_PRIVATE;
pa = mmap(addr, size, prot, flag, fd, off);
if (pa == MAP_FAILED)
{
printf("Test Fail: " TNAME " Error at mmap: %s\n",
strerror(errno));
printf("Test Fail: " TNAME " Error at mmap: %s\n",
strerror(errno));
exit(PTS_FAIL);
}
ch = pa;
*ch = 'b';
@ -93,25 +93,25 @@ int main()
if ((rc =msync(pa, size, MS_SYNC)) != 0)
{
printf(TNAME " Error at msync(): %s\n",
strerror(rc));
printf(TNAME " Error at msync(): %s\n",
strerror(rc));
exit(PTS_UNRESOLVED);
}
munmap(pa, size);
/* Mmap again */
pa = mmap(addr, size, prot, flag, fd, off);
if (pa == MAP_FAILED)
{
printf("Test Fail: " TNAME " Error at 2nd mmap: %s\n",
strerror(errno));
printf("Test Fail: " TNAME " Error at 2nd mmap: %s\n",
strerror(errno));
exit(PTS_FAIL);
}
ch = pa;
if (*ch == 'b')
if (*ch == 'b')
{
printf("Test FAIL\n");
exit(PTS_FAIL);

View File

@ -1,7 +1,7 @@
/*
/*
* Copyright (c) 2002, Intel Corporation. All rights reserved.
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* of this license, see the COPYING file at the top level of this
* source tree.
*
* The munmap( ) function shall fail if:
@ -23,15 +23,15 @@
#include <string.h>
#include <errno.h>
#include "posixtest.h"
#define TNAME "munmap/9-1.c"
int main()
{
char tmpfname[256];
long file_size;
long file_size;
void *pa = NULL;
void *pa = NULL;
void *addr = NULL;
size_t len;
int flag;
@ -40,50 +40,50 @@ int main()
int prot;
int page_size;
page_size = sysconf(_SC_PAGE_SIZE);
file_size = 2 * page_size;
/* We hope to map 2 pages */
len = page_size + 1;
/* Create tmp file */
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_munmap_1_1_%d",
getpid());
snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_munmap_1_1_%ld",
(long)getpid());
unlink(tmpfname);
fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
S_IRUSR | S_IWUSR);
if (fd == -1)
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
{
printf(TNAME " Error at open(): %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
unlink(tmpfname);
if (ftruncate (fd, file_size) == -1)
{
printf("Error at ftruncate: %s\n", strerror(errno));
exit(PTS_UNRESOLVED);
}
}
flag = MAP_SHARED;
prot = PROT_READ | PROT_WRITE;
pa = mmap(addr, len, prot, flag, fd, off);
if (pa == MAP_FAILED)
{
printf ("Test Unresolved: " TNAME " Error at mmap: %s\n",
strerror(errno));
printf ("Test Unresolved: " TNAME " Error at mmap: %s\n",
strerror(errno));
exit(PTS_UNRESOLVED);
}
close (fd);
/* Set len as 0 */
if (munmap (pa, 0) == -1 && errno == EINVAL)
{
printf ("Get EINVAL when len=0\n");
printf ("Test PASSED\n");
printf ("Get EINVAL when len=0\n");
printf ("Test PASSED\n");
exit(PTS_PASS);
}
else