@@ -34,6 +34,7 @@ extern char* heap_end;
3434
3535namespace liu
3636{
37+ static void resume_begin (storage_header&, const char *, LiveUpdate::resume_func);
3738static std::map<uint16_t , LiveUpdate::resume_func> resume_funcs;
3839
3940bool LiveUpdate::is_resumable ()
@@ -45,44 +46,40 @@ bool LiveUpdate::is_resumable(void* location)
4546 return ((storage_header*) location)->validate ();
4647}
4748
48- static bool resume_helper (void * location, LiveUpdate::resume_func func)
49+ static void resume_helper (void * location, std::string key , LiveUpdate::resume_func func)
4950{
5051 // check if an update has occurred
51- if (!LiveUpdate::is_resumable (location)) return false ;
52+ if (!LiveUpdate::is_resumable (location))
53+ throw std::runtime_error (" Trying to resume from invalid storage area" );
5254
5355 LPRINT (" * Restoring data...\n " );
5456 // restore connections etc.
55- extern bool resume_begin (storage_header&, LiveUpdate::resume_func);
56- return resume_begin (*(storage_header*) location, func);
57+ resume_begin (*(storage_header*) location, key.c_str (), func);
5758}
58- bool LiveUpdate::resume (std::string key, resume_func func)
59+ void LiveUpdate::resume (std::string key, resume_func func)
5960{
6061 void * location = OS::liveupdate_storage_area ();
6162 // / memory sanity check
6263 if (heap_end >= (char *) location) {
6364 fprintf (stderr,
6465 " WARNING: LiveUpdate storage area inside heap (margin: %ld)\n " ,
6566 (long int ) (heap_end - (char *) location));
66- return false ;
67+ throw std::runtime_error ( " LiveUpdate storage area inside heap " ) ;
6768 }
68- return resume_helper (location, func);
69+ resume_helper (location, key , func);
6970}
70- bool LiveUpdate::resume_from_heap (void * location, LiveUpdate::resume_func func)
71+ void LiveUpdate::resume_from_heap (void * location, std::string key , LiveUpdate::resume_func func)
7172{
72- return resume_helper (location, func);
73+ resume_helper (location, key , func);
7374}
7475
75- bool resume_begin (storage_header& storage, LiveUpdate::resume_func func)
76+ void resume_begin (storage_header& storage, const char * key , LiveUpdate::resume_func func)
7677{
77- // / restore each entry one by one, calling registered handlers
78- auto num_ents = storage.get_entries ();
79- if (num_ents > 1 ) {
80- LPRINT (" * Resuming %d stored entries\n " , num_ents-1 );
81- } else {
82- LPRINT (" * No stored entries to resume\n " );
83- }
78+ int p = storage.find_partition (key);
79+ LPRINT (" * Resuming from partition %d\n " , p);
8480
85- for (auto * ptr = storage.begin (); ptr->type != TYPE_END;)
81+ // / restore each entry one by one, calling registered handlers
82+ for (auto * ptr = storage.begin (p); ptr->type != TYPE_END;)
8683 {
8784 auto * oldptr = ptr;
8885 // resume wrapper
@@ -102,10 +99,8 @@ bool resume_begin(storage_header& storage, LiveUpdate::resume_func func)
10299 }
103100 // / wake all the slumbering IP stacks
104101 serialized_tcp::wakeup_ip_networks ();
105- // / zero out all the state for security reasons
106- storage.zero ();
107-
108- return true ;
102+ // / zero out the partition for security reasons
103+ storage.zero_partition (p);
109104}
110105
111106void LiveUpdate::on_resume (uint16_t id, resume_func func)
0 commit comments