File: Memory.h

package info (click to toggle)
storm-lang 0.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,984 kB
  • sloc: ansic: 261,420; cpp: 140,270; sh: 14,877; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (28 lines) | stat: -rw-r--r-- 902 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once

// Macro for getting the offset of a member within a structure.
#define OFFSET_OF(baseType, memberName) \
	size_t(&(((baseType *)0)->memberName))

// Macro for getting a pointer to the containing object
// from a pointer to a member within the structure.
#define BASE_PTR(baseType, pointer, member) \
	((baseType *)(((byte *)(pointer)) - OFFSET_OF(baseType, member)))

// Macro for getting an offset into a chunk of memory.
#define OFFSET_IN(ptr, offset, type) \
	(*(type *)(((byte *)(ptr)) + (offset)))

// Example:
// struct Foo { int a, b, c; };
// Assume we have an int * we know is pointing to "b" in "Foo". We can then use
// BASE_PTR(Foo, <ptr>, b); to get the pointer to "Foo" again.
// void *fooPtr = &foo;
// OFFSET_IN(fooPtr, OFFSET_OF(Foo, b), int) = 1;


// Can we read 'addr'?
bool readable(const void *addr);

// Dump the flags for 'addr'.
void memFlags(const void *addr);