fix debug buffer build. add new Jamfile feature for it. attempt to make it build on windows
This commit is contained in:
@@ -58,7 +58,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_DEBUG_BUFFERS
|
||||
#ifndef TORRENT_WINDOWS
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
#include "libtorrent/size_type.hpp"
|
||||
|
||||
struct alloc_header
|
||||
@@ -71,7 +73,7 @@ struct alloc_header
|
||||
#endif
|
||||
|
||||
#if defined TORRENT_DEBUG_BUFFERS && (defined __linux__ || (defined __APPLE__ && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050))
|
||||
void print_backtrace(char* out, int len);
|
||||
void print_backtrace(char* out, int len, int max_depth = 0);
|
||||
#endif
|
||||
|
||||
namespace libtorrent
|
||||
@@ -110,9 +112,19 @@ namespace libtorrent
|
||||
h->magic = 0x1337;
|
||||
#if defined __linux__ || (defined __APPLE__ && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
|
||||
print_backtrace(h->stack, sizeof(h->stack));
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
#define mprotect(buf, size, prot) VirtualProtect(buf, size, prot, NULK)
|
||||
#define PROT_READ PAGE_READONLY
|
||||
#endif
|
||||
mprotect(ret, page, PROT_READ);
|
||||
mprotect(ret + (num_pages-1) * page, page, PROT_READ);
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
#undef mprotect
|
||||
#undef PROT_READ
|
||||
#endif
|
||||
// fprintf(stderr, "malloc: %p head: %p tail: %p size: %d\n", ret + page, ret, ret + page + bytes, int(bytes));
|
||||
|
||||
return ret + page;
|
||||
@@ -141,6 +153,12 @@ namespace libtorrent
|
||||
{
|
||||
|
||||
#ifdef TORRENT_DEBUG_BUFFERS
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
#define mprotect(buf, size, prot) VirtualProtect(buf, size, prot, NULK)
|
||||
#define PROT_READ PAGE_READONLY
|
||||
#define PROT_WRITE PAGE_READWRITE
|
||||
#endif
|
||||
int page = page_size();
|
||||
// make the two surrounding pages non-readable and -writable
|
||||
mprotect(block - page, page, PROT_READ | PROT_WRITE);
|
||||
@@ -151,6 +169,12 @@ namespace libtorrent
|
||||
// fprintf(stderr, "free: %p head: %p tail: %p size: %d\n", block, block - page, block + h->size, int(h->size));
|
||||
h->magic = 0;
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
#undef mprotect
|
||||
#undef PROT_READ
|
||||
#undef PROT_WRITE
|
||||
#endif
|
||||
|
||||
#if defined __linux__ || (defined __APPLE__ && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
|
||||
print_backtrace(h->stack, sizeof(h->stack));
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user