📄 virtual memory.txt
字号:
brk
SYNOPSIS
int brk(void *end_data_segment);
PARAMETERS
end_data_segment: [in] the new end of the data segment.
DESCRIPTION
brk sets the end of the data segment to the value specified by end_data_segment. This value
must be greater than the end of the text segment and lower than 16KB before the end of the
stack.
Note: the brk syscall is in never called directly. It is wrapped by a libc function that
changes the return value. The sbrk fucntion is also implemented as a wrapper.
RETURN VALUE
Returns the new end of the data segment. (If it is not equal the the requested end, then
there has been an error and the memory couldn't be allocated.)
**************************************************************************************
getpagesize
SYNOPSIS
size_t getpagesize(void);
DESCRIPTION
Gets the virtual subsystem page size, in bytes. This is not necessarily equal to the hardware page size.
RETURN VALUE
The page size, in bytes
**************************************************************************************
mmap and munmap
SYNOPSIS
caddr_t mmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset);
int munmap(caddr_t addr, size_t len);
PARAMETERS
addr: for mmap, [in] where to map the object. For munmap, [in] the region to unmap.
len: [in] length of the mapped region.
prot: [in] protection for the mapping space.
flags: [in] see description.
fd: [in] the object to map.
offset: [in] begining of the part of the object to map.
DESCRIPTION
Maps an file object in the virtual address space of the task. In the case where offset or
len are not multiple of a page size, the mapping space may extend beyond the specified
range. addr is only a clue to the system as where to place the mapping region. The system
may choose to map the object elsewhere. A value of zero for addr tells the system to map
the object where it sees fit. A sucessfull mmap on a previously mapped region cancel the
previous mapping on that region. The prot parameter may be one or more or'ed values among
the following:
PROT_EXEC
the mapped range is executable.
PROT_READ
the mapped range is readable.
PROT_WRITE
the mapped range is writable.
The flags parameter my be one or more or'ed values among the following:
MAP_ANON
the new region is not associated with any physical file. In this case, the fd parameter is
used to name the region. If no name is needed, fd may be set to -1.
MAP_FILE
the new region is a mapping of a regular file or a character device.
MAP_FIXED
the system may not choose another memory region than addr for mapping. If this region cannot
be used, the call fails.
MAP_HASSEMAPHORE
notifies the system that the mapped region may contain semaphores.
MAP_INHERIT
allow for mapped regions to be inherited through the exec system call.
MAP_PRIVATE
modifications to the mapped region are private.
MAP_SHARED
modifications to the mapped region are public.
munmap unmaps the region.
RETURN VALUE
On success mmap returns the address of the newly mapped region, munmap returns zero. On
error, those calls return -1 and sets errno to one of the following:
EACCESS: the protection requested for the mapped region is not consistent with the mode of
fd.
EINVAL: the flags value is incorrect or MAP_FIXED was requested but the address range is not
a multiple of a page size.
ENOMEM: MAP_FIXED was requested but the memory range can not be used for mapping or there is
insufficient memory to complete the call.
ENODEV: the file descriptor cannot be mapped.
EBADF, EFAULT.
**************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -