Skip to content

Commit

Permalink
Merge branch 'release/1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
ccutrer committed Jul 6, 2010
2 parents 6b86977 + 50331de commit de4089c
Show file tree
Hide file tree
Showing 68 changed files with 3,066 additions and 833 deletions.
22 changes: 16 additions & 6 deletions Makefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ PLATFORMDIR := $(PLATFORM)/$(ARCH)


ifeq ($(PLATFORM), Darwin) ifeq ($(PLATFORM), Darwin)
DARWIN := 1 DARWIN := 1
BOOST_EXT := -mt BOOST_EXT :=
BOOST_LIB_FLAGS := -L/opt/local/lib BOOST_LIB_FLAGS := -L/opt/local/lib
PQ_LIB_FLAGS := -L/opt/local/lib/postgresql83 PQ_LIB_FLAGS := -L/opt/local/lib/postgresql83
IOMANAGER := kqueue IOMANAGER := kqueue
Expand Down Expand Up @@ -170,11 +170,12 @@ ifeq ($(RAGEL_MAJOR), 6)
RLCODEGEN := RLCODEGEN :=
endif endif


LIBS := $(BOOST_LIB_FLAGS) $(PQ_LIB_FLAGS) -lboost_thread$(BOOST_EXT) -lboost_program_options $(BOOST_EXT) -lboost_regex$(BOOST_EXT) -lboost_date_time$(BOOST_EXT) -lssl -lcrypto -lz -ldl

ifeq ($(PLATFORM), Darwin) ifeq ($(PLATFORM), Darwin)
LIBS += -framework SystemConfiguration -framework CoreFoundation -framework CoreServices -framework Security
endif endif


LIBS := $(BOOST_LIB_FLAGS) $(PQ_LIB_FLAGS) -lboost_thread$(BOOST_EXT) -lboost_regex$(BOOST_EXT) -lboost_date_time$(BOOST_EXT) -lssl -lcrypto -lz -ldl

ifeq ($(PLATFORM), FreeBSD) ifeq ($(PLATFORM), FreeBSD)
LIBS += -lexecinfo LIBS += -lexecinfo
endif endif
Expand Down Expand Up @@ -390,9 +391,9 @@ endif
mordor/examples/wget: mordor/examples/wget.o \ mordor/examples/wget: mordor/examples/wget.o \
mordor/libmordor.a mordor/libmordor.a
ifeq ($(Q),@) ifeq ($(Q),@)
@echo ld $@ @echo ld $@ -lboost_program_options$(BOOST_EXT)
endif endif
$(COMPLINK) $(COMPLINK) -lboost_program_options$(BOOST_EXT)


mordor/streams/socket_stream.o: mordor/streams/socket.cpp mordor/streams/socket_stream.o: mordor/streams/socket.cpp
ifeq ($(Q),@) ifeq ($(Q),@)
Expand All @@ -401,6 +402,13 @@ endif
$(Q)mkdir -p $(@D) $(Q)mkdir -p $(@D)
$(Q)$(CXX) $(CXXFLAGS) -c -o $@ $< $(Q)$(CXX) $(CXXFLAGS) -c -o $@ $<


mordor/streams/http_stream.o: mordor/streams/http.cpp
ifeq ($(Q),@)
@echo c++ $<
endif
$(Q)mkdir -p $(@D)
$(Q)$(CXX) $(CXXFLAGS) -c -o $@ $<



LIBMORDOROBJECTS := \ LIBMORDOROBJECTS := \
mordor/assert.o \ mordor/assert.o \
Expand Down Expand Up @@ -429,14 +437,15 @@ LIBMORDOROBJECTS := \
mordor/semaphore.o \ mordor/semaphore.o \
mordor/sleep.o \ mordor/sleep.o \
mordor/socket.o \ mordor/socket.o \
mordor/socks.o \
mordor/statistics.o \ mordor/statistics.o \
mordor/streams/buffer.o \ mordor/streams/buffer.o \
mordor/streams/buffered.o \ mordor/streams/buffered.o \
mordor/streams/cat.o \ mordor/streams/cat.o \
mordor/streams/fd.o \ mordor/streams/fd.o \
mordor/streams/file.o \ mordor/streams/file.o \
mordor/streams/hash.o \ mordor/streams/hash.o \
mordor/streams/http.o \ mordor/streams/http_stream.o \
mordor/streams/limited.o \ mordor/streams/limited.o \
mordor/streams/memory.o \ mordor/streams/memory.o \
mordor/streams/null.o \ mordor/streams/null.o \
Expand Down Expand Up @@ -471,6 +480,7 @@ endif
$(Q)$(AR) $(ARFLAGS) $@ $(filter %.o,$?) $(Q)$(AR) $(ARFLAGS) $@ $(filter %.o,$?)


