On Thursday, February 21, 2002, at 01:59 PM, Gareth wrote:
I have been playing with minimad for a while now but need some explanations for a few things ;-) The comments say that standard input is mapped into memory using mmap(). So :
Is mmap a C builtin function?
mmap() is a POSIX function; it is implemented as a system call on nearly all operating systems having a UNIX-like kernel.
What do the arguments mean, especially 'stat.st_size'? fdm is the pointer to where the mp3 has been mapped into memory, right?
From the Linux mmap(2) man page:
SYNOPSIS #include <unistd.h> #include <sys/mman.h>
caddr_t mmap(void *start, size_t length, int prot , int flags, int fd, off_t offset);
int munmap(void *start, size_t length);
DESCRIPTION The mmap function asks to map length bytes starting at offset offset from the file (or other object) specified by fd into memory, preferably at address start. This latter address is a hint only, and is usually specified as 0. The actual place where the object is mapped is returned by mmap. The prot argument describes the desired memory pro- tection. It has bits
PROT_EXEC Pages may be executed.
PROT_READ Pages may be read.
PROT_WRITE Pages may be written.
PROT_NONE Pages may not be accessed.
The flags parameter specifies the type of the mapped object, mapping options and whether modifications made to the mapped copy of the page are private to the process or are to be shared with other references. It has bits
MAP_FIXED Do not select a different address than the one specified. If the specified address cannot be used, mmap will fail. If MAP_FIXED is speci- fied, start must be a multiple of the pagesize. Use of this option is discouraged.
MAP_SHARED Share this mapping with all other processes that map this object
MAP_PRIVATE Create a private copy-on-write mapping.
You must specify exactly one of MAP_SHARED and MAP_PRI- VATE.
FYI, stat.st_size is simply the size of the file in bytes as it exists in the filesystem. Thus, the entire file is mapped.
-- Rob Leslie rob@mars.org