Skip to content

Commit 78c6dd2

Browse files
committed
Fix LiveUpdate comparison issue with partitions, cleanup
1 parent 1101a95 commit 78c6dd2

7 files changed

Lines changed: 20 additions & 21 deletions

File tree

lib/LiveUpdate/liveupdate.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,13 @@ struct Storage
140140
// store a TCP connection
141141
void add_connection(uid, Connection_ptr);
142142

143-
Storage(storage_header& sh) : hdr(sh) {}
144-
void add_vector (uid, const void*, size_t count, size_t element_size);
145-
void add_string_vector (uid, const std::vector<std::string>&);
146-
147143
// markers are used to delineate the end of variable-length structures
148144
void put_marker(uid);
149145

146+
Storage(storage_header& sh) : hdr(sh) {}
150147
private:
148+
void add_vector (uid, const void*, size_t count, size_t element_size);
149+
void add_string_vector (uid, const std::vector<std::string>&);
151150
storage_header& hdr;
152151
};
153152

lib/LiveUpdate/partition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int storage_header::find_partition(const char* key)
4646
for (uint32_t p = 0; p < this->partitions; p++)
4747
{
4848
auto& part = ptable.at(p);
49-
if (strncmp(part.name, key, sizeof(part.name)))
49+
if (strncmp(part.name, key, sizeof(part.name)) == 0)
5050
{
5151
uint32_t chsum = part.generate_checksum(this->vla);
5252
if (part.crc == chsum) {
@@ -69,6 +69,6 @@ void storage_header::finish_partition(int p)
6969
void storage_header::zero_partition(int p)
7070
{
7171
auto& part = ptable.at(p);
72-
memset(&vla[part.offset], 0, part.length);
72+
memset(&this->vla[part.offset], 0, part.length);
7373
memset(&part, 0, sizeof(partition_header));
7474
}

lib/LiveUpdate/resume.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern char* heap_end;
3434

3535
namespace liu
3636
{
37-
static void resume_begin(storage_header&, const char*, LiveUpdate::resume_func);
37+
static void resume_begin(storage_header&, std::string, LiveUpdate::resume_func);
3838
static std::map<uint16_t, LiveUpdate::resume_func> resume_funcs;
3939

4040
bool LiveUpdate::is_resumable()
@@ -66,17 +66,21 @@ void LiveUpdate::resume(std::string key, resume_func func)
6666
(long int) (heap_end - (char*) location));
6767
throw std::runtime_error("LiveUpdate storage area inside heap");
6868
}
69-
resume_helper(location, key, func);
69+
resume_helper(location, std::move(key), func);
7070
}
7171
void LiveUpdate::resume_from_heap(void* location, std::string key, LiveUpdate::resume_func func)
7272
{
73-
resume_helper(location, key, func);
73+
resume_helper(location, std::move(key), func);
7474
}
7575

76-
void resume_begin(storage_header& storage, const char* key, LiveUpdate::resume_func func)
76+
void resume_begin(storage_header& storage, std::string key, LiveUpdate::resume_func func)
7777
{
78-
int p = storage.find_partition(key);
79-
LPRINT("* Resuming from partition %d\n", p);
78+
if (key.empty())
79+
throw std::length_error("LiveUpdate partition key cannot be an empty string");
80+
81+
int p = storage.find_partition(key.c_str());
82+
LPRINT("* Resuming from partition %d at %p from %p\n",
83+
p, storage.begin(p), &storage);
8084

8185
/// restore each entry one by one, calling registered handlers
8286
for (auto* ptr = storage.begin(p); ptr->type != TYPE_END;)

lib/LiveUpdate/storage.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void storage_header::add_string_vector(uint16_t id, const std::vector<std::strin
108108
}
109109
void storage_header::add_end()
110110
{
111-
auto& ent = create_entry(TYPE_END);
111+
auto& ent = create_entry(TYPE_END, 0, 0);
112112

113113
// test against heap max
114114
uintptr_t storage_end = (uintptr_t) ent.vla;
@@ -178,11 +178,8 @@ storage_entry* storage_header::next(storage_entry* ptr)
178178
return ptr->next();
179179
}
180180

181-
storage_entry::storage_entry(int16_t t, uint16_t ID, int v)
182-
: type(t), id(ID), len(v) {}
183-
// used for last entry, for the most part
184-
storage_entry::storage_entry(int16_t t)
185-
: type(t), id(0), len(0) {}
181+
storage_entry::storage_entry(int16_t t, uint16_t ID, int L)
182+
: type(t), id(ID), len(L) {}
186183

187184
storage_entry* storage_entry::next() const noexcept
188185
{

lib/LiveUpdate/storage.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ struct varseg_entry
6060
struct storage_entry
6161
{
6262
storage_entry(int16_t type, uint16_t id, int length);
63-
storage_entry(int16_t type);
6463

6564
int16_t type = TYPE_END;
6665
uint16_t id = 0;

lib/LiveUpdate/update.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,13 @@ size_t update_store_data(void* location, const buffer_t* blob)
273273
new (location) storage_header();
274274
auto* storage = (storage_header*) location;
275275

276+
Storage wrapper(*storage);
276277
/// callback for storing stuff, if provided
277278
for (const auto& pair : storage_callbacks)
278279
{
279280
// create partition
280281
int p = storage->create_partition(pair.first);
281282
// run serialization process
282-
Storage wrapper {*storage};
283283
pair.second(wrapper, blob);
284284
// add end for partition
285285
storage->finish_partition(p);

src/kernel/os.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ std::string OS::arch_str_ = ARCH;
7676
void* OS::liveupdate_storage_area() noexcept
7777
{
7878
// Default: 32MB below heap_max
79-
return (void*) (OS::heap_max() - 0x2000000);
79+
return (void*) (OS::heap_max() & 0xFFFFFFF0 - 0x2000000);
8080
}
8181

8282
const std::string& OS::cmdline_args() noexcept

0 commit comments

Comments
 (0)