From 7532a347694c29f1d1c01312ce681eae114ff04b Mon Sep 17 00:00:00 2001 From: Vihaan Jim Date: Thu, 10 Aug 2023 18:11:49 -0400 Subject: [PATCH] Switch from Vec to MemoryRange Instead of getting the slice by creating a large Vec, I now use MapMemory to create this region directly. There is some sort of bug with Vec that doesn't allow creation of large Vec's, and this change makes it possible to load much larger apps (including `vault', although there are still issues like menus to sort out). --- apps/app-loader/src/api.rs | 29 +++++++++++------------------ apps/manifest.json | 2 +- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/apps/app-loader/src/api.rs b/apps/app-loader/src/api.rs index ef0add102..f0c79132e 100644 --- a/apps/app-loader/src/api.rs +++ b/apps/app-loader/src/api.rs @@ -1,7 +1,6 @@ -use std::{io::Read, num::NonZeroUsize}; +use std::io::Read; use gam::{Gam, MenuItem, UxRegistration, menu_matic, APP_NAME_APP_LOADER, APP_MENU_0_APP_LOADER, APP_MENU_1_APP_LOADER, MenuMatic, TextEntryPayload}; use modals::Modals; -use xous::MemoryRange; use num_traits::ToPrimitive; use locales::t; use crate::SERVER_NAME_APP_LOADER; @@ -68,7 +67,9 @@ impl AppLoader { self.modals.start_progress(t!("apploader.addapp.loading", locales::LANG), 0, 3, 0).expect("Couldn't set up progress bar"); - // load the app from the server + ////////////////////////// + // The downloading part // + ////////////////////////// let response = match ureq::get(&format!("{}/{}", self.server.as_ref().expect("AddApp was somehow called without a server!"), name)).call() { Ok(response) => response, Err(e) => { @@ -85,21 +86,11 @@ impl AppLoader { } }; + + let mut memory = xous::map_memory(None, None, len + if len & 0xFFF == 0 { 0 } else { 0x1000 - (len & 0xFFF) }, xous::MemoryFlags::R | xous::MemoryFlags::W).expect("Couldn't map memory"); + response.into_reader().read_exact(&mut memory.as_slice_mut()[..len]).expect("Couldn't read"); + self.modals.update_progress(1).expect("Couldn't update progress"); - - let mut app_file = Vec::with_capacity(len); - response.into_reader() - .read_to_end(&mut app_file).expect("Couldn't read"); - let app_file_slice = app_file.as_slice(); - let (address, offset) = { - let address = app_file_slice.as_ptr() as usize; - (address & !0xFFF, address & 0xFFF) - }; - - let memory = unsafe { MemoryRange::new(address, - len + if len & 0xFFF == 0 { 0 } else { 0x1000 - (len & 0xFFF) }).unwrap() }; - - self.modals.update_progress(2).expect("Couldn't update progress"); ////////////////////// // The loading part // ////////////////////// @@ -118,8 +109,10 @@ impl AppLoader { .unwrap(); assert_eq!(xous::Result::Scalar1(2), result); + self.modals.update_progress(2).expect("Couldn't update progress"); + // load the app from the binary file - let res = xous::send_message(spawn.cid, xous::Message::new_lend_mut(1, memory, if offset == 0 { None } else { Some(NonZeroUsize::new(offset).unwrap()) }, None)).expect("Couldn't send a message to spawn"); + let res = xous::send_message(spawn.cid, xous::Message::new_lend_mut(1, memory, None, None)).expect("Couldn't send a message to spawn"); // we are just going to do some very basic error handling: if the "offset" is None, we are good, otherwise there was a problem // TODO: make this better. Perhaps Buffer::from_raw_parts? match res { diff --git a/apps/manifest.json b/apps/manifest.json index 054d826e9..3290b1ea9 100644 --- a/apps/manifest.json +++ b/apps/manifest.json @@ -7,7 +7,7 @@ "en-tts": "App Loader" } }, - "submenu": 1 + "submenu": 2 }, "ball": { "context_name": "ball demo app",