Fix crash when trying to change staticness of a property
[hiphop-php.git] / hphp / util / abi-cxx.h
blob70271834d6bf9f37b49e2d5deda12e41d8fd3ccf
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_UTIL_ABI_CXX_H_
17 #define incl_HPHP_UTIL_ABI_CXX_H_
19 #include <inttypes.h>
20 #include <string>
22 namespace HPHP {
24 //////////////////////////////////////////////////////////////////////
27 * Given a pointer to somewhere in a C++ function, returns that function's name
28 * or a hex string representation of the address if it can't find the
29 * function's name. Attempts to demangle C++ function names.
31 std::string getNativeFunctionName(void* codeAddr);
33 template<typename Ret, typename... Args>
34 inline std::string getNativeFunctionName(Ret (*ptr)(Args...)) {
35 return getNativeFunctionName(reinterpret_cast<void*>(ptr));
38 /**
39 * Get the vtable offset corresponding to a method pointer. NB: only works
40 * for single inheritance. For no inheritance at all, use
41 * getMethodPtr. ABI-specific, don't play on or around.
43 template <typename MethodPtr>
44 int64_t getVTableOffset(MethodPtr meth) {
45 union {
46 MethodPtr meth;
47 int64_t offset;
48 } u;
49 u.meth = meth;
50 return u.offset - 1;
53 template <typename MethodPtr>
54 union MethodPtrU {
55 MethodPtr meth;
56 void* ptr;
59 template <typename MethodPtr>
60 constexpr void* getMethodPtr(MethodPtr meth) {
61 return ((MethodPtrU<MethodPtr>*)(&meth))->ptr;
64 //////////////////////////////////////////////////////////////////////
69 #endif