Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: base/process/process_handle.cc

Issue 1186873006: Add Get/SetUniqueIdForProcess. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Get rid of DCHECK_IS_ON. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/process/process_handle.h ('k') | content/zygote/zygote_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stdint.h>
6
7 #include "base/logging.h"
8 #include "base/process/process_handle.h"
9 #include "build/build_config.h"
10
11 namespace base {
12
13 namespace {
14 // This is never a valid mangled process ID.
danakj 2015/09/23 21:56:32 This is getting kinda magical and hard to really b
rickyz (no longer on Chrome) 2015/09/24 01:22:03 Good idea, done
15 const uint32_t kInvalidUniqueId = 0xffffffffU;
16
17 uint32_t g_unique_id = kInvalidUniqueId;
18
19 // The process which set |g_unique_id|.
20 ProcessId g_procid;
21
22 // Mangle IDs so that they are not accidentally used as PIDs, e.g. as an
23 // argument to kill or waitpid.
24 uint32_t MangleProcessId(ProcessId process_id) {
25 // Add a large power of 10 so that the pid is still the pid is still readable
danakj 2015/09/23 21:56:31 "the pid is still the pid is still readable" "the
rickyz (no longer on Chrome) 2015/09/24 01:22:03 Done
26 // for debugging
27 return static_cast<uint32_t>(process_id) + 1000000000U;
28 }
29
30 } // namespace
31
32 uint32_t GetUniqueIdForProcess() {
33 if (g_unique_id == kInvalidUniqueId) {
34 return MangleProcessId(GetCurrentProcId());
35 }
36
37 // Make sure we are the same process that set |g_procid|. This check may have
38 // false negatives (if a process ID was reused) but should have no false
39 // positives.
40 DCHECK_EQ(GetCurrentProcId(), g_procid);
41 return g_unique_id;
42 }
43
44 #if defined(OS_LINUX)
45
46 void InitUniqueIdForProcessInPidNamespace(ProcessId pid_outside_of_namespace) {
47 g_unique_id = MangleProcessId(pid_outside_of_namespace);
48 g_procid = GetCurrentProcId();
49 }
50
51 #endif
52
53 } // namespace base
OLDNEW
« no previous file with comments | « base/process/process_handle.h ('k') | content/zygote/zygote_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698