Add noexcept
authorMilian Wolff <mail@milianw.de>
Wed, 10 Dec 2014 18:30:29 +0000 (19:30 +0100)
committerMilian Wolff <mail@milianw.de>
Wed, 10 Dec 2014 18:30:29 +0000 (19:30 +0100)
heaptrack_inject.cpp
heaptrack_preload.cpp

index 720efd9..fbdbb6f 100644 (file)
@@ -35,7 +35,7 @@
 
 namespace {
 
-void overwrite_symbols();
+void overwrite_symbols() noexcept;
 
 namespace hooks {
 
@@ -44,7 +44,7 @@ struct malloc
     static constexpr auto name = "malloc";
     static constexpr auto original = &::malloc;
 
-    static void* hook(size_t size)
+    static void* hook(size_t size) noexcept
     {
         auto ptr = original(size);
         heaptrack_malloc(ptr, size);
@@ -57,7 +57,7 @@ struct free
     static constexpr auto name = "free";
     static constexpr auto original = &::free;
 
-    static void hook(void *ptr)
+    static void hook(void *ptr) noexcept
     {
         heaptrack_free(ptr);
         original(ptr);
@@ -69,7 +69,7 @@ struct realloc
     static constexpr auto name = "realloc";
     static constexpr auto original = &::realloc;
 
-    static void* hook(void *ptr, size_t size)
+    static void* hook(void *ptr, size_t size) noexcept
     {
         auto ret = original(ptr, size);
         heaptrack_realloc(ptr, size, ret);
@@ -82,7 +82,7 @@ struct calloc
     static constexpr auto name = "calloc";
     static constexpr auto original = &::calloc;
 
-    static void* hook(size_t num, size_t size)
+    static void* hook(size_t num, size_t size) noexcept
     {
         auto ptr = original(num, size);
         heaptrack_malloc(ptr, num * size);
@@ -95,7 +95,7 @@ struct cfree
     static constexpr auto name = "cfree";
     static constexpr auto original = &::cfree;
 
-    static void hook(void *ptr)
+    static void hook(void *ptr) noexcept
     {
         heaptrack_free(ptr);
         original(ptr);
@@ -107,7 +107,7 @@ struct dlopen
     static constexpr auto name = "dlopen";
     static constexpr auto original = &::dlopen;
 
-    static void* hook(const char *filename, int flag)
+    static void* hook(const char *filename, int flag) noexcept
     {
         auto ret = original(filename, flag);
         if (ret) {
@@ -123,7 +123,7 @@ struct dlclose
     static constexpr auto name = "dlclose";
     static constexpr auto original = &::dlclose;
 
-    static int hook(void *handle)
+    static int hook(void *handle) noexcept
     {
         auto ret = original(handle);
         if (!ret) {
@@ -138,7 +138,7 @@ struct posix_memalign
     static constexpr auto name = "posix_memalign";
     static constexpr auto original = &::posix_memalign;
 
-    static int hook(void **memptr, size_t alignment, size_t size)
+    static int hook(void **memptr, size_t alignment, size_t size) noexcept
     {
         auto ret = original(memptr, alignment, size);
         if (!ret) {
@@ -155,7 +155,7 @@ struct hook
     void* originalAddress;
 
     template<typename Hook>
-    static constexpr hook wrap()
+    static constexpr hook wrap() noexcept
     {
         static_assert(sizeof(&Hook::hook) == sizeof(void*), "Mismatched pointer sizes");
         static_assert(std::is_convertible<decltype(&Hook::hook), decltype(Hook::original)>::value,
@@ -184,7 +184,7 @@ struct elftable
     T* table = nullptr;
     ElfW(Xword) size = ElfW(Xword)();
 
-    bool consume(const ElfW(Dyn) *dyn)
+    bool consume(const ElfW(Dyn) *dyn) noexcept
     {
         if (dyn->d_tag == AddrTag) {
             table = reinterpret_cast<T*>(dyn->d_un.d_ptr);
@@ -201,7 +201,7 @@ using elf_string_table = elftable<const char, DT_STRTAB, DT_STRSZ>;
 using elf_jmprel_table = elftable<ElfW(Rela), DT_JMPREL, DT_PLTRELSZ>;
 using elf_symbol_table = elftable<ElfW(Sym), DT_SYMTAB, DT_SYMENT>;
 
-void try_overwrite_symbols(const ElfW(Dyn) *dyn, const ElfW(Addr) base, const bool restore)
+void try_overwrite_symbols(const ElfW(Dyn) *dyn, const ElfW(Addr) base, const bool restore) noexcept
 {
     elf_symbol_table symbols;
     elf_jmprel_table jmprels;
@@ -235,7 +235,7 @@ void try_overwrite_symbols(const ElfW(Dyn) *dyn, const ElfW(Addr) base, const bo
     }
 }
 
-int iterate_phdrs(dl_phdr_info *info, size_t /*size*/, void *data)
+int iterate_phdrs(dl_phdr_info *info, size_t /*size*/, void *data) noexcept
 {
     if (strstr(info->dlpi_name, "/libheaptrack_inject.so")) {
         // prevent infinite recursion: do not overwrite our own symbols
@@ -251,7 +251,7 @@ int iterate_phdrs(dl_phdr_info *info, size_t /*size*/, void *data)
     return 0;
 }
 
-void overwrite_symbols()
+void overwrite_symbols() noexcept
 {
     dl_iterate_phdr(&iterate_phdrs, nullptr);
 }
@@ -260,7 +260,7 @@ void overwrite_symbols()
 
 extern "C" {
 
-void heaptrack_inject(const char *outputFileName)
+void heaptrack_inject(const char *outputFileName) noexcept
 {
     heaptrack_init(outputFileName, [] () {
         overwrite_symbols();
index 6d3eb17..c774ab1 100644 (file)
@@ -39,7 +39,7 @@ struct hook
     using Signature = SignatureT*;
     Signature original = nullptr;
 
-    void init()
+    void init() noexcept
     {
         auto ret = dlsym(RTLD_NEXT, Base::identifier);
         if (!ret) {
@@ -50,12 +50,12 @@ struct hook
     }
 
     template<typename... Args>
-    auto operator() (Args... args) const -> decltype(original(args...))
+    auto operator() (Args... args) const noexcept -> decltype(original(args...))
     {
         return original(args...);
     }
 
-    explicit operator bool () const
+    explicit operator bool () const noexcept
     {
         return original;
     }
@@ -80,7 +80,7 @@ HOOK(dlclose);
  *
  * This is only called at startup and will eventually be replaced by the "proper" calloc implementation.
  */
-void* dummy_calloc(size_t num, size_t size)
+void* dummy_calloc(size_t num, size_t size) noexcept
 {
     const size_t MAX_SIZE = 1024;
     static char* buf[MAX_SIZE];
@@ -126,7 +126,7 @@ extern "C" {
 
 /// TODO: memalign, pvalloc, ...?
 
-void* malloc(size_t size) throw()
+void* malloc(size_t size) noexcept
 {
     if (!hooks::malloc) {
         hooks::init();
@@ -137,7 +137,7 @@ void* malloc(size_t size) throw()
     return ptr;
 }
 
-void free(void* ptr) throw()
+void free(void* ptr) noexcept
 {
     if (!hooks::free) {
         hooks::init();
@@ -151,7 +151,7 @@ void free(void* ptr) throw()
     hooks::free(ptr);
 }
 
-void* realloc(void* ptr, size_t size) throw()
+void* realloc(void* ptr, size_t size) noexcept
 {
     if (!hooks::realloc) {
         hooks::init();
@@ -166,7 +166,7 @@ void* realloc(void* ptr, size_t size) throw()
     return ret;
 }
 
-void* calloc(size_t num, size_t size) throw()
+void* calloc(size_t num, size_t size) noexcept
 {
     if (!hooks::calloc) {
         hooks::init();
@@ -181,7 +181,7 @@ void* calloc(size_t num, size_t size) throw()
     return ret;
 }
 
-void cfree(void* ptr) throw()
+void cfree(void* ptr) noexcept
 {
     if (!hooks::cfree) {
         hooks::init();
@@ -197,7 +197,7 @@ void cfree(void* ptr) throw()
     hooks::cfree(ptr);
 }
 
-int posix_memalign(void **memptr, size_t alignment, size_t size) throw()
+int posix_memalign(void **memptr, size_t alignment, size_t size) noexcept
 {
     if (!hooks::posix_memalign) {
         hooks::init();
@@ -212,7 +212,7 @@ int posix_memalign(void **memptr, size_t alignment, size_t size) throw()
     return ret;
 }
 
-void* aligned_alloc(size_t alignment, size_t size) throw()
+void* aligned_alloc(size_t alignment, size_t size) noexcept
 {
     if (!hooks::aligned_alloc) {
         hooks::init();
@@ -227,7 +227,7 @@ void* aligned_alloc(size_t alignment, size_t size) throw()
     return ret;
 }
 
-void* valloc(size_t size) throw()
+void* valloc(size_t size) noexcept
 {
     if (!hooks::valloc) {
         hooks::init();
@@ -242,7 +242,7 @@ void* valloc(size_t size) throw()
     return ret;
 }
 
-void *dlopen(const char *filename, int flag) throw()
+void *dlopen(const char *filename, int flag) noexcept
 {
     if (!hooks::dlopen) {
         hooks::init();
@@ -257,7 +257,7 @@ void *dlopen(const char *filename, int flag) throw()
     return ret;
 }
 
-int dlclose(void *handle) throw()
+int dlclose(void *handle) noexcept
 {
     if (!hooks::dlclose) {
         hooks::init();