2 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "DFGFunctionWhitelist.h"
31 #include "CodeBlock.h"
35 #include <wtf/NeverDestroyed.h>
36 #include <wtf/text/StringBuilder.h>
38 namespace JSC
{ namespace DFG
{
40 FunctionWhitelist
& FunctionWhitelist::ensureGlobalWhitelist()
42 static LazyNeverDestroyed
<FunctionWhitelist
> functionWhitelist
;
43 static std::once_flag initializeWhitelistFlag
;
44 std::call_once(initializeWhitelistFlag
, [] {
45 const char* functionWhitelistFile
= Options::dfgFunctionWhitelistFile();
46 functionWhitelist
.construct(functionWhitelistFile
);
48 return functionWhitelist
;
51 FunctionWhitelist::FunctionWhitelist(const char* filename
)
53 parseFunctionNamesInFile(filename
);
56 void FunctionWhitelist::parseFunctionNamesInFile(const char* filename
)
61 FILE* f
= fopen(filename
, "r");
63 dataLogF("Failed to open file %s. Did you add the file-read-data entitlement to WebProcess.sb?\n", filename
);
69 while ((line
= fgets(buffer
, sizeof(buffer
), f
))) {
70 if (strstr(line
, "//") == line
)
73 // Get rid of newlines at the ends of the strings.
74 size_t length
= strlen(line
);
75 if (line
[length
- 1] == '\n') {
76 line
[length
- 1] = '\0';
84 m_entries
.add(String(line
, length
));
87 int result
= fclose(f
);
89 dataLogF("Failed to close file %s: %s\n", filename
, strerror(errno
));
92 bool FunctionWhitelist::contains(CodeBlock
* codeBlock
) const
94 ASSERT(!isCompilationThread());
95 if (!Options::dfgFunctionWhitelistFile())
98 if (m_entries
.isEmpty())
101 String name
= String::fromUTF8(codeBlock
->inferredName());
102 if (m_entries
.contains(name
))
105 String hash
= String::fromUTF8(codeBlock
->hashAsStringIfPossible());
106 if (m_entries
.contains(hash
))
109 String nameAndHash
= name
;
110 nameAndHash
.append('#');
111 nameAndHash
.append(hash
);
112 return m_entries
.contains(nameAndHash
);
115 } } // namespace JSC::DFG
117 #endif // ENABLE(DFG_JIT)