c++ - Enabling mprotect does not return to normal state? -


i trying create program track memory of process.. have @ point trying protect memory using protect function:

static void protect(void* ptr, size_t size) { memorymgr& mgr = memorymgr::instance(); assert(!(size%s_pagealign)); assert(ptr == (void*)((unsigned long long)(ptr)&0xfffffffffffff000));  printf("protecting: 0x%x - 0x%x\n" ,(unsigned long long)(ptr), (unsigned long long)(ptr) + size); assert(mgr.m_protected.insert(memorymgr::protected_t::value_type(ptr, size)).second); int r = mprotect(ptr, size, prot_read); if (r) {     perror("mprotect");     cout << "error: " << r << endl;     cout.flush();     exit(1); } s_alloccnt += size / s_pagealign + ((size%s_pagealign)? 1 : 0); 

}

and have regisered interuupt handler does:

static void handler(int sig, siginfo_t *si, void *unused) {     memorymgr::onsegfault(si ->si_addr, sig); }  int memorymgr::onsegfault(void* addr, int serious) {     memorymgr& mgr = instance();     protected_t::iterator ptr = std::find_if(begin(mgr.m_protected), end(mgr.m_protected), [addr](protected_t::value_type& ptr) -> bool {         return ((ptr.first <= addr) && (addr < (ptr.first + ptr.second)));     });     if (ptr == mgr.m_protected.end()) {         cout << "ignoring segfault @ addr: " << (unsigned long long)(addr) << endl;         mprotect((void*)((unsigned long long)(addr)&0xfffffffffffff000), s_pagealign, prot_read | prot_write);         s_ignoredpagefaults++;         return 1;     }     printf("segaulting @ ptr : 0x%x - 0x%x\n", (unsigned long long)(ptr ->first), (unsigned long long)(ptr ->first) + ptr ->second);     s_segfaultcnt += ptr ->second/s_pagealign + ((ptr ->second%s_pagealign)? 1 : 0);     int r = mprotect(ptr ->first, ptr ->second, prot_read | prot_write);     if (r) {         cout << "mprotect failed" << endl;         cout.flush();         return 0;     }     return 1; } 

the process seems stuck @ fwrite... can see in logs memory process trying access has long gone segaulted , returned normal state.. can see process not halt on first memory read block after quite lot of pages... have idea/clue ?

thanks.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -