diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/allocators.h | 165 | ||||
-rw-r--r-- | src/checkpoints.cpp | 2 | ||||
-rw-r--r-- | src/crypter.cpp | 12 | ||||
-rw-r--r-- | src/crypter.h | 11 | ||||
-rw-r--r-- | src/main.cpp | 5 | ||||
-rw-r--r-- | src/qt/locale/bitcoin_cs.ts | 186 | ||||
-rw-r--r-- | src/test/allocator_tests.cpp | 115 | ||||
-rw-r--r-- | src/util.cpp | 2 |
8 files changed, 377 insertions, 121 deletions
diff --git a/src/allocators.h b/src/allocators.h index ddeabc48c5..99afa10c25 100644 --- a/src/allocators.h +++ b/src/allocators.h @@ -7,6 +7,8 @@ #include <string.h> #include <string> +#include <boost/thread/mutex.hpp> +#include <map> #ifdef WIN32 #ifdef _WIN32_WINNT @@ -22,23 +24,156 @@ // Note that VirtualLock does not provide this as a guarantee on Windows, // but, in practice, memory that has been VirtualLock'd almost never gets written to // the pagefile except in rare circumstances where memory is extremely low. -#define mlock(p, n) VirtualLock((p), (n)); -#define munlock(p, n) VirtualUnlock((p), (n)); #else #include <sys/mman.h> -#include <limits.h> -/* This comes from limits.h if it's not defined there set a sane default */ -#ifndef PAGESIZE -#include <unistd.h> -#define PAGESIZE sysconf(_SC_PAGESIZE) +#include <limits.h> // for PAGESIZE +#include <unistd.h> // for sysconf #endif -#define mlock(a,b) \ - mlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\ - (((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1)))) -#define munlock(a,b) \ - munlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\ - (((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1)))) + +/** + * Thread-safe class to keep track of locked (ie, non-swappable) memory pages. + * + * Memory locks do not stack, that is, pages which have been locked several times by calls to mlock() + * will be unlocked by a single call to munlock(). This can result in keying material ending up in swap when + * those functions are used naively. This class simulates stacking memory locks by keeping a counter per page. + * + * @note By using a map from each page base address to lock count, this class is optimized for + * small objects that span up to a few pages, mostly smaller than a page. To support large allocations, + * something like an interval tree would be the preferred data structure. + */ +template <class Locker> class LockedPageManagerBase +{ +public: + LockedPageManagerBase(size_t page_size): + page_size(page_size) + { + // Determine bitmask for extracting page from address + assert(!(page_size & (page_size-1))); // size must be power of two + page_mask = ~(page_size - 1); + } + + // For all pages in affected range, increase lock count + void LockRange(void *p, size_t size) + { + boost::mutex::scoped_lock lock(mutex); + if(!size) return; + const size_t base_addr = reinterpret_cast<size_t>(p); + const size_t start_page = base_addr & page_mask; + const size_t end_page = (base_addr + size - 1) & page_mask; + for(size_t page = start_page; page <= end_page; page += page_size) + { + Histogram::iterator it = histogram.find(page); + if(it == histogram.end()) // Newly locked page + { + locker.Lock(reinterpret_cast<void*>(page), page_size); + histogram.insert(std::make_pair(page, 1)); + } + else // Page was already locked; increase counter + { + it->second += 1; + } + } + } + + // For all pages in affected range, decrease lock count + void UnlockRange(void *p, size_t size) + { + boost::mutex::scoped_lock lock(mutex); + if(!size) return; + const size_t base_addr = reinterpret_cast<size_t>(p); + const size_t start_page = base_addr & page_mask; + const size_t end_page = (base_addr + size - 1) & page_mask; + for(size_t page = start_page; page <= end_page; page += page_size) + { + Histogram::iterator it = histogram.find(page); + assert(it != histogram.end()); // Cannot unlock an area that was not locked + // Decrease counter for page, when it is zero, the page will be unlocked + it->second -= 1; + if(it->second == 0) // Nothing on the page anymore that keeps it locked + { + // Unlock page and remove the count from histogram + locker.Unlock(reinterpret_cast<void*>(page), page_size); + histogram.erase(it); + } + } + } + + // Get number of locked pages for diagnostics + int GetLockedPageCount() + { + boost::mutex::scoped_lock lock(mutex); + return histogram.size(); + } + +private: + Locker locker; + boost::mutex mutex; + size_t page_size, page_mask; + // map of page base address to lock count + typedef std::map<size_t,int> Histogram; + Histogram histogram; +}; + +/** Determine system page size in bytes */ +static inline size_t GetSystemPageSize() +{ + size_t page_size; +#if defined(WIN32) + SYSTEM_INFO sSysInfo; + GetSystemInfo(&sSysInfo); + page_size = sSysInfo.dwPageSize; +#elif defined(PAGESIZE) // defined in limits.h + page_size = PAGESIZE; +#else // assume some POSIX OS + page_size = sysconf(_SC_PAGESIZE); +#endif + return page_size; +} + +/** + * OS-dependent memory page locking/unlocking. + * Defined as policy class to make stubbing for test possible. + */ +class MemoryPageLocker +{ +public: + /** Lock memory pages. + * addr and len must be a multiple of the system page size + */ + bool Lock(const void *addr, size_t len) + { +#ifdef WIN32 + return VirtualLock(const_cast<void*>(addr), len); +#else + return mlock(addr, len) == 0; +#endif + } + /** Unlock memory pages. + * addr and len must be a multiple of the system page size + */ + bool Unlock(const void *addr, size_t len) + { +#ifdef WIN32 + return VirtualUnlock(const_cast<void*>(addr), len); +#else + return munlock(addr, len) == 0; #endif + } +}; + +/** + * Singleton class to keep track of locked (ie, non-swappable) memory pages, for use in + * std::allocator templates. + */ +class LockedPageManager: public LockedPageManagerBase<MemoryPageLocker> +{ +public: + static LockedPageManager instance; // instantiated in util.cpp +private: + LockedPageManager(): + LockedPageManagerBase<MemoryPageLocker>(GetSystemPageSize()) + {} +}; // // Allocator that locks its contents from being paged @@ -69,7 +204,7 @@ struct secure_allocator : public std::allocator<T> T *p; p = std::allocator<T>::allocate(n, hint); if (p != NULL) - mlock(p, sizeof(T) * n); + LockedPageManager::instance.LockRange(p, sizeof(T) * n); return p; } @@ -78,7 +213,7 @@ struct secure_allocator : public std::allocator<T> if (p != NULL) { memset(p, 0, sizeof(T) * n); - munlock(p, sizeof(T) * n); + LockedPageManager::instance.UnlockRange(p, sizeof(T) * n); } std::allocator<T>::deallocate(p, n); } diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index 2df647e83d..8208854962 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -29,7 +29,7 @@ namespace Checkpoints (105000, uint256("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")) (134444, uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe")) (168000, uint256("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763")) - (185333, uint256("0x00000000000002334c71b8706940c20348af897a9cfc0f1a6dab0d14d4ceb815")) + (193000, uint256("0x000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317")) ; static MapCheckpoints mapCheckpointsTestnet = diff --git a/src/crypter.cpp b/src/crypter.cpp index 411a1ee4c1..181b8fa00a 100644 --- a/src/crypter.cpp +++ b/src/crypter.cpp @@ -17,12 +17,6 @@ bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::v if (nRounds < 1 || chSalt.size() != WALLET_CRYPTO_SALT_SIZE) return false; - // Try to keep the key data out of swap (and be a bit over-careful to keep the IV that we don't even use out of swap) - // Note that this does nothing about suspend-to-disk (which will put all our key data on disk) - // Note as well that at no point in this program is any attempt made to prevent stealing of keys by reading the memory of the running process. - mlock(&chKey[0], sizeof chKey); - mlock(&chIV[0], sizeof chIV); - int i = 0; if (nDerivationMethod == 0) i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha512(), &chSalt[0], @@ -44,12 +38,6 @@ bool CCrypter::SetKey(const CKeyingMaterial& chNewKey, const std::vector<unsigne if (chNewKey.size() != WALLET_CRYPTO_KEY_SIZE || chNewIV.size() != WALLET_CRYPTO_KEY_SIZE) return false; - // Try to keep the key data out of swap - // Note that this does nothing about suspend-to-disk (which will put all our key data on disk) - // Note as well that at no point in this program is any attempt made to prevent stealing of keys by reading the memory of the running process. - mlock(&chKey[0], sizeof chKey); - mlock(&chIV[0], sizeof chIV); - memcpy(&chKey[0], &chNewKey[0], sizeof chKey); memcpy(&chIV[0], &chNewIV[0], sizeof chIV); diff --git a/src/crypter.h b/src/crypter.h index d1bdb92c91..04538a3fa5 100644 --- a/src/crypter.h +++ b/src/crypter.h @@ -78,19 +78,26 @@ public: { memset(&chKey, 0, sizeof chKey); memset(&chIV, 0, sizeof chIV); - munlock(&chKey, sizeof chKey); - munlock(&chIV, sizeof chIV); fKeySet = false; } CCrypter() { fKeySet = false; + + // Try to keep the key data out of swap (and be a bit over-careful to keep the IV that we don't even use out of swap) + // Note that this does nothing about suspend-to-disk (which will put all our key data on disk) + // Note as well that at no point in this program is any attempt made to prevent stealing of keys by reading the memory of the running process. + LockedPageManager::instance.LockRange(&chKey[0], sizeof chKey); + LockedPageManager::instance.LockRange(&chIV[0], sizeof chIV); } ~CCrypter() { CleanKey(); + + LockedPageManager::instance.UnlockRange(&chKey[0], sizeof chKey); + LockedPageManager::instance.UnlockRange(&chIV[0], sizeof chIV); } }; diff --git a/src/main.cpp b/src/main.cpp index 56596ef183..f71cfe7caa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -281,9 +281,12 @@ bool CTransaction::IsStandard() const if (!txin.scriptSig.IsPushOnly()) return false; } - BOOST_FOREACH(const CTxOut& txout, vout) + BOOST_FOREACH(const CTxOut& txout, vout) { if (!::IsStandard(txout.scriptPubKey)) return false; + if (txout.nValue == 0) + return false; + } return true; } diff --git a/src/qt/locale/bitcoin_cs.ts b/src/qt/locale/bitcoin_cs.ts index 81f94e388e..edc7e52aa4 100644 --- a/src/qt/locale/bitcoin_cs.ts +++ b/src/qt/locale/bitcoin_cs.ts @@ -21,7 +21,13 @@ This is experimental software. Distributed under the MIT/X11 software license, see the accompanying file COPYING or http://www.opensource.org/licenses/mit-license.php. This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (http://www.openssl.org/) and cryptographic software written by Eric Young (eay@cryptsoft.com) and UPnP software written by Thomas Bernard.</source> - <translation type="unfinished"/> + <translation>Copyright © 2009-2012 Vývojáři Bitcoinu + +Tohle je experimentální program. + +Šířen pod licencí MIT/X11, viz přiložený soubor COPYING nebo http://www.opensource.org/licenses/mit-license.php. + +Tento produkt zahrnuje programy vyvinuté OpenSSL Projektem pro použití v OpenSSL Toolkitu (http://www.openssl.org/) a kryptografický program od Erika Younga (eay@cryptsoft.com) a program UPnP od Thomase Bernarda.</translation> </message> </context> <context> @@ -215,18 +221,18 @@ This product includes software developed by the OpenSSL Project for use in the O <message> <location line="+1"/> <source>Warning: If you encrypt your wallet and lose your passphrase, you will <b>LOSE ALL OF YOUR BITCOINS</b>!</source> - <translation type="unfinished"/> + <translation>Varování: Pokud si zašifruješ peněženku a ztratíš či zapomeneš heslo, <b>PŘIJDEŠ O VŠECHNY BITCOINY</b>!</translation> </message> <message> <location line="+0"/> <source>Are you sure you wish to encrypt your wallet?</source> - <translation type="unfinished"/> + <translation>Jsi si jistý, že chceš peněženku zašifrovat?</translation> </message> <message> <location line="+106"/> <location line="+24"/> <source>Warning: The Caps Lock key is on!</source> - <translation type="unfinished"/> + <translation>Upozornění: Caps Lock je zapnutý!</translation> </message> <message> <location line="-121"/> @@ -278,7 +284,7 @@ This product includes software developed by the OpenSSL Project for use in the O <message> <location line="+14"/> <source>Wallet passphrase was successfully changed.</source> - <translation type="unfinished"/> + <translation>Heslo k peněžence bylo v pořádku změněno.</translation> </message> </context> <context> @@ -456,12 +462,12 @@ This product includes software developed by the OpenSSL Project for use in the O <message> <location line="+1"/> <source>&Debug window</source> - <translation>&Ladící okno</translation> + <translation>&Ladicí okno</translation> </message> <message> <location line="+1"/> <source>Open debugging and diagnostic console</source> - <translation>Otevři ladící a diagnostickou konzoli</translation> + <translation>Otevři ladicí a diagnostickou konzoli</translation> </message> <message> <location line="-56"/> @@ -481,7 +487,7 @@ This product includes software developed by the OpenSSL Project for use in the O <message> <location line="+186"/> <source>&About Bitcoin</source> - <translation type="unfinished"/> + <translation>O &Bitcoinu</translation> </message> <message> <location line="+44"/> @@ -643,7 +649,7 @@ Adresa: %4 <message> <location filename="../bitcoin.cpp" line="+112"/> <source>A fatal error occurred. Bitcoin can no longer continue safely and will quit.</source> - <translation type="unfinished"/> + <translation>Stala se fatální chyba. Bitcoin nemůže bezpečně pokračovat v činnosti, a proto skončí.</translation> </message> </context> <context> @@ -728,7 +734,7 @@ Adresa: %4 <location filename="../guiutil.cpp" line="+425"/> <location line="+12"/> <source>Bitcoin-Qt</source> - <translation type="unfinished"/> + <translation>Bitcoin-Qt</translation> </message> <message> <location line="-12"/> @@ -997,12 +1003,12 @@ Adresa: %4 <message> <location line="+124"/> <source>Immature:</source> - <translation type="unfinished"/> + <translation>Nedozráno:</translation> </message> <message> <location line="+13"/> <source>Mined balance that has not yet matured</source> - <translation type="unfinished"/> + <translation>Vytěžené mince, které ještě nejsou zralé</translation> </message> <message> <location line="+46"/> @@ -1178,7 +1184,7 @@ Adresa: %4 <message> <location line="+7"/> <source>Show the Bitcoin-Qt help message to get a list with possible Bitcoin command-line options.</source> - <translation type="unfinished"/> + <translation>Seznam parametrů Bitcoinu pro příkazovou řádku získáš v nápovědě Bitcoinu Qt.</translation> </message> <message> <location line="+3"/> @@ -1198,22 +1204,22 @@ Adresa: %4 <message> <location line="-104"/> <source>Bitcoin - Debug window</source> - <translation type="unfinished"/> + <translation>Bitcoin - ladicí okno</translation> </message> <message> <location line="+25"/> <source>Bitcoin Core</source> - <translation type="unfinished"/> + <translation>Jádro Bitcoinu</translation> </message> <message> <location line="+279"/> <source>Debug log file</source> - <translation type="unfinished"/> + <translation>Soubor s ladicími záznamy</translation> </message> <message> <location line="+7"/> <source>Open the Bitcoin debug log file from the current data directory. This can take a few seconds for large log files.</source> - <translation type="unfinished"/> + <translation>Otevři soubor s ladicími záznamy Bitcoinu z aktuálního datového adresáře. U velkých logů to může pár vteřin zabrat.</translation> </message> <message> <location line="+102"/> @@ -1313,7 +1319,7 @@ Adresa: %4 <message> <location line="+23"/> <source>The recipient address is not valid, please recheck.</source> - <translation type="unfinished"/> + <translation>Adresa příjemce je neplatná, překontroluj ji prosím.</translation> </message> <message> <location line="+5"/> @@ -1415,7 +1421,7 @@ Adresa: %4 <message> <location filename="../forms/signverifymessagedialog.ui" line="+14"/> <source>Signatures - Sign / Verify a Message</source> - <translation type="unfinished"/> + <translation>Podpisy - podepsat/ověřit zprávu</translation> </message> <message> <location line="+13"/> @@ -1443,7 +1449,7 @@ Adresa: %4 <location line="-193"/> <location line="+203"/> <source>Alt+A</source> - <translation type="unfinished"/> + <translation>Alt+A</translation> </message> <message> <location line="-193"/> @@ -1453,7 +1459,7 @@ Adresa: %4 <message> <location line="+10"/> <source>Alt+P</source> - <translation type="unfinished"/> + <translation>Alt+P</translation> </message> <message> <location line="+12"/> @@ -1490,17 +1496,17 @@ Adresa: %4 <message> <location line="-64"/> <source>Enter the signing address, message (ensure you copy line breaks, spaces, tabs, etc. exactly) and signature below to verify the message. Be careful not to read more into the signature than what is in the signed message itself, to avoid being tricked by a man-in-the-middle attack.</source> - <translation type="unfinished"/> + <translation>K ověření podpisu zprávy zadej podepisující adresu, zprávu (ověř si, že správně kopíruješ zalomení řádků, mezery, tabulátory apod.) a podpis. Dávej pozor na to, abys nezkopíroval do podpisu víc, než co je v samotné podepsané zprávě, abys nebyl napálen man-in-the-middle útokem.</translation> </message> <message> <location line="+21"/> <source>The address the message was signed with (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)</source> - <translation type="unfinished"/> + <translation>Adresa, kterou je zpráva podepsána (např. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)</translation> </message> <message> <location line="+40"/> <source>Verify the message to ensure it was signed with the specified Bitcoin address</source> - <translation type="unfinished"/> + <translation>Ověř zprávu, aby ses ujistil, že byla podepsána danou Bitcoinovou adresou</translation> </message> <message> <location line="+17"/> @@ -1535,18 +1541,18 @@ Adresa: %4 <location line="+73"/> <location line="+8"/> <source>Please check the address and try again.</source> - <translation type="unfinished"/> + <translation>Zkontroluj ji prosím a zkus to pak znovu.</translation> </message> <message> <location line="-81"/> <location line="+81"/> <source>The entered address does not refer to a key.</source> - <translation type="unfinished"/> + <translation>Zadaná adresa nepasuje ke klíči.</translation> </message> <message> <location line="-73"/> <source>Wallet unlock was cancelled.</source> - <translation type="unfinished"/> + <translation>Odemčení peněženky bylo zrušeno.</translation> </message> <message> <location line="+8"/> @@ -1556,23 +1562,23 @@ Adresa: %4 <message> <location line="+12"/> <source>Message signing failed.</source> - <translation type="unfinished"/> + <translation>Podepisování zprávy selhalo.</translation> </message> <message> <location line="+5"/> <source>Message signed.</source> - <translation type="unfinished"/> + <translation>Zpráv podepsána.</translation> </message> <message> <location line="+59"/> <source>The signature could not be decoded.</source> - <translation type="unfinished"/> + <translation>Podpis nejde dekódovat.</translation> </message> <message> <location line="+0"/> <location line="+13"/> <source>Please check the signature and try again.</source> - <translation type="unfinished"/> + <translation>Zkontroluj ho prosím a zkus to pak znovu.</translation> </message> <message> <location line="+0"/> @@ -1582,12 +1588,12 @@ Adresa: %4 <message> <location line="+7"/> <source>Message verification failed.</source> - <translation type="unfinished"/> + <translation>Ověřování zprávy selhalo.</translation> </message> <message> <location line="+5"/> <source>Message verified.</source> - <translation type="unfinished"/> + <translation>Zpráva ověřena.</translation> </message> </context> <context> @@ -1600,12 +1606,12 @@ Adresa: %4 <message numerus="yes"> <location line="-2"/> <source>Open for %n block(s)</source> - <translation type="unfinished"><numerusform></numerusform><numerusform></numerusform><numerusform></numerusform></translation> + <translation><numerusform>Otevřeno pro 1 blok</numerusform><numerusform>Otevřeno pro %n bloky</numerusform><numerusform>Otevřeno pro %n bloků</numerusform></translation> </message> <message> <location line="+8"/> <source>%1/offline</source> - <translation type="unfinished"/> + <translation>%1/offline</translation> </message> <message> <location line="+2"/> @@ -1620,12 +1626,12 @@ Adresa: %4 <message> <location line="+18"/> <source>Status</source> - <translation type="unfinished"/> + <translation>Stav</translation> </message> <message numerus="yes"> <location line="+7"/> <source>, broadcast through %n node(s)</source> - <translation type="unfinished"><numerusform></numerusform><numerusform></numerusform><numerusform></numerusform></translation> + <translation><numerusform>, rozesláno přes 1 uzel</numerusform><numerusform>, rozesláno přes %n uzly</numerusform><numerusform>, rozesláno přes %n uzlů</numerusform></translation> </message> <message> <location line="+4"/> @@ -1635,36 +1641,36 @@ Adresa: %4 <message> <location line="+7"/> <source>Source</source> - <translation type="unfinished"/> + <translation>Zdroj</translation> </message> <message> <location line="+0"/> <source>Generated</source> - <translation type="unfinished"/> + <translation>Vygenerováno</translation> </message> <message> <location line="+6"/> <location line="+17"/> <source>From</source> - <translation type="unfinished"/> + <translation>Od</translation> </message> <message> <location line="+1"/> <location line="+22"/> <location line="+58"/> <source>To</source> - <translation type="unfinished"/> + <translation>Pro</translation> </message> <message> <location line="-77"/> <location line="+2"/> <source>own address</source> - <translation type="unfinished"/> + <translation>vlastní adresa</translation> </message> <message> <location line="-2"/> <source>label</source> - <translation type="unfinished"/> + <translation>označení</translation> </message> <message> <location line="+37"/> @@ -1673,17 +1679,17 @@ Adresa: %4 <location line="+17"/> <location line="+30"/> <source>Credit</source> - <translation type="unfinished"/> + <translation>Příjem</translation> </message> <message numerus="yes"> <location line="-102"/> <source>matures in %n more block(s)</source> - <translation type="unfinished"><numerusform></numerusform><numerusform></numerusform><numerusform></numerusform></translation> + <translation><numerusform>dozraje po jednom bloku</numerusform><numerusform>dozraje po %n blocích</numerusform><numerusform>dozraje po %n blocích</numerusform></translation> </message> <message> <location line="+2"/> <source>not accepted</source> - <translation type="unfinished"/> + <translation>neakceptováno</translation> </message> <message> <location line="+44"/> @@ -1691,67 +1697,67 @@ Adresa: %4 <location line="+15"/> <location line="+30"/> <source>Debit</source> - <translation type="unfinished"/> + <translation>Výdaj</translation> </message> <message> <location line="-39"/> <source>Transaction fee</source> - <translation type="unfinished"/> + <translation>Transakční poplatek</translation> </message> <message> <location line="+16"/> <source>Net amount</source> - <translation type="unfinished"/> + <translation>Čistá částka</translation> </message> <message> <location line="+6"/> <source>Message</source> - <translation type="unfinished"/> + <translation>Zpráva</translation> </message> <message> <location line="+2"/> <source>Comment</source> - <translation type="unfinished"/> + <translation>Komentář</translation> </message> <message> <location line="+2"/> <source>Transaction ID</source> - <translation type="unfinished"/> + <translation>ID transakce</translation> </message> <message> <location line="+3"/> <source>Generated coins must mature 120 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, its state will change to "not accepted" and it won't be spendable. This may occasionally happen if another node generates a block within a few seconds of yours.</source> - <translation type="unfinished"/> + <translation>Vygenerované mince musí čekat 120 bloků, než mohou být utraceny. Když jsi vygeneroval tenhle blok, tak byl rozposlán do sítě, aby byl přidán do řetězce bloků. Pokud se mu nepodaří dostat se do řetězce, změní se na "neakceptovaný" a nepůjde utratit. To se občas může stát, pokud jiný uzel vygeneruje blok zhruba ve stejném okamžiku jako ty.</translation> </message> <message> <location line="+7"/> <source>Debug information</source> - <translation type="unfinished"/> + <translation>Ladicí informace</translation> </message> <message> <location line="+8"/> <source>Transaction</source> - <translation type="unfinished"/> + <translation>Transakce</translation> </message> <message> <location line="+5"/> <source>Inputs</source> - <translation type="unfinished"/> + <translation>Vstupy</translation> </message> <message> <location line="+23"/> <source>Amount</source> - <translation>Množství</translation> + <translation>Částka</translation> </message> <message> <location line="+1"/> <source>true</source> - <translation type="unfinished"/> + <translation>true</translation> </message> <message> <location line="+0"/> <source>false</source> - <translation type="unfinished"/> + <translation>false</translation> </message> <message> <location line="-212"/> @@ -2197,142 +2203,142 @@ Adresa: %4 <message> <location line="-92"/> <source>Accept connections from outside (default: 1 if no -proxy or -connect)</source> - <translation type="unfinished"/> + <translation>Přijímat spojení zvenčí (výchozí: 1, pokud není zadáno -proxy nebo -connect)</translation> </message> <message> <location line="-20"/> <source>Set maximum size of high-priority/low-fee transactions in bytes (default: 27000)</source> - <translation type="unfinished"/> + <translation>Nastavit maximální velikost prioritních/nízkopoplatkových transakcí v bajtech (výchozí: 27000)</translation> </message> <message> <location line="+5"/> <source>Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction.</source> - <translation type="unfinished"/> + <translation>Upozornění: -paytxfee je nastaveno velmi vysoko! Toto je transakční poplatek, který zaplatíš za každou poslanou transakci.</translation> </message> <message> <location line="+3"/> <source>Warning: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.</source> - <translation type="unfinished"/> + <translation>Upozornění: Zobrazené transakce nemusí být správné! Možná potřebuješ aktualizovat nebo ostatní uzly potřebují aktualizovat.</translation> </message> <message> <location line="+3"/> <source>Warning: Please check that your computer's date and time are correct! If your clock is wrong Bitcoin will not work properly.</source> - <translation type="unfinished"/> + <translation>Upozornění: Zkontroluj, že máš v počítači správně nastavený datum a čas! Pokud jsou nastaveny špatně, Bitcoin nebude fungovat správně.</translation> </message> <message> <location line="+13"/> <source>An error occurred while setting up the RPC port %i for listening: %s</source> - <translation type="unfinished"/> + <translation>Při nastavování naslouchacího RPC portu %i nastala chyba: %s</translation> </message> <message> <location line="+4"/> <source>Block creation options:</source> - <translation type="unfinished"/> + <translation>Možnosti vytvoření bloku:</translation> </message> <message> <location line="+6"/> <source>Connect only to the specified node(s)</source> - <translation type="unfinished"/> + <translation>Připojovat se pouze k zadaným uzlům</translation> </message> <message> <location line="+3"/> <source>Discover own IP address (default: 1 when listening and no -externalip)</source> - <translation type="unfinished"/> + <translation>Zjistit vlastní IP adresu (výchozí: 1, pokud naslouchá a není zadáno -externalip)</translation> </message> <message> <location line="+11"/> <source>Failed to listen on any port. Use -listen=0 if you want this.</source> - <translation type="unfinished"/> + <translation>Nepodařilo se naslouchat na žádném portu. Použij -listen=0, pokud to byl tvůj záměr.</translation> </message> <message> <location line="+2"/> <source>Find peers using DNS lookup (default: 1 unless -connect)</source> - <translation type="unfinished"/> + <translation>Hledat uzly přes DNS (výchozí: 1, pokud není zadáno -connect)</translation> </message> <message> <location line="+9"/> <source>Invalid -tor address: '%s'</source> - <translation type="unfinished"/> + <translation>Neplatná -tor adresa: '%s'</translation> </message> <message> <location line="+10"/> <source>Maximum per-connection receive buffer, <n>*1000 bytes (default: 5000)</source> - <translation type="unfinished"/> + <translation>Maximální velikost přijímacího bufferu pro každé spojení, <n>*1000 bajtů (výchozí: 5000)</translation> </message> <message> <location line="+1"/> <source>Maximum per-connection send buffer, <n>*1000 bytes (default: 1000)</source> - <translation type="unfinished"/> + <translation>Maximální velikost odesílacího bufferu pro každé spojení, <n>*1000 bajtů (výchozí: 1000)</translation> </message> <message> <location line="+1"/> <source>Only connect to nodes in network <net> (IPv4, IPv6 or Tor)</source> - <translation type="unfinished"/> + <translation>Připojovat se pouze k uzlům v <net> síti (IPv4, IPv6 nebo Tor)</translation> </message> <message> <location line="+2"/> <source>Output extra debugging information. Implies all other -debug* options</source> - <translation type="unfinished"/> + <translation>Tisknout speciální ladicí informace. Implikuje použití všechny -debug* voleb</translation> </message> <message> <location line="+1"/> <source>Output extra network debugging information</source> - <translation type="unfinished"/> + <translation>Tisknout speciální ladicí informace o síti</translation> </message> <message> <location line="+2"/> <source>Prepend debug output with timestamp</source> - <translation>Připojit před ladící výstup časové razítko</translation> + <translation>Připojit před ladicí výstup časové razítko</translation> </message> <message> <location line="+4"/> <source>SSL options: (see the Bitcoin Wiki for SSL setup instructions)</source> - <translation type="unfinished"/> + <translation>Možnosti SSL: (viz instrukce nastavení SSL v Bitcoin Wiki)</translation> </message> <message> <location line="+1"/> <source>Select the version of socks proxy to use (4-5, default: 5)</source> - <translation type="unfinished"/> + <translation>Zvol verzi socks proxy (4-5, výchozí: 5)</translation> </message> <message> <location line="+3"/> <source>Send trace/debug info to console instead of debug.log file</source> - <translation>Posílat stopovací/ladící informace do konzole místo do souboru debug.log</translation> + <translation>Posílat stopovací/ladicí informace do konzole místo do souboru debug.log</translation> </message> <message> <location line="+1"/> <source>Send trace/debug info to debugger</source> - <translation>Posílat stopovací/ladící informace do debuggeru</translation> + <translation>Posílat stopovací/ladicí informace do debuggeru</translation> </message> <message> <location line="+7"/> <source>Set maximum block size in bytes (default: 250000)</source> - <translation type="unfinished"/> + <translation>Nastavit maximální velikost bloku v bajtech (výchozí: 250000)</translation> </message> <message> <location line="+1"/> <source>Set minimum block size in bytes (default: 0)</source> - <translation type="unfinished"/> + <translation>Nastavit minimální velikost bloku v bajtech (výchozí: 0)</translation> </message> <message> <location line="+1"/> <source>Shrink debug.log file on client startup (default: 1 when no -debug)</source> - <translation type="unfinished"/> + <translation>Při spuštění klienta zmenšit soubor debug.log (výchozí: 1, pokud není zadáno -debug)</translation> </message> <message> <location line="+15"/> <source>Use UPnP to map the listening port (default: 0)</source> - <translation type="unfinished"/> + <translation>Použít UPnP k namapování naslouchacího portu (výchozí: 0)</translation> </message> <message> <location line="+1"/> <source>Use UPnP to map the listening port (default: 1 when listening)</source> - <translation type="unfinished"/> + <translation>Použít UPnP k namapování naslouchacího portu (výchozí: 1, pokud naslouchá)</translation> </message> <message> <location line="+1"/> <source>Use proxy to reach tor hidden services (default: same as -proxy)</source> - <translation type="unfinished"/> + <translation>Použít proxy k připojení ke skryté služby (výchozí: stejné jako -proxy)</translation> </message> <message> <location line="+2"/> @@ -2342,12 +2348,12 @@ Adresa: %4 <message> <location line="+2"/> <source>Warning: Disk space is low!</source> - <translation type="unfinished"/> + <translation>Upozornění: Na disku je málo místa!</translation> </message> <message> <location line="+1"/> <source>Warning: This version is obsolete, upgrade required!</source> - <translation type="unfinished"/> + <translation>Upozornění: tahle verze je zastaralá, měl bys ji aktualizovat!</translation> </message> <message> <location line="-41"/> @@ -2567,7 +2573,7 @@ Adresa: %4 <message> <location line="-18"/> <source>Unable to bind to %s on this computer. Bitcoin is probably already running.</source> - <translation type="unfinished"/> + <translation>Nedaří se mi připojit na %s na tomhle počítači. Bitcoin už pravděpodobně jednou běží.</translation> </message> <message> <location line="+48"/> diff --git a/src/test/allocator_tests.cpp b/src/test/allocator_tests.cpp new file mode 100644 index 0000000000..d5cb8e8101 --- /dev/null +++ b/src/test/allocator_tests.cpp @@ -0,0 +1,115 @@ +#include <boost/test/unit_test.hpp> + +#include "init.h" +#include "main.h" +#include "util.h" + +BOOST_AUTO_TEST_SUITE(allocator_tests) + +// Dummy memory page locker for platform independent tests +static const void *last_lock_addr, *last_unlock_addr; +static size_t last_lock_len, last_unlock_len; +class TestLocker +{ +public: + bool Lock(const void *addr, size_t len) + { + last_lock_addr = addr; + last_lock_len = len; + return true; + } + bool Unlock(const void *addr, size_t len) + { + last_unlock_addr = addr; + last_unlock_len = len; + return true; + } +}; + +BOOST_AUTO_TEST_CASE(test_LockedPageManagerBase) +{ + const size_t test_page_size = 4096; + LockedPageManagerBase<TestLocker> lpm(test_page_size); + size_t addr; + last_lock_addr = last_unlock_addr = 0; + last_lock_len = last_unlock_len = 0; + + /* Try large number of small objects */ + addr = 0; + for(int i=0; i<1000; ++i) + { + lpm.LockRange(reinterpret_cast<void*>(addr), 33); + addr += 33; + } + /* Try small number of page-sized objects, straddling two pages */ + addr = test_page_size*100 + 53; + for(int i=0; i<100; ++i) + { + lpm.LockRange(reinterpret_cast<void*>(addr), test_page_size); + addr += test_page_size; + } + /* Try small number of page-sized objects aligned to exactly one page */ + addr = test_page_size*300; + for(int i=0; i<100; ++i) + { + lpm.LockRange(reinterpret_cast<void*>(addr), test_page_size); + addr += test_page_size; + } + /* one very large object, straddling pages */ + lpm.LockRange(reinterpret_cast<void*>(test_page_size*600+1), test_page_size*500); + BOOST_CHECK(last_lock_addr == reinterpret_cast<void*>(test_page_size*(600+500))); + /* one very large object, page aligned */ + lpm.LockRange(reinterpret_cast<void*>(test_page_size*1200), test_page_size*500-1); + BOOST_CHECK(last_lock_addr == reinterpret_cast<void*>(test_page_size*(1200+500-1))); + + BOOST_CHECK(lpm.GetLockedPageCount() == ( + (1000*33+test_page_size-1)/test_page_size + // small objects + 101 + 100 + // page-sized objects + 501 + 500)); // large objects + BOOST_CHECK((last_lock_len & (test_page_size-1)) == 0); // always lock entire pages + BOOST_CHECK(last_unlock_len == 0); // nothing unlocked yet + + /* And unlock again */ + addr = 0; + for(int i=0; i<1000; ++i) + { + lpm.UnlockRange(reinterpret_cast<void*>(addr), 33); + addr += 33; + } + addr = test_page_size*100 + 53; + for(int i=0; i<100; ++i) + { + lpm.UnlockRange(reinterpret_cast<void*>(addr), test_page_size); + addr += test_page_size; + } + addr = test_page_size*300; + for(int i=0; i<100; ++i) + { + lpm.UnlockRange(reinterpret_cast<void*>(addr), test_page_size); + addr += test_page_size; + } + lpm.UnlockRange(reinterpret_cast<void*>(test_page_size*600+1), test_page_size*500); + lpm.UnlockRange(reinterpret_cast<void*>(test_page_size*1200), test_page_size*500-1); + + /* Check that everything is released */ + BOOST_CHECK(lpm.GetLockedPageCount() == 0); + + /* A few and unlocks of size zero (should have no effect) */ + addr = 0; + for(int i=0; i<1000; ++i) + { + lpm.LockRange(reinterpret_cast<void*>(addr), 0); + addr += 1; + } + BOOST_CHECK(lpm.GetLockedPageCount() == 0); + addr = 0; + for(int i=0; i<1000; ++i) + { + lpm.UnlockRange(reinterpret_cast<void*>(addr), 0); + addr += 1; + } + BOOST_CHECK(lpm.GetLockedPageCount() == 0); + BOOST_CHECK((last_unlock_len & (test_page_size-1)) == 0); // always unlock entire pages +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/util.cpp b/src/util.cpp index d6d9a368f0..461f42d177 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -86,6 +86,8 @@ void locking_callback(int mode, int i, const char* file, int line) } } +LockedPageManager LockedPageManager::instance; + // Init class CInit { |