diff options
-rw-r--r-- | CMakeLists.txt | 42 | ||||
-rw-r--r-- | README.md | 13 | ||||
-rw-r--r-- | cmake/FindMiniupnpc.cmake | 185 | ||||
-rw-r--r-- | cmake/FindUnbound.cmake | 23 | ||||
-rwxr-xr-x | external/CMakeLists.txt | 314 | ||||
-rwxr-xr-x | external/unbound/monero-config.sh | 3 | ||||
-rw-r--r-- | src/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/common/dns_utils.cpp | 3 | ||||
-rw-r--r-- | src/crypto/slow-hash.c | 8 | ||||
-rw-r--r-- | src/cryptonote_core/checkpoints_create.cpp | 1 | ||||
-rw-r--r-- | src/rpc/core_rpc_server.cpp | 22 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 14 | ||||
-rw-r--r-- | tests/unit_tests/slow_memmem.cpp | 126 |
13 files changed, 500 insertions, 262 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e908e0dfe..78e4b426f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,13 +87,30 @@ else() endif() set(STATIC ${DEFAULT_STATIC} CACHE BOOL "Link libraries statically") +IF(STATIC) + IF(MSVC) + SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll.a .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + ELSE() + SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + ENDIF() +ENDIF() + if (UNIX AND NOT APPLE) # Note that at the time of this writing the -Wstrict-prototypes flag added below will make this fail find_package(Threads) endif() -# Find unbound - don't move this to the end, cmake is weird about this -find_package(Unbound REQUIRED) +add_subdirectory(external) + +# Final setup for miniupnpc +if(UPNP_STATIC) + add_definitions("-DUPNP_STATIC") +else() + add_definitions("-DUPNP_DYNAMIC") + include_directories(${UPNP_INCLUDE}) +endif() + +# Final setup for libunbound include_directories(${UNBOUND_INCLUDE}) if(MSVC) @@ -184,7 +201,7 @@ if(STATIC) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_RUNTIME ON) endif() -find_package(Boost 1.53 REQUIRED COMPONENTS system filesystem thread date_time chrono regex serialization program_options) +find_package(Boost 1.53 QUIET REQUIRED COMPONENTS system filesystem thread date_time chrono regex serialization program_options) if(NOT Boost_FOUND) MESSAGE(FATAL_ERROR "${BoldRed}Could not find Boost libraries, please make sure you have installed Boost or libboost-all-dev (1.53 or 1.55+) or the equivalent${ColourReset}") @@ -196,11 +213,14 @@ endif() include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) if(MINGW) - set(Boost_LIBRARIES "${Boost_LIBRARIES};pthread;mswsock;ws2_32") + set(EXTRA_LIBRARIES pthread;mswsock;ws2_32) elseif(APPLE OR FREEBSD) - set(Boost_LIBRARIES "${Boost_LIBRARIES}") + set(EXTRA_LIBRARIES "") elseif(NOT MSVC) - #set(Boost_LIBRARIES "${Boost_LIBRARIES};rt;pthread") + find_library(RT rt) + find_library(PTHREAD pthread) + find_library(DL dl) + set(EXTRA_LIBRARIES ${RT} ${PTHREAD} ${DL}) endif() file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/version") @@ -215,15 +235,5 @@ else() add_custom_target(version ALL) endif() -add_subdirectory(external) - -# Final setup for miniupnpc -if(UPNP_STATIC) - add_definitions("-DUPNP_STATIC") -else() - add_definitions("-DUPNP_DYNAMIC") - include_directories(${UPNP_INCLUDE}) -endif() - add_subdirectory(src) add_subdirectory(tests) @@ -51,11 +51,12 @@ Parts of the project are originally copyright (c) 2012-2013 The Cryptonote devel ### On Unix and Linux: Dependencies: GCC 4.7.3 or later, CMake 2.8.6 or later, libunbound 1.4.16 or later (note: Unbound is not a dependency, libunbound is), and Boost 1.53 or later (except 1.54, [more details here](http://goo.gl/RrCFmA)). +Static Build Additional Dependencies: ldns 1.6.17 or later, expat 1.1 or later, bison or yacc **Basic Process:** * To build, change to the root of the source code directory, and run `make`. -* The resulting executables can be found in build/release/src. +* The resulting executables can be found in `build/release/src` or `build/debug/src`, depending on what you're building. **Advanced options:** @@ -78,6 +79,7 @@ Alternatively, it can be built in an easier and more automated fashion using Hom ### On Windows: Dependencies: mingw-w64, msys2, CMake 2.8.6 or later, libunbound 1.4.16 or later (note: Unbound is not a dependency, libunbound is), and Boost 1.53 or 1.55 (except 1.54, [more details here](http://goo.gl/RrCFmA)). +Static Build Additional Dependencies: ldns 1.6.17 or later, expat 1.1 or later **Preparing the Build Environment** @@ -91,6 +93,7 @@ pacman -Su ``` * For those of you already familiar with pacman, you can run the normal `pacman -Syu` to update, but you may get errors and need to restart MSYS2 if pacman's dependencies are updated. * Install dependencies: `pacman -S mingw-w64-x86_64-gcc make mingw-w64-x86_64-cmake mingw-w64-x86_64-unbound mingw-w64-x86_64-boost` +* If you are planning to build statically you will also need to install: `pacman -S mingw-w64-x86_64-ldns mingw-w64-x86_64-expat` (note that these are likely already installed by the unbound dependency installation above) **Building** @@ -108,9 +111,17 @@ cmake -G "MSYS Makefiles" -D CMAKE_BUILD_TYPE=Release -D CMAKE_TOOLCHAIN_FILE=.. cmake -G "MSYS Makefiles" -D CMAKE_BUILD_TYPE=Release -D CMAKE_TOOLCHAIN_FILE=../cmake/32-bit-toolchain.cmake -D MSYS2_FOLDER=c:/msys32 .. ``` * You can now run `make` to have it build +* The resulting executables can be found in `build/release/src` or `build/debug/src`, depending on what you're building. If you installed MSYS2 in a folder other than c:/msys64, make the appropriate substitution above. +**Advanced options:** + +* Parallel build: run `make -j<number of threads>` instead of `make`. +* Statically linked release build: run `make release-static`. +* Debug build: run `make build-debug`. +* Test suite: run `make test-release` to run tests in addition to building. Running `make test-debug` will do the same to the debug version. + ### On FreeBSD: The project can be built from scratch by following instructions for Unix and Linux above. diff --git a/cmake/FindMiniupnpc.cmake b/cmake/FindMiniupnpc.cmake new file mode 100644 index 000000000..0bf331da2 --- /dev/null +++ b/cmake/FindMiniupnpc.cmake @@ -0,0 +1,185 @@ +# --------------------------------- FindMiniupnpc Start --------------------------------- +# Locate miniupnp library +# This module defines +# MINIUPNP_FOUND, if false, do not try to link to miniupnp +# MINIUPNP_LIBRARY, the miniupnp variant +# MINIUPNP_INCLUDE_DIR, where to find miniupnpc.h and family) +# MINIUPNPC_VERSION_PRE1_6 --> set if we detect the version of miniupnpc is +# pre 1.6 +# MINIUPNPC_VERSION_PRE1_5 --> set if we detect the version of miniupnpc is +# pre 1.5 +# +# Note that the expected include convention is +# #include "miniupnpc.h" +# and not +# #include <miniupnpc/miniupnpc.h> +# This is because, the miniupnpc location is not standardized and may exist +# in locations other than miniupnpc/ + +#============================================================================= +# Copyright 2011 Mark Vejvoda +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distributed this file outside of CMake, substitute the full +# License text for the above reference.) + +if (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY) + # Already in cache, be silent + set(MINIUPNP_FIND_QUIETLY TRUE) +endif (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY) + +find_path(MINIUPNP_INCLUDE_DIR miniupnpc.h + PATH_SUFFIXES miniupnpc) +find_library(MINIUPNP_LIBRARY miniupnpc) + +if (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY) + set (MINIUPNP_FOUND TRUE) +endif () + +if (MINIUPNP_FOUND) + include(CheckCXXSourceRuns) + if (NOT MINIUPNP_FIND_QUIETLY) + message (STATUS "Found the miniupnpc libraries at ${MINIUPNP_LIBRARY}") + message (STATUS "Found the miniupnpc headers at ${MINIUPNP_INCLUDE_DIR}") + endif (NOT MINIUPNP_FIND_QUIETLY) + + message(STATUS "Detecting version of miniupnpc in path: ${MINIUPNP_INCLUDE_DIR}") + + set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) + set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) + check_cxx_source_runs(" + #include <miniwget.h> + #include <miniupnpc.h> + #include <upnpcommands.h> + #include <stdio.h> + int main() + { + static struct UPNPUrls urls; + static struct IGDdatas data; + + GetUPNPUrls (&urls, &data, \"myurl\",0); + + return 0; + }" + MINIUPNPC_VERSION_1_7_OR_HIGHER) + +IF (NOT MINIUPNPC_VERSION_1_7_OR_HIGHER) + set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) + set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) + check_cxx_source_runs(" + #include <miniwget.h> + #include <miniupnpc.h> + #include <upnpcommands.h> + #include <stdio.h> + int main() + { + struct UPNPDev *devlist = NULL; + int upnp_delay = 5000; + const char *upnp_multicastif = NULL; + const char *upnp_minissdpdsock = NULL; + int upnp_sameport = 0; + int upnp_ipv6 = 0; + int upnp_error = 0; + devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport, upnp_ipv6, &upnp_error); + + return 0; + }" + MINIUPNPC_VERSION_PRE1_7) + ENDIF() + + IF (NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER) + set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) + set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) + check_cxx_source_runs(" + #include <miniwget.h> + #include <miniupnpc.h> + #include <upnpcommands.h> + #include <stdio.h> + int main() + { + struct UPNPDev *devlist = NULL; + int upnp_delay = 5000; + const char *upnp_multicastif = NULL; + const char *upnp_minissdpdsock = NULL; + int upnp_sameport = 0; + int upnp_ipv6 = 0; + int upnp_error = 0; + devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport); + + return 0; + }" + MINIUPNPC_VERSION_PRE1_6) + + ENDIF() + + IF (NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER) + set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) + set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) + check_cxx_source_runs(" + #include <miniwget.h> + #include <miniupnpc.h> + #include <upnpcommands.h> + #include <stdio.h> + static struct UPNPUrls urls; + static struct IGDdatas data; + int main() + { + char externalIP[16] = \"\"; + UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIP); + + return 0; + }" + MINIUPNPC_VERSION_1_5_OR_HIGHER) + ENDIF() + + IF (NOT MINIUPNPC_VERSION_1_5_OR_HIGHER AND NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER) + set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) + set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) + check_cxx_source_runs(" + #include <miniwget.h> + #include <miniupnpc.h> + #include <upnpcommands.h> + #include <stdio.h> + static struct UPNPUrls urls; + static struct IGDdatas data; + int main() + { + char externalIP[16] = \"\"; + UPNP_GetExternalIPAddress(urls.controlURL, data.servicetype, externalIP); + + return 0; + }" + MINIUPNPC_VERSION_PRE1_5) + +ENDIF() + +IF(MINIUPNPC_VERSION_PRE1_5) + message(STATUS "Found miniupnpc version is pre v1.5") +ENDIF() +IF(MINIUPNPC_VERSION_PRE1_6) + message(STATUS "Found miniupnpc version is pre v1.6") +ENDIF() +IF(MINIUPNPC_VERSION_PRE1_7) + message(STATUS "Found miniupnpc version is pre v1.7") +ENDIF() + +IF(NOT MINIUPNPC_VERSION_PRE1_5 AND NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7) + IF(MINIUPNPC_VERSION_1_5_OR_HIGHER) + message(STATUS "Found miniupnpc version is v1.5 or higher") + ELSE() + message(STATUS "Found miniupnpc version is v1.7 or higher") + ENDIF() +ENDIF() + +else () + message (STATUS "Could not find miniupnp") +endif () + +MARK_AS_ADVANCED(MINIUPNP_INCLUDE_DIR MINIUPNP_LIBRARY) +# --------------------------------- FindMiniupnpc End ---------------------------------
\ No newline at end of file diff --git a/cmake/FindUnbound.cmake b/cmake/FindUnbound.cmake index 032bcf45e..9728cd2f0 100644 --- a/cmake/FindUnbound.cmake +++ b/cmake/FindUnbound.cmake @@ -37,25 +37,4 @@ FIND_PATH(UNBOUND_INCLUDE_DIR /usr/ ) -if(STATIC) - if(MINGW) - find_library(UNBOUND_LIBRARIES libunbound.dll.a) - else() - find_library(UNBOUND_LIBRARIES libunbound.a) - endif() -else() - find_library(UNBOUND_LIBRARIES unbound) -endif() - -IF(UNBOUND_INCLUDE_DIR) - MESSAGE(STATUS "Found libunbound include (unbound.h) in ${UNBOUND_INCLUDE_DIR}") - IF(UNBOUND_LIBRARIES) - MESSAGE(STATUS "Found libunbound library") - set(UNBOUND_INCLUDE ${UNBOUND_INCLUDE_DIR}) - set(UNBOUND_LIBRARY ${UNBOUND_LIBRARIES}) - ELSE() - MESSAGE(FATAL_ERROR "${BoldRed}Could not find libunbound library, please make sure you have installed libunbound or libunbound-dev or the equivalent${ColourReset}") - ENDIF() -ELSE() - MESSAGE(FATAL_ERROR "${BoldRed}Could not find libunbound library, please make sure you have installed libunbound or libunbound-dev or the equivalent${ColourReset}") -ENDIF() +find_library(UNBOUND_LIBRARIES unbound) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index f121162df..83e9e6dee 100755 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -28,216 +28,38 @@ # # Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers -# --------------------------------- FindMiniupnpc Start --------------------------------- -# Locate miniupnp library -# This module defines -# MINIUPNP_FOUND, if false, do not try to link to miniupnp -# MINIUPNP_LIBRARY, the miniupnp variant -# MINIUPNP_INCLUDE_DIR, where to find miniupnpc.h and family) -# MINIUPNPC_VERSION_PRE1_6 --> set if we detect the version of miniupnpc is -# pre 1.6 -# MINIUPNPC_VERSION_PRE1_5 --> set if we detect the version of miniupnpc is -# pre 1.5 -# -# Note that the expected include convention is -# #include "miniupnpc.h" -# and not -# #include <miniupnpc/miniupnpc.h> -# This is because, the miniupnpc location is not standardized and may exist -# in locations other than miniupnpc/ -#============================================================================= -# Copyright 2011 Mark Vejvoda -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distributed this file outside of CMake, substitute the full -# License text for the above reference.) +# This is broken up into two parts: first we check for miniupnp, compile it if we can't +# find it, and thereafter we check for libunbound, and compile it if we can't find it. +# We always compile if we are building statically to reduce static dependency issues... +# ...except for FreeBSD, because FreeBSD is a special case that doesn't play well with +# others. -if (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY) - # Already in cache, be silent - set(MINIUPNP_FIND_QUIETLY TRUE) -endif (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY) +find_package(MiniUpnpc QUIET) -find_path(MINIUPNP_INCLUDE_DIR miniupnpc.h - PATH_SUFFIXES miniupnpc) -find_library(MINIUPNP_LIBRARY miniupnpc) - -if (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY) - set (MINIUPNP_FOUND TRUE) -endif () - -if (MINIUPNP_FOUND) - include(CheckCXXSourceRuns) - if (NOT MINIUPNP_FIND_QUIETLY) - message (STATUS "Found the miniupnpc libraries at ${MINIUPNP_LIBRARY}") - message (STATUS "Found the miniupnpc headers at ${MINIUPNP_INCLUDE_DIR}") - endif (NOT MINIUPNP_FIND_QUIETLY) - - message(STATUS "Detecting version of miniupnpc in path: ${MINIUPNP_INCLUDE_DIR}") - - set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) - set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) - check_cxx_source_runs(" - #include <miniwget.h> - #include <miniupnpc.h> - #include <upnpcommands.h> - #include <stdio.h> - int main() - { - static struct UPNPUrls urls; - static struct IGDdatas data; - - GetUPNPUrls (&urls, &data, \"myurl\",0); - - return 0; - }" - MINIUPNPC_VERSION_1_7_OR_HIGHER) - -IF (NOT MINIUPNPC_VERSION_1_7_OR_HIGHER) - set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) - set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) - check_cxx_source_runs(" - #include <miniwget.h> - #include <miniupnpc.h> - #include <upnpcommands.h> - #include <stdio.h> - int main() - { - struct UPNPDev *devlist = NULL; - int upnp_delay = 5000; - const char *upnp_multicastif = NULL; - const char *upnp_minissdpdsock = NULL; - int upnp_sameport = 0; - int upnp_ipv6 = 0; - int upnp_error = 0; - devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport, upnp_ipv6, &upnp_error); - - return 0; - }" - MINIUPNPC_VERSION_PRE1_7) - ENDIF() - - IF (NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER) - set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) - set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) - check_cxx_source_runs(" - #include <miniwget.h> - #include <miniupnpc.h> - #include <upnpcommands.h> - #include <stdio.h> - int main() - { - struct UPNPDev *devlist = NULL; - int upnp_delay = 5000; - const char *upnp_multicastif = NULL; - const char *upnp_minissdpdsock = NULL; - int upnp_sameport = 0; - int upnp_ipv6 = 0; - int upnp_error = 0; - devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport); - - return 0; - }" - MINIUPNPC_VERSION_PRE1_6) - - ENDIF() - - IF (NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER) - set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) - set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) - check_cxx_source_runs(" - #include <miniwget.h> - #include <miniupnpc.h> - #include <upnpcommands.h> - #include <stdio.h> - static struct UPNPUrls urls; - static struct IGDdatas data; - int main() - { - char externalIP[16] = \"\"; - UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIP); - - return 0; - }" - MINIUPNPC_VERSION_1_5_OR_HIGHER) - ENDIF() - - IF (NOT MINIUPNPC_VERSION_1_5_OR_HIGHER AND NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER) - set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) - set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) - check_cxx_source_runs(" - #include <miniwget.h> - #include <miniupnpc.h> - #include <upnpcommands.h> - #include <stdio.h> - static struct UPNPUrls urls; - static struct IGDdatas data; - int main() - { - char externalIP[16] = \"\"; - UPNP_GetExternalIPAddress(urls.controlURL, data.servicetype, externalIP); - - return 0; - }" - MINIUPNPC_VERSION_PRE1_5) - -ENDIF() - -IF(MINIUPNPC_VERSION_PRE1_5) - message(STATUS "Found miniupnpc version is pre v1.5") -ENDIF() -IF(MINIUPNPC_VERSION_PRE1_6) - message(STATUS "Found miniupnpc version is pre v1.6") -ENDIF() -IF(MINIUPNPC_VERSION_PRE1_7) - message(STATUS "Found miniupnpc version is pre v1.7") -ENDIF() - -IF(NOT MINIUPNPC_VERSION_PRE1_5 AND NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7) - IF(MINIUPNPC_VERSION_1_5_OR_HIGHER) - message(STATUS "Found miniupnpc version is v1.5 or higher") - ELSE() - message(STATUS "Found miniupnpc version is v1.7 or higher") - ENDIF() -ENDIF() - -else () - message (STATUS "Could not find miniupnp") -endif () - -MARK_AS_ADVANCED(MINIUPNP_INCLUDE_DIR MINIUPNP_LIBRARY) -# --------------------------------- FindMiniupnpc End --------------------------------- - -# And now on to the Monero part of things - -# FreeBSD doesn't play well with the local copy -SET(USE_SHARED false) +# FreeBSD doesn't play well with the local copy, so default to using shared +SET(USE_SHARED_MINIUPNPC false) # If we have the correct shared version and we're not building static, use it -IF(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER AND !STATIC) - SET(USE_SHARED true) +IF(STATIC) + SET(USE_SHARED_MINIUPNPC false) +ELSEIF(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER) + SET(USE_SHARED_MINIUPNPC true) ENDIF() -# If we're on FreeBSD -IF(FREEBSD) - SET(USE_SHARED true) -ENDIF() - -if(USE_SHARED) +if(USE_SHARED_MINIUPNPC) message(STATUS "Using shared miniupnpc found at ${MINIUPNP_INCLUDE_DIR}") set(UPNP_STATIC false PARENT_SCOPE) set(UPNP_INCLUDE ${MINIUPNP_INCLUDE_DIR} PARENT_SCOPE) set(UPNP_LIBRARIES ${MINIUPNP_LIBRARY} PARENT_SCOPE) else() - message(STATUS "Using static miniupnpc from external") - + if(STATIC) + message(STATUS "Using miniupnpc from local source tree for static build") + else() + message(STATUS "Using miniupnpc from local source tree (/external/miniupnpc)") + endif() + set(UPNPC_BUILD_STATIC ON CACHE BOOL "Build static library") set(UPNPC_BUILD_SHARED OFF CACHE BOOL "Build shared library") set(UPNPC_BUILD_TESTS OFF CACHE BOOL "Build test executables") @@ -253,3 +75,101 @@ else() set(UPNP_STATIC true PARENT_SCOPE) set(UPNP_LIBRARIES "upnpc-static" PARENT_SCOPE) endif() + +find_package(Unbound) + +IF(!UNBOUND_INCLUDE_DIR OR STATIC) + if(STATIC) + message(STATUS "Using libunbound from local source tree for static build") + else() + message(STATUS "Using libunbound from local source tree (/external/unbound)") + endif() + + INCLUDE(ExternalProject) + + FIND_PACKAGE(OpenSSL QUIET) + IF(!OPENSSL_LIBRARIES) + MESSAGE(FATAL_ERROR "${BoldRed}Could not find the openssl library. Please make sure you have installed openssl or libssl-dev or the equivalent${ColourReset}") + ELSE() + MESSAGE(STATUS "Found openssl libraries") + ENDIF() + + FIND_PACKAGE(Expat QUIET) + IF(!EXPAT_LIBRARIES) + MESSAGE(FATAL_ERROR "${BoldRed}Could not find the expat library. Please make sure you have installed libexpat or libexpat-dev or the equivalent${ColourReset}") + ELSE() + MESSAGE(STATUS "Found expat libraries") + ENDIF() + + IF(MINGW) + set(ENV{USE_WINSOCK} 1) + set(ENV{CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) + set(ENV{GCC_PREFIX} ${GCC_PREFIX}) + set(ENV{CMAKE_FIND_ROOT_PATH} ${CMAKE_FIND_ROOT_PATH}) + EXTERNALPROJECT_ADD( + libunbound + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/unbound + URL ${CMAKE_CURRENT_SOURCE_DIR}/unbound/ + CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/unbound/monero-config.sh + BUILD_COMMAND $(MAKE) + UPDATE_COMMAND "" + PATCH_COMMAND "" + INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libtool --mode=install cp ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libunbound.la ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build + LOG_DOWNLOAD 1 + LOG_UPDATE 1 + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_TEST 1 + LOG_INSTALL 1 + ) + ELSEIF(APPLE) + execute_process(COMMAND brew --prefix OUTPUT_VARIABLE BREW_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE) + EXTERNALPROJECT_ADD( + libunbound + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/unbound + URL ${CMAKE_CURRENT_SOURCE_DIR}/unbound/ + CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/unbound/configure --prefix=${BREW_PREFIX} --enable-shared --enable-static --disable-gost --disable-rpath --with-libevent=no --without-pyunbound --without-pythonmodule --without-pthreads --with-libunbound-only + BUILD_COMMAND $(MAKE) + UPDATE_COMMAND "" + PATCH_COMMAND "" + INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libtool --mode=install cp ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libunbound.la ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build + LOG_DOWNLOAD 1 + LOG_UPDATE 1 + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_TEST 1 + LOG_INSTALL 1 + ) + ELSE() + EXTERNALPROJECT_ADD( + libunbound + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/unbound + URL ${CMAKE_CURRENT_SOURCE_DIR}/unbound/ + CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/unbound/configure --disable-shared --enable-static --disable-gost --disable-rpath --with-libevent=no --without-pyunbound --without-pythonmodule --without-pthreads --with-libunbound-only + BUILD_COMMAND $(MAKE) + UPDATE_COMMAND "" + PATCH_COMMAND "" + INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libtool --mode=install cp ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libunbound.la ${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build + LOG_DOWNLOAD 1 + LOG_UPDATE 1 + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_TEST 1 + LOG_INSTALL 1 + ) + ENDIF() + + set(UNBOUND_STATIC true PARENT_SCOPE) + set(UNBOUND_INCLUDE "${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build" PARENT_SCOPE) + set(UNBOUND_LIBRARY "${CMAKE_CURRENT_BINARY_DIR}/unbound/src/libunbound-build/libunbound.a;${OPENSSL_LIBRARIES}" PARENT_SCOPE) +ELSE() + MESSAGE(STATUS "Found libunbound include (unbound.h) in ${UNBOUND_INCLUDE_DIR}") + IF(UNBOUND_LIBRARIES) + MESSAGE(STATUS "Found libunbound shared library") + set(UNBOUND_STATIC false PARENT_SCOPE) + set(UNBOUND_INCLUDE ${UNBOUND_INCLUDE_DIR} PARENT_SCOPE) + set(UNBOUND_LIBRARY ${UNBOUND_LIBRARIES} PARENT_SCOPE) + ELSE() + MESSAGE(FATAL_ERROR "${BoldRed}Found libunbound includes, but could not find libunbound library. Please make sure you have installed libunbound or libunbound-dev or the equivalent${ColourReset}") + ENDIF() +ENDIF() diff --git a/external/unbound/monero-config.sh b/external/unbound/monero-config.sh new file mode 100755 index 000000000..cfdc7e04b --- /dev/null +++ b/external/unbound/monero-config.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +./configure --prefix=${CMAKE_FIND_ROOT_PATH} --build=${GCC_PREFIX} --host=${GCC_PREFIX} --disable-shared --enable-static --sysconfdir=${CMAKE_FIND_ROOT_PATH}/etc --localstatedir=${CMAKE_FIND_ROOT_PATH}/var --sbindir=${CMAKE_FIND_ROOT_PATH}/bin --disable-gost --disable-rpath --with-libevent=no --with-libexpat=${CMAKE_FIND_ROOT_PATH} --without-pyunbound --without-pythonmodule --with-ssl=${CMAKE_FIND_ROOT_PATH} --without-pthreads --with-libunbound-only diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2393213cb..321d0555b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,14 +63,14 @@ add_library(mnemonics ${MNEMONICS}) add_executable(daemon ${DAEMON} ${P2P} ${CRYPTONOTE_PROTOCOL}) add_executable(connectivity_tool ${CONN_TOOL}) add_executable(simpleminer ${MINER}) -target_link_libraries(daemon rpc cryptonote_core crypto common ${UNBOUND_LIBRARIES} ${UPNP_LIBRARIES} ${Boost_LIBRARIES}) -target_link_libraries(connectivity_tool cryptonote_core crypto common ${UNBOUND_LIBRARIES} ${Boost_LIBRARIES}) -target_link_libraries(simpleminer cryptonote_core crypto common ${UNBOUND_LIBRARIES} ${Boost_LIBRARIES}) +target_link_libraries(daemon rpc cryptonote_core crypto common ${UNBOUND_LIBRARY} ${UPNP_LIBRARIES} ${Boost_LIBRARIES} ${EXTRA_LIBRARIES}) +target_link_libraries(connectivity_tool cryptonote_core crypto common ${UNBOUND_LIBRARY} ${Boost_LIBRARIES} ${EXTRA_LIBRARIES}) +target_link_libraries(simpleminer cryptonote_core crypto common ${UNBOUND_LIBRARY} ${Boost_LIBRARIES} ${EXTRA_LIBRARIES}) add_library(rpc ${RPC}) add_library(wallet ${WALLET}) target_link_libraries(wallet mnemonics) add_executable(simplewallet ${SIMPLEWALLET} ) -target_link_libraries(simplewallet wallet rpc cryptonote_core crypto common mnemonics ${UNBOUND_LIBRARIES} ${UPNP_LIBRARIES} ${Boost_LIBRARIES}) +target_link_libraries(simplewallet wallet rpc cryptonote_core crypto common mnemonics ${UNBOUND_LIBRARY} ${UPNP_LIBRARIES} ${Boost_LIBRARIES} ${EXTRA_LIBRARIES}) add_dependencies(daemon version) add_dependencies(rpc version) add_dependencies(simplewallet version) diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 8c4038568..d21b538a6 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -29,7 +29,8 @@ #include "common/dns_utils.h" #include <cstring> #include <sstream> -#include <unbound.h> +// check local first (in the event of static or in-source compilation of libunbound) +#include "unbound.h" #include <stdlib.h> #include "include_base_utils.h" diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c index ec356d53b..787545830 100644 --- a/src/crypto/slow-hash.c +++ b/src/crypto/slow-hash.c @@ -105,7 +105,7 @@ _a = _mm_load_si128(R128(a)); \ /* - * An SSE-optimized implementation of the second half of CryptoNote step 3. + * An SSE-optimized implementation of the second half of CryptoNight step 3. * After using AES to mix a scratchpad value into _c (done by the caller), * this macro xors it with _b and stores the result back to the same index (j) that it * loaded the scratchpad value from. It then performs a second random memory @@ -281,7 +281,7 @@ STATIC INLINE void aes_expand_key(const uint8_t *key, uint8_t *expandedKey) ek[10] = t1; } -/* +/** * @brief a "pseudo" round of AES (similar to but slightly different from normal AES encryption) * * To fill its 2MB scratch buffer, CryptoNight uses a nonstandard implementation @@ -323,7 +323,7 @@ STATIC INLINE void aes_pseudo_round(const uint8_t *in, uint8_t *out, } } -/* +/** * @brief aes_pseudo_round that loads data from *in and xors it with *xor first * * This function performs the same operations as aes_pseudo_round, but before @@ -522,7 +522,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash) hash_process(&state.hs, data, length); memcpy(text, state.init, INIT_SIZE_BYTE); - /* CryptoNight Step 2: Iteratively encrypt the results from keccak to fill + /* CryptoNight Step 2: Iteratively encrypt the results from Keccak to fill * the 2MB large random access buffer. */ diff --git a/src/cryptonote_core/checkpoints_create.cpp b/src/cryptonote_core/checkpoints_create.cpp index 4ac2f0e5b..9ad0a27e8 100644 --- a/src/cryptonote_core/checkpoints_create.cpp +++ b/src/cryptonote_core/checkpoints_create.cpp @@ -75,6 +75,7 @@ bool create_checkpoints(cryptonote::checkpoints& checkpoints) ADD_CHECKPOINT(230700, "93e631240ceac831da1aebfc5dac8f722c430463024763ebafa888796ceaeedf"); ADD_CHECKPOINT(231350, "b5add137199b820e1ea26640e5c3e121fd85faa86a1e39cf7e6cc097bdeb1131"); ADD_CHECKPOINT(232150, "955de8e6b6508af2c24f7334f97beeea651d78e9ade3ab18fec3763be3201aa8"); + ADD_CHECKPOINT(249380, "654fb0a81ce3e5caf7e3264a70f447d4bd07586c08fa50f6638cc54da0a52b2d"); return true; } diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index e80451cda..036cb64ff 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -111,7 +111,7 @@ namespace cryptonote } return true; } -#define CHECK_CORE_BUSY() if(!check_core_busy()){res.status = CORE_RPC_STATUS_BUSY;return true;} +#define CHECK_CORE_BUSY() do { if(!check_core_busy()){res.status = CORE_RPC_STATUS_BUSY;return true;} } while(0) //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::check_core_ready() { @@ -121,7 +121,7 @@ namespace cryptonote } return check_core_busy(); } -#define CHECK_CORE_READY() if(!check_core_ready()){res.status = CORE_RPC_STATUS_BUSY;return true;} +#define CHECK_CORE_READY() do { if(!check_core_ready()){res.status = CORE_RPC_STATUS_BUSY;return true;} } while(0) //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_get_height(const COMMAND_RPC_GET_HEIGHT::request& req, COMMAND_RPC_GET_HEIGHT::response& res, connection_context& cntx) @@ -398,17 +398,19 @@ namespace cryptonote return true; } //------------------------------------------------------------------------------------------------------------------------------ - uint64_t slow_memmem(void* start_buff, size_t buflen,void* pat,size_t patlen) + // equivalent of strstr, but with arbitrary bytes (ie, NULs) + // This does not differentiate between "not found" and "found at offset 0" + uint64_t slow_memmem(const void* start_buff, size_t buflen,const void* pat,size_t patlen) { - void* buf = start_buff; - void* end=(char*)buf+buflen-patlen; - while((buf=memchr(buf,((char*)pat)[0],buflen))) + const void* buf = start_buff; + const void* end=(const char*)buf+buflen; + if (patlen > buflen || patlen == 0) return 0; + while(buflen>0 && (buf=memchr(buf,((const char*)pat)[0],buflen-patlen+1))) { - if(buf>end) - return 0; if(memcmp(buf,pat,patlen)==0) - return (char*)buf - (char*)start_buff; - buf=(char*)buf+1; + return (const char*)buf - (const char*)start_buff; + buf=(const char*)buf+1; + buflen = (const char*)end - (const char*)buf; } return 0; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 14695ddd8..d663df0d9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -61,16 +61,16 @@ add_executable(unit_tests ${UNIT_TESTS}) add_executable(net_load_tests_clt net_load_tests/clt.cpp) add_executable(net_load_tests_srv net_load_tests/srv.cpp) -target_link_libraries(core_proxy cryptonote_core common crypto ${UNBOUND_LIBRARIES} ${UPNP_LIBRARIES} ${Boost_LIBRARIES}) -target_link_libraries(coretests cryptonote_core common crypto ${UNBOUND_LIBRARIES} ${Boost_LIBRARIES}) +target_link_libraries(core_proxy cryptonote_core common crypto ${UNBOUND_LIBRARY} ${UPNP_LIBRARIES} ${Boost_LIBRARIES} ${EXTRA_LIBRARIES}) +target_link_libraries(coretests cryptonote_core common crypto ${UNBOUND_LIBRARY} ${Boost_LIBRARIES} ${EXTRA_LIBRARIES}) target_link_libraries(difficulty-tests cryptonote_core) -target_link_libraries(functional_tests cryptonote_core wallet common crypto ${UNBOUND_LIBRARIES} ${Boost_LIBRARIES}) +target_link_libraries(functional_tests cryptonote_core wallet common crypto ${UNBOUND_LIBRARY} ${Boost_LIBRARIES} ${EXTRA_LIBRARIES}) target_link_libraries(hash-tests crypto) target_link_libraries(hash-target-tests crypto cryptonote_core) -target_link_libraries(performance_tests cryptonote_core common crypto ${UNBOUND_LIBRARIES} ${Boost_LIBRARIES}) -target_link_libraries(unit_tests gtest_main cryptonote_core wallet crypto common ${UNBOUND_LIBRARIES} ${Boost_LIBRARIES}) -target_link_libraries(net_load_tests_clt cryptonote_core common crypto gtest_main ${UNBOUND_LIBRARIES} ${Boost_LIBRARIES}) -target_link_libraries(net_load_tests_srv cryptonote_core common crypto gtest_main ${UNBOUND_LIBRARIES} ${Boost_LIBRARIES}) +target_link_libraries(performance_tests cryptonote_core common crypto ${UNBOUND_LIBRARY} ${Boost_LIBRARIES} ${EXTRA_LIBRARIES}) +target_link_libraries(unit_tests gtest_main rpc cryptonote_core wallet crypto common ${UNBOUND_LIBRARY} ${Boost_LIBRARIES} ${EXTRA_LIBRARIES}) +target_link_libraries(net_load_tests_clt cryptonote_core common crypto gtest_main ${UNBOUND_LIBRARY} ${Boost_LIBRARIES} ${EXTRA_LIBRARIES}) +target_link_libraries(net_load_tests_srv cryptonote_core common crypto gtest_main ${UNBOUND_LIBRARY} ${Boost_LIBRARIES} ${EXTRA_LIBRARIES}) if(NOT MSVC) set_property(TARGET gtest gtest_main unit_tests net_load_tests_clt net_load_tests_srv APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-sign-compare") diff --git a/tests/unit_tests/slow_memmem.cpp b/tests/unit_tests/slow_memmem.cpp new file mode 100644 index 000000000..b1a7622b2 --- /dev/null +++ b/tests/unit_tests/slow_memmem.cpp @@ -0,0 +1,126 @@ +// Copyright (c) 2014, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. 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. +// +// 3. Neither the name of the copyright holder 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 HOLDER 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. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <stdint.h> +#include <malloc.h> +#include "gtest/gtest.h" + +//#define TEST_ORIGINAL +//#define VERBOSE + +#ifdef TEST_ORIGINAL +uint64_t slow_memmem_original(void* start_buff, size_t buflen,void* pat,size_t patlen) +{ + void* buf = start_buff; + void* end=(char*)buf+buflen-patlen; + while((buf=memchr(buf,((char*)pat)[0],buflen))) + { + if(buf>end) + return 0; + if(memcmp(buf,pat,patlen)==0) + return (char*)buf - (char*)start_buff; + buf=(char*)buf+1; + } + return 0; +} + +#define slow_memmem slow_memmem_original +#else +namespace cryptonote { + uint64_t slow_memmem(const void* start_buff, size_t buflen,const void* pat,size_t patlen); +} +using namespace cryptonote; +#endif + +static const struct { + size_t buflen; + const char *buf; + size_t patlen; + const char *pat; + uint64_t res; +} T[]={ + {0,"",0,"",0}, + {1,"",0,"",0}, + {0,"",1,"",0}, + {1,"x",1,"x",0}, + {2,"x",1,"",1}, + {1,"x",1,"",0}, + {1,"x",2,"",0}, + {1,"x",2,"x",0}, + {2,"ax",2,"x",0}, + {1,"xx",2,"xx",0}, + {4,"abcd",3,"abc",0}, + {4,"abcd",3,"bcd",1}, + {4,"abcd",4,"abcd",0}, + {4,"abcd",1,"d",3}, + {4,"abcd",1,"c",2}, + {4,"abcd",1,"bc",1}, + {4,"abcd",1,"",0}, + {3,"abcd",1,"d",0}, + {5,"aaaab",2,"ab",3}, + {7,"aaaabab",2,"ab",3}, + {7,"aaaabab",3,"abc",0}, + {4,"abcd",2,"cd",2}, + {3,"abcd",2,"cd",0}, + {3,"a\0b",1,"",1}, + {3,"a\0b",2,"\0b",1}, + {8,"xxxxxxab",3,"xyz",0}, + {8,"xxxxxxab",6,"abcdef",0}, + {9,"\0xxxxxab",3,"ab",6}, + {4,"\0\0a",3,"\0a",1}, +}; + +TEST(slowmem,Success) +{ + size_t n; + for (n=0;n<sizeof(T)/sizeof(T[0]);++n) { +#ifdef VERBOSE + printf("%3zu: ",n); + fflush(stdout); +#endif + void *buf=malloc(T[n].buflen); + memcpy(buf,T[n].buf,T[n].buflen); + void *pat=malloc(T[n].patlen); + memcpy(pat,T[n].pat,T[n].patlen); + uint64_t res=slow_memmem(buf,T[n].buflen,pat,T[n].patlen); + free(pat); + free(buf); + ASSERT_EQ(res,T[n].res); +ASSERT_EQ(1,1); +#ifdef VERBOSE + if (res!=T[n].res) printf("failed (got %zu, expected %zu)",res,T[n].res); else printf("ok"); + printf("\n"); +#endif + } +} |