|
1221 | 1221 | mapped as well will see the memory writes immediately. |
1222 | 1222 | \item memory mapping and setting access rights is used by the Electric Fence |
1223 | 1223 | library which is used for error detection on dynamic memory use. |
| 1224 | +\item There is also \texttt{madvise} system call that allows the process |
| 1225 | +to give the kernel some hints in how it is going to access the (mapped) memory |
| 1226 | +in given address range. E.g. the \texttt{MADV\_SEQUENTIAL} advice implies |
| 1227 | +the pages should be read-ahead and then freed once they are accessed. |
1224 | 1228 | \end{itemize} |
1225 | 1229 |
|
1226 | 1230 | %%%%% |
|
1241 | 1245 | while(p1 < p2) \{ |
1242 | 1246 | c = *p1; *p1++ = *p2; *p2-- = c; |
1243 | 1247 | \} |
1244 | | - \emprg{munmap}(addr, fsz); |
| 1248 | + \emprg{munmap}(addr, fsz); |
1245 | 1249 | \emprg{close}(fd); |
1246 | 1250 | return (0); |
1247 | 1251 | \} |
|
1252 | 1256 | \item This program will reverse the bytes in a file. |
1253 | 1257 | \item One of the advantages of shared memory segments is that it is possible |
1254 | 1258 | to work with the data using pointer arithmetic. Generally it is necessary |
1255 | | -to watch out for alignment when dereferencing a pointer, e.g. on SPARC |
| 1259 | +to watch out for alignment when dereferencing a pointer, e.g. on SPARC |
1256 | 1260 | unaligned access will cause the \texttt{SIGBUS} signal, see example |
1257 | 1261 | \example{mmap/aligned.c}. |
1258 | 1262 | \end{itemize} |
|
1265 | 1269 |
|
1266 | 1270 | \begin{slide} |
1267 | 1271 | \sltitle{Accessing dynamic link libraries} |
1268 | | -\texttt{void *\funnm{dlopen}(const char *\emph{path}, int \emph{mode});} |
| 1272 | +\texttt{void *\funnm{dlopen}(const char *\emph{path}, int \emph{mode});} |
1269 | 1273 | \begin{itemize} |
1270 | 1274 | \item loads \emph{path} unless already loaded, returns |
1271 | 1275 | a \emsl{handle} or \texttt{NULL} |
|
0 commit comments