ATLAS Offline Software
Loading...
Searching...
No Matches
page_access.h
Go to the documentation of this file.
1// dear emacs, this is -*- C++ -*-
2
3/*
4 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef CXXUTILS_PAGEADDRESS_H
8#define CXXUTILS_PAGEADDRESS_H 1
9#include <cstdio>
10#include <sys/mman.h> /* mprotect */
11#define DEBUG 1
12namespace athena {
13 const void* page_address(const void* addr);
14 void* page_address(void* addr);
15 void* next_page_address(void* addr);
16 int page_protect(void* addr, int prot);
19template <typename T>
20size_t page_protect(T* addr, int prot) {
21 void* pageAddr(page_address((void*)addr));
22 size_t lProtected((long)addr-(long)pageAddr+sizeof(T));
23 int rc=mprotect(pageAddr, lProtected, prot);
24 if (rc) printf("page_protect WARNING: mprotect heap failed for address %p\n", (void*)addr);
25#ifdef DEBUG
26 else printf("page_protect DEBUG: set protection @%i for range @%lx - @%zx containing addr=%p\n",
27 prot,(long unsigned int)page_address(addr),(long unsigned int)addr+sizeof(T), (void*)addr);
28#endif
29 return (rc == 0 ? lProtected : 0);
30}
31}
32#endif
static Double_t rc
const void * page_address(const void *addr)
void * next_page_address(void *addr)
int page_protect(void *addr, int prot)