kernel 2.2.16 and mmap function
Posted: Mon Dec 20, 2004 12:25 pm
Hi, Lutz.
Code in .1 and .2 (see down) are not according with requirements in MMAP(2).
MMAP(2) Linux Programmer's Manual MMAP(2)
NAME
mmap, munmap - map or unmap files or devices into memory
...
void * mmap(void *start, size_t length, int prot , int
flags, int fd, off_t offset);
...
fd should be a valid file descriptor, unless MAP_ANONYMOUS
is set, in which case the argument is ignored
...
MAP_ANONYMOUS
The mapping is not backed by any file; the fd and
offset arguments are ignored. This flag in con-
junction with MAP_SHARED is implemented since Linux 2.4.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
newlisp.c
--
int loadFile(char * fileName, UINT offset, int encryptFlag)
{
STREAM stream;
...
if(makeStreamFromFile(&stream, fileName, dataLen + MAX_STRING, offset) == 0)
return(0);
...
evaluateString(&stream, 0);
...
closeStrStream(&stream);
return(TRUE);
}
nl-string.c
--
int makeStreamFromFile(STREAM * stream, char * fileName, UINT size, UINT offset)
{
if((stream->handle = open(fileName, O_RDONLY | O_BINARY)) == -1) return(0);
.1 ^^^^^^^^^^^^^^^^^^^
/*
correctly will be
if((stream->handle = open(fileName, O_RDWR)) == -1) return(0);
*/
...
return(TRUE);
}
CELL * p_share(CELL * params)
{
...
if(params != nilCell)
{
...
return(nilCell);
}
if((address.ptr = (UINT*)mmap(
0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0)) == (void*)-1)
.2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/*
correctly will be, but "fd" is not scope here
if((address.ptr = (UINT*)mmap(
0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == (void*)-1)
*/
return(nilCell);
memset((char *)address.num, 0, pagesize);
return(stuffInteger(address.num));
...
}
May be better to use next functions for organization share memory
int shmget (key_t key, int size, int flag);
void *shmat (int shmid, void *addr, int flag);
void shmdt (void *ptr);
int shmctl (int shmid, int cmd, struct shmid_ds *buf);
Bye, Boa.
Code in .1 and .2 (see down) are not according with requirements in MMAP(2).
MMAP(2) Linux Programmer's Manual MMAP(2)
NAME
mmap, munmap - map or unmap files or devices into memory
...
void * mmap(void *start, size_t length, int prot , int
flags, int fd, off_t offset);
...
fd should be a valid file descriptor, unless MAP_ANONYMOUS
is set, in which case the argument is ignored
...
MAP_ANONYMOUS
The mapping is not backed by any file; the fd and
offset arguments are ignored. This flag in con-
junction with MAP_SHARED is implemented since Linux 2.4.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
newlisp.c
--
int loadFile(char * fileName, UINT offset, int encryptFlag)
{
STREAM stream;
...
if(makeStreamFromFile(&stream, fileName, dataLen + MAX_STRING, offset) == 0)
return(0);
...
evaluateString(&stream, 0);
...
closeStrStream(&stream);
return(TRUE);
}
nl-string.c
--
int makeStreamFromFile(STREAM * stream, char * fileName, UINT size, UINT offset)
{
if((stream->handle = open(fileName, O_RDONLY | O_BINARY)) == -1) return(0);
.1 ^^^^^^^^^^^^^^^^^^^
/*
correctly will be
if((stream->handle = open(fileName, O_RDWR)) == -1) return(0);
*/
...
return(TRUE);
}
CELL * p_share(CELL * params)
{
...
if(params != nilCell)
{
...
return(nilCell);
}
if((address.ptr = (UINT*)mmap(
0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0)) == (void*)-1)
.2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/*
correctly will be, but "fd" is not scope here
if((address.ptr = (UINT*)mmap(
0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == (void*)-1)
*/
return(nilCell);
memset((char *)address.num, 0, pagesize);
return(stuffInteger(address.num));
...
}
May be better to use next functions for organization share memory
int shmget (key_t key, int size, int flag);
void *shmat (int shmid, void *addr, int flag);
void shmdt (void *ptr);
int shmctl (int shmid, int cmd, struct shmid_ds *buf);
Bye, Boa.