Added rollback to unmap previous haystack maps on error in `map_haystacks()` before returning.

Fortune for naka's current commit: Future blessing − 末吉
master
Avril 3 years ago
parent d9eed51762
commit b0623182be
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -89,6 +89,13 @@ _mixin void _drain_val(void* x, ...) { IGNORE(x); } // This compiles to no-op on
// Function macros
// debug-only statements
#ifdef DEBUG
#define DBG(x) x
#else
#define DBG(x) ((void)0)
#endif
// Assertions
#define assert_msg(expr, ...) ( (expr) ? 1 : FATAL(__VA_ARGS__))

@ -48,14 +48,22 @@ noreturn void usage_then_exit(int err, int argc, char** argv)
static int map_haystacks(const char* const * h, map_t maps[pOUT])
{
const char* path;
usize d =0;
while( (path = *h++) )
{
map_t *pOUT c = maps++;
INFO("Mapping haystack file `%s' (to map addr %p)", path, c);
debug_assert(c);
if(!map_handle_err(map_file(path, false, 0, 0, c)))
//TODO: Handle unmapping previous haystacks before return
if(!map_handle_err(map_file(path, false, 0, 0, c))) {
//Handle unmapping previous haystacks before return
// Prep reset maps to before `c` for unwind
maps-=1;
ERROR("Failed to map file `%s', rolling back %lu maps. (erp: %p, prev: %p)", path, d, c, maps);
for(usize i=0;i<d;i++)
if(!map_handle_err(map_free(* (--maps)))) WARN("Failed to free map at %p (in %lu unwind)", maps, i);
return 0;
}
d+=1;
}
return 1;
}

Loading…
Cancel
Save