mprotect

Using mprotect to make text segment writable on macOS

我怕爱的太早我们不能终老 提交于 2020-07-01 17:53:11
问题 This is essentially what I'm trying to do, #include <sys/mman.h> int zero() { return 0; } int main(int argc, const char *argv[]) { return mprotect((void *) &zero, 4096, PROT_READ | PROT_WRITE); } so I'm trying to make code writable, essentially. This doesn't work on the current macOS (Catalina 10.15.2), it just returns -1 and sets errno to EACCES , which as far as I know is because of lack of entitlement/code signing. I've found the entitlement I need to set, but I have no idea how to go

iPhone application crashes with Mprotect failed error (MonoTouch)

Deadly 提交于 2020-01-09 08:02:31
问题 I have a problem with my iPhone application developed with MonoTouch. I am developing an application that contacts a WCF Service, and when the WCF Service answer back, I update an UITableView with the returned data, when this is done it sends a new WCF async call, and when it answer back it updates the table again and so on. The problem is that when it has done this in a variable amount of time, it crashes with an Mprotect failed error 12. This only happens when the application is running

Explanation of MProtect Errno 12 (ENOMEM)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-30 11:29:50
问题 I'm writing an iPhone application using Monotouch and recently the app has started crashing stating Mprotect failed at 0x863a000 (length 8192) with errno 12 followed by a rather lengthly stack trace and Springboard informing that "the application exited abormally with signal 6". I've read this question which states that the app has exhaused all the memory available on the iPhone. We have applied some general Dispose patterns to the app and generally disposed of any heavy objects as soon as we

C SIGSEGV Handler & Mprotect

戏子无情 提交于 2019-12-18 05:09:12
问题 I'm constructing a program which uses mprotect() to restrict a block of memory from accessing. When the memory is requested, a SIGSEGV is thrown which I listen for using a signal() call. Once the SIGSEGV has been detected, I need to somehow access the pointer to the memory that was requested (that threw the fault) and the size of the segment requested. Is this possible? void fifoSigHandler(){ // Needs to only remove protection from requested block of virtual memory mprotect(fifoVm,(size_t

Is there a better way than parsing /proc/self/maps to figure out memory protection?

坚强是说给别人听的谎言 提交于 2019-12-17 09:34:20
问题 On Linux (or Solaris) is there a better way than hand parsing /proc/self/maps repeatedly to figure out whether or not you can read, write or execute whatever is stored at one or more addresses in memory? For instance, in Windows you have VirtualQuery . In Linux, I can mprotect to change those values, but I can't read them back. Furthermore, is there any way to know when those permissions change (e.g. when someone uses mmap on a file behind my back) other than doing something terribly invasive

Loading MachineCode From File Into Memory and Executing in C — mprotect Failing

强颜欢笑 提交于 2019-12-13 11:49:37
问题 Hi I'm trying to load raw machine code into memory and run it from within a C program, right now when the program executes it breaks when trying to run mprotect on the memory to make it executable. I'm also not entirely sure that if the memory does get set right it will execute. I am currently running this on Ubuntu Linux x86 (Maybe the problem is Ubuntu's over-protection?) What I currently have is the following: #include <memory.h> #include <sys/mman.h> #include <stdio.h> int main ( int argc

Does mprotect flush the instruction cache on ARM Linux?

£可爱£侵袭症+ 提交于 2019-12-12 11:02:01
问题 I am writing a JIT on ARM Linux that executes an instruction set that contains self-modifying code. The instruction set does not have any cache flush instructions (similar to x86 in that respect). If I write out some code to a page and then call mprotect on that page, is that sufficient to invalidate the instruction cache? Or do I also need to use the cacheflush syscall on those pages? 回答1: You'd expect that the mmap/mprotect syscalls would establish mappings that are updated immediately, and

mprotect always returns invalid arguments

此生再无相见时 提交于 2019-12-12 10:21:45
问题 I'm trying to modify a value in the .text segment using protect to give me writing access: int pageSize = sysconf(_SC_PAGE_SIZE); int *toModify = (int *)(foo+5); if (mprotect(toModify, pageSize, PROT_WRITE) < 0 ) { perror("mprotect failed with error:"); return -1; } *toModify = 5; printf("Modify :%i",foo()); mprotect does never work. It always returns an mprotect failed with error:: Invalid argument error. foo is a method that returns an int that is stored 5bytes after the function(thats the

Detouring and using a _thiscall as a hook (GCC calling convention)

丶灬走出姿态 提交于 2019-12-08 04:57:07
问题 I've recently been working on detouring functions (only in Linux) and so far I've had great success. I was developing my own detouring class until I found this. I modernized the code a bit and converted it to C++ (as a class of course). That code is just like any other detour implementation, it replaces the original function address with a JMP to my own specified 'hook' function. It also creates a 'trampoline' for the original function. Everything works flawlessly but I'd like to do one

Can I write-protect every page in the address space of a Linux process?

烂漫一生 提交于 2019-12-03 20:17:55
问题 I'm wondering if there's a way to write-protect every page in a Linux process' address space (from inside of the process itself, by way of mprotect() ). By "every page", I really mean every page of the process's address space that might be written to by an ordinary program running in user mode -- so, the program text, the constants, the globals, and the heap -- but I would be happy with just constants, globals, and heap. I don't want to write-protect the stack -- that seems like a bad idea.