コード例 #1
0
ファイル: member-reflection.cpp プロジェクト: MatmaRex/hhvm
HPHP_REFLECTABLES
#undef X

bool init_member_reflection() {
  embedded_data desc;
  if (!get_embedded_data("member_reflection", &desc)) {
    // We might not be embedding the shared object, depending on platform, so
    // don't cry too loudly if we don't find it.
    Logger::Verbose("init_member_reflection: Unable to find embedded data\n");
    return false;
  }

  char tmp_filename[] = "/tmp/hhvm_member_reflection_XXXXXX";
  auto const handle = dlopen_embedded_data(desc, tmp_filename);
  if (!handle) {
    Logger::Warning("init_member_reflection: "
                    "Failed to dlopen embedded data\n");
    return false;
  }

  g_member_reflection_vtable =
    reinterpret_cast<decltype(g_member_reflection_vtable)>(
      dlsym(handle, detail::kMemberReflectionTableName)
    );
  if (!g_member_reflection_vtable) {
    Logger::Warning("init_member_reflection: dlsym failed: %s\n", dlerror());
    return false;
  }

  return true;
}
コード例 #2
0
ファイル: extern-compiler.cpp プロジェクト: fredemmott/hhvm
folly::Optional<std::string> hackcExtractPath() {
  if (!RuntimeOption::EvalHackCompilerUseEmbedded) return folly::none;

  auto check = [] (const std::string& s) {
    return !s.empty() && access(s.data(), X_OK) == 0;
  };
  if (!tl_extractPath.isNull() && check(*tl_extractPath)) {
    return *tl_extractPath;
  }

  std::unique_lock<std::mutex> lock{s_extractLock};
  if (check(s_extractPath)) {
    *tl_extractPath.getCheck() = s_extractPath;
    return *tl_extractPath;
  }

  auto set = [&] (const std::string& s) {
    s_extractPath = s;
    *tl_extractPath.getCheck() = s;
    return s;
  };

  auto const trust = RuntimeOption::EvalHackCompilerTrustExtract;
  auto const location = RuntimeOption::EvalHackCompilerExtractPath;
  // As an optimization we can just choose to trust the extracted version
  // without reading it.
  if (trust && check(location)) return set(location);

  embedded_data desc;
  if (!get_embedded_data("hackc_binary", &desc)) {
    Logger::Error("Embedded hackc binary is missing");
    return folly::none;
  }
  auto const gz_binary = read_embedded_data(desc);
  int len = safe_cast<int>(gz_binary.size());

  auto const bin_str = gzdecode(gz_binary.data(), len);
  SCOPE_EXIT { free(bin_str); };
  if (!bin_str || !len) {
    Logger::Error("Embedded hackc binary could not be decompressed");
    return folly::none;
  }

  auto const binary = std::string(bin_str, len);
  if (createHackc(location, binary)) return set(location);

  int fd = -1;
  SCOPE_EXIT { if (fd != -1) close(fd); };

  auto fallback = RuntimeOption::EvalHackCompilerFallbackPath;
  if ((fd = mkstemp(&fallback[0])) == -1) {
    Logger::FError(
      "Unable to create temp file for hackc binary: {}", folly::errnoStr(errno)
    );
    return folly::none;
  }

  if (folly::writeFull(fd, binary.data(), binary.size()) == -1) {
    Logger::FError(
      "Failed to write extern hackc binary: {}", folly::errnoStr(errno)
    );
    return folly::none;
  }

  if (chmod(fallback.data(), 0755) != 0) {
    Logger::Error("Unable to mark hackc binary as writable");
    return folly::none;
  }

  return set(fallback);
}