3 segattach, segdetach, segfree \- map/unmap a segment in virtual memory
11 void* segattach(int attr, char *class, void *va, ulong len)
14 int segdetach(void *addr)
17 int segfree(void *va, ulong len)
21 creates a new memory segment, adds it
22 to the calling process's address space, and returns its lowest address.
23 Segments belong to system-dependent classes.
30 are available on all systems.
32 Shared segments are inherited by the children of the attaching process
33 and remain untouched across a
37 will release a shared segment if it overlaps the segments
40 otherwise the segment will be inherited.
42 Some machines provide a segment class
44 Lock segments allow access to special lock hardware provided
45 by some multiprocessors, in particular the SGI Power Series machines.
47 Systems may also provide interfaces to special hardware devices like
48 frame buffers through the
51 Device memory mapped by this method is typically uncached by default.
60 specifies the new segment's attributes.
61 The only attributes implemented on all classes of segment is
63 which allows only read access on the segment, and
65 which causes the segment to be detached when the process does an
67 Specific devices may implement
68 attributes to control caching and allocation, but these will vary
74 specify the position of the segment in the process's address space.
76 is rounded down to the nearest page boundary and
79 The system does not permit segments to overlap.
82 is zero, the system will choose a suitable address.
85 removes a segment from a process's address space. Memory used by
88 may be any address within the bounds of the segment.
90 The system will not permit the initial stack segment to be detached
91 from the address space.
94 tells the system that it may free any physical memory within the span
97 but leaves that portion of the process's address space valid.
98 The system will not free any memory outside that span,
99 and may not free all or even any of the specified memory.
100 If free'd memory is later referenced,
101 it will be initialized as appropriate for the segment type.
102 For example data and text segments will be read from the executable file,
103 and bss segments will be filled with zero bytes.
105 The MIPS R2000 and R3000 have no hardware instructions
106 to implement locks. The following method can be used
107 to build them from software.
112 If this succeeds, the machine is an SGI Power Series and
113 the memory contains hardware locks.
114 Each 4096-byte page has 64
116 words at its beginning; each word implements
117 a test-and-set semaphore when read; the low bit of the word
118 is zero on success, one on failure.
121 fails, there is no hardware support but the operating system
125 instruction will be trapped by the kernel and interpreted
133 is greater or equal zero on success, negative on failure.
134 The following assembly language implements such a test-and-set.
137 .ta 8n +8n +8n +8n +8n +8n +8n
142 MOVW R1, sema+0(FP) /* save arg on stack */
146 NOR R0, R0, R0 /* NOP */
147 WORD $(023<<26) /* MFC3 R0, R0 */
152 .B /sys/src/libc/9syscall
167 There is a small fixed limit on the number of segments that may be attached,
168 as well as a maximum segment size.