/work/obj-fuzz/dist/include/mozilla/plugins/IpdlTuple.h
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef dom_plugins_ipc_ipdltuple_h |
2 | | #define dom_plugins_ipc_ipdltuple_h |
3 | | |
4 | | #include "mozilla/plugins/FunctionBrokerIPCUtils.h" |
5 | | #include "mozilla/Variant.h" |
6 | | |
7 | | namespace mozilla { |
8 | | namespace plugins { |
9 | | |
10 | | /** |
11 | | * IpdlTuple is used by automatic function brokering to pass parameter |
12 | | * lists for brokered functions. It supports a limited set of types |
13 | | * (see IpdlTuple::IpdlTupleElement). |
14 | | */ |
15 | | class IpdlTuple |
16 | | { |
17 | | public: |
18 | 0 | uint32_t NumElements() const { return mTupleElements.Length(); } |
19 | | |
20 | | template<typename EltType> |
21 | | EltType* Element(uint32_t index) |
22 | | { |
23 | | if ((index >= mTupleElements.Length()) || |
24 | | !mTupleElements[index].GetVariant().is<EltType>()) { |
25 | | return nullptr; |
26 | | } |
27 | | return &mTupleElements[index].GetVariant().as<EltType>(); |
28 | | } |
29 | | |
30 | | template<typename EltType> |
31 | | const EltType* Element(uint32_t index) const |
32 | | { |
33 | | return const_cast<IpdlTuple*>(this)->Element<EltType>(index); |
34 | | } |
35 | | |
36 | | template <typename EltType> |
37 | | void AddElement(const EltType& aElt) |
38 | | { |
39 | | IpdlTupleElement* newEntry = mTupleElements.AppendElement(); |
40 | | newEntry->Set(aElt); |
41 | | } |
42 | | |
43 | | private: |
44 | | struct InvalidType {}; |
45 | | |
46 | | // Like Variant but with a default constructor. |
47 | | template <typename ... Types> |
48 | | struct MaybeVariant |
49 | | { |
50 | | public: |
51 | 0 | MaybeVariant() : mValue(InvalidType()) {} |
52 | | MaybeVariant(MaybeVariant&& o) : mValue(std::move(o.mValue)) {} |
53 | | |
54 | | template <typename Param> void Set(const Param& aParam) |
55 | | { |
56 | | mValue = mozilla::AsVariant(aParam); |
57 | | } |
58 | | |
59 | | typedef mozilla::Variant<InvalidType, Types...> MaybeVariantType; |
60 | 0 | MaybeVariantType& GetVariant() { return mValue; } |
61 | 0 | const MaybeVariantType& GetVariant() const { return mValue; } |
62 | | |
63 | | private: |
64 | | MaybeVariantType mValue; |
65 | | }; |
66 | | |
67 | | #if defined(XP_WIN) |
68 | | typedef MaybeVariant<int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t, |
69 | | int64_t,uint64_t,nsCString,bool,OpenFileNameIPC, |
70 | | OpenFileNameRetIPC,NativeWindowHandle, |
71 | | IPCSchannelCred,IPCInternetBuffers,StringArray, |
72 | | IPCPrintDlg> IpdlTupleElement; |
73 | | #else |
74 | | typedef MaybeVariant<int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t, |
75 | | int64_t,uint64_t,nsCString,bool> IpdlTupleElement; |
76 | | #endif // defined(XP_WIN) |
77 | | |
78 | | friend struct IPC::ParamTraits<IpdlTuple>; |
79 | | friend struct IPC::ParamTraits<IpdlTuple::IpdlTupleElement>; |
80 | | friend struct IPC::ParamTraits<IpdlTuple::InvalidType>; |
81 | | |
82 | | nsTArray<IpdlTupleElement> mTupleElements; |
83 | | }; |
84 | | |
85 | | template <> template<> |
86 | | inline void IpdlTuple::IpdlTupleElement::Set<nsDependentCSubstring>(const nsDependentCSubstring& aParam) |
87 | 0 | { |
88 | 0 | mValue = MaybeVariantType(mozilla::VariantType<nsCString>(), aParam); |
89 | 0 | } |
90 | | |
91 | | } // namespace plugins |
92 | | } // namespace mozilla |
93 | | |
94 | | namespace IPC { |
95 | | |
96 | | using namespace mozilla::plugins; |
97 | | |
98 | | template <> |
99 | | struct ParamTraits<IpdlTuple> |
100 | | { |
101 | | typedef IpdlTuple paramType; |
102 | | |
103 | | static void Write(Message* aMsg, const paramType& aParam) |
104 | 0 | { |
105 | 0 | WriteParam(aMsg, aParam.mTupleElements); |
106 | 0 | } |
107 | | |
108 | | static bool Read(const Message* aMsg, PickleIterator* aIter, |
109 | | paramType* aParam) |
110 | 0 | { |
111 | 0 | return ReadParam(aMsg, aIter, &aParam->mTupleElements); |
112 | 0 | } |
113 | | |
114 | | static void Log(const paramType& aParam, std::wstring* aLog) |
115 | 0 | { |
116 | 0 | LogParam(aParam.mTupleElements, aLog); |
117 | 0 | } |
118 | | }; |
119 | | |
120 | | template<> |
121 | | struct ParamTraits<IpdlTuple::IpdlTupleElement> |
122 | | { |
123 | | typedef IpdlTuple::IpdlTupleElement paramType; |
124 | | |
125 | | static void Write(Message* aMsg, const paramType& aParam) |
126 | 0 | { |
127 | 0 | MOZ_RELEASE_ASSERT(!aParam.GetVariant().is<IpdlTuple::InvalidType>()); |
128 | 0 | WriteParam(aMsg, aParam.GetVariant()); |
129 | 0 | } |
130 | | |
131 | | static bool Read(const Message* aMsg, PickleIterator* aIter, |
132 | | paramType* aParam) |
133 | 0 | { |
134 | 0 | bool ret = ReadParam(aMsg, aIter, &aParam->GetVariant()); |
135 | 0 | MOZ_RELEASE_ASSERT(!aParam->GetVariant().is<IpdlTuple::InvalidType>()); |
136 | 0 | return ret; |
137 | 0 | } |
138 | | |
139 | | struct LogMatcher |
140 | | { |
141 | 0 | explicit LogMatcher(std::wstring* aLog) : mLog(aLog) {} |
142 | | |
143 | | template <typename EntryType> |
144 | | void match(const EntryType& aParam) |
145 | 0 | { |
146 | 0 | LogParam(aParam, mLog); |
147 | 0 | } Unexecuted instantiation: void IPC::ParamTraits<mozilla::plugins::IpdlTuple::MaybeVariant<signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::LogMatcher::match<mozilla::plugins::IpdlTuple::InvalidType>(mozilla::plugins::IpdlTuple::InvalidType const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::plugins::IpdlTuple::MaybeVariant<signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::LogMatcher::match<signed char>(signed char const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::plugins::IpdlTuple::MaybeVariant<signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::LogMatcher::match<unsigned char>(unsigned char const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::plugins::IpdlTuple::MaybeVariant<signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::LogMatcher::match<short>(short const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::plugins::IpdlTuple::MaybeVariant<signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::LogMatcher::match<unsigned short>(unsigned short const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::plugins::IpdlTuple::MaybeVariant<signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::LogMatcher::match<int>(int const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::plugins::IpdlTuple::MaybeVariant<signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::LogMatcher::match<unsigned int>(unsigned int const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::plugins::IpdlTuple::MaybeVariant<signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::LogMatcher::match<long>(long const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::plugins::IpdlTuple::MaybeVariant<signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::LogMatcher::match<unsigned long>(unsigned long const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::plugins::IpdlTuple::MaybeVariant<signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::LogMatcher::match<nsTString<char> >(nsTString<char> const&) Unexecuted instantiation: void IPC::ParamTraits<mozilla::plugins::IpdlTuple::MaybeVariant<signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, nsTString<char>, bool> >::LogMatcher::match<bool>(bool const&) |
148 | | |
149 | | private: |
150 | | std::wstring* mLog; |
151 | | }; |
152 | | |
153 | | static void Log(const paramType& aParam, std::wstring* aLog) |
154 | 0 | { |
155 | 0 | aParam.GetVariant().match(LogMatcher(aLog)); |
156 | 0 | } |
157 | | }; |
158 | | |
159 | | template<> |
160 | | struct ParamTraits<IpdlTuple::InvalidType> |
161 | | { |
162 | | typedef IpdlTuple::InvalidType paramType; |
163 | | |
164 | | static void Write(Message* aMsg, const paramType& aParam) |
165 | 0 | { |
166 | 0 | MOZ_ASSERT_UNREACHABLE("Attempt to serialize an invalid tuple element"); |
167 | 0 | } |
168 | | |
169 | | static bool Read(const Message* aMsg, PickleIterator* aIter, |
170 | | paramType* aParam) |
171 | 0 | { |
172 | 0 | MOZ_ASSERT_UNREACHABLE("Attempt to deserialize an invalid tuple element"); |
173 | 0 | return false; |
174 | 0 | } |
175 | | |
176 | | static void Log(const paramType& aParam, std::wstring* aLog) |
177 | 0 | { |
178 | 0 | aLog->append(L"<Invalid Tuple Entry>"); |
179 | 0 | } |
180 | | }; |
181 | | |
182 | | } // namespace IPC |
183 | | |
184 | | #endif /* dom_plugins_ipc_ipdltuple_h */ |