BSDNativeLoader.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. namespace NativeLibraryLoader.MAC
  6. {
  7. internal class BSDNativeLoader : INativeLoader
  8. {
  9. public void CoreFreeLibrary(IntPtr intPtr)
  10. {
  11. dlclose(intPtr);
  12. }
  13. public string CoreGetLastError()
  14. {
  15. return dlerror();
  16. }
  17. public IntPtr CoreGetProcAddress(IntPtr intPtr, string entryPoint)
  18. {
  19. return dlsym(intPtr, entryPoint);
  20. }
  21. public IntPtr CoreLoadLibrary(string path)
  22. {
  23. return dlopen(path,RtldNow);
  24. }
  25. private const string LibName = "libc";
  26. const int RtldNow = 0x002;
  27. [DllImport(LibName)]
  28. static extern IntPtr dlopen(string fileName, int flags);
  29. [DllImport(LibName)]
  30. static extern IntPtr dlsym(IntPtr handle, string name);
  31. [DllImport(LibName)]
  32. static extern IntPtr dlclose(IntPtr handle);
  33. [DllImport(LibName)]
  34. static extern string dlerror();
  35. }
  36. }