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

📄 1.2.t

📁 早期freebsd实现
💻 T
字号:
.\" Copyright (c) 1983, 1993.\"	The Regents of the University of California.  All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\"    notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\"    notice, this list of conditions and the following disclaimer in the.\"    documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\"    must display the following acknowledgement:.\"	This product includes software developed by the University of.\"	California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\"    may be used to endorse or promote products derived from this software.\"    without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\"	@(#)1.2.t	8.1 (Berkeley) 6/8/93.\".sh "Memory management\(dg.NH 3Text, data and stack.PP.FS\(dg This section represents the interface planned for laterreleases of the system.  Of the calls described in this section,only \fIsbrk\fP and \fIgetpagesize\fP are included in 4.3BSD..FEEach process begins execution with three logical areas of memorycalled text, data and stack.  The text area is read-only and shared, while the data and stackareas are private to the process.  Both the data and stack areas maybe extended and contracted on program request.  The call.DSaddr = sbrk(incr);result caddr_t addr; int incr;.DEchanges the size of the data area by \fIincr\fP bytes andreturns the new end of the data area, while.DSaddr = sstk(incr);result caddr_t addr; int incr;.DEchanges the size of the stack area.The stack area is also automatically extended as needed.On the VAX the text and data areas are adjacent in the P0 region,while the stack section is in the P1 region, and grows downward..NH 3Mapping pages.PPThe system supports sharing of data between processesby allowing pages to be mapped into memory.  These mappedpages may be \fIshared\fP with other processes or \fIprivate\fPto the process.Protection and sharing options are defined in \fI<sys/mman.h>\fP as:.DS.ta \w'#define\ \ 'u +\w'MAP_HASSEMAPHORE\ \ 'u +\w'0x0080\ \ 'u/* protections are chosen from these bits, or-ed together */#define	PROT_READ	0x04	/* pages can be read */#define	PROT_WRITE	0x02	/* pages can be written */#define	PROT_EXEC	0x01	/* pages can be executed */.DE.DS.ta \w'#define\ \ 'u +\w'MAP_HASSEMAPHORE\ \ 'u +\w'0x0080\ \ 'u/* flags contain mapping type, sharing type and options *//* mapping type; choose one */#define MAP_FILE	0x0001	/* mapped from a file or device */#define MAP_ANON	0x0002	/* allocated from memory, swap space */#define MAP_TYPE	0x000f	/* mask for type field */.DE.DS.ta \w'#define\ \ 'u +\w'MAP_HASSEMAPHORE\ \ 'u +\w'0x0080\ \ 'u/* sharing types; choose one */#define	MAP_SHARED	0x0010	/* share changes */#define	MAP_PRIVATE	0x0000	/* changes are private */.DE.DS.ta \w'#define\ \ 'u +\w'MAP_HASSEMAPHORE\ \ 'u +\w'0x0080\ \ 'u/* other flags */#define MAP_FIXED	0x0020	/* map addr must be exactly as requested */#define MAP_INHERIT	0x0040	/* region is retained after exec */#define MAP_HASSEMAPHORE	0x0080	/* region may contain semaphores */#define MAP_NOPREALLOC	0x0100	/* do not preallocate space */.DEThe cpu-dependent size of a page is returned by the\fIgetpagesize\fP system call:.DSpagesize = getpagesize();result int pagesize;.DE.LPThe call:.DSmaddr = mmap(addr, len, prot, flags, fd, pos);result caddr_t maddr; caddr_t addr; int *len, prot, flags, fd; off_t pos;.DEcauses the pages starting at \fIaddr\fP and continuingfor at most \fIlen\fP bytes to be mapped from the object represented bydescriptor \fIfd\fP, starting at byte offset \fIpos\fP.The starting address of the region is returned;for the convenience of the system,it may differ from that suppliedunless the MAP_FIXED flag is given,in which case the exact address will be used or the call will fail.The actual amount mapped is returned in \fIlen\fP.The \fIaddr\fP, \fIlen\fP, and \fIpos\fP parametersmust all be multiples of the pagesize.A successful \fImmap\fP will delete any previous mappingin the allocated address range.The parameter \fIprot\fP specifies the accessibilityof the mapped pages.The parameter \fIflags\fP specifiesthe type of object to be mapped,mapping options, andwhether modifications made tothis mapped copy of the pageare to be kept \fIprivate\fP, or are to be \fIshared\fP withother references.Possible types include MAP_FILE,mapping a regular file or character-special device memory,and MAP_ANON, which maps memory not associated with any specific file.The file descriptor used for creating MAP_ANON regions is used onlyfor naming, and may be given as \-1 if no nameis associated with the region.\(dd.FS\(dd The current design does not allow a processto specify the location of swap space.In the future we may define an additional mapping type, MAP_SWAP,in which the file descriptor argument specifies a fileor device to which swapping should be done..FEThe MAP_INHERIT flag allows a region to be inherited after an \fIexec\fP.The MAP_HASSEMAPHORE flag allows special handling forregions that may contain semaphores.The MAP_NOPREALLOC flag allows processes to allocate regions whosevirtual address space, if fully allocated,would exceed the available memory plus swap resources.Such regions may get a SIGSEGV signal if they page fault and resourcesare not available to service their request;typically they would free up some resources via \fIunmap\fP so thatwhen they return from the signal the pagefault could be successfully completed..PPA facility is provided to synchronize a mapped region with the fileit maps; the call.DSmsync(addr, len);caddr_t addr; int len;.DEwrites any modified pages back to the filesystem and updatesthe file modification time.If \fIlen\fP is 0, all modified pages within the region containing \fIaddr\fPwill be flushed;if \fIlen\fP is non-zero, only the pages containing \fIaddr\fP and \fIlen\fPsucceeding locations will be examined.Any required synchronization of memory cacheswill also take place at this time.Filesystem operations on a file that is mapped for shared modificationsare unpredictable except after an \fImsync\fP..PPA mapping can be removed by the call.DSmunmap(addr, len);caddr_t addr; int len;.DEThis call deletes the mappings for the specified address range,and causes further references to addresses within the rangeto generate invalid memory references..NH 3Page protection control.PPA process can control the protection of pages using the call.DSmprotect(addr, len, prot);caddr_t addr; int len, prot;.DEThis call changes the specified pages to have protection \fIprot\fP\|.Not all implementations will guarantee protection on a page basis;the granularity of protection changes may be as large as an entire region..NH 3Giving and getting advice.PPA process that has knowledge of its memory behavior mayuse the \fImadvise\fP call:.DSmadvise(addr, len, behav);caddr_t addr; int len, behav;.DE\fIBehav\fP describes expected behavior, as givenin \fI<sys/mman.h>\fP:.DS.ta \w'#define\ \ 'u +\w'MADV_SEQUENTIAL\ \ 'u +\w'00\ \ \ \ 'u#define	MADV_NORMAL	0	/* no further special treatment */#define	MADV_RANDOM	1	/* expect random page references */#define	MADV_SEQUENTIAL	2	/* expect sequential references */#define	MADV_WILLNEED	3	/* will need these pages */#define	MADV_DONTNEED	4	/* don't need these pages */#define	MADV_SPACEAVAIL	5	/* insure that resources are reserved */.DEFinally, a process may obtain information about whether pages arecore resident by using the call.DSmincore(addr, len, vec)caddr_t addr; int len; result char *vec;.DEHere the current core residency of the pages is returnedin the character array \fIvec\fP, with a value of 1 meaningthat the page is in-core..NH 3Synchronization primitives.PPPrimitives are provided for synchronization using semaphores in shared memory.Semaphores must lie within a MAP_SHARED region with at least modesPROT_READ and PROT_WRITE.The MAP_HASSEMAPHORE flag must have been specified when the region was created.To acquire a lock a process calls:.DSvalue = mset(sem, wait)result int value; semaphore *sem; int wait;.DE\fIMset\fP indivisibly tests and sets the semaphore \fIsem\fP.If the the previous value is zero, the process has acquired the lockand \fImset\fP returns true immediately.Otherwise, if the \fIwait\fP flag is zero,failure is returned.If \fIwait\fP is true and the previous value is non-zero,\fImset\fP relinquishes the processor until notified that it should retry..LPTo release a lock a process calls:.DSmclear(sem)semaphore *sem;.DE\fIMclear\fP indivisibly tests and clears the semaphore \fIsem\fP.If the ``WANT'' flag is zero in the previous value,\fImclear\fP returns immediately.If the ``WANT'' flag is non-zero in the previous value,\fImclear\fP arranges for waiting processes to retry before returning..PPTwo routines provide services analogous to the kernel\fIsleep\fP and \fIwakeup\fP functions interpreted in the domain ofshared memory.A process may relinquish the processor by calling \fImsleep\fPwith a set semaphore:.DSmsleep(sem)semaphore *sem;.DEIf the semaphore is still set when it is checked by the kernel,the process will be put in a sleeping stateuntil some other process issues an \fImwakeup\fP for the same semaphorewithin the region using the call:.DSmwakeup(sem)semaphore *sem;.DEAn \fImwakeup\fP may awaken all sleepers on the semaphore,or may awaken only the next sleeper on a queue.

⌨️ 快捷键说明

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