mmap a file without an overwrite risk?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Attached are 2 c files with main.c having reproduce instructions

I noticed if I try to read a large file it's a bit slow and mallocing/mmap a large amount of memory waits hundreds of milliseconds from the OS. However mmap is incredibly fast but leaves my software open to memory corruption. I attached a reproducable

I tried various MAP flags and couldn't think of a way to get rid of the risk. The gist of the problem is if I mmap a file another process can overwrite data which appears in mine, or delete the file causing my code to have a bus error. Not shown in the code is me trying to write to every page in hopes it'd prevent my memory from being overwritten, it didn't work either.

If there's nothing I can do is there an alternative way to load a file quicker than malloc+read? Files can be >100MB or GBs in size

Attachment: main.c
Description: Binary data

Attachment: app2.c
Description: Binary data


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux