test-platform.cc 1.65 KB
Newer Older
1
// Copyright 2013 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5
#include <stdint.h>
6

7
#include "src/base/build_config.h"
8
#include "src/base/platform/platform.h"
9
#include "test/cctest/cctest-utils.h"
10
#include "test/cctest/cctest.h"
11

12 13 14 15 16 17
using OS = v8::base::OS;

namespace v8 {
namespace internal {

#ifdef V8_CC_GNU
18

19
static uintptr_t sp_addr = 0;
20

21 22
void GetStackPointerCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
  GET_STACK_POINTER_TO(sp_addr);
23 24
  args.GetReturnValue().Set(v8::Integer::NewFromUnsigned(
      args.GetIsolate(), static_cast<uint32_t>(sp_addr)));
25 26 27
}

TEST(StackAlignment) {
28
  v8::Isolate* isolate = CcTest::isolate();
29
  v8::HandleScope handle_scope(isolate);
30
  v8::Local<v8::ObjectTemplate> global_template =
31
      v8::ObjectTemplate::New(isolate);
32 33 34
  global_template->Set(
      isolate, "get_stack_pointer",
      v8::FunctionTemplate::New(isolate, GetStackPointerCallback));
35

36
  LocalContext env(nullptr, global_template);
37 38 39 40 41 42
  CompileRun(
      "function foo() {"
      "  return get_stack_pointer();"
      "}");

  v8::Local<v8::Object> global_object = env->Global();
43 44 45
  v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
      global_object->Get(isolate->GetCurrentContext(), v8_str("foo"))
          .ToLocalChecked());
46

47
  v8::Local<v8::Value> result =
48
      foo->Call(isolate->GetCurrentContext(), global_object, 0, nullptr)
49 50
          .ToLocalChecked();
  CHECK_EQ(0u, result->Uint32Value(isolate->GetCurrentContext()).FromJust() %
51
                   OS::ActivationFrameAlignment());
52
}
53
#endif  // V8_CC_GNU
54 55 56

}  // namespace internal
}  // namespace v8