一个进程可以覆盖另一个进程的内存吗?
我的项目由 3 个流程组成。进程 1 是进程 2 和 3 的“服务器”,并实现共享内存。进程 2 因应用程序错误而随机崩溃,试图访问它自己的内存,但该内存已以某种方式损坏。
错误是: 内存位置某些地址的指令无效,某些地址不好。
我应该从哪里开始查找以及在进程 1 中查找什么类型的内容,以查看它是否覆盖了进程 2 的内存?
谢谢。
My project is composed of 3 processes. Process 1 is a "server" of process 2 and 3 and implements shared memory. Process 2 randomly crashes with application errors, trying to access it's own memory, that has been corrupted somehow.
Error is:
Invalid instruction at some address at memory location some not good address.
Where would I start looking and what type of things would I look for in process 1, to see if it is overwriting process 2's memory?
Thank You.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不小心覆盖了另一个进程的内存(没有它的配合)?不*,因为你必须“偶然”正确地做很多事情。 (您必须“意外地”打开进程的句柄,并且还“意外地”调用
WriteProcessMemory
。)故意的吗?是的,使用
WriteProcessMemory
函数。* 如果您共享内存,出现错误的可能性就会急剧上升。
Accidentally overwrite the memory of another process (without its cooperation)? No*, because you have to "accidentally" do a lot of things correctly. (You have to "accidentally" open a handle to the process, and also "accidentally" call
WriteProcessMemory
.)Intentionally? Yes, using the
WriteProcessMemory
function.* If you're sharing memory, the likelihood of an error skyrockets.
操作系统将阻止一个进程覆盖另一个进程的内存,除非您作为内核的一部分运行。使用 valgrind 等内存调试器来追踪任何内存访问错误的原因。
编辑:您还可以包括使用操作系统调用来访问另一个进程的内存的可能性,但正如每个人所说,您很可能没有这样做。在共享内存中传递指针是这里最有可能的错误,但我仍然建议使用像 valgrind 这样的工具。
The OS will prevent a process from overwriting another process's memory, unless you are running as part of the kernel. Use a memory debugger like valgrind to track down the cause of any memory access errors.
Edit: you can also include the possibility of using OS calls to access another process's memory, but as everyone has said, you most likely aren't doing that. Passing pointers in the shared memory is the most likely error here, but I still suggest using a tool like valgrind.
一个进程只有主动尝试才能覆盖另一个进程的内存。调试是一个例子,共享内存是另一个例子。意外写入另一个进程的代码或数据区域的可能性很小。
所以问题很可能是进程 2 中的一个错误。我的意思是,进程 2 甚至没有共享其内存,对吧?所以进程1不可能覆盖它。
A process can only overwrite another process' memory if it actively tries to. Debugging is one example, shared memory is another. Accidental writing to either code or data area of another process is very unlikely.
So the problem is, most likely, a bug withing process 2. I mean, process 2 is not even sharing its memory, right? So process 1 cannot possibly overwrite it.
共享内存中的数据结构是否包含绝对指针?这不仅是一个坏主意,因为绝对指针在其他进程中没有意义,而且一个进程可能会说服另一个进程疯狂地写入其内存。
一般来说,内存管理单元防止任何进程直接覆盖/损坏另一个进程的内存。共享内存(包括文件映射)和 WriteProcessMemory 函数是一般规则的例外。
Do the data structures in the shared memory include any absolute pointers? Not only is this a bad idea, because absolute pointers aren't meaningful in other processes, but one process could convince the other process to write wildly through its memory.
In general, the memory management unit prevents any process from directly overwriting/corrupting another process's memory. Shared memory (including file mappings) and the
WriteProcessMemory
function are exceptions to the general rule.