⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmap.2

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 2
字号:
.TH mmap 2.SH Namemmap \- maps memory of a character device.SH Syntax#include <sys/types.h>.br#include <sys/mman.h>.nfcaddr_t mmap(\fIaddr\fP, \fIlen\fP, \fIprot\fP, \fIflags\fP, \fIfd\fP, \fIoff\fP)caddr_t \fIaddr\fP;size_t \fIlen\fP;int \fIprot\fP;int \fIflags\fP;int \fIfd\fP;off_t \fIoff\fP;.fi.SH Arguments.TP 10\fIaddr\fPSpecifies the address space of the calling processwhere .PN mmapbegins mapping the memory associated with the specified character device..TP 10\fIlen\fPSpecifies the number of bytes to map..TP 10\fIprot\fPSpecifies the protection flag for the mapping.The protectionflag is the bitwise inclusive OR of these valid protection flag bitsdefined in.PN mman.h :.PN PROT_READor .PN PROT_WRITE ..TP 10\fIflags\fPSpecifies the mapping flag.The mapping flag is the bitwise inclusive OR of these valid flag mappingbitsdefined in.PN mman.h :.PN MAP_SHAREDor.PN MAP_FIXED ..TP 10\fIfd\fPSpecifies the file descriptor for the character device being mapped..TP 10\fIoff\fPSpecifies the offset in bytes into the character device's memory..SH Description.NXR "memory mapping" "mmap call".NXR "mmap call"The.PN mmapsystem call maps the memory of a character device (\fIfd\fP)starting at a specified offset (\fIoff\fP)for a specified number of bytes(\fIlen\fP)into the address space of the calling process.The.PN mmaproutine does not map into private data, stack, or text segments.This routine does not replace any existing mappings.All the mapped regions are inherited by a child process on a fork..PPWhen calling.PN mmap ,you need to:.IP \(bu 5Align the offset.IPYou must align the offset(\fIoff\fP)on a page boundary as returned by the.PN getpagesizesystem call..IP \(bu 5Indicate the number of bytes to map.IPThe number of bytes to map(\fIlen\fP)need not be a multiple of the page size as returned by.PN getpagesize .However, .PN mmapwill round the value of\fIlen\fPto the nearest multiple of the page size as returned by.PN getpagesizeand perform the mapping over whole pages..IP \(bu 5Specify the protection for the mapping.IPYou specify the protection for the mapping by ORing the\fIprot\fPargument with one or more of the constants.PN PROT_READor.PN PROT_WRITE .If you specify only.PN PROT_READ ,both VAX and RISC architectures will grant read access.If you specify only.PN PROT_WRITE ,then both VAX and RISC architectureswill grant read and write access..IP \(bu 5Indicate the address at which the mapping occurs.IPThe\fIaddr\fPand\fIflags\fParguments are used by .PN mmapto determine the actual address at whichthe mapping is done.You specify the mapping flag by ORing the\fIflags\fPargument with one or more of the constants.PN MAP_FIXEDor.PN MAP_SHARED ..IPBased on the values you specify for\fIaddr\fPand\fIflags\fP,.PN mmapperforms the mapping as follows:.IP - 15If\fIaddr\fPis equal to zero, .PN mmapselects the address at which the mapping isdone..IP - 15If\fIaddr\fPis not equal to zero andyou specified.PN MAP_FIXED ,the mapping is done at the address specified in\fIaddr\fP.You can obtain the boundary on which\fIaddr\fPmust be aligned by calling the.PN getsysinfosystem call..IP - 15If\fIaddr\fPis not equal to zero andyou did not specify.PN MAP_FIXED , the mapping is done at the address rounded down to the boundary returnedby.PN getsysinfo .The value returned by.PN getsysinfois machine-dependent..SH RestrictionsYou must observe the following restrictions when calling.PN mmap :.IP \(bu 5Maximum number of mapped regions for each process.IPThe shared memory functionality upon which.PN mmapis implemented requires that you notexceed the maximum number ofshared memory segments allowed for each process.The default value is six shared memory segments for each process.You can configure (in the system configuration file)the number of shared memory segments for each process byusing the constant.PN SMSEG ..IP \(bu 5Maximum number of mapped regions on the system.IPThe shared memory functionality imposes a limit on the maximum number ofmapped regions on the system.The default limit is 100,sufficient to support a maximum configuration ofall devices that can be mapped.The maximum configuration is 2*21 devices (2 VME adapters, 21 devices foreachbus)..IP \(bu 5A process mapping the same region of device memory.IPA process cannot map the same region of device memory more than onceinto its address space.This limitation is a result of the lack of multiple attach capabilityfor shared memory.However, a single process can map different regions of device memorysimultaneously into its address space.Two regions of memory are identical only if they start at the sameoffset in device memory and are of the same length..IP \(bu 5Use ofthe.MS mprotect 2system call .IPThe.PN mprotectsystem calldoes not work on the addresses mapped by a call to.PN mmap .The reason is that.PN mprotectdoes not work for shared memory and therefore cannot be usedto change protection for the address space mapped by.PN mmap ..SH Return ValueIf successful,.PN mmapreturns the address where the mapping was done.Otherwise, it returns \-1and sets the\fIerrno\fPargument to one of the errors listed in the Diagnostics section..SH DiagnosticsThe call to.PN mmap fails if one or more of the following is true:.TP 10[EBADF]The device, represented by the file descriptor\fIfd\fP,is not open..TP 10[EACCES]The device, represented by the file descriptor\fIfd\fP,is not open for read operations and you specifiedthe protection flag.PN PROT_READin\fIprot\fP.Or, the device is not open for write operations and you specified theprotection flag.PN PROT_WRITEin\fIprot\fP..TP 10[ENXIO]Addresses in the range [\fIoff\fP,\fIoff\fP+\fIlen\fP]are invalid for this device,represented by the file descriptor\fIfd\fP..TP 10[EINVAL]You did not specify either.PN MAP_SHAREDor.PN MAP_FIXEDin the\fIflags\fPargument..TP 10[EINVAL]You did not specify either.PN PROT_READor.PN PROT_WRITEin the\fIprot\fPargument..TP 10[EINVAL]The file descriptor,\fIfd\fP,is not a valid file descriptor for a character device..TP 10[ENODEV]The file descriptor,\fIfd\fP,refers to a device that does not support the.PN mmapsystem call..TP 10[ENOMEM]There is not enough room in the address space to perform the mapping..SH See Alsogetpagesize(2), getsysinfo(2), mmapalignment(1), munmap(2)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -