fix debug buffer build. add new Jamfile feature for it. attempt to make it build on windows

This commit is contained in:
Arvid Norberg 2013-11-29 09:41:53 +00:00
parent f99be2455a
commit f382876832
4 changed files with 36 additions and 5 deletions

View File

@ -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

View File

@ -349,9 +349,14 @@ feature.compose <extensions>off : <define>TORRENT_DISABLE_EXTENSION ;
feature asio-debugging : off on : composite propagated link-incompatible ;
feature.compose <asio-debugging>on : <define>TORRENT_ASIO_DEBUGGING ;
# deprecated use allocator=pool instead
feature pool-allocators : on off : composite propagated link-incompatible ;
feature.compose <pool-allocators>off : <define>TORRENT_DISABLE_POOL_ALLOCATOR ;
feature allocator : pool system debug : composite ;
feature.compose <allocator>system : <define>TORRENT_DISABLE_POOL_ALLOCATOR ;
feature.compose <allocator>debug : <define>TORRENT_DISABLE_POOL_ALLOCATOR <define>TORRENT_DEBUG_BUFFERS ;
feature piece-allocator : valloc memalign posix_memalign : composite propagated ;
feature.compose <piece-allocator>memalign : <define>TORRENT_USE_MEMALIGN=1 ;
feature.compose <piece-allocator>posix_memalign : <define>TORRENT_USE_POSIX_MEMALIGN=1 ;

View File

@ -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) |

View File

@ -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