interface.cpp 968 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "interface.h"
  2. #include "original/vdso_support.h"
  3. #ifdef HAVE_VDSO_SUPPORT
  4. size_t NVdso::Enumerate(TSymbol* s, size_t len) {
  5. if (!len) {
  6. return 0;
  7. }
  8. base::VDSOSupport vdso;
  9. if (!vdso.IsPresent()) {
  10. return 0;
  11. }
  12. size_t n = 0;
  13. for (base::VDSOSupport::SymbolIterator it = vdso.begin(); it != vdso.end(); ++it) {
  14. *s++ = TSymbol(it->name, (void*)it->address);
  15. ++n;
  16. if (!--len) {
  17. break;
  18. }
  19. }
  20. return n;
  21. }
  22. void* NVdso::Function(const char* name, const char* version) {
  23. base::VDSOSupport::SymbolInfo info;
  24. // Have to cast away the `const` to make this reinterpret_cast-able to a function pointer.
  25. return base::VDSOSupport().LookupSymbol(name, version, STT_FUNC, &info) ? (void*) info.address : nullptr;
  26. }
  27. #else
  28. size_t NVdso::Enumerate(TSymbol*, size_t) {
  29. return 0;
  30. }
  31. void* NVdso::Function(const char*, const char*) {
  32. return nullptr;
  33. }
  34. #endif