1 : // Copyright 2014 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Internal implementation of a size-limited quarantine. This file is not
16 : // meant to be included directly.
17 :
18 : #ifndef SYZYGY_AGENT_ASAN_QUARANTINES_SIZE_LIMITED_QUARANTINE_IMPL_H_
19 : #define SYZYGY_AGENT_ASAN_QUARANTINES_SIZE_LIMITED_QUARANTINE_IMPL_H_
20 :
21 : namespace agent {
22 : namespace asan {
23 : namespace quarantines {
24 :
25 : template<typename OT, typename SFT>
26 : bool SizeLimitedQuarantineImpl<OT, SFT>::Push(
27 E : const Object& object) {
28 : SizeFunctor get_size;
29 E : size_t size = get_size(object);
30 E : if (max_object_size_ != kUnboundedSize && size > max_object_size_)
31 E : return false;
32 E : if (max_quarantine_size_ != kUnboundedSize && size > max_quarantine_size_)
33 i : return false;
34 E : if (!PushImpl(object))
35 i : return false;
36 E : size_ += size;
37 E : ++count_;
38 E : return true;
39 E : }
40 :
41 : template<typename OT, typename SFT>
42 : bool SizeLimitedQuarantineImpl<OT, SFT>::Pop(
43 E : Object* object) {
44 E : DCHECK_NE(static_cast<Object*>(NULL), object);
45 : if (max_quarantine_size_ == kUnboundedSize ||
46 E : size_ <= max_quarantine_size_)
47 E : return false;
48 E : if (!PopImpl(object))
49 i : return false;
50 : SizeFunctor get_size;
51 E : size_t size = get_size(*object);
52 E : DCHECK_LE(size, size_);
53 E : size_ -= size;
54 E : --count_;
55 E : return true;
56 E : }
57 :
58 : template<typename OT, typename SFT>
59 : void SizeLimitedQuarantineImpl<OT, SFT>::Empty(
60 E : ObjectVector* objects) {
61 E : DCHECK_NE(static_cast<ObjectVector*>(NULL), objects);
62 E : EmptyImpl(objects);
63 E : size_ = 0;
64 E : count_ = 0;
65 E : }
66 :
67 : template<typename OT, typename SFT>
68 E : size_t SizeLimitedQuarantineImpl<OT, SFT>::GetCount() {
69 E : return count_;
70 E : }
71 :
72 : template<typename OT, typename SFT>
73 : size_t SizeLimitedQuarantineImpl<OT, SFT>::GetLockId(
74 E : const Object& object) {
75 E : return GetLockIdImpl(object);
76 E : }
77 :
78 : template<typename OT, typename SFT>
79 E : void SizeLimitedQuarantineImpl<OT, SFT>::Lock(size_t id) {
80 E : LockImpl(id);
81 E : }
82 :
83 : template<typename OT, typename SFT>
84 E : void SizeLimitedQuarantineImpl<OT, SFT>::Unlock(size_t id) {
85 E : UnlockImpl(id);
86 E : }
87 :
88 : } // namespace quarantines
89 : } // namespace asan
90 : } // namespace agent
91 :
92 : #endif // SYZYGY_AGENT_ASAN_QUARANTINES_SIZE_LIMITED_QUARANTINE_IMPL_H_
|