OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CRAZY_LINKER_THREAD_H |
| 6 #define CRAZY_LINKER_THREAD_H |
| 7 |
| 8 #include <stdarg.h> |
| 9 #include <stddef.h> |
| 10 |
| 11 namespace crazy { |
| 12 |
| 13 // Per-thread context used during crazy linker operations. |
| 14 class ThreadData { |
| 15 |
| 16 public: |
| 17 ThreadData() {} |
| 18 |
| 19 // Init new ThreadData instance. |
| 20 void Init(); |
| 21 |
| 22 // Return the current error message. This also clears the internal |
| 23 // error message, which means that the next call to this method |
| 24 // will return a pointer to an empty string unless AppendError() |
| 25 // was called. |
| 26 const char* GetError() const { |
| 27 return dlerror_; |
| 28 } |
| 29 |
| 30 // Swap the error buffers. |
| 31 void SwapErrorBuffers(); |
| 32 |
| 33 // Set message string in current dlerror buffer. |
| 34 void SetError(const char* fmt, ...) { |
| 35 va_list args; |
| 36 va_start(args, fmt); |
| 37 SetErrorArgs(fmt, args); |
| 38 va_end(args); |
| 39 } |
| 40 |
| 41 void SetErrorArgs(const char* fmt, va_list args); |
| 42 |
| 43 // Append message string to current dlerror buffer. |
| 44 void AppendError(const char* fmt, ...) { |
| 45 va_list args; |
| 46 va_start(args, fmt); |
| 47 AppendErrorArgs(fmt, args); |
| 48 va_end(args); |
| 49 } |
| 50 |
| 51 void AppendErrorArgs(const char* fmt, va_list args); |
| 52 |
| 53 private: |
| 54 // Pointer to the current dlerror buffer. This points to one |
| 55 // of the dlerror_buffers[] arrays, swapped on each dlerror() |
| 56 // call. |
| 57 char* dlerror_; |
| 58 |
| 59 // Size of each dlerror message buffer size. |
| 60 static const size_t kBufferSize = 512; |
| 61 |
| 62 // Two buffers used to store dlerror messages. |
| 63 char dlerror_buffers_[2][kBufferSize]; |
| 64 }; |
| 65 |
| 66 // Retrieves the ThreadData structure for the current thread. |
| 67 // The first time this is called on a given thread, this creates |
| 68 // a fresh new object, so this should never return NULL. |
| 69 ThreadData* GetThreadData(); |
| 70 |
| 71 // Faster variant that should only be called when GetThreadData() was |
| 72 // called at least once on the current thread. |
| 73 ThreadData* GetThreadDataFast(); |
| 74 |
| 75 // Set the linker error string for the current thread. |
| 76 void SetLinkerErrorString(const char* str); |
| 77 |
| 78 // Set the formatted linker error for the current thread. |
| 79 void SetLinkerError(const char* fmt, ...); |
| 80 |
| 81 } // namespace crazy; |
| 82 |
| 83 #endif // CRAZY_LINKER_THREAD_H |
OLD | NEW |