Commit b4a68235 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[csa] add release-mode check macro

In analogy to the CHECK() macro, this generates an assertion check in CSA that is enabled in release builds. Intended for some security-relevant assertions in TypedArray builtins.

Bug: 
Change-Id: Ie15a3892c4698a916bcd53bd9bfb4411eec6ebe4
Reviewed-on: https://chromium-review.googlesource.com/506158
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45381}
parent d4f80f4c
......@@ -43,43 +43,47 @@ void CodeStubAssembler::HandleBreakOnNode() {
BreakOnNode(node_id);
}
void CodeStubAssembler::Assert(const NodeGenerator& codition_body,
void CodeStubAssembler::Assert(const NodeGenerator& condition_body,
const char* message, const char* file,
int line) {
#if defined(DEBUG)
if (FLAG_debug_code) {
Label ok(this);
Label not_ok(this, Label::kDeferred);
if (message != nullptr && FLAG_code_comments) {
Comment("[ Assert: %s", message);
} else {
Comment("[ Assert");
}
Node* condition = codition_body();
DCHECK_NOT_NULL(condition);
Branch(condition, &ok, &not_ok);
BIND(&not_ok);
if (message != nullptr) {
char chars[1024];
Vector<char> buffer(chars);
if (file != nullptr) {
SNPrintF(buffer, "CSA_ASSERT failed: %s [%s:%d]\n", message, file,
line);
} else {
SNPrintF(buffer, "CSA_ASSERT failed: %s\n", message);
}
CallRuntime(
Runtime::kGlobalPrint, SmiConstant(Smi::kZero),
HeapConstant(factory()->NewStringFromAsciiChecked(&(buffer[0]))));
}
DebugBreak();
Goto(&ok);
BIND(&ok);
Comment("] Assert");
Check(condition_body, message, file, line);
}
#endif
}
void CodeStubAssembler::Check(const NodeGenerator& condition_body,
const char* message, const char* file, int line) {
Label ok(this);
Label not_ok(this, Label::kDeferred);
if (message != nullptr && FLAG_code_comments) {
Comment("[ Assert: %s", message);
} else {
Comment("[ Assert");
}
Node* condition = condition_body();
DCHECK_NOT_NULL(condition);
Branch(condition, &ok, &not_ok);
BIND(&not_ok);
if (message != nullptr) {
char chars[1024];
Vector<char> buffer(chars);
if (file != nullptr) {
SNPrintF(buffer, "CSA_ASSERT failed: %s [%s:%d]\n", message, file, line);
} else {
SNPrintF(buffer, "CSA_ASSERT failed: %s\n", message);
}
CallRuntime(
Runtime::kGlobalPrint, SmiConstant(Smi::kZero),
HeapConstant(factory()->NewStringFromAsciiChecked(&(buffer[0]))));
}
DebugBreak();
Goto(&ok);
BIND(&ok);
Comment("] Assert");
}
Node* CodeStubAssembler::Select(Node* condition, const NodeGenerator& true_body,
const NodeGenerator& false_body,
MachineRepresentation rep) {
......
......@@ -265,6 +265,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
void Assert(const NodeGenerator& condition_body, const char* string = nullptr,
const char* file = nullptr, int line = 0);
void Check(const NodeGenerator& condition_body, const char* string = nullptr,
const char* file = nullptr, int line = 0);
Node* Select(Node* condition, const NodeGenerator& true_body,
const NodeGenerator& false_body, MachineRepresentation rep);
......@@ -1599,6 +1601,9 @@ class ToDirectStringAssembler : public CodeStubAssembler {
const Flags flags_;
};
#define CSA_CHECK(csa, x) \
(csa)->Check([&] { return (x); }, #x, __FILE__, __LINE__)
#ifdef DEBUG
#define CSA_ASSERT(csa, x) \
(csa)->Assert([&] { return (x); }, #x, __FILE__, __LINE__)
......@@ -1626,9 +1631,9 @@ class ToDirectStringAssembler : public CodeStubAssembler {
#endif // DEBUG
#ifdef ENABLE_SLOW_DCHECKS
#define CSA_SLOW_ASSERT(csa, x) \
if (FLAG_enable_slow_asserts) { \
(csa)->Assert([&] { return (x); }, #x, __FILE__, __LINE__); \
#define CSA_SLOW_ASSERT(csa, x) \
if (FLAG_enable_slow_asserts) { \
CSA_ASSERT(csa, x); \
}
#else
#define CSA_SLOW_ASSERT(csa, x) ((void)0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment