don't use local-file-change context for mapreduce
[hiphop-php.git] / hphp / util / embedded-data.h
blobcacc7c12fd13e200631580caa99d81d6369ef8fe
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present 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 #ifndef incl_HPHP_UTIL_EMBEDDED_DATA_H_
18 #define incl_HPHP_UTIL_EMBEDDED_DATA_H_
20 #ifdef __cplusplus
22 #include <cstdint>
23 #include <string>
25 namespace HPHP {
27 ///////////////////////////////////////////////////////////////////////////////
29 struct embedded_data {
30 std::string m_filename;
31 uint64_t m_start;
32 uint64_t m_len;
33 #ifdef _MSC_VER
34 void* m_handle;
35 #endif
38 bool get_embedded_data(const char* section, embedded_data* desc,
39 const std::string& filename = "");
41 std::string read_embedded_data(const embedded_data& desc);
44 * dlopen() the embedded shared object given by `desc'.
46 * Unfortunately, there's no way to do the equivalent of dlopen() on data
47 * within another file, or even in memory. This means we have to copy the
48 * section into a temporary file and then dlopen() that.
50 * If trust is true, than any existing file with the same name as the first
51 * extract path will be used without extracting the data. Otherwise if the file
52 * exists, its contents will be verified before using. If the file does not
53 * exist, it will be created and the embedded data copied into it. If this fails
54 * for any reason, the fallback path is used, if provided.
56 * Returns the result of dlopen() on success, else nullptr. Also logs the
57 * failure condition with Logger on failure.
59 void* dlopen_embedded_data(const embedded_data& desc,
60 std::string extractPath,
61 std::string fallbackPath,
62 const std::string& buildId,
63 bool trust);
66 * Clean up any fallback files that we created at process shutdown time.
68 void embedded_data_cleanup();
71 ///////////////////////////////////////////////////////////////////////////////
75 #else //__cplusplus
78 * Read data from the named section and place it into the given buffer (of size
79 * len) Returns the number of bytes (not null-terminated) read or -1 if
80 * unsuccessful
82 ssize_t hphp_read_embedded_data(const char* section, char* buf, size_t len);
84 #endif //__cplusplus
86 #endif