chromium 11.0.969.72
[chromium.git] / patches / patch-v8_src_platform-openbsd.cc
1 $NetBSD$
2
3 --- v8/src/platform-openbsd.cc.orig     2011-04-13 08:24:41.000000000 +0000
4 +++ v8/src/platform-openbsd.cc
5 @@ -164,6 +164,7 @@ void* OS::Allocate(const size_t requeste
6  
7  
8  void OS::Free(void* buf, const size_t length) {
9 +  // TODO(1240712): munmap has a return value which is ignored here.
10    int result = munmap(buf, length);
11    USE(result);
12    ASSERT(result == 0);
13 @@ -197,13 +198,7 @@ void OS::Abort() {
14  
15  
16  void OS::DebugBreak() {
17 -#if (defined(__arm__) || defined(__thumb__))
18 -# if defined(CAN_USE_ARMV5_INSTRUCTIONS)
19 -  asm("bkpt 0");
20 -# endif
21 -#else
22    asm("int $3");
23 -#endif
24  }
25  
26  
27 @@ -309,8 +304,30 @@ void OS::SignalCodeMovingGC() {
28  
29  
30  int OS::StackWalk(Vector<OS::StackFrame> frames) {
31 -  UNIMPLEMENTED();
32 -  return 1;
33 +  int frames_size = frames.length();
34 +  ScopedVector<void*> addresses(frames_size);
35 +
36 +  int frames_count = backtrace(addresses.start(), frames_size);
37 +
38 +  char** symbols = backtrace_symbols(addresses.start(), frames_count);
39 +  if (symbols == NULL) {
40 +    return kStackWalkError;
41 +  }
42 +
43 +  for (int i = 0; i < frames_count; i++) {
44 +    frames[i].address = addresses[i];
45 +    // Format a text representation of the frame based on the information
46 +    // available.
47 +    SNPrintF(MutableCStrVector(frames[i].text, kStackWalkMaxTextLen),
48 +             "%s",
49 +             symbols[i]);
50 +    // Make sure line termination is in place.
51 +    frames[i].text[kStackWalkMaxTextLen - 1] = '\0';
52 +  }
53 +
54 +  free(symbols);
55 +
56 +  return frames_count;
57  }
58  
59  
60 @@ -502,6 +519,16 @@ class OpenBSDMutex : public Mutex {
61      return result;
62    }
63  
64 +  virtual bool TryLock() {
65 +    int result = pthread_mutex_trylock(&mutex_);
66 +    // Return false if the lock is busy and locking failed.
67 +    if (result == EBUSY) {
68 +      return false;
69 +    }
70 +    ASSERT(result == 0);  // Verify no other errors.
71 +    return true;
72 +  }
73 +
74   private:
75    pthread_mutex_t mutex_;   // Pthread mutex for POSIX platforms.
76  };
77 @@ -571,18 +598,37 @@ Semaphore* OS::CreateSemaphore(int count
78  #ifdef ENABLE_LOGGING_AND_PROFILING
79  
80  static Sampler* active_sampler_ = NULL;
81 +static pthread_t vm_tid_ = 0;
82 +
83 +typedef struct sigcontext ucontext_t;
84  
85  static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
86    USE(info);
87    if (signal != SIGPROF) return;
88 -  if (active_sampler_ == NULL) return;
89 -
90 -  TickSample sample;
91 +  if (active_sampler_ == NULL || !active_sampler_->IsActive()) return;
92 +  if (vm_tid_ != pthread_self()) return;
93  
94 -  // We always sample the VM state.
95 -  sample.state = VMState::current_state();
96 -
97 -  active_sampler_->Tick(&sample);
98 +  TickSample sample_obj;
99 +  TickSample* sample = CpuProfiler::TickSampleEvent();
100 +  if (sample == NULL) sample = &sample_obj;
101 +
102 +  // Extracting the sample from the context is extremely machine dependent.
103 +  ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
104 +  sample->state = Top::current_vm_state();
105 +
106 +#if V8_HOST_ARCH_IA32
107 +  sample->pc = reinterpret_cast<Address>(ucontext->sc_eip);
108 +  sample->sp = reinterpret_cast<Address>(ucontext->sc_esp);
109 +  sample->fp = reinterpret_cast<Address>(ucontext->sc_ebp);
110 +#elif V8_HOST_ARCH_X64
111 +  sample->pc = reinterpret_cast<Address>(ucontext->sc_rip);
112 +  sample->sp = reinterpret_cast<Address>(ucontext->sc_rsp);
113 +  sample->fp = reinterpret_cast<Address>(ucontext->sc_rbp);
114 +#else
115 +  UNIMPLEMENTED();
116 +#endif
117 +  active_sampler_->SampleStack(sample);
118 +  active_sampler_->Tick(sample);
119  }
120  
121  
122 @@ -616,6 +662,7 @@ void Sampler::Start() {
123    // There can only be one active sampler at the time on POSIX
124    // platforms.
125    if (active_sampler_ != NULL) return;
126 +  vm_tid_ = pthread_self();
127  
128    // Request profiling signals.
129    struct sigaction sa;