2
votes

I'm planning on using the CreateFileMapping() function with INVALID_HANDLE_VALUE for hFile so that the storage is backed by the paging file. There could be several processes that are creating these mapped objects. I also need to run another process which can just read from these mapped objects. Is there a way for this process to programmatically fetch a list of memory mapped objects ? Even if it were a system command that the process could run and then parse to figure out the list of handles, it would work.

I have seen a few questions similar to this on stack overflow, but could not find a concrete answer. Any insights appreciated.

1
No, it is your responsibility to co-ordinate the names for the file mappings so that the reading process knows what names to use. (One possible approach would be a master file mapping with a known name, containing the names of all the other mappings.) - Harry Johnston

1 Answers

2
votes

While it is technically possible to get the list of handles in a process and then try to figure out which handles are memory mapped files, you quickly end up having to call undocumented functions and you also have to deal with the named pipe hang issue.

I would recommend that you take a different approach:

  • Give the mappings a name so you can open them by name. This might require a mapping with a known name that just contains a list of the other names.

  • Use handle inheritance or DuplicateObject to get the handles into the other process. Use a named pipe or window messages to send the handle value of the duplicated handle to the other process.

  • Just use normal files. FILE_ATTRIBUTE_TEMPORARY and FILE_FLAG_DELETE_ON_CLOSE might help.