1 // Copyright 2019 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "src/extensions/cputracemark-extension.h" 6 7 #include "include/v8-isolate.h" 8 #include "include/v8-template.h" 9 10 namespace v8 { 11 namespace internal { 12 13 v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(v8::Isolate * isolate,v8::Local<v8::String> str)14CpuTraceMarkExtension::GetNativeFunctionTemplate(v8::Isolate* isolate, 15 v8::Local<v8::String> str) { 16 return v8::FunctionTemplate::New(isolate, CpuTraceMarkExtension::Mark); 17 } 18 Mark(const v8::FunctionCallbackInfo<v8::Value> & args)19void CpuTraceMarkExtension::Mark( 20 const v8::FunctionCallbackInfo<v8::Value>& args) { 21 if (args.Length() < 1 || !args[0]->IsUint32()) { 22 args.GetIsolate()->ThrowError( 23 "First parameter to cputracemark() must be a unsigned int32."); 24 return; 25 } 26 27 #if V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 28 29 #if defined(__clang__) 30 // for non msvc build 31 uint32_t param = 32 args[0]->Uint32Value(args.GetIsolate()->GetCurrentContext()).ToChecked(); 33 34 int magic_dummy; 35 36 #if defined(__i386__) && defined(__pic__) 37 __asm__ __volatile__("push %%ebx; cpuid; pop %%ebx" 38 : "=a"(magic_dummy) 39 : "a"(0x4711 | (param << 16)) 40 : "ecx", "edx"); 41 #else 42 __asm__ __volatile__("cpuid" 43 : "=a"(magic_dummy) 44 : "a"(0x4711 | (param << 16)) 45 : "ecx", "edx", "ebx"); 46 #endif // defined(__i386__) && defined(__pic__) 47 48 #else 49 // no msvc build support yet. 50 #endif //! V8_LIBC_MSVCRT 51 52 #endif // V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64 53 } 54 55 } // namespace internal 56 } // namespace v8 57