X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=blobdiff_plain;f=test%2Fgeekos_test_vm%2Finclude%2Fgeekos%2Frange.h;fp=test%2Fgeekos_test_vm%2Finclude%2Fgeekos%2Frange.h;h=15bd023e0a95433104ee4e52e23d9682f953998c;hp=0000000000000000000000000000000000000000;hb=a70930549d1b741704dd7af4e6bb0e89f6f8a519;hpb=afb634a80f946634454a5d067a92aa600227bd93 diff --git a/test/geekos_test_vm/include/geekos/range.h b/test/geekos_test_vm/include/geekos/range.h new file mode 100644 index 0000000..15bd023 --- /dev/null +++ b/test/geekos_test_vm/include/geekos/range.h @@ -0,0 +1,55 @@ +/* + * Range checking + * Copyright (c) 2003, David H. Hovemeyer + * $Revision: 1.1 $ + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "COPYING". + */ + +#ifndef GEEKOS_RANGE_H +#define GEEKOS_RANGE_H + +#include + +/* + * TODO: think about these, make sure they're correct + */ + +/** + * Check that given range is "proper". + * @param start the start of the range + * @param size the size of the range + * @return true if range is properly within the space + * 0(inclusive)..ULONG_MAX(inclusive) + */ +static __inline__ bool +Check_Range_Proper(ulong_t start, ulong_t size) +{ + /* + * Wrap around is only permitted if the sum is zero. + * E.g., start=ULONG_MAX, size==1 is a valid range. + */ + ulong_t sum = start + size; + return start <= sum || (sum == 0); +} + +/** + * Check that given range lies entirely under the + * maximum value specified (exclusive). + * @param start the start of the range + * @param size the size of the range + * @param max the lowest address NOT allowed to be in the range + * @return true if range falls entirely within the range + * 0(inclusive)..max(exclusive) + */ +static __inline__ bool +Check_Range_Under(ulong_t start, ulong_t size, ulong_t max) +{ + if (!Check_Range_Proper(start, size)) + return false; + + return start < max && (start + size) <= max; +} + +#endif /* GEEKOS_RANGE_H */