Low-level shared memory on iOS

时光总嘲笑我的痴心妄想 提交于 2019-12-19 10:21:57

问题


I'm trying to construct a block of shared memory on iOS. It compiles and links, but shmget() throws a SIGSYS signal on the most innocent parameters:

NSString *p = [[NSBundle mainBundle] pathForResource:@"crash" ofType: nil];
key_t tok = ftok([p UTF8String], 918273);
int mid = shmget(tok, 4096, IPC_CREAT|S_IRUSR|S_IWUSR);

tok is a large positive integer, not -1. Size - tried 1024, same effect.

Is SysV shared memory even supported on iOS? The headers and the libraries are present, or compiler/linker would complain. Same code works on the simulator. What am I doing wrong?

My interest stems from this question.


回答1:


The shm_open()/mmap() combo works as advertised, both on simulator and on device (tested on iOS 4) without any explicit permission changes.

Note: shm_open() is weirdly documented as variadic. In reality, you need to specify a third parameter with an access mask - a combination of S_IRUSR-like flags, or an octal chmod value.

EDIT: looks like it broke in iOS 7. shm_open returns -1 with errno=2 (ENOENT) even though O_CREAT flag is specified.




回答2:


On iOS you cannot use shared memory at all I don't know the exact details but I do know that a) its for security and b) its part of the sandboxing environment

So I know above from myself and my presence in the jailbreak scene however here are a few links describing sandboxing and how they affect shared memory

http://www.trailofbits.com/resources/ios4_security_evaluation_paper.pdf

http://lists.apple.com/archives/cocoa-dev/2012/Apr/msg00535.html



来源:https://stackoverflow.com/questions/11589105/low-level-shared-memory-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!