Saturday, 15 January 2011

linux - Avoid dumping information in a core file -


I want to avoid dumping some information from my program in a core file in case of any accident.

For this, I can use coredump_filter ()

The man page provides the following details

The file has a little mask of value memory mapping types (See mmap (2)). If a bit is set in the mask, then similar memory mapping is omitted; Otherwise they are not left in the bits of this file the following meanings:

  Dump unnamed anonymous confidential mapping. Bit 1 anonymous shared mapping dump bit 2 dump file-backed private mapping bit3 dump file-supported shared mapping bit 4 (since linux 2.6.24) dump ELF heading bit 5 (since Linux 2.6.28) Private huge Dump pages. Bit 6 (Linux since 2.6.28) Dump shared huge pages.  

I want to know which set and reset will be done in my case. I am not particularly clear from these private and shared areas.

I have buffer (unsigned char *) in memory I do not want to throw it in a core file in case of any accident. Is there any special flag that I want to use for the mmap? Please help. thank you in advanced.

coredump_filter will set the process-global settings only, so it's all you Memory or anyone will not allow dump, basically.

However, there is a flag for madvise , which probably does something close to you: MADV_DONTDUMP . It will flag specific memory pages to appear in the coredump. Your program will need to run madvise itself, though; You can not set it from outside the process (I think using the gdb ).

Note that madvise is only running on the whole page, however. You can not set the flag to "these 193 bytes" or not to flag anything. If you mark the page in your buffer, that same page will be left or not, if this is a problem for you, then I think that instead of you malloc The buffer must have mmap , so that it is single in a page.


No comments:

Post a Comment