Skip to content

Commit 45c11ef

Browse files
committed
Refactor OXT and fix some problems uncovered by AddressSanitizer. Thread interruption is now more stable: we work around some mysterious issues on OS X and we only interrupt signals when the thread is actually inside an oxt::syscall function.
1 parent 81101ee commit 45c11ef

17 files changed

+538
-479
lines changed

ext/common/agents/Base.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define _GNU_SOURCE
2727
#endif
2828

29+
#include <oxt/initialize.hpp>
2930
#include <oxt/system_calls.hpp>
3031
#include <oxt/backtrace.hpp>
3132
#include <sys/types.h>
@@ -660,6 +661,7 @@ initializeAgent(int argc, char *argv[], const char *processName) {
660661
if (hasEnvOption("PASSENGER_ABORT_HANDLER", true)) {
661662
installAbortHandler();
662663
}
664+
oxt::initialize();
663665
setup_syscall_interruption_support();
664666
setvbuf(stdout, NULL, _IONBF, 0);
665667
setvbuf(stderr, NULL, _IONBF, 0);

ext/common/agents/HelperAgent/RequestHandler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ RequestHandler::getClientPointer(const ClientPtr &client) {
188188
#include <MultiLibeio.cpp>
189189
#include <iostream>
190190
#include <agents/Base.h>
191+
#include <oxt/initialize.hpp>
191192

192193
using namespace std;
193194
using namespace Passenger;
@@ -228,6 +229,7 @@ ignoreSigpipe() {
228229

229230
int
230231
main() {
232+
oxt::initialize();
231233
setup_syscall_interruption_support();
232234
ignoreSigpipe();
233235
//installAbortHandler();

ext/oxt/backtrace.cpp

Lines changed: 0 additions & 163 deletions
This file was deleted.

ext/oxt/detail/backtrace_enabled.hpp

Lines changed: 5 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OXT - OS eXtensions for boosT
33
* Provides important functionality necessary for writing robust server software.
44
*
5-
* Copyright (c) 2010 Phusion
5+
* Copyright (c) 2010, 2011, 2012 Phusion
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -27,32 +27,10 @@
2727

2828
#define OXT_BACKTRACE_IS_ENABLED
2929

30-
#include <boost/thread/mutex.hpp>
3130
#include <boost/current_function.hpp>
32-
#include <exception>
33-
#include <string>
34-
#include <list>
35-
#include <vector>
36-
#include "../spin_lock.hpp"
37-
#include "../macros.hpp"
3831

3932
namespace oxt {
4033

41-
using namespace std;
42-
using namespace boost;
43-
struct trace_point;
44-
class tracable_exception;
45-
struct thread_registration;
46-
47-
extern boost::mutex _thread_registration_mutex;
48-
extern list<thread_registration *> _registered_threads;
49-
50-
void _init_backtrace_tls();
51-
void _finalize_backtrace_tls();
52-
bool _get_backtrace_list_and_its_lock(vector<trace_point *> **backtrace_list, spin_lock **lock);
53-
string _format_backtrace(const list<trace_point *> *backtrace_list);
54-
string _format_backtrace(const vector<trace_point *> *backtrace_list);
55-
5634
/**
5735
* A single point in a backtrace. Creating this object will cause it
5836
* to push itself to the thread's backtrace list. This backtrace list
@@ -61,96 +39,21 @@ string _format_backtrace(const vector<trace_point *> *backtrace_list);
6139
* backtrace list.
6240
*
6341
* Except if you set the 'detached' argument to true.
64-
*
65-
* Implementation detail - do not use directly!
66-
* @internal
6742
*/
6843
struct trace_point {
6944
const char *function;
7045
const char *source;
7146
unsigned int line;
7247
bool m_detached;
7348

74-
trace_point(const char *function, const char *source, unsigned int line) {
75-
this->function = function;
76-
this->source = source;
77-
this->line = line;
78-
m_detached = false;
79-
80-
vector<trace_point *> *backtrace_list;
81-
spin_lock *lock;
82-
if (OXT_LIKELY(_get_backtrace_list_and_its_lock(&backtrace_list, &lock))) {
83-
spin_lock::scoped_lock l(*lock);
84-
backtrace_list->push_back(this);
85-
}
86-
}
87-
88-
trace_point(const char *function, const char *source, unsigned int line, bool detached) {
89-
this->function = function;
90-
this->source = source;
91-
this->line = line;
92-
m_detached = true;
93-
}
94-
95-
~trace_point() {
96-
if (OXT_LIKELY(!m_detached)) {
97-
vector<trace_point *> *backtrace_list;
98-
spin_lock *lock;
99-
if (OXT_LIKELY(_get_backtrace_list_and_its_lock(&backtrace_list, &lock))) {
100-
spin_lock::scoped_lock l(*lock);
101-
backtrace_list->pop_back();
102-
}
103-
}
104-
}
105-
106-
void update(const char *source, unsigned int line) {
107-
this->source = source;
108-
this->line = line;
109-
}
49+
trace_point(const char *function, const char *source, unsigned int line);
50+
trace_point(const char *function, const char *source, unsigned int line, bool detached);
51+
~trace_point();
52+
void update(const char *source, unsigned int line);
11053
};
11154

11255
#define TRACE_POINT() oxt::trace_point __p(BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)
11356
#define TRACE_POINT_WITH_NAME(name) oxt::trace_point __p(name, __FILE__, __LINE__)
11457
#define UPDATE_TRACE_POINT() __p.update(__FILE__, __LINE__)
11558

116-
/**
117-
* @internal
118-
*/
119-
struct thread_registration {
120-
string name;
121-
spin_lock *backtrace_lock;
122-
vector<trace_point *> *backtrace;
123-
};
124-
125-
/**
126-
* @internal
127-
*/
128-
struct initialize_backtrace_support_for_this_thread {
129-
thread_registration *registration;
130-
list<thread_registration *>::iterator it;
131-
132-
initialize_backtrace_support_for_this_thread(const string &name) {
133-
_init_backtrace_tls();
134-
registration = new thread_registration();
135-
registration->name = name;
136-
_get_backtrace_list_and_its_lock(&registration->backtrace,
137-
&registration->backtrace_lock);
138-
139-
boost::mutex::scoped_lock l(_thread_registration_mutex);
140-
_registered_threads.push_back(registration);
141-
it = _registered_threads.end();
142-
it--;
143-
}
144-
145-
~initialize_backtrace_support_for_this_thread() {
146-
{
147-
boost::mutex::scoped_lock l(_thread_registration_mutex);
148-
_registered_threads.erase(it);
149-
delete registration;
150-
}
151-
_finalize_backtrace_tls();
152-
}
153-
};
154-
15559
} // namespace oxt
156-

0 commit comments

Comments
 (0)