On 19 August 2013 18:37, Laszlo Ersek <ler...@redhat.com> wrote: > ((3) memory_region_size() is slightly different from > int128_get64(mr->size); it has a special case for int128_2_64() -- and I > don't understand that.
The special case is because valid memory region sizes range from 0 to 2^64, *inclusive*. [2^64-sized regions tend to be containers representing address spaces like PCI or the system memory space.] Inside memory.c we store the size in an int128 in the way you'd expect. However some of the memory region APIs take or return the size of the region as a uint64_t, with the convention that UINT64_MAX means "actually 2^64" (with a size of really 2^64 - 1 not being valid). So the special case here is doing the conversion from an int128 representation of the size to the uint64_t representation. You can see the same thing going the other way in memory_region_init(), where we take the size as a uint64_t and convert it to an int128 with mr->size = int128_make64(size); if (size == UINT64_MAX) { mr->size = int128_2_64(); } (Note that int128_get64() of an int128 which == 2^64 or more will assert, so int128_get64(mr->size) is a bit of a code smell; it happens to be OK here because we know that a RAM-backed MR will never be a 2^64-sized region.) -- PMM