Mapping +unmappign haystacks from cl.

TODO: On mapping failure of haystack, unmap the previous ones before exiting `map_haystacks()`

Fortune for naka's current commit: Middle blessing − 中吉
master
Avril 3 years ago
parent aff04b6d4b
commit d82407951a
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -2,6 +2,8 @@
#ifndef _PROJECT_H #ifndef _PROJECT_H
#define _PROJECT_H #define _PROJECT_H
#include <limits.h>
#include "macros.h" #include "macros.h"
#include "ints.h" #include "ints.h"
#include "version.h" #include "version.h"

@ -45,6 +45,20 @@ noreturn void usage_then_exit(int err, int argc, char** argv)
exit(err); exit(err);
} }
static int map_haystacks(const char* const * h, map_t maps[pOUT])
{
const char* path;
while( (path = *h++) )
{
map_t *pOUT c = maps++;
TRACE("attempting to map `%s' to map %p", path, c);
debug_assert(c);
if(!map_handle_err(map_file(path, false, 0, 0, c)))
//TODO: Handle unmapping previous haystacks before return
return 0;
}
return 1;
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -63,7 +77,13 @@ inv_args:
if(!map_handle_err(map_file(argv[1], false, 0, 0, &needle))) return PROG_RET_MAP_NEEDLE_FAILED; if(!map_handle_err(map_file(argv[1], false, 0, 0, &needle))) return PROG_RET_MAP_NEEDLE_FAILED;
if(!map_handle_err(map_preload(&needle, false))) WARN("Failed to advise kernel about memory access: needle"); if(!map_handle_err(map_preload(&needle, false))) WARN("Failed to advise kernel about memory access: needle");
//TODO: Map argv[2...] // Remove exe name from argv: now is (needle, haystacks...)
argv+=1;
// Setup haystack maps
map_t haystacks[argc-2];
TRACE("Attempting to map %d haystacks", argc-2);
if(!map_haystacks((const char**)(argv+1), haystacks)) return PROG_RET_MAP_HAYSTACK_FAILED;
//TODO: Setup thread-pool. //TODO: Setup thread-pool.
//TODO: Dispatch haystack maps to threadpool. //TODO: Dispatch haystack maps to threadpool.
//TODO: Use either `cmp_find()` or `cmp_find_many()` to find the `needle` (mapped above) within those haystacks. //TODO: Use either `cmp_find()` or `cmp_find_many()` to find the `needle` (mapped above) within those haystacks.
@ -71,6 +91,10 @@ inv_args:
//TODO: Join the threadpool and consolidate results. //TODO: Join the threadpool and consolidate results.
//TODO: Iterate through the haystack numbers match results, return the first non-match haystack number through `PROG_RET_MATCH_HAYSTACK_N_FAILED(n)` (haystack numbers are always nonzero). If all were matched, return 0 //TODO: Iterate through the haystack numbers match results, return the first non-match haystack number through `PROG_RET_MATCH_HAYSTACK_N_FAILED(n)` (haystack numbers are always nonzero). If all were matched, return 0
for(int i=0;i<(argc-2);i++) {
TRACE("Attempting to unmap haystack %d (%p, `%s')", i, haystacks+i, argv[i+1]);
if(!map_handle_err(map_free(haystacks[i]))) return PROG_RET_UNMAP_HAYSTACK_N_FAILED(i+1);
}
if(!map_handle_err(map_free(needle))) return PROG_RET_UNMAP_NEEDLE_FAILED; if(!map_handle_err(map_free(needle))) return PROG_RET_UNMAP_NEEDLE_FAILED;
TRACE("main end"); TRACE("main end");
return 0; return 0;

Loading…
Cancel
Save