Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


(no commit message)
[palacios.git] / palacios / include / geekos / range.h
1 /*
2  * Range checking
3  * Copyright (c) 2003, David H. Hovemeyer <daveho@cs.umd.edu>
4  * $Revision: 1.1.1.1 $
5  * 
6  * This is free software.  You are permitted to use,
7  * redistribute, and modify it as specified in the file "COPYING".
8  */
9
10 #ifndef GEEKOS_RANGE_H
11 #define GEEKOS_RANGE_H
12
13 #include <geekos/ktypes.h>
14
15 /*
16  * TODO: think about these, make sure they're correct
17  */
18
19 /**
20  * Check that given range is "proper".
21  * @param start the start of the range
22  * @param size the size of the range
23  * @return true if range is properly within the space
24  *   0(inclusive)..ULONG_MAX(inclusive)
25  */
26 static __inline__ bool
27 Check_Range_Proper(ulong_t start, ulong_t size)
28 {
29     /*
30      * Wrap around is only permitted if the sum is zero.
31      * E.g., start=ULONG_MAX, size==1 is a valid range.
32      */
33     ulong_t sum = start + size;
34     return start <= sum || (sum == 0);
35 }
36
37 /**
38  * Check that given range lies entirely under the
39  * maximum value specified (exclusive).
40  * @param start the start of the range
41  * @param size the size of the range
42  * @param max the lowest address NOT allowed to be in the range
43  * @return true if range falls entirely within the range
44  *   0(inclusive)..max(exclusive)
45  */
46 static __inline__ bool
47 Check_Range_Under(ulong_t start, ulong_t size, ulong_t max)
48 {
49     if (!Check_Range_Proper(start, size))
50         return false;
51
52     return start < max && (start + size) <= max;
53 }
54
55 #endif  /* GEEKOS_RANGE_H */