diff --git a/.regression.yml b/.regression.yml index 8810bef53..70c9fbe77 100644 --- a/.regression.yml +++ b/.regression.yml @@ -15,6 +15,6 @@ time_limit: 180 features: - variant=release asserts=production invariant-checks=off debug-iterators=off debug-symbols=on - - encryption=openssl statistics=on logging=verbose disk-stats=on dht=logging request-log=on + - encryption=openssl statistics=on logging=verbose disk-stats=on dht=logging request-log=on allocator=debug - ipv6=off dht=off extensions=off logging=none deprecated-functions=off diff --git a/Jamfile b/Jamfile index c6a97300f..97fee1e66 100755 --- a/Jamfile +++ b/Jamfile @@ -349,9 +349,14 @@ feature.compose off : TORRENT_DISABLE_EXTENSION ; feature asio-debugging : off on : composite propagated link-incompatible ; feature.compose on : TORRENT_ASIO_DEBUGGING ; +# deprecated use allocator=pool instead feature pool-allocators : on off : composite propagated link-incompatible ; feature.compose off : TORRENT_DISABLE_POOL_ALLOCATOR ; +feature allocator : pool system debug : composite ; +feature.compose system : TORRENT_DISABLE_POOL_ALLOCATOR ; +feature.compose debug : TORRENT_DISABLE_POOL_ALLOCATOR TORRENT_DEBUG_BUFFERS ; + feature piece-allocator : valloc memalign posix_memalign : composite propagated ; feature.compose memalign : TORRENT_USE_MEMALIGN=1 ; feature.compose posix_memalign : TORRENT_USE_POSIX_MEMALIGN=1 ; diff --git a/docs/building.rst b/docs/building.rst index 07c713ae0..a8bbf046b 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -298,11 +298,13 @@ Build features: | | connections. The shipped public domain SHA-1 | | | implementation is used. | +--------------------------+----------------------------------------------------+ -| ``pool-allocators`` | * ``on`` - default, uses pool allocators for send | -| | buffers. | -| | * ``off`` - uses ``malloc()`` and ``free()`` | +| ``allocator`` | * ``pool`` - default, uses pool allocators for | +| | send buffers. | +| | * ``system`` - uses ``malloc()`` and ``free()`` | | | instead. Might be useful to debug buffer issues | | | with tools like electric fence or libgmalloc. | +| | * ``debug`` - instruments buffer usage to catch | +| | bugs in libtorrent. | +--------------------------+----------------------------------------------------+ | ``link`` | * ``static`` - builds libtorrent as a static | | | library (.a / .lib) | diff --git a/src/allocator.cpp b/src/allocator.cpp index 471726448..0bb7d3383 100644 --- a/src/allocator.cpp +++ b/src/allocator.cpp @@ -58,7 +58,9 @@ POSSIBILITY OF SUCH DAMAGE. #endif #ifdef TORRENT_DEBUG_BUFFERS +#ifndef TORRENT_WINDOWS #include +#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