flat assembler
Message board for the users of flat assembler.
Index
> Linux > How to shm_open everything? |
Author |
|
ProphetOfDoom 04 Oct 2017, 16:52
Note: when I said "entire address space" I really meant all the pages that are in use.
|
|||
04 Oct 2017, 16:52 |
|
ProphetOfDoom 04 Oct 2017, 23:56
It just occurred to me that I could just set rbp and rsp to point to some already existing block of shared memory, then carry on and hope that the OS/kernel doesn't notice and get upset. The drawbacks of this I see are 1) would the OS let me place the new stack in a relatively high region of memory? and 2) would my new "stack" automatically grow downwards or would I have to allocate crazy amounts of memory "just in case"? and 3) I'm no further forward with the heap - and I'm not thrilled at the idea of writing my own malloc/free.
|
|||
04 Oct 2017, 23:56 |
|
fasmnewbie 05 Oct 2017, 01:00
|
|||
05 Oct 2017, 01:00 |
|
ProphetOfDoom 05 Oct 2017, 02:39
Hi fasmnewbie,
Thanks for your reply. I read the entire page with great interest but unfortunately I don't think it's what I'm looking for. I want to share already existing memory (heap and stack) with another process. mmap creates new memory. I'm familiar with mmap... In fact I'm using it in my debugger/debuggee for sharing source code (probably frowned upon I know but I didn't want to get bogged down in all that ELF/DWARF nonsense). I got excited when I read about the amalloc/acreate functions on that page, because they seemed really useful when combined with my "new stack" idea, but it seems like those functions are not available on Linux or MacOS. Here's where I am at the moment: I've got a simple debugger working that forks a process, notices a division by zero or a breakpoint and prints a simple backtrace. Now I want to examine local variables and follow pointers around in the traced process. I can send the local variables to the debugger using a pipe, but when you consider that these locals might be pointing to heap objects, which in turn might point to other heap objects (to arbitrary depths) the whole operation becomes ridiculously inefficient. If it was just Linux I could probably examine the memory whilst the process was stopped, but MacOS lacks both a working ptrace and a /proc filesystem. Any more thoughts? |
|||
05 Oct 2017, 02:39 |
|
revolution 05 Oct 2017, 03:46
ProphetOfDoom wrote: It just occurred to me that I could just set rbp and rsp to point to some already existing block of shared memory, then carry on and hope that the OS/kernel doesn't notice and get upset. The drawbacks of this I see are 1) would the OS let me place the new stack in a relatively high region of memory? and 2) would my new "stack" automatically grow downwards or would I have to allocate crazy amounts of memory "just in case"? and 3) I'm no further forward with the heap - and I'm not thrilled at the idea of writing my own malloc/free. Most OSes only allow one stack region per thread, I expect Linux is the same in this regard also. |
|||
05 Oct 2017, 03:46 |
|
ProphetOfDoom 05 Oct 2017, 03:58
Thanks revolution. Interesting to know. If annoying.
|
|||
05 Oct 2017, 03:58 |
|
ProphetOfDoom 05 Oct 2017, 05:36
Okay so it might be the end for my crazy workarounds to please MacOS and make it accept code written for Linux.
After Googling and stressing all night, I finally managed to get the mach kernel system call task_for_pid() working, which suggests that I may be able to read and write memory with some other mach functions. So I'll just do an #if #elif #endif and insert OS-specific code. No more mad memory gymnastics. The solution in the end was quite simple: I needed to create a self-signed certificate for development, then sign my debugger with the certificate, then run it using sudo. I am very relieved. I'll post here if I run into any more issues.Now I'm going to bed. |
|||
05 Oct 2017, 05:36 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.