Elf handles

3 posts / 0 new
Last post
alfkil
alfkil's picture
Offline
Last seen: 2 months 1 week ago
Joined: 2011-05-10 22:02
Elf handles

I am using this class in Spotless to handle elf handles. When trying to close the handle after the child has died, there is a crash. If I don't close the handle (comment out the line responsible for closing), there is still a system handle on the file, meaning that it cannot be overwritten or updated. Hence I have to reboot each time I run Spotless on itself.

Solution?

  1. //
  2. //
  3. // elfhandle.hpp - keep track of elf handles in application runtime flow (Debug 101)
  4. //
  5. //
  6.  
  7. #ifndef DB101_ELFHANDLE_HPP
  8. #define DB101_ELFHANDLE_HPP
  9.  
  10. #include <proto/exec.h>
  11. #include <proto/elf.h>
  12.  
  13. #include <string>
  14.  
  15. using namespace std;
  16.  
  17. class ElfHandle
  18. {
  19. private:
  20. string name;
  21. APTR handle; //problem with c++ and Elf32_Handle typedef in AmigaOS
  22. bool isOpen;
  23.  
  24. public:
  25. ElfHandle (APTR handle, string name, bool isOpen = false);
  26. ~ElfHandle();
  27.  
  28. APTR getHandle () { return handle; }
  29. string getName() { return name; }
  30.  
  31. bool open () {
  32. handle = IElf->OpenElfTags(OET_ReadOnlyCopy, TRUE, OET_ElfHandle, handle, TAG_DONE);
  33. isOpen = true;
  34. return isOpen;
  35. }
  36. void close () {
  37. IElf->CloseElfTags ((Elf32_Handle)handle, CET_ReClose, FALSE, TAG_DONE);
  38. }
  39.  
  40. bool performRelocation () {
  41. IElf->RelocateSectionTags((Elf32_Handle)handle, GST_SectionName, ".stabstr", GST_Load, TRUE, TAG_DONE );
  42. return IElf->RelocateSectionTags((Elf32_Handle)handle, GST_SectionName, ".stab", GST_Load, TRUE, TAG_DONE );
  43. }
  44.  
  45. char *getStabstrSection () { return (char *)IElf->GetSectionTags((Elf32_Handle)handle, GST_SectionName, ".stabstr", TAG_DONE); }
  46. uint32_t *getStabSection () { return (uint32_t *)IElf->GetSectionTags((Elf32_Handle)handle, GST_SectionName, ".stab", TAG_DONE); }
  47. Elf32_Shdr *getStabSectionHeader () { return IElf->GetSectionHeaderTags ((Elf32_Handle)handle, GST_SectionName, ".stab", TAG_DONE); }
  48. uint32_t getStabsSize () {
  49. Elf32_Shdr *header = IElf->GetSectionHeaderTags ((Elf32_Handle)handle, GST_SectionName, ".stab", TAG_DONE);
  50. return header->sh_size;
  51. }
  52. void lock();
  53. };
  54. #endif //DB101_ELFHANDLE_HPP
salass00
salass00's picture
Offline
Last seen: 1 month 1 week ago
Joined: 2011-02-03 11:27
Re: Elf handles

Since you are reopening an existing elf handle (OET_ElfHandle) you should set CET_ReClose to TRUE in your CloseElfTags() call.

alfkil
alfkil's picture
Offline
Last seen: 2 months 1 week ago
Joined: 2011-05-10 22:02
Re: Elf handles

Cool. I didn't know that. Thanks!

Log in or register to post comments