I want to create a dump in windows with the function MiniDumpWriteDump
. The problem is that that function takes a Handle to a file to write the result to. I want the data in memory so that I can send it over the internet. Therefore, I was wondering if there is a way to create a handle without a file backing it and I can just get a pointer to the data?
我想在Windows中使用MiniDumpWriteDump函数创建转储。问题是该函数将Handle传递给文件以将结果写入。我想要内存中的数据,以便我可以通过互联网发送它。因此,我想知道是否有一种方法来创建一个没有文件支持它的句柄,我可以得到一个指向数据的指针?
5 个解决方案
#1
3
You can use memory mapped files. See here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366537(v=vs.85).aspx
您可以使用内存映射文件。请看:http://msdn.microsoft.com/en-us/library/windows/desktop/aa366537(v = vs.85).aspx
You need to pass hFile = INVALID_HANDLE_VALUE and specify maximal size of file. Please, check msdn for the details.
您需要传递hFile = INVALID_HANDLE_VALUE并指定文件的最大大小。请检查msdn以获取详细信息。
#2
2
There are a couple of possibilities.
有几种可能性。
One would be to use CreateFile
, but pass FILE_ATTRIBUTE_TEMPORARY
. This will create a file, but tells Windows to attempt to keep as much of the file in the cache as possible. While this doesn't completely avoid creating a file, if you have enough memory it can often eliminate any (or much, anyway) I/O to/from the disk from happening.
一种是使用CreateFile,但是传递FILE_ATTRIBUTE_TEMPORARY。这将创建一个文件,但告诉Windows尝试尽可能多地保留缓存中的文件。虽然这并不能完全避免创建文件,但如果你有足够的内存,它通常可以消除发生进出磁盘的任何(或多次)I / O.
Another possibility (though one I've never tested) would be to pass a handle to a named (or maybe even an anonymous) pipe. You can generally write to a pipe like you would a file, so as long as the crash dump writer just needs to be able to pass the handle to WriteFile
, chances are pretty good this will work fine. From there, you could (for example) have another small program that would read the data from the pipe and write it to a socket. Obviously it would be nice to be able to avoid the extra processing to translate from pipe to socket, but such is life some times.
另一种可能性(虽然我从未测试过)可能是将句柄传递给命名(或者甚至是匿名)管道。你通常可以写一个像文件一样的管道,所以只要崩溃转储编写器只需要能够将句柄传递给WriteFile,很可能这样做会很好。从那里,你可以(例如)有另一个小程序,它将从管道中读取数据并将其写入套接字。显然,能够避免从管道转换为套接字的额外处理会很好,但这种生活有时候也是如此。
If you haven't tried it, you might want to test with just passing a socket handle to the crash dump writer. Although it's somewhat limited, Windows does support treating a socket handle like a normal file (or whatever) handle. There's certainly nothing close to a guarantee that it'll work, but it may be worth a shot anyway.
如果您还没有尝试过,可能只想将套接字句柄传递给崩溃转储编写器进行测试。虽然它有些限制,但Windows确实支持将套接字句柄视为普通文件(或其他)句柄。肯定没有什么能保证它能够正常工作,但无论如何它都值得一试。
#3
0
The crash dump is indeed process's memory. So, it doesn't make sense. Why don't you simply send the file and delete after successful send?
崩溃转储确实是进程的内存。所以,它没有意义。你为什么不简单地发送文件并在成功发送后删除?
By the way, you can compress the file and send it, because crashdumps are usually big files.
顺便说一下,你可以压缩文件并发送它,因为crashdumps通常是大文件。
#4
0
The documentation says to pass a file handle, so if you do anything else you're breaking the contract and (if it works at all) the behaviour will not be reliable.
文档说要传递一个文件句柄,所以如果你做了其他任何事情你就违反了合同(如果它完全有效),那么这种行为将是不可靠的。
#5
0
Pass a named pipe handle. Pipe the data back to yourself.
传递命名管道句柄。将数据传回给自己。
#1
3
You can use memory mapped files. See here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366537(v=vs.85).aspx
您可以使用内存映射文件。请看:http://msdn.microsoft.com/en-us/library/windows/desktop/aa366537(v = vs.85).aspx
You need to pass hFile = INVALID_HANDLE_VALUE and specify maximal size of file. Please, check msdn for the details.
您需要传递hFile = INVALID_HANDLE_VALUE并指定文件的最大大小。请检查msdn以获取详细信息。
#2
2
There are a couple of possibilities.
有几种可能性。
One would be to use CreateFile
, but pass FILE_ATTRIBUTE_TEMPORARY
. This will create a file, but tells Windows to attempt to keep as much of the file in the cache as possible. While this doesn't completely avoid creating a file, if you have enough memory it can often eliminate any (or much, anyway) I/O to/from the disk from happening.
一种是使用CreateFile,但是传递FILE_ATTRIBUTE_TEMPORARY。这将创建一个文件,但告诉Windows尝试尽可能多地保留缓存中的文件。虽然这并不能完全避免创建文件,但如果你有足够的内存,它通常可以消除发生进出磁盘的任何(或多次)I / O.
Another possibility (though one I've never tested) would be to pass a handle to a named (or maybe even an anonymous) pipe. You can generally write to a pipe like you would a file, so as long as the crash dump writer just needs to be able to pass the handle to WriteFile
, chances are pretty good this will work fine. From there, you could (for example) have another small program that would read the data from the pipe and write it to a socket. Obviously it would be nice to be able to avoid the extra processing to translate from pipe to socket, but such is life some times.
另一种可能性(虽然我从未测试过)可能是将句柄传递给命名(或者甚至是匿名)管道。你通常可以写一个像文件一样的管道,所以只要崩溃转储编写器只需要能够将句柄传递给WriteFile,很可能这样做会很好。从那里,你可以(例如)有另一个小程序,它将从管道中读取数据并将其写入套接字。显然,能够避免从管道转换为套接字的额外处理会很好,但这种生活有时候也是如此。
If you haven't tried it, you might want to test with just passing a socket handle to the crash dump writer. Although it's somewhat limited, Windows does support treating a socket handle like a normal file (or whatever) handle. There's certainly nothing close to a guarantee that it'll work, but it may be worth a shot anyway.
如果您还没有尝试过,可能只想将套接字句柄传递给崩溃转储编写器进行测试。虽然它有些限制,但Windows确实支持将套接字句柄视为普通文件(或其他)句柄。肯定没有什么能保证它能够正常工作,但无论如何它都值得一试。
#3
0
The crash dump is indeed process's memory. So, it doesn't make sense. Why don't you simply send the file and delete after successful send?
崩溃转储确实是进程的内存。所以,它没有意义。你为什么不简单地发送文件并在成功发送后删除?
By the way, you can compress the file and send it, because crashdumps are usually big files.
顺便说一下,你可以压缩文件并发送它,因为crashdumps通常是大文件。
#4
0
The documentation says to pass a file handle, so if you do anything else you're breaking the contract and (if it works at all) the behaviour will not be reliable.
文档说要传递一个文件句柄,所以如果你做了其他任何事情你就违反了合同(如果它完全有效),那么这种行为将是不可靠的。
#5
0
Pass a named pipe handle. Pipe the data back to yourself.
传递命名管道句柄。将数据传回给自己。