Add missing includes for OSS build
[hiphop-php.git] / hphp / util / vdso.cpp
blobd71e7455a755bdbbf504ae6a548ee12e583c8eeb
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 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 +----------------------------------------------------------------------+
17 #include "hphp/util/vdso.h"
19 #define _GNU_SOURCE 1
20 #include <dlfcn.h>
22 #include <cstring>
24 namespace HPHP { namespace Util {
25 ///////////////////////////////////////////////////////////////////////////////
27 static Vdso s_vdso;
29 Vdso::Vdso() : m_handle(nullptr), m_clock_gettime_ns(nullptr) {
30 m_handle = dlopen("linux-vdso.so.1", RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
31 if (!m_handle) {
32 return;
35 m_clock_gettime_ns =
36 (int64_t (*)(clockid_t))dlsym(m_handle, "__vdso_clock_gettime_ns");
37 m_clock_gettime =
38 (int (*)(clockid_t, timespec *))dlsym(m_handle, "__vdso_clock_gettime");
41 Vdso::~Vdso() {
42 if (m_handle) {
43 dlclose(m_handle);
47 int64_t Vdso::ClockGetTimeNS(int clk_id) {
48 return s_vdso.clockGetTimeNS(clk_id);
51 int Vdso::ClockGetTime(int clk_id, timespec *ts) {
52 return s_vdso.clockGetTime(clk_id, ts);
55 ALWAYS_INLINE int64_t Vdso::clockGetTimeNS(int clk_id) {
56 if (m_clock_gettime_ns)
57 return m_clock_gettime_ns(clk_id);
58 return -1;
61 ALWAYS_INLINE int Vdso::clockGetTime(int clk_id, timespec *ts) {
62 if (m_clock_gettime) {
63 memset(ts, 0, sizeof(*ts));
64 return m_clock_gettime(clk_id, ts);
66 return -1;
69 ///////////////////////////////////////////////////////////////////////////////