Commit f7927265 authored by dslomov@chromium.org's avatar dslomov@chromium.org

Provide "freeBuffer()" primitive for testing under ASan.

R=machenbach@chromium.org

Review URL: https://codereview.chromium.org/85883002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18091 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ddb4ad85
......@@ -41,6 +41,7 @@
#include "platform.h"
#include "snapshot.h"
#include "trig-table.h"
#include "extensions/free-buffer-extension.h"
#include "extensions/externalize-string-extension.h"
#include "extensions/gc-extension.h"
#include "extensions/statistics-extension.h"
......@@ -100,6 +101,9 @@ void Bootstrapper::Initialize(bool create_heap_objects) {
void Bootstrapper::InitializeOncePerProcess() {
#ifdef ADDRESS_SANITIZER
FreeBufferExtension::Register();
#endif
GCExtension::Register();
ExternalizeStringExtension::Register();
StatisticsExtension::Register();
......@@ -2278,6 +2282,11 @@ bool Genesis::InstallExtensions(Handle<Context> native_context,
current = current->next();
}
#ifdef ADDRESS_SANITIZER
if (FLAG_expose_free_buffer) {
InstallExtension(isolate, "v8/free-buffer", &extension_states);
}
#endif
if (FLAG_expose_gc) InstallExtension(isolate, "v8/gc", &extension_states);
if (FLAG_expose_externalize_string) {
InstallExtension(isolate, "v8/externalize", &extension_states);
......
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "free-buffer-extension.h"
#include "platform.h"
#include "v8.h"
namespace v8 {
namespace internal {
v8::Handle<v8::FunctionTemplate> FreeBufferExtension::GetNativeFunction(
v8::Handle<v8::String> str) {
return v8::FunctionTemplate::New(FreeBufferExtension::FreeBuffer);
}
void FreeBufferExtension::FreeBuffer(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Handle<v8::ArrayBuffer> arrayBuffer = args[0].As<v8::ArrayBuffer>();
v8::ArrayBuffer::Contents contents = arrayBuffer->Externalize();
V8::ArrayBufferAllocator()->Free(contents.Data(), contents.ByteLength());
}
void FreeBufferExtension::Register() {
static char buffer[100];
Vector<char> temp_vector(buffer, sizeof(buffer));
OS::SNPrintF(temp_vector, "native function freeBuffer();");
static FreeBufferExtension buffer_free_extension(buffer);
static v8::DeclareExtension declaration(&buffer_free_extension);
}
} } // namespace v8::internal
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef V8_EXTENSIONS_FREE_BUFFER_EXTENSION_H_
#define V8_EXTENSIONS_FREE_BUFFER_EXTENSION_H_
#include "v8.h"
namespace v8 {
namespace internal {
class FreeBufferExtension : public v8::Extension {
public:
explicit FreeBufferExtension(const char* source)
: v8::Extension("v8/free-buffer", source) {}
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
v8::Handle<v8::String> name);
static void FreeBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Register();
};
} } // namespace v8::internal
#endif // V8_EXTENSIONS_FREE_BUFFER_EXTENSION_H_
......@@ -407,6 +407,9 @@ DEFINE_bool(enable_vldr_imm, false,
// bootstrapper.cc
DEFINE_string(expose_natives_as, NULL, "expose natives in global object")
DEFINE_string(expose_debug_as, NULL, "expose debug in global object")
#ifdef ADDRESS_SANITIZER
DEFINE_bool(expose_free_buffer, false, "expose freeBuffer extension")
#endif
DEFINE_bool(expose_gc, false, "expose gc extension")
DEFINE_string(expose_gc_as, NULL,
"expose gc extension under the specified name")
......
......@@ -334,6 +334,8 @@
'../../src/execution.h',
'../../src/extensions/externalize-string-extension.cc',
'../../src/extensions/externalize-string-extension.h',
'../../src/extensions/free-buffer-extension.cc',
'../../src/extensions/free-buffer-extension.h',
'../../src/extensions/gc-extension.cc',
'../../src/extensions/gc-extension.h',
'../../src/extensions/statistics-extension.cc',
......
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