Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does mmap need shm_open?

Tags:

c

linux

I have a situation where I need to perform file IO but I'm sandboxed. So, I'm using shm_open with mmap, to return a file descriptor which I can happily read/write to/from in memory.

The problem I have is that a platform that I am porting to does not have shm_open. Does mmap require arg 5 to be a "file descriptor"? Or is there some other way I can use mmap without shm_open?

Thanks!

like image 586
austintino Avatar asked Dec 06 '25 06:12

austintino


1 Answers

You can use the MAP_ANONYMOUS flag to just map a piece of memory. This is basically the same as calling malloc, and no data you write will be saved as it's all in memory.

like image 139
Some programmer dude Avatar answered Dec 07 '25 19:12

Some programmer dude