简体   繁体   English

C IPC:撤销对共享 memory 的访问,类似于 Microsoft/Apple 剪贴板

[英]C IPC: Revoke access to shared memory, similar to Microsoft/Apple Clipboard

As I understand it, the way you interact with the clipboard in Windows(And MacOS too, I think) is similar to:据我了解,您在 Windows(我认为也是 MacOS)中与剪贴板交互的方式类似于:

  1. Open the clipboard (Requesting access)打开剪贴板(请求访问)
  2. Clear the clipboard清除剪贴板
  3. Allocate new Global Memory, and get a pointer to that memory分配新的全局 Memory,并获得指向该 memory 的指针
  4. Fill the memory填写memory
  5. Release the memory handle松开 memory 手柄
  6. Indicate to the system that the clipboard is ready.向系统指示剪贴板已准备就绪。

Those final steps are what I am concerned with- Reading up on shared memory APIs, I see no way for a provider of shared memory to enforce/verify that someone it has shared the memory with has in fact released it.这些最后的步骤是我所关心的——阅读共享的 memory API,我认为共享 memory 的提供者无法强制/验证共享 ZCD69B4957F06CD818D7BF3D61980E2 的人实际上已经发布了它。 Without such a guarantee, the "Copier" could manipulate the data freely even when it was supposed to be "Done", without the knowledge of the clipboard owner.如果没有这样的保证,“复印机”可以在剪贴板所有者不知情的情况下自由操作数据,即使它应该是“完成”的。

Can someone help me find how one process can create shared memory (Similar to shm_open()), share that memory, and then know when the client they shared to has completely released that memory (Or force revoke it- either works)?有人可以帮我找到一个进程如何创建共享的 memory(类似于 shm_open()),共享该 memory,然后知道他们共享的客户端何时完全发布了 ZCD69B4957F06CD818D7BF3D61 工作?

Alternatively, am I either having a key misunderstanding in how these clipboards work, or are these OS taking further special OS level action that a normal program can not replicate?或者,我是否对这些剪贴板的工作方式存在重大误解,或者这些操作系统是否采取了普通程序无法复制的进一步特殊操作系统级别的操作?

I may have found the answer, please let me know this makes sense here, I won't be able to try it for a couple of days:我可能已经找到了答案,请让我知道这是有道理的,我将无法尝试几天:

In the man page for fcntl it mentions the following behavior: EBUSY cmd is F_ADD_SEALS, arg includes F_SEAL_WRITE, and there exists a writable, shared mapping on the file referred to by fdfcntl的手册页中,它提到了以下行为: EBUSY cmd is F_ADD_SEALS, arg includes F_SEAL_WRITE, and there exists a writable, shared mapping on the file referred to by fd

So you could create a block of shared memory, pass it to a trusted arbiter, and not trust that block until you successfully apply F_SEAL_WRITE (Thus knowing the client has released all open writable mappings, and is unable to create any more)因此,您可以创建一个共享 memory 块,将其传递给受信任的仲裁器,并且在成功应用 F_SEAL_WRITE 之前不信任该块(因此知道客户端已释放所有开放的可写映射,并且无法再创建)

I was looking for this for most of this week, but found the answer almost right after posting to stackoverflow.这周的大部分时间我都在寻找这个,但几乎在发布到 stackoverflow 后就找到了答案。 If I got this right, sorry for the trouble but hopefully it helps people in the future!如果我做对了,很抱歉给您带来麻烦,但希望它对未来的人们有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM