Ejemplo n.º 1
0
TEST_F(PacksTests, test_check_platform) {
  auto fpack = Pack("foobar", getPackWithDiscovery());
  if (kSDKPlatform == "darwin") {
    EXPECT_TRUE(fpack.checkPlatform());
  } else {
    EXPECT_FALSE(fpack.checkPlatform());
  }
}
Ejemplo n.º 2
0
TEST_F(PacksTests, test_check_platform) {
  auto fpack = Pack("discovery_pack", getPackWithDiscovery());
  // Depending on the current build platform, this check will be true or false.
  if (kSDKPlatform == "darwin") {
    EXPECT_TRUE(fpack.checkPlatform());
  } else {
    EXPECT_FALSE(fpack.checkPlatform());
  }
}
Ejemplo n.º 3
0
//-------------------------------------------------------------------------------------------------------
int main (int argc, char* argv[])
{
	if (!checkPlatform ())
	{
		printf ("Platform verification failed! Please check your Compiler Settings!\n");
		return -1;
	}

	const char* fileName = "again.dll";
	//const char* fileName = "adelay.dll";
	//const char* fileName = "surrounddelay.dll";
	//const char* fileName = "vstxsynth.dll";
	//const char* fileName = "drawtest.dll";

	if (argc > 1)
		fileName = argv[1];

	printf ("HOST> Load library...\n");
	PluginLoader loader;
	if (!loader.loadLibrary (fileName))
	{
		printf ("Failed to load VST Plugin library!\n");
		return -1;
	}

	PluginEntryProc mainEntry = loader.getMainEntry ();
	if (!mainEntry)
	{
		printf ("VST Plugin main entry not found!\n");
		return -1;
	}

	printf ("HOST> Create effect...\n");
	AEffect* effect = mainEntry (HostCallback);
	if (!effect)
	{
		printf ("Failed to create effect instance!\n");
		return -1;
	}

	printf ("HOST> Init sequence...\n");
	effect->dispatcher (effect, effOpen, 0, 0, 0, 0);
	effect->dispatcher (effect, effSetSampleRate, 0, 0, 0, kSampleRate);
	effect->dispatcher (effect, effSetBlockSize, 0, kBlockSize, 0, 0);

	checkEffectProperties (effect);
	checkEffectProcessing (effect);
	checkEffectEditor (effect);

	printf ("HOST> Close effect...\n");
	effect->dispatcher (effect, effClose, 0, 0, 0, 0);
	return 0;
}
Ejemplo n.º 4
0
void Pack::initialize(const std::string& name,
                      const std::string& source,
                      const pt::ptree& tree) {
  name_ = name;
  source_ = source;
  discovery_queries_.clear();
  if (tree.count("discovery") > 0) {
    for (const auto& item : tree.get_child("discovery")) {
      discovery_queries_.push_back(item.second.get_value<std::string>());
    }
  }

  discovery_cache_ = std::make_pair<int, bool>(0, false);
  stats_ = {0, 0, 0};

  platform_.clear();
  if (tree.count("platform") > 0) {
    platform_ = tree.get<std::string>("platform");
  }

  version_.clear();
  if (tree.count("version") > 0) {
    version_ = tree.get<std::string>("version");
  }

  schedule_.clear();
  if (tree.count("queries") > 0) {
    for (const auto& q : tree.get_child("queries")) {
      if (q.second.count("platform")) {
        if (!checkPlatform(q.second.get<std::string>("platform"))) {
          continue;
        }
      }

      if (q.second.count("version")) {
        if (!checkVersion(q.second.get<std::string>("version"))) {
          continue;
        }
      }

      ScheduledQuery query;
      query.interval =
          q.second.get<int>("interval", FLAGS_schedule_default_interval);
      query.splayed_interval =
          splayValue(query.interval, FLAGS_schedule_splay_percent);
      query.query = q.second.get<std::string>("query");
      query.options["snapshot"] = q.second.get<bool>("snapshot", false);
      query.options["removed"] = q.second.get<bool>("removed", true);
      schedule_[q.first] = query;
    }
  }
}
Ejemplo n.º 5
0
int main(int argc, char** argv, char** envp)
{
	if (argc == 1)
	{
		std::cerr << "This is Darling dyld for " ARCH_NAME ".\n";
		std::cerr << "Copyright (C) 2012-2013 Lubos Dolezel\n"
			"Copyright (C) 2011 Shinichiro Hamaji\n\n";
		
		std::cerr << "Usage: " << argv[0] << " program-path [arguments...]\n\n";
		std::cerr << "Environment variables:\n"
			"\tDYLD_DEBUG=1 - enable debug info (lots of output)\n"
			"\tDYLD_MTRACE=1 - enable mtrace\n"
#ifdef DEBUG
			"\tDYLD_IGN_MISSING_SYMS=1 - replace missing symbol references with a stub function\n"
			"\tDYLD_TRAMPOLINE=1 - access all bound functions via a debug trampoline\n"
#endif
			"\tDYLD_ROOT_PATH=<path> - set the base for library path resolution (overrides autodetection)\n"
			"\tDYLD_BIND_AT_LAUNCH=1 - force dyld to bind all lazy references on startup\n";
		return 1;
	}
	
	try
	{
		if (!::realpath(argv[0], g_dyld_path))
			::strcpy(g_dyld_path, argv[0]);

		if (argc == 2)
		{
			if (!strcmp(argv[1], "--register"))
			{
				Darling::binfmtRegister(g_dyld_path);
				return 0;
			}
			else if (!strcmp(argv[1], "--deregister"))
			{
				Darling::binfmtDeregister();
				return 0;
			}
		}
		
		setupDyldPath(argv[0]);
		// sets up @executable_path
		setupExecutablePath(argv[1]);
	
		// setlocale(LC_CTYPE, "");
		if (getenv("DYLD_MTRACE") && atoi(getenv("DYLD_MTRACE")))
			mtrace();
		if (getenv("DYLD_TRAMPOLINE") && atoi(getenv("DYLD_TRAMPOLINE")))
			g_trampoline = true;
		if (getenv("DYLD_NO_WEAK"))
			g_noWeak = true;

		g_mainBinary = MachO::readFile(argv[1], ARCH_NAME);
		
		if (!g_mainBinary)
			throw std::runtime_error("Cannot open binary file");

		checkPlatform(argv[1], g_mainBinary);

		// Modify the argument list so that the dyld name disappears from the process list.
		// The Linux kernel doesn't really support this - it remembers the byte length of the cmdline, which will now decrease.
		// Any app that examines this process' /proc/.../cmdline will from now on see a group of empty arguments after the real arguments.
		// We fix this for NSProcessInfo in libobjcdarwin.
		/*	
		uintptr_t totalLen = argv[argc-1] + strlen(argv[argc-1]) + 1 - argv[0];
		uintptr_t shortenedLen = totalLen - (strlen(argv[0]) + 1);

		memmove(argv[0], argv[1], shortenedLen);
		memset(argv[0]+shortenedLen, 0, totalLen - shortenedLen);

		// Reconstruct the argv array
		for (int pos = 0, index = 1; index < argc-1; pos++)
		{
			if (!argv[0][pos])
				argv[index++] = &argv[0][pos+1];
		}
		*/

		g_argv = argv+1;
		g_argc = argc-1;
		g_loader = new MachOLoader;
		
		autoSysrootSearch();
		bool forceBind = false;
		
		if (g_trampoline || getenv("DYLD_BIND_AT_LAUNCH") != nullptr)
			forceBind = true;
		
		g_loader->run(*g_mainBinary, g_argc, g_argv, envp, forceBind);
		
		delete g_loader;
		g_loader = 0;
		return 2;
	}
	catch (fat_architecture_not_supported& e)
	{
		if (char* p = strstr(argv[0], "/" DYLD_FULL_NAME)) // multilib
		{
			// Try to automatically execute "the other" dyld on multilib systems
			// if that other dyld's platform is supported in the fat binary
			if (std::find(e.archs().begin(), e.archs().end(), ARCH_CROSS_NAME) != e.archs().end())
			{
				strcpy(p+1, DYLD_CROSS_NAME);
				execvp(argv[0], argv);
			}
		}
		
		std::cerr << argv[1] << " is a fat binary, but doesn't support the following architecture: " << ARCH_NAME << std::endl;
	}
	catch (std::exception& e)
	{
		std::cerr << e.what() << std::endl;
		return 1;
	}
}
Ejemplo n.º 6
0
Status ATCConfigParserPlugin::update(const std::string& source,
                                     const ParserConfig& config) {
  auto cv = config.find(kParserKey);
  if (cv == config.end()) {
    return Status(1, "No configuration for ATC (Auto Table Construction)");
  }
  auto obj = data_.getObject();

  data_.copyFrom(cv->second.doc(), obj);
  data_.add(kParserKey, obj);

  const auto& ac_tables = data_.doc()[kParserKey];
  auto tables = RegistryFactory::get().registry("table");
  auto registered = registeredATCTables();

  for (const auto& ac_table : ac_tables.GetObject()) {
    std::string table_name{ac_table.name.GetString()};
    auto params = ac_table.value.GetObject();

    std::string query{params.HasMember("query") && params["query"].IsString()
                          ? params["query"].GetString()
                          : ""};
    std::string path{params.HasMember("path") && params["path"].IsString()
                         ? params["path"].GetString()
                         : ""};
    std::string platform{params.HasMember("platform") &&
                                 params["platform"].IsString()
                             ? params["platform"].GetString()
                             : ""};

    if (query.empty() || path.empty()) {
      LOG(WARNING) << "ATC Table: " << table_name << " is misconfigured";
      continue;
    }

    if (!checkPlatform(platform)) {
      VLOG(1) << "Skipping ATC table: " << table_name
              << " because platform doesn't match";
      continue;
    }

    TableColumns columns;
    std::string columns_value;
    columns_value.reserve(256);

    for (const auto& column : params["columns"].GetArray()) {
      columns.push_back(make_tuple(
          std::string(column.GetString()), TEXT_TYPE, ColumnOptions::DEFAULT));
      columns_value += std::string(column.GetString()) + ",";
    }

    registered.erase(table_name);
    std::string table_settings{table_name + query + columns_value + path};
    std::string old_setting;
    auto s = getDatabaseValue(
        kPersistentSettings, kDatabaseKeyPrefix + table_name, old_setting);

    // The ATC table hasn't changed so we skip ahead
    if (table_settings == old_setting) {
      continue;
    }

    // Remove the old table to replace with the new one
    s = removeATCTables({table_name});
    if (!s.ok()) {
      LOG(WARNING) << "ATC table overrides core table; Refusing registration";
      continue;
    }

    s = setDatabaseValue(
        kPersistentSettings, kDatabaseKeyPrefix + table_name, table_settings);

    if (!s.ok()) {
      LOG(WARNING) << "Could not write to database";
      continue;
    }

    s = tables->add(
        table_name, std::make_shared<ATCPlugin>(path, columns, query), true);

    if (!s.ok()) {
      LOG(WARNING) << s.getMessage();
      deleteDatabaseValue(kPersistentSettings, kDatabaseKeyPrefix + table_name);
      continue;
    }

    PluginResponse resp;
    Registry::call(
        "sql", "sql", {{"action", "attach"}, {"table", table_name}}, resp);
    LOG(INFO) << "Registered ATC table: " << table_name;
  }

  if (registered.size() > 0) {
    VLOG(1)
        << "Removing any ATC tables that were removed in this configuration "
           "change";
    removeATCTables(registered);
  }
  return Status();
}
Ejemplo n.º 7
0
void Pack::initialize(const std::string& name,
                      const std::string& source,
                      const pt::ptree& tree) {
  name_ = name;
  source_ = source;
  discovery_queries_.clear();
  if (tree.count("discovery") > 0) {
    for (const auto& item : tree.get_child("discovery")) {
      discovery_queries_.push_back(item.second.get_value<std::string>());
    }
  }

  discovery_cache_ = std::make_pair<int, bool>(0, false);
  stats_ = {0, 0, 0};

  platform_.clear();
  if (tree.count("platform") > 0) {
    platform_ = tree.get<std::string>("platform", "");
  }

  version_.clear();
  if (tree.count("version") > 0) {
    version_ = tree.get<std::string>("version", "");
  }

  schedule_.clear();
  if (tree.count("queries") == 0) {
    // This pack contained no queries.
    return;
  }

  // If the splay percent is less than 1 reset to a sane estimate.
  if (FLAGS_schedule_splay_percent <= 1) {
    FLAGS_schedule_splay_percent = 10;
  }

  // Iterate the queries (or schedule) and check platform/version/sanity.
  for (const auto& q : tree.get_child("queries")) {
    if (q.second.count("platform")) {
      if (!checkPlatform(q.second.get<std::string>("platform", ""))) {
        continue;
      }
    }

    if (q.second.count("version")) {
      if (!checkVersion(q.second.get<std::string>("version", ""))) {
        continue;
      }
    }

    ScheduledQuery query;
    query.query = q.second.get<std::string>("query", "");
    query.interval = q.second.get("interval", FLAGS_schedule_default_interval);
    if (query.interval <= 0 || query.query.empty()) {
      // Invalid pack query.
      continue;
    }

    query.splayed_interval = restoreSplayedValue(q.first, query.interval);
    query.options["snapshot"] = q.second.get<bool>("snapshot", false);
    query.options["removed"] = q.second.get<bool>("removed", true);
    schedule_[q.first] = query;
  }
}
Ejemplo n.º 8
0
bool Pack::checkPlatform() const { return checkPlatform(platform_); }
Ejemplo n.º 9
0
bool Pack::shouldPackExecute() {
  return checkVersion() && checkPlatform() && checkDiscovery();
}
Ejemplo n.º 10
0
void Pack::initialize(const std::string& name,
                      const std::string& source,
                      const pt::ptree& tree) {
    name_ = name;
    source_ = source;
    // Check the shard limitation, shards falling below this value are included.
    if (tree.count("shard") > 0) {
        shard_ = tree.get<size_t>("shard", 0);
    }

    // Check for a platform restriction.
    platform_.clear();
    if (tree.count("platform") > 0) {
        platform_ = tree.get<std::string>("platform", "");
    }

    // Check for a version restriction.
    version_.clear();
    if (tree.count("version") > 0) {
        version_ = tree.get<std::string>("version", "");
    }

    // Apply the shard, platform, and version checking.
    // It is important to set each value such that the packs meta-table can report
    // each of the restrictions.
    if ((shard_ > 0 && shard_ < getMachineShard()) || !checkPlatform() ||
            !checkVersion()) {
        return;
    }

    discovery_queries_.clear();
    if (tree.count("discovery") > 0) {
        for (const auto& item : tree.get_child("discovery")) {
            discovery_queries_.push_back(item.second.get_value<std::string>());
        }
    }

    // Initialize a discovery cache at time 0.
    discovery_cache_ = std::make_pair<size_t, bool>(0, false);
    valid_ = true;

    // If the splay percent is less than 1 reset to a sane estimate.
    if (FLAGS_schedule_splay_percent <= 1) {
        FLAGS_schedule_splay_percent = 10;
    }

    schedule_.clear();
    if (tree.count("queries") == 0) {
        // This pack contained no queries.
        return;
    }

    // Iterate the queries (or schedule) and check platform/version/sanity.
    for (const auto& q : tree.get_child("queries")) {
        if (q.second.count("shard") > 0) {
            auto shard = q.second.get<size_t>("shard", 0);
            if (shard > 0 && shard < getMachineShard()) {
                continue;
            }
        }

        if (q.second.count("platform")) {
            if (!checkPlatform(q.second.get<std::string>("platform", ""))) {
                continue;
            }
        }

        if (q.second.count("version")) {
            if (!checkVersion(q.second.get<std::string>("version", ""))) {
                continue;
            }
        }

        ScheduledQuery query;
        query.query = q.second.get<std::string>("query", "");
        query.interval = q.second.get("interval", FLAGS_schedule_default_interval);
        if (query.interval <= 0 || query.query.empty() || query.interval > 592200) {
            // Invalid pack query.
            VLOG(1) << "Query has invalid interval: " << q.first << ": "
                    << query.interval;
            continue;
        }

        query.splayed_interval = restoreSplayedValue(q.first, query.interval);
        query.options["snapshot"] = q.second.get<bool>("snapshot", false);
        query.options["removed"] = q.second.get<bool>("removed", true);
        schedule_[q.first] = query;
    }
}
Ejemplo n.º 11
0
void Pack::initialize(const std::string& name,
                      const std::string& source,
                      const rj::Value& obj) {
  name_ = name;
  source_ = source;
  // Check the shard limitation, shards falling below this value are included.
  if (obj.HasMember("shard")) {
    shard_ = JSON::valueToSize(obj["shard"]);
  }

  // Check for a platform restriction.
  platform_.clear();
  if (obj.HasMember("platform") && obj["platform"].IsString()) {
    platform_ = obj["platform"].GetString();
  }

  // Check for a version restriction.
  version_.clear();
  if (obj.HasMember("version") && obj["version"].IsString()) {
    version_ = obj["version"].GetString();
  }

  // Apply the shard, platform, and version checking.
  // It is important to set each value such that the packs meta-table can report
  // each of the restrictions.
  if ((shard_ > 0 && shard_ < getMachineShard()) || !checkPlatform() ||
      !checkVersion()) {
    return;
  }

  discovery_queries_.clear();
  if (obj.HasMember("discovery") && obj["discovery"].IsArray()) {
    for (const auto& item : obj["discovery"].GetArray()) {
      discovery_queries_.push_back(item.GetString());
    }
  }

  // Initialize a discovery cache at time 0.
  discovery_cache_ = std::make_pair<size_t, bool>(0, false);
  valid_ = true;

  // If the splay percent is less than 1 reset to a sane estimate.
  if (FLAGS_schedule_splay_percent <= 1) {
    FLAGS_schedule_splay_percent = 10;
  }

  schedule_.clear();
  if (!obj.HasMember("queries") || !obj["queries"].IsObject()) {
    // This pack contained no queries.
    return;
  }

  // Iterate the queries (or schedule) and check platform/version/sanity.
  for (const auto& q : obj["queries"].GetObject()) {
    if (q.value.HasMember("shard")) {
      auto shard = JSON::valueToSize(q.value["shard"]);
      if (shard > 0 && shard < getMachineShard()) {
        continue;
      }
    }

    if (q.value.HasMember("platform") && q.value["platform"].IsString()) {
      if (!checkPlatform(q.value["platform"].GetString())) {
        continue;
      }
    }

    if (q.value.HasMember("version") && q.value["version"].IsString()) {
      if (!checkVersion(q.value["version"].GetString())) {
        continue;
      }
    }

    if (!q.value.HasMember("query") || !q.value["query"].IsString()) {
      continue;
    }

    ScheduledQuery query;
    query.query = q.value["query"].GetString();
    if (!q.value.HasMember("interval")) {
      query.interval = FLAGS_schedule_default_interval;
    } else {
      query.interval = JSON::valueToSize(q.value["interval"]);
    }
    if (query.interval <= 0 || query.query.empty() ||
        query.interval > kMaxQueryInterval) {
      // Invalid pack query.
      LOG(WARNING) << "Query has invalid interval: " << q.name.GetString()
                   << ": " << query.interval;
      continue;
    }

    query.splayed_interval =
        restoreSplayedValue(q.name.GetString(), query.interval);

    if (!q.value.HasMember("snapshot")) {
      query.options["snapshot"] = false;
    } else {
      query.options["snapshot"] = JSON::valueToBool(q.value["snapshot"]);
    }

    if (!q.value.HasMember("removed")) {
      query.options["removed"] = true;
    } else {
      query.options["removed"] = JSON::valueToBool(q.value["removed"]);
    }
    query.options["blacklist"] = (q.value.HasMember("blacklist"))
                                     ? q.value["blacklist"].GetBool()
                                     : true;

    schedule_.emplace(std::make_pair(q.name.GetString(), std::move(query)));
  }
}