OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <errno.h> | 5 #include <errno.h> |
6 #include <signal.h> | 6 #include <signal.h> |
7 #include <string.h> | 7 #include <string.h> |
8 #include <sys/prctl.h> | 8 #include <sys/prctl.h> |
9 #include <sys/syscall.h> | 9 #include <sys/syscall.h> |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 | 54 |
55 void SetIsInSigHandler() { | 55 void SetIsInSigHandler() { |
56 sigset_t mask; | 56 sigset_t mask; |
57 if (sigemptyset(&mask) || | 57 if (sigemptyset(&mask) || |
58 sigaddset(&mask, SIGBUS) || | 58 sigaddset(&mask, SIGBUS) || |
59 sigprocmask(SIG_BLOCK, &mask, NULL)) { | 59 sigprocmask(SIG_BLOCK, &mask, NULL)) { |
60 SANDBOX_DIE("Failed to block SIGBUS"); | 60 SANDBOX_DIE("Failed to block SIGBUS"); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 bool IsDefaultSignalAction(const struct sigaction& sa) { | |
65 if (sa.sa_flags & SA_SIGINFO || | |
66 sa.sa_handler != SIG_DFL) { | |
Markus (顧孟勤)
2013/09/05 22:23:25
SIG_IGN is probably also OK, but we can hold off o
jln (very slow on Chromium)
2013/09/05 22:29:05
It'll mostly be for the spurious SIGSYS bug report
| |
67 return false; | |
68 } | |
69 return true; | |
70 } | |
71 | |
64 } // namespace | 72 } // namespace |
65 | 73 |
66 namespace playground2 { | 74 namespace playground2 { |
67 | 75 |
68 Trap::Trap() | 76 Trap::Trap() |
69 : trap_array_(NULL), | 77 : trap_array_(NULL), |
70 trap_array_size_(0), | 78 trap_array_size_(0), |
71 trap_array_capacity_(0), | 79 trap_array_capacity_(0), |
72 has_unsafe_traps_(false) { | 80 has_unsafe_traps_(false) { |
73 // Set new SIGSYS handler | 81 // Set new SIGSYS handler |
74 struct sigaction sa = { }; | 82 struct sigaction sa = { }; |
75 sa.sa_sigaction = SigSysAction; | 83 sa.sa_sigaction = SigSysAction; |
76 sa.sa_flags = SA_SIGINFO | SA_NODEFER; | 84 sa.sa_flags = SA_SIGINFO | SA_NODEFER; |
77 if (sigaction(SIGSYS, &sa, NULL) < 0) { | 85 struct sigaction old_sa = { }; |
Markus (顧孟勤)
2013/09/05 22:23:25
Why do you need to zero out this structure? I know
jln (very slow on Chromium)
2013/09/05 22:29:05
Done.
| |
86 if (sigaction(SIGSYS, &sa, &old_sa) < 0) { | |
78 SANDBOX_DIE("Failed to configure SIGSYS handler"); | 87 SANDBOX_DIE("Failed to configure SIGSYS handler"); |
79 } | 88 } |
80 | 89 |
90 if (!IsDefaultSignalAction(old_sa)) { | |
91 // TODO(jln): make this FATAL, at least in DEBUG mode. | |
92 LOG(ERROR) << "Existing signal handler when trying to install SIGSYS"; | |
Markus (顧孟勤)
2013/09/05 22:23:25
It would be nice, if we could actually log what th
jln (very slow on Chromium)
2013/09/05 22:29:05
Yeah, and in the spurious SIGSYS case, it's likely
| |
93 } | |
94 | |
81 // Unmask SIGSYS | 95 // Unmask SIGSYS |
82 sigset_t mask; | 96 sigset_t mask; |
83 if (sigemptyset(&mask) || | 97 if (sigemptyset(&mask) || |
84 sigaddset(&mask, SIGSYS) || | 98 sigaddset(&mask, SIGSYS) || |
85 sigprocmask(SIG_UNBLOCK, &mask, NULL)) { | 99 sigprocmask(SIG_UNBLOCK, &mask, NULL)) { |
86 SANDBOX_DIE("Failed to configure SIGSYS handler"); | 100 SANDBOX_DIE("Failed to configure SIGSYS handler"); |
87 } | 101 } |
88 } | 102 } |
89 | 103 |
90 Trap *Trap::GetInstance() { | 104 Trap *Trap::GetInstance() { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 if (global_trap_ && id > 0 && id <= global_trap_->trap_array_size_) { | 352 if (global_trap_ && id > 0 && id <= global_trap_->trap_array_size_) { |
339 return global_trap_->trap_array_[id - 1]; | 353 return global_trap_->trap_array_[id - 1]; |
340 } else { | 354 } else { |
341 return ErrorCode(); | 355 return ErrorCode(); |
342 } | 356 } |
343 } | 357 } |
344 | 358 |
345 Trap *Trap::global_trap_; | 359 Trap *Trap::global_trap_; |
346 | 360 |
347 } // namespace playground2 | 361 } // namespace playground2 |
OLD | NEW |