Skip to content

Commit 6033898

Browse files
Set liveupdate location 32MB below heap max..
1 parent 9997f23 commit 6033898

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

ws_uplink.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ namespace uplink {
4242

4343
const std::string WS_uplink::UPLINK_CFG_FILE{"config.json"};
4444

45-
void* UPDATE_LOC = (void*) 0x3200000; // at 50mb
46-
4745
WS_uplink::WS_uplink(net::Inet<net::IP4>& inet)
4846
: inet_{inet}, id_{inet.link_addr().to_string()},
4947
parser_({this, &WS_uplink::handle_transport})
5048
{
49+
// This is not totally safe...
50+
LIVEUPD_LOCATION = (void*) (OS::heap_max() - 0x2000000); // 32MB below heap_max
51+
MYINFO("Maximum heap at (%p), assigning liveupdate location 32MB below (%p)", (void*)OS::heap_max(), LIVEUPD_LOCATION);
52+
5153
OS::add_stdout({this, &WS_uplink::send_log});
5254

5355
read_config();
@@ -71,10 +73,10 @@ namespace uplink {
7173
Expects(inet.ip_addr() != 0 && "Network interface not configured");
7274
Expects(not config_.url.empty());
7375

74-
if(liu::LiveUpdate::is_resumable(UPDATE_LOC))
76+
if(liu::LiveUpdate::is_resumable(LIVEUPD_LOCATION))
7577
{
7678
MYINFO("Found resumable state, try restoring...");
77-
auto success = liu::LiveUpdate::resume(UPDATE_LOC, {this, &WS_uplink::restore});
79+
auto success = liu::LiveUpdate::resume(LIVEUPD_LOCATION, {this, &WS_uplink::restore});
7880
CHECK(success, "Success");
7981
}
8082

@@ -256,7 +258,7 @@ namespace uplink {
256258
ws_->close();
257259
// do the update
258260
Timers::oneshot(std::chrono::milliseconds(10), [this, buffer] (auto) {
259-
liu::LiveUpdate::begin(UPDATE_LOC, buffer, {this, &WS_uplink::store});
261+
liu::LiveUpdate::begin(LIVEUPD_LOCATION, buffer, {this, &WS_uplink::store});
260262
});
261263
}
262264

ws_uplink.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class WS_uplink {
8888

8989
std::vector<char> logbuf_;
9090

91+
void* LIVEUPD_LOCATION;
92+
9193
void inject_token(http::Request& req, http::Client::Options&, const http::Client::Host)
9294
{
9395
if (not token_.empty())

0 commit comments

Comments
 (0)