1 /* 2 * Copyright 2014, Paweł Dziepak, pdziepak@quarnos.org. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef ELF_TLS_H 6 #define ELF_TLS_H 7 8 9 #include "runtime_loader_private.h" 10 #include "utility.h" 11 12 13 class TLSBlock; 14 15 class TLSBlockTemplate { 16 public: 17 TLSBlockTemplate() { } 18 inline TLSBlockTemplate(void* address, size_t fileSize, 19 size_t memorySize); 20 21 void SetGeneration(unsigned generation) 22 { fGeneration = generation; } 23 unsigned Generation() const { return fGeneration; } 24 25 void SetBaseAddress(addr_t baseAddress); 26 27 TLSBlock CreateBlock(); 28 29 private: 30 unsigned fGeneration; 31 32 void* fAddress; 33 size_t fFileSize; 34 size_t fMemorySize; 35 }; 36 37 class TLSBlockTemplates { 38 public: 39 static TLSBlockTemplates& Get(); 40 41 unsigned Register(const TLSBlockTemplate& block); 42 void Unregister(unsigned dso); 43 44 void SetBaseAddress(unsigned dso, addr_t baseAddress); 45 46 unsigned GetGeneration(unsigned dso) const; 47 48 TLSBlock CreateBlock(unsigned dso); 49 50 private: 51 inline TLSBlockTemplates(); 52 53 static TLSBlockTemplates* fInstance; 54 55 unsigned fGeneration; 56 57 utility::vector<TLSBlockTemplate> fTemplates; 58 utility::vector<unsigned> fFreeDSOs; 59 }; 60 61 62 TLSBlockTemplate::TLSBlockTemplate(void* address, size_t fileSize, 63 size_t memorySize) 64 : 65 fAddress(address), 66 fFileSize(fileSize), 67 fMemorySize(memorySize) 68 { 69 } 70 71 72 void* get_tls_address(unsigned dso, addr_t offset); 73 void destroy_thread_tls(); 74 75 76 #endif // ELF_TLS_H 77