LIBMORDORTESTOBJECTS := \ LIBMORDORTESTOBJECTS := \
mordor/test/antxmllistener.o \
mordor/test/test.o \ mordor/test/test.o \
mordor/test/stdoutlistener.o mordor/test/stdoutlistener.o


Expand Down
77 changes: 77 additions & 0 deletions autoexp.dat
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,77 @@
; Add to C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\autoexp.dat in the [Visualizer] section
; The visualizer isn't perfect - it uses ; instead of :, and , instead of / between path segments
; Also, it doesn't perform any encoding

Mordor::URI{
preview (
#(
#if ($e.m_schemeDefined) ( #(
#if (($e.m_scheme._Myres) < ($e.m_scheme._BUF_SIZE)) ( [$e.m_scheme._Bx._Buf,sb] ) #else ( [$e.m_scheme._Bx._Ptr,sb] ),
";")
) #else ( "" ),
#if ($e.authority.m_hostDefined) ( #("//", $e.authority) ) #else ( "" ),
#if ($e.path.type == ABSOLUTE || $e.path.segments._Myfirst != $e.path.segments._Mylast) ( $e.path ) #else ( "" ),
#if ($e.m_queryDefined) ( #(
"?",
#if (($e.m_query._Myres) < ($e.m_query._BUF_SIZE)) ( [$e.m_query._Bx._Buf,sb] ) #else ( [$e.m_query._Bx._Ptr,sb] ))
) #else ( "" ),
#if ($e.m_fragmentDefined) ( #(
"#",
#if (($e.m_fragment._Myres) < ($e.m_fragment._BUF_SIZE)) ( [$e.m_fragment._Bx._Buf,sb] ) #else ( [$e.m_fragment._Bx._Ptr,sb] ))
) #else ( "" )
)
)
children (
#(
#if ($e.m_schemeDefined) ( #(scheme: $e.m_scheme) ) #else ( #array(expr: 0, size: 0) ),
#if ($e.authority.m_hostDefined) ( #(authority: $e.authority) ) #else ( #array(expr: 0, size: 0) ),
#if ($e.path.type == ABSOLUTE || $e.path.segments._Myfirst != $e.path.segments._Mylast) ( #(path: $e.path) ) #else ( #array(expr: 0, size: 0) ),
#if ($e.m_queryDefined) ( #(query: $e.m_query) ) #else ( #array(expr: 0, size: 0) ),
#if ($e.m_fragmentDefined) ( #(fragment: $e.m_fragment) ) #else ( #array(expr: 0, size: 0) ),
#(Actual Members: [$e,!])
)
)
}

Mordor::URI::Authority{
preview (
#(
#if ($e.m_userinfoDefined) ( #( #if (($e.m_userinfo._Myres) < ($e.m_userinfo._BUF_SIZE)) ( [$e.m_userinfo._Bx._Buf,sb] ) #else ( [$e.m_userinfo._Bx._Ptr,sb] ), "@") ) #else ( "" ),
#if ($e.m_hostDefined) ( #if (($e.m_host._Myres) < ($e.m_host._BUF_SIZE)) ( [$e.m_host._Bx._Buf,sb] ) #else ( [$e.m_host._Bx._Ptr,sb] ) ) #else ( "" ),
#if ($e.m_portDefined) ( #( ";", $e.m_port) ) #else ( "" )
)
)
children (
#(
#if ($e.m_userinfoDefined) ( #( userinfo: $e.m_userinfo) ) #else ( #array(expr: 0, size: 0) ),
#if ($e.m_hostDefined) ( #( host: $e.m_host) ) #else ( #array(expr: 0, size: 0) ),
#if ($e.m_portDefined) ( #( port: $e.m_port) ) #else ( #array(expr: 0, size: 0) ),
#(Actual Members: [$e,!])
)
)
}

