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

Side by Side Diff: chrome/browser/android/seccomp_support_detector.cc

Issue 1018953004: Add SeccompSupportDetector for Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
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 "chrome/browser/android/seccomp_support_detector.h"
6
7 #include <sys/utsname.h>
8
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/metrics/histogram_macros.h"
11 #include "chrome/common/chrome_utility_messages.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/utility_process_host.h"
14
15 using content::BrowserThread;
16
17 enum AndroidSeccompStatus {
jln (very slow on Chromium) 2015/03/18 20:49:15 No enum class?
Robert Sesek 2015/03/18 21:41:35 It doesn't work well with the UMA_HISTOGRAM_ENUMER
18 kDetectionFailed,
jln (very slow on Chromium) 2015/03/18 20:49:15 The Chromium appendix to the style guide says to u
Robert Sesek 2015/03/18 21:41:36 Ah, yeah I was using the Google style. I'll follow
19 kNotSupported,
20 kPrctlSupported,
21 kSyscallSupported,
22 kBothSupported,
23 kLastStatus,
24 };
25
26 void SeccompSupportDetector::StartDetection() {
jln (very slow on Chromium) 2015/03/18 20:49:15 //static?
Robert Sesek 2015/03/18 21:41:36 Done.
27 // This class owns itself. It is created here and the object is released
jln (very slow on Chromium) 2015/03/18 20:49:15 "It is created here" -> "An instance is created he
Robert Sesek 2015/03/18 21:41:35 Done.
28 // after seccomp suport is detected.
jln (very slow on Chromium) 2015/03/18 20:49:15 The lifetime of this refcounted class is a little
Robert Sesek 2015/03/18 21:41:35 I initially did as you suggested and let the Closu
29 SeccompSupportDetector* detector = new SeccompSupportDetector();
30 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
31 base::Bind(&SeccompSupportDetector::DetectKernelVersion, detector));
32 }
33
34 SeccompSupportDetector::SeccompSupportDetector() {
35 }
36
37 SeccompSupportDetector::~SeccompSupportDetector() {
38 }
39
40 void SeccompSupportDetector::DetectKernelVersion() {
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
42
43 // This method will report the kernel major and minor versions by
44 // taking the lower 16 bits of each version number and combining
45 // it into a 32-bit number.
46
47 // Support known Android kernel versions, and leave room up to 3.50.
jln (very slow on Chromium) 2015/03/18 20:49:15 3.20 is actually 4.0
Robert Sesek 2015/03/18 21:41:35 Done.
48 const int kVersionRanges[] = {
49 0x00020006,
50 0x00030000,
51 0x00030003,
52 0x00030004,
53 0x00030008,
54 0x00030010,
55 0x00030014,
56 0x00030017,
57 0x00030018,
58 0x00030050,
59 };
60
61 utsname uts;
jln (very slow on Chromium) 2015/03/18 20:49:15 nit: I prefer to use "struct X" for low-level C co
Robert Sesek 2015/03/18 21:41:35 Acknowledged.
62 if (uname(&uts) == 0) {
63 int major, minor;
64 if (sscanf(uts.release, "%d.%d", &major, &minor) == 2) {
jln (very slow on Chromium) 2015/03/18 20:49:15 Ok to put all 2.6.X kernels in the same bucket? F
Robert Sesek 2015/03/18 21:41:35 Yeah, I think so. I don't even know if Chrome runs
65 int version = ((major & 0xFFFF) << 16) | (minor & 0xFFFF);
66 UMA_HISTOGRAM_CUSTOM_ENUMERATION(
67 "Android.KernelVersion", version,
68 base::CustomHistogram::ArrayToCustomRanges(
69 kVersionRanges, arraysize(kVersionRanges)));
70 }
71 }
72
73 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
74 base::Bind(&SeccompSupportDetector::DetectSeccomp, this));
75 }
76
77 void SeccompSupportDetector::DetectSeccomp() {
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
79
80 content::UtilityProcessHost* utility_process_host =
81 content::UtilityProcessHost::Create(
82 this, base::MessageLoopProxy::current());
83 utility_process_host->Send(new ChromeUtilityMsg_DetectSeccompSupport());
84 }
85
86 void SeccompSupportDetector::OnProcessCrashed(int exit_code) {
87 UMA_HISTOGRAM_ENUMERATION("Android.SeccompStatus",
88 kDetectionFailed,
89 kLastStatus);
90 Release();
91 }
92
93 bool SeccompSupportDetector::OnMessageReceived(const IPC::Message& message) {
94 bool handled = false;
95 IPC_BEGIN_MESSAGE_MAP(SeccompSupportDetector, message)
96 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DetectSeccompSupport_Result,
97 OnDetectSeccompSupportResult)
98 IPC_MESSAGE_UNHANDLED(handled = false)
99 IPC_END_MESSAGE_MAP()
100 return handled;
101 }
102
103 void SeccompSupportDetector::OnDetectSeccompSupportResult(
104 bool prctl_supported, bool syscall_supported) {
105
106 AndroidSeccompStatus status = kNotSupported;
107 if (prctl_supported && syscall_supported)
108 status = kBothSupported;
109 else if (prctl_supported)
110 status = kPrctlSupported;
111 else if (syscall_supported)
112 status = kSyscallSupported;
113
114 UMA_HISTOGRAM_ENUMERATION("Android.SeccompStatus",
115 status,
116 kLastStatus);
117
118 Release();
119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698