Process.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "il2cpp-config.h"
  2. #if IL2CPP_TARGET_DARWIN
  3. #include <sys/types.h>
  4. #if !IL2CPP_TARGET_IOS
  5. #include <libproc.h>
  6. #endif
  7. #include <unistd.h>
  8. #include <stdlib.h>
  9. #include "os/Process.h"
  10. #include "utils/Il2CppError.h"
  11. struct ProcessHandle
  12. {
  13. pid_t pid;
  14. };
  15. namespace il2cpp
  16. {
  17. namespace os
  18. {
  19. int Process::GetCurrentProcessId()
  20. {
  21. return getpid();
  22. }
  23. utils::Expected<ProcessHandle*> Process::GetProcess(int processId)
  24. {
  25. // If/when we implement the CreateProcess_internal icall we will likely
  26. // need to so something smarter here to find the process if we did
  27. // not create it and return a known pseudo-handle. For now this
  28. // is sufficient though.
  29. return (ProcessHandle*)(intptr_t)processId;
  30. }
  31. void Process::FreeProcess(ProcessHandle* handle)
  32. {
  33. // We have nothing to do here.
  34. }
  35. utils::Expected<std::string> Process::GetProcessName(ProcessHandle* handle)
  36. {
  37. #if !IL2CPP_TARGET_IOS
  38. const size_t bufferLength = 256;
  39. char buf[bufferLength];
  40. int length = proc_name((int)((intptr_t)handle), buf, bufferLength);
  41. if (length <= 0)
  42. return std::string();
  43. return std::string(buf, length);
  44. #else
  45. return utils::Il2CppError(utils::NotSupported, "GetProcessName is not supported for non-Windows/OSX/Linux desktop platforms");
  46. #endif
  47. }
  48. intptr_t Process::GetMainWindowHandle(int32_t pid)
  49. {
  50. return 0;
  51. }
  52. }
  53. }
  54. #endif