diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 95adc95..7b439b2 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -7,6 +7,8 @@ use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Symfony\Component\HttpFoundation\Request;
 use Drupal\Core\Language\Language;
 
+include_once DRUPAL_ROOT . '/core/includes/loader.inc';
+
 /**
  * @file
  * Functions that need to be loaded on every Drupal request.
@@ -367,127 +369,6 @@ function timer_stop($name) {
 }
 
 /**
- * Finds the appropriate configuration directory.
- *
- * Finds a matching configuration directory by stripping the website's
- * hostname from left to right and pathname from right to left. The first
- * configuration file found will be used and the remaining ones will be ignored.
- * If no configuration file is found, return a default value '$confdir/default'.
- *
- * With a site located at http://www.example.com:8080/mysite/test/, the file,
- * settings.php, is searched for in the following directories:
- *
- * - $confdir/8080.www.example.com.mysite.test
- * - $confdir/www.example.com.mysite.test
- * - $confdir/example.com.mysite.test
- * - $confdir/com.mysite.test
- *
- * - $confdir/8080.www.example.com.mysite
- * - $confdir/www.example.com.mysite
- * - $confdir/example.com.mysite
- * - $confdir/com.mysite
- *
- * - $confdir/8080.www.example.com
- * - $confdir/www.example.com
- * - $confdir/example.com
- * - $confdir/com
- *
- * - $confdir/default
- *
- * If a file named sites.php is present in the $confdir, it will be loaded
- * prior to scanning for directories. It should define an associative array
- * named $sites, which maps domains to directories. It should be in the form
- * of:
- * @code
- * $sites = array(
- *   'The url to alias' => 'A directory within the sites directory'
- * );
- * @endcode
- * For example:
- * @code
- * $sites = array(
- *   'devexample.com' => 'example.com',
- *   'localhost.example' => 'example.com',
- * );
- * @endcode
- * The above array will cause Drupal to look for a directory named
- * "example.com" in the sites directory whenever a request comes from
- * "example.com", "devexample.com", or "localhost/example". That is useful
- * on development servers, where the domain name may not be the same as the
- * domain of the live server. Since Drupal stores file paths into the database
- * (files, system table, etc.) this will ensure the paths are correct while
- * accessed on development servers.
- *
- * @param bool $require_settings
- *   Only configuration directories with an existing settings.php file
- *   will be recognized. Defaults to TRUE. During initial installation,
- *   this is set to FALSE so that Drupal can detect a matching directory,
- *   then create a new settings.php file in it.
- * @param bool $reset
- *   Force a full search for matching directories even if one had been
- *   found previously. Defaults to FALSE.
- *
- * @return
- *   The path of the matching directory.
- */
-function conf_path($require_settings = TRUE, $reset = FALSE) {
-  $conf = &drupal_static(__FUNCTION__, '');
-
-  if ($conf && !$reset) {
-    return $conf;
-  }
-
-  $script_name = $_SERVER['SCRIPT_NAME'];
-  if (!$script_name) {
-    $script_name = $_SERVER['SCRIPT_FILENAME'];
-  }
-  $http_host = $_SERVER['HTTP_HOST'];
-  $conf = find_conf_path($http_host, $script_name, $require_settings);
-  return $conf;
-}
-
-/**
- * Finds the appropriate configuration directory for a given host and path.
- *
- * @param $http_host
- *   The hostname and optional port number, e.g. "www.example.com" or
- *   "www.example.com:8080".
- * @param $script_name
- *   The part of the url following the hostname, including the leading slash.
- *
- * @return
- *   The path of the matching configuration directory.
- *
- * @see conf_path()
- */
-function find_conf_path($http_host, $script_name, $require_settings = TRUE) {
-  $confdir = 'sites';
-
-  $sites = array();
-  if (file_exists(DRUPAL_ROOT . '/' . $confdir . '/sites.php')) {
-    // This will overwrite $sites with the desired mappings.
-    include(DRUPAL_ROOT . '/' . $confdir . '/sites.php');
-  }
-
-  $uri = explode('/', $script_name);
-  $server = explode('.', implode('.', array_reverse(explode(':', rtrim($http_host, '.')))));
-  for ($i = count($uri) - 1; $i > 0; $i--) {
-    for ($j = count($server); $j > 0; $j--) {
-      $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
-      if (isset($sites[$dir]) && file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $sites[$dir])) {
-        $dir = $sites[$dir];
-      }
-      if (file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir . '/settings.php') || (!$require_settings && file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir))) {
-        $conf = "$confdir/$dir";
-        return $conf;
-      }
-    }
-  }
-  $conf = "$confdir/default";
-  return $conf;
-}
-
-/**
  * Returns the path of the configuration directory.
  *
  * @return string
@@ -691,17 +572,9 @@ function unicode_check() {
  * Sets the base URL, cookie domain, and session name from configuration.
  */
 function drupal_settings_initialize() {
-  global $base_url, $base_path, $base_root, $script_path;
+  global $base_url, $base_path, $base_root, $script_path, $cookie_domain, $is_https, $base_secure_url, $base_insecure_url;
 
-  // Export the following settings.php variables to the global namespace
-  global $databases, $cookie_domain, $conf, $installed_profile, $update_free_access, $db_url, $db_prefix, $drupal_hash_salt, $is_https, $base_secure_url, $base_insecure_url, $config_directory_name;
-  $conf = array();
-
-  // Make conf_path() available as local variable in settings.php.
-  $conf_path = conf_path();
-  if (file_exists(DRUPAL_ROOT . '/' . $conf_path . '/settings.php')) {
-    include_once DRUPAL_ROOT . '/' . $conf_path . '/settings.php';
-  }
+  drupal_settings_load();
   $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on';
 
   if (isset($base_url)) {
@@ -1116,7 +989,7 @@ function drupal_load($type, $name) {
   $filename = drupal_get_filename($type, $name);
 
   if ($filename) {
-    include_once DRUPAL_ROOT . '/' . $filename;
+    drupal_include(DRUPAL_ROOT . '/' . $filename);
     $files[$type][$name] = TRUE;
 
     return TRUE;
diff --git a/core/includes/loader.inc b/core/includes/loader.inc
new file mode 100644
index 0000000..9dd82d5
--- /dev/null
+++ b/core/includes/loader.inc
@@ -0,0 +1,210 @@
+<?php
+
+/**
+ * @file
+ * Functions that need to be loaded before every Drupal request.
+ *
+ * This file alone can not be upgraded via the browser.
+ */
+
+/**
+ * Finds the appropriate configuration directory.
+ *
+ * Finds a matching configuration directory by stripping the website's
+ * hostname from left to right and pathname from right to left. The first
+ * configuration file found will be used and the remaining ones will be ignored.
+ * If no configuration file is found, return a default value '$confdir/default'.
+ *
+ * With a site located at http://www.example.com:8080/mysite/test/, the file,
+ * settings.php, is searched for in the following directories:
+ *
+ * - $confdir/8080.www.example.com.mysite.test
+ * - $confdir/www.example.com.mysite.test
+ * - $confdir/example.com.mysite.test
+ * - $confdir/com.mysite.test
+ *
+ * - $confdir/8080.www.example.com.mysite
+ * - $confdir/www.example.com.mysite
+ * - $confdir/example.com.mysite
+ * - $confdir/com.mysite
+ *
+ * - $confdir/8080.www.example.com
+ * - $confdir/www.example.com
+ * - $confdir/example.com
+ * - $confdir/com
+ *
+ * - $confdir/default
+ *
+ * If a file named sites.php is present in the $confdir, it will be loaded
+ * prior to scanning for directories. It should define an associative array
+ * named $sites, which maps domains to directories. It should be in the form
+ * of:
+ * @code
+ * $sites = array(
+ *   'The url to alias' => 'A directory within the sites directory'
+ * );
+ * @endcode
+ * For example:
+ * @code
+ * $sites = array(
+ *   'devexample.com' => 'example.com',
+ *   'localhost.example' => 'example.com',
+ * );
+ * @endcode
+ * The above array will cause Drupal to look for a directory named
+ * "example.com" in the sites directory whenever a request comes from
+ * "example.com", "devexample.com", or "localhost/example". That is useful
+ * on development servers, where the domain name may not be the same as the
+ * domain of the live server. Since Drupal stores file paths into the database
+ * (files, system table, etc.) this will ensure the paths are correct while
+ * accessed on development servers.
+ *
+ * @param bool $require_settings
+ *   Only configuration directories with an existing settings.php file
+ *   will be recognized. Defaults to TRUE. During initial installation,
+ *   this is set to FALSE so that Drupal can detect a matching directory,
+ *   then create a new settings.php file in it.
+ * @param bool $reset
+ *   Force a full search for matching directories even if one had been
+ *   found previously. Defaults to FALSE.
+ *
+ * @return
+ *   The path of the matching directory.
+ */
+function conf_path($require_settings = TRUE, $reset = FALSE) {
+  $conf = &drupal_static(__FUNCTION__, '');
+
+  if ($conf && !$reset) {
+    return $conf;
+  }
+
+  $script_name = $_SERVER['SCRIPT_NAME'];
+  if (!$script_name) {
+    $script_name = $_SERVER['SCRIPT_FILENAME'];
+  }
+  $http_host = $_SERVER['HTTP_HOST'];
+  $conf = find_conf_path($http_host, $script_name, $require_settings);
+  return $conf;
+}
+
+/**
+ * Finds the appropriate configuration directory for a given host and path.
+ *
+ * @param $http_host
+ *   The hostname and optional port number, e.g. "www.example.com" or
+ *   "www.example.com:8080".
+ * @param $script_name
+ *   The part of the url following the hostname, including the leading slash.
+ *
+ * @return
+ *   The path of the matching configuration directory.
+ *
+ * @see conf_path()
+ */
+function find_conf_path($http_host, $script_name, $require_settings = TRUE) {
+  $confdir = 'sites';
+
+  $sites = array();
+  if (file_exists(DRUPAL_ROOT . '/' . $confdir . '/sites.php')) {
+    // This will overwrite $sites with the desired mappings.
+    include(DRUPAL_ROOT . '/' . $confdir . '/sites.php');
+  }
+
+  $uri = explode('/', $script_name);
+  $server = explode('.', implode('.', array_reverse(explode(':', rtrim($http_host, '.')))));
+  for ($i = count($uri) - 1; $i > 0; $i--) {
+    for ($j = count($server); $j > 0; $j--) {
+      $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
+      if (isset($sites[$dir]) && file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $sites[$dir])) {
+        $dir = $sites[$dir];
+      }
+      if (file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir . '/settings.php') || (!$require_settings && file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir))) {
+        $conf = "$confdir/$dir";
+        return $conf;
+      }
+    }
+  }
+  $conf = "$confdir/default";
+  return $conf;
+}
+
+function drupal_settings_load() {
+  global $base_url, $base_path, $base_root, $script_path;
+
+  // Export the following settings.php variables to the global namespace
+  global $databases, $cookie_domain, $conf, $installed_profile, $update_free_access, $db_url, $db_prefix, $drupal_hash_salt, $is_https, $base_secure_url, $base_insecure_url, $config_directory_name;
+
+  $conf = array();
+
+  // Make conf_path() available as local variable in settings.php.
+  $conf_path = conf_path();
+  if (file_exists(DRUPAL_ROOT . '/' . $conf_path . '/settings.php')) {
+    include_once DRUPAL_ROOT . '/' . $conf_path . '/settings.php';
+  }
+  stream_filter_register('drupal', 'DrupalStreamFilter');
+}
+
+function drupal_include($path) {
+  global $conf;
+
+  $written_path = '';
+  if (!empty($conf['php_path'])) {
+    $written_path = $conf['php_path'] . '/' . $path;
+  }
+
+  if (!empty($conf['php_prefix'])) {
+    $written_path = "php://filter/read=drupal/resource=$written_path";
+  }
+
+  include_once ($written_path && file_exists($written_path) ? $written_path : $path);
+}
+
+function drupal_write_php($path, $data) {
+  global $conf;
+  $data = preg_replace('/^<?php', '<?php // '. $GLOBALS['conf']['php_prefix'] ."\n", $data);
+  if (!empty($conf['php_path'])) {
+    $path = $conf['php_path'] . '/' . $path;
+  }
+  // The recursive mkdir() problem is not relevant here because practically
+  // always the first digit of chmod() is 0.
+  @mkdir(dirname($path), 0700, TRUE);
+  file_put_contents($path, $data);
+}
+
+class DrupalStreamFilter extends PHP_User_Filter {
+  protected $data;
+  protected $header;
+  protected $headerLength;
+
+  function onCreate() {
+    $this->data = '';
+    $this->header = '<?php // '. $GLOBALS['conf']['php_prefix'];
+    $this->headerLength = strlen($this->header);
+    return TRUE;
+  }
+
+  public function filter($in, $out, &$consumed, $closing) {
+    // Read all the stream data and store it in the $data property.
+    while ($bucket = stream_bucket_make_writeable($in)) {
+      $this->data = $bucket->data;
+      $this->bucket = $bucket;
+      $consumed = 0;
+    }
+
+    // When the stream is being closed, send back all the data after verify.
+    if ($closing) {
+      if (substr($this->data, 0, $this->headerLength) !== $this->header) {
+        // Do we want a pretty little fatal here? return PSFS_ERR_FATAL;
+        $this->data = '';
+      }
+      $consumed = strlen($this->data);
+      $this->bucket->data = $this->data;
+      $this->bucket->datalen = strlen($this->data);
+      if (!empty($this->bucket->data)) {
+        stream_bucket_append($out, $this->bucket);
+        return PSFS_PASS_ON;
+      }
+      return PSFS_FEED_ME;
+    }
+  }
+}
