/usr/include/tclutil/Mem_Map.h is in skycat 3.1.2+starlink1~b-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | // -*-c++-*-
#ifndef MEM_MAP_H
#define MEM_MAP_H
/*
* E.S.O. - VLT project
* $Id: Mem_Map.h,v 1.1.1.1 2009/03/31 14:11:52 cguirao Exp $
*
* Mem_Map.h - utility class wrapper for mmap(2), Author: Doug Schmidt
* (ripped from ACE C++ library for use in OCS by K. Gillies,
* "...Doug says it's okay...."
*
* who when what
* -------------- -------- ----------------------------------------
* Allan Brighton 02 Aug 96 Created, added status() method, removed TRACE
* 06 Aug 96 Changed ssize_t to int, since it is not defined on sunos
* define MAP_FAILED to (void*)-1, not def on HP,sunos
* 03 Dec 96 Added filename() method to return filename mapped.
* Reformatted .h file and put comments above declarations
* for readability.
* Peter W. Draper 27 Sep 05 All lengths are now size_t, which usually means
* an unsigned long, consequently all use of
* -1 as a special length has been changed to 0.
*/
#include <sys/types.h>
#include <sys/param.h>
// the wrapper is needed on some HPs
extern "C" {
#include <sys/mman.h>
}
#include <fcntl.h>
/* allan: 6.8.96: add defs missing on HP and/or sunos */
#ifndef MAP_FAILED
#define MAP_FAILED NULL
#endif
#ifndef MS_SYNC
#define MS_SYNC 0
#endif
/*
#ifdef NEED_MMAP_PROTO
extern "C" {
extern caddr_t mmap(caddr_t, size_t, int, int, int, off_t);
extern int munmap(caddr_t, size_t);
}
#endif
*/
// MMAP additional flags
#define PROT_RDWR (PROT_READ|PROT_WRITE)
// Default file permissions.
#define MMAP_DEFAULT_PERMS 0666
#define MMAP_INVALID_HANDLE 0
// Default size of mapped page on SunOS, HP and Solaris.
#define MMAP_PAGE_SIZE 4096
// MAXPATHLEN not defined on Hurd, as it is "bogus."
#ifndef MAXPATHLEN
#define MAXPATHLEN 4096
#endif
// External used to round request.
size_t
round_to_pagesize (off_t len);
// C++ interface to the mmap(2) UNIX system call.
class Mem_Map {
public:
// Default constructor.
Mem_Map (void);
// Map a file from an open file descriptor <handle>. This function
// will lookup the length of the file if it is not given.
Mem_Map (int handle,
size_t length = 0,
int prot = PROT_READ,
int share = MAP_SHARED,
void *addr = 0,
off_t pos = 0);
// Map a file specified by <file_name>.
Mem_Map (const char file_name[],
size_t len = 0,
int flags = O_RDWR,
int mode = MMAP_DEFAULT_PERMS,
int prot = PROT_READ,
int share = MAP_SHARED,
void *addr = 0,
off_t pos = 0);
// Map a file from an open file descriptor <handle>. This function
// will lookup the length of the file if it is not given.
int map (int handle,
size_t length = 0,
int prot = PROT_READ,
int share = MAP_SHARED,
void *addr = 0,
off_t pos = 0);
// Remap the file associated with <handle_>.
int map (size_t length = 0,
int prot = PROT_READ,
int share = MAP_SHARED,
void *addr = 0,
off_t pos = 0);
// Map a file specified by <file_name>.
int map (const char file_name[],
size_t len = 0,
int flags = O_RDWR,
int mode = MMAP_DEFAULT_PERMS,
int prot = PROT_READ,
int share = MAP_SHARED,
void *addr = 0,
off_t pos = 0);
// Destructor.
~Mem_Map (void);
const char* filename() {return filename_;}
// Open the file without mapping it.
int open (const char file_name[],
int flags = O_RDWR,
int mode = MMAP_DEFAULT_PERMS);
// Close down the <handle_> if necessary.
int close (void);
// This operator passes back the starting address of the mapped file.
int operator () (void *&addr);
// Return the base address.
void *addr (void) const;
// This function returns the number of bytes currently mapped in the
// file.
size_t size (void) const;
// Unmap the region starting at <base_addr_>.
int unmap (size_t len = 0);
// Unmap the region starting at <addr_>.
int unmap (void *addr, size_t len);
// Sync <len> bytes of the memory region to the backing store
// starting at <base_addr_>. If <len> == 0 then sync the whole
// region.
int sync (size_t len = 0, int flags = MS_SYNC);
// Sync <len> bytes of the memory region to the backing store
// starting at <addr_>.
int sync (void *addr, size_t len, int flags = MS_SYNC);
// Change the protection of the pages of the mapped region to <prot>
// starting at <base_addr_> up to <len> bytes. If <len> == 0 then
// change protection of all pages in the mapped region.
int protect (size_t len = 0, int prot = PROT_READ);
// Change the protection of the pages of the mapped region to <prot>
// starting at <addr> up to <len> bytes.
int protect (void *addr, size_t len, int prot = PROT_READ);
// Close down and remove the file from the file system.
int remove (void);
#if 0
// Hook into the underlying VM system.
int advise (int behavior, size_t len = 0);
#endif
// Return the underlying <handle_>.
int handle (void) const;
// Dump the state of an object.
void dump (void) const;
// Return the status after the constructor
int status() {return status_;}
private:
// Base address of the memory-mapped file.
void *base_addr_;
// Name of the file that is mapped.
char filename_[MAXPATHLEN + 1];
// Length of the mapping.
size_t length_;
// HANDLE for the open file.
int handle_;
// status after constructor (allan)
int status_;
// Keeps track of whether we need to close the handle. This is set
// if we opened the file.
int close_handle_;
// This method does the dirty work of actually calling ::mmap to map
// the file into memory.
int map_it (int handle,
size_t len = 0,
int prot = PROT_READ,
int share = MAP_SHARED,
void *addr = 0,
off_t pos = 0);
Mem_Map (const Mem_Map &) {}
void operator = (const Mem_Map &) {}
};
// inlines
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
inline int
Mem_Map::handle (void) const
{
return this->handle_;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
inline int
Mem_Map::map (int handle,
size_t len,
int prot,
int share,
void *addr,
off_t pos)
{
return this->map_it (handle, len, prot, share, addr, pos);
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Remap the file associated with <this->handle_>.
inline int
Mem_Map::map (size_t len,
int prot,
int share,
void *addr,
off_t pos)
{
return this->map_it (this->handle(), len, prot,
share, addr, pos);
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// This operator passes back the starting address of the mapped file.
inline int
Mem_Map::operator () (void *&addr)
{
if (this->base_addr_ == (void*)MAP_FAILED) { /* allan: not defined on HP */
return -1;
} else {
addr = this->base_addr_;
return 0;
}
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Return the base address.
inline void *
Mem_Map::addr (void) const
{
return this->base_addr_;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// This function returns the number of bytes currently mapped in the
// file.
inline size_t
Mem_Map::size (void) const
{
return this->length_;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Unmap the region starting at <this->base_addr_>.
inline int
Mem_Map::unmap (size_t len)
{
return ::munmap ((caddr_t)this->base_addr_, len == 0 ? this->length_ : len);
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Unmap the region starting at <addr_>.
inline int
Mem_Map::unmap (void *addr, size_t len)
{
return ::munmap ((caddr_t)addr, len == 0 ? this->length_ : len);
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Sync <len> bytes of the memory region to the backing store starting
// at <this->base_addr_>. If <len> == 0 then sync the whole mapped
// region.
inline int
Mem_Map::sync (size_t len, int flags)
{
return ::msync ((caddr_t)this->base_addr_,
len == 0 ? this->length_ : len, flags);
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Sync <len> bytes of the memory region to the backing store starting
// at <addr_>.
inline int
Mem_Map::sync (void *addr, size_t len, int flags)
{
return ::msync((caddr_t)addr, len, flags);
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Change the protection of the pages of the mapped region to <prot>
// starting at <this->base_addr_> up to <len> bytes. If <len> == 0
// then change protection of all pages in the mapped region.
inline int
Mem_Map::protect (size_t len, int prot)
{
if (len == 0) {
len = this->length_;
}
return ::mprotect((caddr_t)this->base_addr_, len, prot);
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Change the protection of the pages of the mapped region to <prot>
// starting at <addr> up to <len> bytes.
inline int
Mem_Map::protect(void *addr, size_t len, int prot)
{
return ::mprotect((caddr_t)addr, len, prot);
}
#if 0
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Hook into the underlying VM system.
inline int
Mem_Map::advise (int behavior, size_t len)
{
if (len == 0) {
len = this->length_;
}
return ::madvise ((caddr_t)this->base_addr_, len, behavior);
}
#endif
#endif /* ACE_MEM_MAP_H */
|