Minor changes to IPC layer in preparation for Win port.
This CL doesn't introduce any major change (neither on
Windows nor on Linux). It mainly refactor the codebase
to make the Windows IPC cls easier to review:
- Rename the GN target platform_posix to platform_impl
(Soon the same target will have a platform_windows.cc)
- Add a platform_unittest to cover the platform TLS logic.
- Refactor ThreadTaskRunner to directly expose a TaskRunner
interface (soon platform_windows.cc will need it as well).
- Refactor a bunch of places to take a ScopedSocketHandle
rather than a ScopedFile. They are the same type on POSIX
but not on Windows (where the latter wraps a SOCKET).
- Remove the fd() argument from the base SharedMemory class.
That makes sense only on POSIX and it caused a lot of empty
implementation around (note: this will cause a Chromium
roll failure, we need to match the removal in .MojoSharedMemory)
- Minor other tweaks to get rid of platform-specific includes.
Bug: 174454879
Test: manual on Windows.
Change-Id: Iead1ec87213c56fd3bb170c72d482f71fa33e7e3
diff --git a/src/base/utils.cc b/src/base/utils.cc
index 1f66a38..0e15bf6 100644
--- a/src/base/utils.cc
+++ b/src/base/utils.cc
@@ -17,11 +17,15 @@
#include "perfetto/ext/base/utils.h"
#include "perfetto/base/build_config.h"
+#include "perfetto/base/logging.h"
-#if PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || \
- PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID)
-#include <unistd.h> // For getpagesize().
-#elif PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE)
+#if PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || \
+ PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) || \
+ PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE)
+#include <unistd.h> // For getpagesize() and geteuid().
+#endif
+
+#if PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE)
#include <mach/vm_page_size.h>
#endif
@@ -82,5 +86,27 @@
#endif
}
+uid_t GetCurrentUserId() {
+#if PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || \
+ PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) || \
+ PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE)
+ return geteuid();
+#else
+ // TODO(primiano): On Windows we could hash the current user SID and derive a
+ // numeric user id [1]. It is not clear whether we need that. Right now that
+ // would not bring any benefit. Returning 0 unil we can prove we need it.
+ // [1]:https://android-review.googlesource.com/c/platform/external/perfetto/+/1513879/25/src/base/utils.cc
+ return 0;
+#endif
+}
+
+void SetEnv(const std::string& key, const std::string& value) {
+#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
+ PERFETTO_CHECK(::_putenv_s(key.c_str(), value.c_str()) == 0);
+#else
+ PERFETTO_CHECK(::setenv(key.c_str(), value.c_str(), /*overwrite=*/true) == 0);
+#endif
+}
+
} // namespace base
} // namespace perfetto