merged RC_1_1 into master

This commit is contained in:
arvidn 2018-11-23 23:42:11 +01:00
commit bac57a6e69
10 changed files with 7 additions and 266 deletions

View File

@ -20,7 +20,6 @@ set(libtorrent_include_files
alert
alert_manager
alert_types
allocator
announce_entry
assert
bandwidth_limit
@ -269,7 +268,6 @@ set(sources
web_connection_base
alert
alert_manager
allocator
announce_entry
assert
bandwidth_limit

View File

@ -615,7 +615,6 @@ lib iphlpapi : : <name>iphlpapi <link>shared ;
SOURCES =
alert
alert_manager
allocator
announce_entry
assert
bandwidth_limit

View File

@ -6,7 +6,6 @@ nobase_include_HEADERS = \
alert.hpp \
alert_manager.hpp \
alert_types.hpp \
allocator.hpp \
announce_entry.hpp \
assert.hpp \
bandwidth_limit.hpp \

View File

@ -1,51 +0,0 @@
/*
Copyright (c) 2009-2018, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TORRENT_ALLOCATOR_HPP_INCLUDED
#define TORRENT_ALLOCATOR_HPP_INCLUDED
#include <cstddef>
#include "libtorrent/config.hpp"
namespace libtorrent {
TORRENT_EXTRA_EXPORT int page_size();
TORRENT_EXTRA_EXPORT char* page_malloc(std::size_t bytes);
TORRENT_EXTRA_EXPORT void page_free(char* block);
#ifdef TORRENT_DEBUG_BUFFERS
TORRENT_EXTRA_EXPORT bool page_in_use(char const* block);
#endif
}
#endif

View File

@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/fwd.hpp"
#include "libtorrent/debug.hpp"
#include "libtorrent/storage.hpp"
#include "libtorrent/allocator.hpp"
#include "libtorrent/io_service.hpp"
#include "libtorrent/disk_io_thread_pool.hpp"
#include "libtorrent/disk_io_job.hpp"

View File

@ -43,7 +43,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/disk_job_fence.hpp"
#include "libtorrent/aux_/storage_piece_set.hpp"
#include "libtorrent/storage_defs.hpp"
#include "libtorrent/allocator.hpp"
#include "libtorrent/part_file.hpp"
#include "libtorrent/stat_cache.hpp"
#include "libtorrent/bitfield.hpp"

View File

@ -45,7 +45,6 @@ libtorrent_rasterbar_la_SOURCES = \
web_connection_base.cpp \
alert.cpp \
alert_manager.cpp \
allocator.cpp \
announce_entry.cpp \
assert.cpp \
bandwidth_limit.cpp \

View File

@ -1,198 +0,0 @@
/*
Copyright (c) 2009-2018, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/allocator.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp" // for print_backtrace
#include <cstdint>
#if !defined TORRENT_WINDOWS
#include <cstdlib> // posix_memalign/free
#include <unistd.h> // _SC_PAGESIZE
#endif
#if TORRENT_USE_MEMALIGN || TORRENT_USE_POSIX_MEMALIGN || defined TORRENT_WINDOWS
#include <malloc.h> // memalign and _aligned_malloc
#include <stdlib.h> // _aligned_malloc on mingw
#endif
#ifdef TORRENT_WINDOWS
// windows.h must be included after stdlib.h under mingw
#include "libtorrent/aux_/windows.hpp"
#endif
#ifdef TORRENT_MINGW
#define _aligned_malloc __mingw_aligned_malloc
#define _aligned_free __mingw_aligned_free
#endif
#ifdef TORRENT_DEBUG_BUFFERS
#ifndef TORRENT_WINDOWS
#include <sys/mman.h>
#endif
struct alloc_header
{
std::int64_t size;
int magic;
char stack[3072];
};
#endif
namespace libtorrent {
int page_size()
{
static int s = 0;
if (s != 0) return s;
#ifdef TORRENT_BUILD_SIMULATOR
s = 4096;
#elif defined TORRENT_WINDOWS
SYSTEM_INFO si;
GetSystemInfo(&si);
s = si.dwPageSize;
#elif defined TORRENT_BEOS
s = B_PAGE_SIZE;
#else
s = int(::sysconf(_SC_PAGESIZE));
#endif
// assume the page size is 4 kiB if we
// fail to query it
if (s <= 0) s = 4096;
return s;
}
char* page_malloc(std::size_t bytes)
{
TORRENT_ASSERT(bytes > 0);
// just sanity check (this needs to be pretty high
// for cases where the cache size is several gigabytes)
TORRENT_ASSERT(bytes < 0x30000000);
TORRENT_ASSERT(int(bytes) >= page_size());
#ifdef TORRENT_DEBUG_BUFFERS
const int page = page_size();
const int num_pages = (bytes + (page - 1)) / page + 2;
const int orig_bytes = bytes;
bytes = num_pages * page;
#endif
void* ret;
#if TORRENT_USE_POSIX_MEMALIGN
if (::posix_memalign(&ret, std::size_t(page_size()), std::size_t(bytes))
!= 0) ret = nullptr;
#elif TORRENT_USE_MEMALIGN
ret = ::memalign(std::size_t(page_size()), std::size_t(bytes));
#elif defined TORRENT_WINDOWS
ret = ::_aligned_malloc(std::size_t(bytes), std::size_t(page_size()));
#else
ret = valloc(std::size_t(bytes));
#endif
if (ret == nullptr) return nullptr;
#ifdef TORRENT_DEBUG_BUFFERS
// make the two surrounding pages non-readable and -writable
alloc_header* h = static_cast<alloc_header*>(ret);
h->size = orig_bytes;
h->magic = 0x1337;
print_backtrace(h->stack, sizeof(h->stack));
#ifdef TORRENT_WINDOWS
#define mprotect(buf, size, prot) VirtualProtect(buf, size, prot, nullptr)
#define PROT_READ PAGE_READONLY
#endif
mprotect(ret, std::size_t(page), PROT_READ);
mprotect(static_cast<char*>(ret) + (num_pages - 1) * page, std::size_t(page), PROT_READ);
#ifdef TORRENT_WINDOWS
#undef mprotect
#undef PROT_READ
#endif
// std::fprintf(stderr, "malloc: %p head: %p tail: %p size: %d\n", ret + page, ret, ret + page + bytes, int(bytes));
return static_cast<char*>(ret) + page;
#else
return static_cast<char*>(ret);
#endif // TORRENT_DEBUG_BUFFERS
}
void page_free(char* block)
{
if (block == nullptr) return;
#ifdef TORRENT_DEBUG_BUFFERS
#ifdef TORRENT_WINDOWS
#define mprotect(buf, size, prot) VirtualProtect(buf, size, prot, nullptr)
#define PROT_READ PAGE_READONLY
#define PROT_WRITE PAGE_READWRITE
#endif
int const page = page_size();
// make the two surrounding pages non-readable and -writable
mprotect(block - page, std::size_t(page), PROT_READ | PROT_WRITE);
alloc_header* h = reinterpret_cast<alloc_header*>(block - page);
int const num_pages = int((h->size + (page - 1)) / page + 2);
TORRENT_ASSERT(h->magic == 0x1337);
mprotect(block + (num_pages - 2) * page, std::size_t(page), PROT_READ | PROT_WRITE);
// std::fprintf(stderr, "free: %p head: %p tail: %p size: %d\n", block, block - page, block + h->size, int(h->size));
h->magic = 0;
block -= page;
#ifdef TORRENT_WINDOWS
#undef mprotect
#undef PROT_READ
#undef PROT_WRITE
#endif
print_backtrace(h->stack, sizeof(h->stack));
#endif // TORRENT_DEBUG_BUFFERS
#ifdef TORRENT_WINDOWS
_aligned_free(block);
#else
::free(block);
#endif // TORRENT_WINDOWS
}
#ifdef TORRENT_DEBUG_BUFFERS
bool page_in_use(char const* block)
{
const int page = page_size();
alloc_header const* h = reinterpret_cast<alloc_header const*>(block - page);
return h->magic == 0x1337;
}
#endif
}

View File

@ -33,7 +33,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/disk_buffer_pool.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/allocator.hpp"
#include "libtorrent/aux_/session_settings.hpp"
#include "libtorrent/io_service.hpp"
#include "libtorrent/disk_observer.hpp"
@ -137,8 +136,6 @@ namespace libtorrent {
#if TORRENT_USE_INVARIANT_CHECKS
return m_buffers_in_use.count(buffer) == 1;
#elif defined TORRENT_DEBUG_BUFFERS
return page_in_use(buffer);
#else
TORRENT_UNUSED(buffer);
return true;
@ -196,8 +193,8 @@ namespace libtorrent {
if (j.data() == nullptr) break;
char* buf = j.data();
TORRENT_ASSERT(is_disk_buffer(buf, l));
free_buffer_impl(buf, l);
remove_buffer_in_use(buf);
free_buffer_impl(buf, l);
}
return -1;
}
@ -213,8 +210,8 @@ namespace libtorrent {
{
char* buf = i.data();
TORRENT_ASSERT(is_disk_buffer(buf, l));
free_buffer_impl(buf, l);
remove_buffer_in_use(buf);
free_buffer_impl(buf, l);
}
check_buffer_level(l);
}
@ -227,7 +224,7 @@ namespace libtorrent {
TORRENT_ASSERT(l.owns_lock());
TORRENT_UNUSED(l);
char* ret = page_malloc(default_block_size);
char* ret = static_cast<char*>(std::malloc(default_block_size));
if (ret == nullptr)
{
@ -271,8 +268,8 @@ namespace libtorrent {
for (char* buf : bufvec)
{
TORRENT_ASSERT(is_disk_buffer(buf, l));
free_buffer_impl(buf, l);
remove_buffer_in_use(buf);
free_buffer_impl(buf, l);
}
check_buffer_level(l);
@ -282,8 +279,8 @@ namespace libtorrent {
{
std::unique_lock<std::mutex> l(m_pool_mutex);
TORRENT_ASSERT(is_disk_buffer(buf, l));
free_buffer_impl(buf, l);
remove_buffer_in_use(buf);
free_buffer_impl(buf, l);
check_buffer_level(l);
}
@ -375,7 +372,7 @@ namespace libtorrent {
TORRENT_ASSERT(l.owns_lock());
TORRENT_UNUSED(l);
page_free(buf);
std::free(buf);
--m_in_use;
}

View File

@ -2774,7 +2774,7 @@ bool is_downloading_state(int const st)
req.event = e;
// since sending our IPv6 address to the tracker may be sensitive. Only
// since sending our IPv4/v6 address to the tracker may be sensitive. Only
// do that if we're not in anonymous mode and if it's a private torrent
if (!settings().get_bool(settings_pack::anonymous_mode)
&& m_torrent_file