Mordor::URI::Path{
preview (
#if ($e.type == RELATIVE && $e.segments._Myfirst == $e.segments._Mylast) (
""
) #else (
#(
#if ($e.type == ABSOLUTE) (
"/"
) #else (
""
),
#array(
expr:
#if ((($e.segments._Myfirst[$i])._Myres) < (($e.segments._Myfirst[$i])._BUF_SIZE)) (
[($e.segments._Myfirst[$i])._Bx._Buf,sb]
) #else (
[($e.segments._Myfirst[$i])._Bx._Ptr,sb]
),
size: $e.segments._Mylast - $e.segments._Myfirst
)
)
)
)
}
8 changes: 8 additions & 0 deletions mordor.xcodeproj/project.pbxproj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
3CAB29E9112B347400607AEE /* timer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CAB2798112B096700607AEE /* timer.cpp */; }; 3CAB29E9112B347400607AEE /* timer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CAB2798112B096700607AEE /* timer.cpp */; };
3CAC4A341151622F00F85725 /* iomanager_kqueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CAB271B112B096700607AEE /* iomanager_kqueue.cpp */; }; 3CAC4A341151622F00F85725 /* iomanager_kqueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CAB271B112B096700607AEE /* iomanager_kqueue.cpp */; };
3CC4CE561138646D001C21F2 /* progress.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CC4CE551138646D001C21F2 /* progress.h */; }; 3CC4CE561138646D001C21F2 /* progress.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CC4CE551138646D001C21F2 /* progress.h */; };
C34893CA11BEB1300044E9C8 /* socks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C34893C811BEB1300044E9C8 /* socks.cpp */; };
C34893CB11BEB1300044E9C8 /* socks.h in Headers */ = {isa = PBXBuildFile; fileRef = C34893C911BEB1300044E9C8 /* socks.h */; };
E29FD2AA1136FD1D004BC293 /* timeout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E29FD2A81136FD1D004BC293 /* timeout.cpp */; }; E29FD2AA1136FD1D004BC293 /* timeout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E29FD2A81136FD1D004BC293 /* timeout.cpp */; };
E29FD2AB1136FD1D004BC293 /* timeout.h in Headers */ = {isa = PBXBuildFile; fileRef = E29FD2A91136FD1D004BC293 /* timeout.h */; }; E29FD2AB1136FD1D004BC293 /* timeout.h in Headers */ = {isa = PBXBuildFile; fileRef = E29FD2A91136FD1D004BC293 /* timeout.h */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
Expand Down Expand Up @@ -279,6 +281,8 @@
3CAB27A1112B096700607AEE /* xml_parser.rl */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp.preprocessed; fileEncoding = 4; path = xml_parser.rl; sourceTree = "<group>"; }; 3CAB27A1112B096700607AEE /* xml_parser.rl */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp.preprocessed; fileEncoding = 4; path = xml_parser.rl; sourceTree = "<group>"; };
3CAB29B1112B340600607AEE /* libmordor.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libmordor.a; sourceTree = BUILT_PRODUCTS_DIR; }; 3CAB29B1112B340600607AEE /* libmordor.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libmordor.a; sourceTree = BUILT_PRODUCTS_DIR; };
3CC4CE551138646D001C21F2 /* progress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = progress.h; sourceTree = "<group>"; }; 3CC4CE551138646D001C21F2 /* progress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = progress.h; sourceTree = "<group>"; };
C34893C811BEB1300044E9C8 /* socks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = socks.cpp; sourceTree = "<group>"; };
C34893C911BEB1300044E9C8 /* socks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = socks.h; sourceTree = "<group>"; };
E29FD2A81136FD1D004BC293 /* timeout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = timeout.cpp; sourceTree = "<group>"; }; E29FD2A81136FD1D004BC293 /* timeout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = timeout.cpp; sourceTree = "<group>"; };
E29FD2A91136FD1D004BC293 /* timeout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = timeout.h; sourceTree = "<group>"; }; E29FD2A91136FD1D004BC293 /* timeout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = timeout.h; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
Expand Down Expand Up @@ -330,6 +334,8 @@
3CAB26D4112B096700607AEE /* mordor */ = { 3CAB26D4112B096700607AEE /* mordor */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C34893C811BEB1300044E9C8 /* socks.cpp */,
C34893C911BEB1300044E9C8 /* socks.h */,
3CAB26D5112B096700607AEE /* .gitignore */, 3CAB26D5112B096700607AEE /* .gitignore */,
3CAB26D6112B096700607AEE /* anymap.h */, 3CAB26D6112B096700607AEE /* anymap.h */,
3CAB26D7112B096700607AEE /* assert.cpp */, 3CAB26D7112B096700607AEE /* assert.cpp */,
Expand Down Expand Up @@ -591,6 +597,7 @@
files = ( files = (
E29FD2AB1136FD1D004BC293 /* timeout.h in Headers */, E29FD2AB1136FD1D004BC293 /* timeout.h in Headers */,
3CC4CE561138646D001C21F2 /* progress.h in Headers */, 3CC4CE561138646D001C21F2 /* progress.h in Headers */,
C34893CB11BEB1300044E9C8 /* socks.h in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand Down Expand Up @@ -692,6 +699,7 @@
3CAB29E9112B347400607AEE /* timer.cpp in Sources */, 3CAB29E9112B347400607AEE /* timer.cpp in Sources */,
E29FD2AA1136FD1D004BC293 /* timeout.cpp in Sources */, E29FD2AA1136FD1D004BC293 /* timeout.cpp in Sources */,
3CAC4A341151622F00F85725 /* iomanager_kqueue.cpp in Sources */, 3CAC4A341151622F00F85725 /* iomanager_kqueue.cpp in Sources */,
C34893CA11BEB1300044E9C8 /* socks.cpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand Down
22 changes: 21 additions & 1 deletion mordor/atomic.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@


#include "predef.h" #include "predef.h"


#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1 && defined(__arm__))
#include <boost/smart_ptr/detail/sp_counted_base_spin.hpp>
#endif

namespace Mordor { namespace Mordor {


#ifdef WINDOWS #ifdef WINDOWS
Expand Down Expand Up @@ -166,7 +170,7 @@ atomicSwap(volatile T &t, T newvalue)
return comparand; return comparand;
} }
#endif #endif
#elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) #elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 1 && !defined(__arm__))
template <class T> template <class T>
typename boost::enable_if_c<sizeof(T) <= sizeof(void *), T>::type typename boost::enable_if_c<sizeof(T) <= sizeof(void *), T>::type
atomicDecrement(volatile T& t) { return __sync_sub_and_fetch(&t, 1); } atomicDecrement(volatile T& t) { return __sync_sub_and_fetch(&t, 1); }
Expand Down Expand Up @@ -220,6 +224,22 @@ atomicIncrement(volatile T& t) { return __gnu_cxx::__exchange_and_add((_Atomic_w
template <class T> template <class T>
typename boost::enable_if_c<sizeof(T) <= sizeof(_Atomic_word), T>::type typename boost::enable_if_c<sizeof(T) <= sizeof(_Atomic_word), T>::type
atomicAdd(volatile T& t, T v) { return __gnu_cxx::__exchange_and_add((_Atomic_word*)_&t, v) + v; } atomicAdd(volatile T& t, T v) { return __gnu_cxx::__exchange_and_add((_Atomic_word*)_&t, v) + v; }
#elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 1 && defined(__arm__))
template <class T>
typename boost::enable_if_c<sizeof(T) <= sizeof(int), T>::type
atomicAdd(volatile T& t, T v) { return boost::detail::atomic_exchange_and_add((int *)&t, (int)v) + v; }
template <class T>
typename boost::enable_if_c<sizeof(T) <= sizeof(int), T>::type
atomicIncrement(volatile T& t) { return atomicAdd(t, (T)1); }
template <class T>
typename boost::enable_if_c<sizeof(T) <= sizeof(int), T>::type
atomicCompareAndSwap(volatile T &t, T newvalue, T comparand) {
::boost::detail::spinlock_pool<1>::scoped_lock lock((void *)&t);
T oldvalue = t;
if (oldvalue == comparand)
t = newvalue;
return oldvalue;
}
#endif #endif


template <typename T> template <typename T>
Expand Down
102 changes: 102 additions & 0 deletions mordor/examples/decodebacktrace.cpp
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright (c) 2009 - Mozy, Inc.

#include "mordor/predef.h"

#include <iostream>

#include <DbgHelp.h>

#include "mordor/config.h"
#include "mordor/streams/buffered.h"
#include "mordor/streams/std.h"

using namespace Mordor;

int main(int argc, const char *argv[])
{
if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " <symbolpath> <binary>..." << std::endl
<< " Look for backtrace addresses on stdin, and attempt to convert them to" << std::endl
<< " symbols of the given binaries." << std::endl << std::endl;
return 1;
}

std::vector<DWORD64> loadedModules;
try {
Config::loadFromEnvironment();
// Re-init symbols (it got initted statically in exception.cpp) with
// a symbol search path
if (!SymCleanup(GetCurrentProcess()))
MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("SymCleanup");
if (!SymInitialize(GetCurrentProcess(), argv[1], FALSE))
MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("SymInitialize");

// Load up the specified modules in their default load location
// Does *not* currently handle ASLR (basically, it would need to
// do two passes through the log, and calculate the actual load address
// of a module based on where the (limited) symbols that are in the
// file ended up; or, use a minidump to aid the process)
for (int i = 2; i < argc; ++i) {
DWORD64 baseAddress =
SymLoadModule64(GetCurrentProcess(), NULL, argv[i], NULL, 0, 0);
if (baseAddress == 0) {
if (GetLastError() == ERROR_SUCCESS)
continue;
MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("SymLoadModule64");
}
loadedModules.push_back(baseAddress);
}
char buf[sizeof(SYMBOL_INFO) + MAX_SYM_NAME - 1];
SYMBOL_INFO *symbol = (SYMBOL_INFO*)buf;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
symbol->MaxNameLen = MAX_SYM_NAME;
DWORD64 displacement64 = 0;

Stream::ptr stream(new StdinStream());
stream.reset(new BufferedStream(stream));
StdoutStream output;
std::string line;
do {
line = stream->getDelimited('\n', true);
std::string copy(line);
if (copy.size() >= 35 &&
strncmp(copy.c_str(), "[struct Mordor::tag_backtrace *] = ", 35)
== 0)
copy = copy.substr(35);
char *end;
DWORD64 address = strtoull(copy.c_str(), &end, 16);
if ( (end - copy.c_str()) == 8 || (end - copy.c_str()) == 16) {
if (SymFromAddr(GetCurrentProcess(), address, &displacement64, symbol)) {
std::ostringstream os;
if (copy != line)
os << "[struct Mordor::tag_backtrace *] = ";
os << copy.substr(0, (end - copy.c_str())) << ": "
<< symbol->Name << "+" << displacement64;
IMAGEHLP_LINE64 line;
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
DWORD displacement = 0;
if (SymGetLineFromAddr64(GetCurrentProcess(),
address, &displacement, &line)) {
std::cout << ": " << line.FileName << "("
<< line.LineNumber << ")+" << displacement;
}
os << std::endl;
std::string newline = os.str();
output.write(newline.c_str(), newline.size());
} else {
output.write(line.c_str(), line.size());
}
} else {
output.write(line.c_str(), line.size());
}
} while (!line.empty() && line.back() == '\n');
} catch (...) {
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
for (size_t i = 0; i < loadedModules.size(); ++i)
SymUnloadModule64(GetCurrentProcess(), loadedModules[i]);
return 2;
}
for (size_t i = 0; i < loadedModules.size(); ++i)
SymUnloadModule64(GetCurrentProcess(), loadedModules[i]);
return 0;
}
Loading

0 comments on commit de4089c

Please sign in to comment.