+ if (strlen(dyld_alt_path) > 0) {
+ use_alt_dyld = 1;
+ }
+ }
+ PE_parse_boot_argn("dyld_flags", &dyld_flags, sizeof(dyld_flags));
+
+ if (PE_parse_boot_argn("-disable_syscallfilter", &namep, sizeof(namep))) {
+ syscallfilter_disable = 1;
+ }
+
+#if __arm64__
+ if (PE_parse_boot_argn("legacy_footprint_entitlement_mode", &legacy_footprint_entitlement_mode, sizeof(legacy_footprint_entitlement_mode))) {
+ /*
+ * legacy_footprint_entitlement_mode specifies the behavior we want associated
+ * with the entitlement. The supported modes are:
+ *
+ * LEGACY_FOOTPRINT_ENTITLEMENT_IGNORE:
+ * Indicates that we want every process to have the memory accounting
+ * that is available in iOS 12.0 and beyond.
+ *
+ * LEGACY_FOOTPRINT_ENTITLEMENT_IOS11_ACCT:
+ * Indicates that for every process that has the 'legacy footprint entitlement',
+ * we want to give it the old iOS 11.0 accounting behavior which accounted some
+ * of the process's memory to the kernel.
+ *
+ * LEGACY_FOOTPRINT_ENTITLEMENT_LIMIT_INCREASE:
+ * Indicates that for every process that has the 'legacy footprint entitlement',
+ * we want it to have a higher memory limit which will help them acclimate to the
+ * iOS 12.0 (& beyond) accounting behavior that does the right accounting.
+ * The bonus added to the system-wide task limit to calculate this higher memory limit
+ * is available in legacy_footprint_bonus_mb.
+ */
+
+ if (legacy_footprint_entitlement_mode < LEGACY_FOOTPRINT_ENTITLEMENT_IGNORE ||
+ legacy_footprint_entitlement_mode > LEGACY_FOOTPRINT_ENTITLEMENT_LIMIT_INCREASE) {
+ legacy_footprint_entitlement_mode = LEGACY_FOOTPRINT_ENTITLEMENT_LIMIT_INCREASE;
+ }
+ }
+#endif /* __arm64__ */
+#endif /* DEVELOPMENT || DEBUG */
+}
+
+#if CONFIG_BASESYSTEMROOT
+
+extern const char* IOGetBootUUID(void);
+extern const char* IOGetApfsPrebootUUID(void);
+
+// Get the UUID of the Preboot (and Recovery) folder associated with the
+// current boot volume, if applicable. The meaning of the UUID can be
+// filesystem-dependent and not all kinds of boots will have a UUID.
+// If available, the string will be returned. It does not need to be
+// deallocate. (Future: if we need to return the string as a copy that the
+// caller must free, we'll introduce a new functcion for that.)
+// NULL will be returned if the current boot has no applicable Preboot UUID.
+static
+const char *
+get_preboot_uuid(void)
+{
+ const char *maybe_uuid_string;
+
+ // try IOGetApfsPrebootUUID
+ maybe_uuid_string = IOGetApfsPrebootUUID();
+ if (maybe_uuid_string) {
+ uuid_t maybe_uuid;
+ int error = uuid_parse(maybe_uuid_string, maybe_uuid);
+ if (error == 0) {
+ return maybe_uuid_string;
+ }
+ }
+
+ // try IOGetBootUUID
+ maybe_uuid_string = IOGetBootUUID();
+ if (maybe_uuid_string) {
+ uuid_t maybe_uuid;
+ int error = uuid_parse(maybe_uuid_string, maybe_uuid);
+ if (error == 0) {
+ return maybe_uuid_string;
+ }
+ }
+
+ // didn't find it
+ return NULL;
+}
+
+#if defined(__arm64__)
+extern const char *IOGetBootObjectsPath(void);
+#endif
+
+// Find the BaseSystem.dmg to be used as the initial root volume during certain
+// kinds of boots.
+// This may mount volumes and lookup vnodes.
+// The DEVELOPMENT kernel will look for BaseSystem.rooted.dmg first.
+// If it returns 0 (no error), then it also writes the absolute path to the
+// BaseSystem.dmg into its argument (which must be a char[MAXPATHLEN]).
+static
+int
+bsd_find_basesystem_dmg(char *bsdmgpath_out, bool *rooted_dmg, bool *skip_signature_check)
+{
+ int error;
+ size_t len;
+ char *dmgbasepath;
+ char *dmgpath;
+ bool allow_rooted_dmg = false;
+
+ dmgbasepath = zalloc_flags(ZV_NAMEI, Z_ZERO | Z_WAITOK);
+ dmgpath = zalloc_flags(ZV_NAMEI, Z_ZERO | Z_WAITOK);
+ vnode_t imagevp = NULLVP;
+
+#if DEVELOPMENT || DEBUG
+ allow_rooted_dmg = true;
+#endif
+
+ //must provide output bool
+ if (rooted_dmg && skip_signature_check) {
+ *rooted_dmg = false;
+ *skip_signature_check = false;
+ } else {
+ error = EINVAL;
+ goto done;
+ }
+
+ error = vfs_mount_recovery();
+ if (error) {
+ goto done;
+ }
+
+ len = strlcpy(dmgbasepath, "/System/Volumes/Recovery/", MAXPATHLEN);
+ if (len > MAXPATHLEN) {
+ error = ENAMETOOLONG;
+ goto done;
+ }
+
+ if (csr_check(CSR_ALLOW_ANY_RECOVERY_OS) == 0) {
+ *skip_signature_check = true;
+ allow_rooted_dmg = true;
+ }
+
+#if defined(__arm64__)
+ const char *boot_obj_path = IOGetBootObjectsPath();
+ if (boot_obj_path) {
+ if (boot_obj_path[0] == '/') {
+ dmgbasepath[len - 1] = '\0';
+ }
+
+ len = strlcat(dmgbasepath, boot_obj_path, MAXPATHLEN);
+ if (len > MAXPATHLEN) {
+ error = ENAMETOOLONG;
+ goto done;
+ }
+
+ len = strlcat(dmgbasepath, "/usr/standalone/firmware/", MAXPATHLEN);
+ if (len > MAXPATHLEN) {
+ error = ENAMETOOLONG;
+ goto done;
+ }
+
+ if (allow_rooted_dmg) {
+ len = strlcpy(dmgpath, dmgbasepath, MAXPATHLEN);
+ if (len > MAXPATHLEN) {
+ error = ENAMETOOLONG;
+ goto done;
+ }
+
+ len = strlcat(dmgpath, "arm64eBaseSystem.rooted.dmg", MAXPATHLEN);
+ if (len > MAXPATHLEN) {
+ error = ENAMETOOLONG;
+ goto done;
+ }
+
+ error = vnode_lookup(dmgpath, 0, &imagevp, vfs_context_kernel());
+ if (error == 0) {
+ *rooted_dmg = true;
+ *skip_signature_check = true;
+ goto done;
+ }
+ memset(dmgpath, 0, MAXPATHLEN);
+ }
+
+ len = strlcpy(dmgpath, dmgbasepath, MAXPATHLEN);
+ if (len > MAXPATHLEN) {
+ error = ENAMETOOLONG;
+ goto done;
+ }
+
+ len = strlcat(dmgpath, "arm64eBaseSystem.dmg", MAXPATHLEN);
+ if (len > MAXPATHLEN) {
+ error = ENAMETOOLONG;
+ goto done;
+ }
+
+ error = vnode_lookup(dmgpath, 0, &imagevp, vfs_context_kernel());
+ if (error == 0) {
+ goto done;
+ }
+ memset(dmgpath, 0, MAXPATHLEN);
+ dmgbasepath[strlen("/System/Volumes/Recovery/")] = '\0';