diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2014-08-16 11:30:35 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2014-08-16 11:30:35 (GMT) |
commit | 161c0f8ab227af5033b1b6456607b9b9c3bc60df (patch) | |
tree | cadf14ab1bfe857ac9a7904fe9ea98de554751d8 /src/arch/vmpa.h | |
parent | 56ee4d3ecddeee05f11083fcc1595e3756b91790 (diff) |
Improved the code for handling vmpa_t definitions.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@388 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/vmpa.h')
-rw-r--r-- | src/arch/vmpa.h | 81 |
1 files changed, 27 insertions, 54 deletions
diff --git a/src/arch/vmpa.h b/src/arch/vmpa.h index 461780c..7f417b5 100644 --- a/src/arch/vmpa.h +++ b/src/arch/vmpa.h @@ -25,7 +25,6 @@ #define _ARCH_VMPA_H -#include <alloca.h> #include <limits.h> #include <stdbool.h> #include <stdint.h> @@ -37,82 +36,57 @@ +/* Taille de la plus longue chaîne de représentation */ +#define VMPA_MAX_LEN (sizeof(STR(ULLONG_MAX)) + 1) +/* Constitution guidée de tampons pour impression */ +#define VMPA_BUFFER(name) char name[VMPA_MAX_LEN] -#define VMPA_MAX_SIZE (sizeof(STR(ULLONG_MAX)) + 1) - - +#define VMPA_NO_PHYSICAL ((off_t)-1) +#define VMPA_NO_VIRTUAL ((uint64_t)-2) /* Adresse mémoire ou position physique */ -struct _vmpa2_t +typedef struct _vmpa2t { off_t physical; /* Position physique */ uint64_t virtual; /* Adresse virtuelle */ - MemoryDataSize last_phys_size; /* Dernière taille demandée #1 */ - MemoryDataSize last_virt_size; /* Dernière taille demandée #2 */ - size_t last_phys_len; /* Dernière taille fournie #1 */ - size_t last_virt_len; /* Dernière taille fournie #2 */ - char phys_cache[VMPA_MAX_SIZE]; /* Impression physique cachée */ - char virt_cache[VMPA_MAX_SIZE]; /* Impression virtuelle cachée */ - -}; - - - -/* Adresse mémoire ou position physique */ -typedef struct _vmpa2_t vmpa2_t; - - -typedef struct _vmpa2_t vmpa2t; - - - - -/* Crée la copie d'un adressage mémoire en local. */ -//inline vmpa2t *local_dup_vmpa(const vmpa2t *) __attribute__((always_inline)); - - - -#define local_dup_vmpa(src) \ - ({ \ - vmpa2t *__result; \ - __result = alloca(sizeof(vmpa2t)); \ - copy_vmpa(__result, src); \ - __result; \ - }) - - - -/* Copie la définition d'un adressage dans un autre. */ -void copy_vmpa(vmpa2t *, const vmpa2t *); - - - +} vmpa2t; /* Initialise une localisation dans l'espace mémoire/physique. */ void init_vmpa(vmpa2t *, off_t, uint64_t); - - - /* Crée une localisation dans l'adressage mémoire. */ vmpa2t *make_vmpa(off_t, uint64_t); +#define delete_vmpa(a) free(a) +/* Copie la définition d'un adressage dans un autre. */ +void copy_vmpa(vmpa2t *, const vmpa2t *); -#define cmp_vmpa(a, b) 0 +/* Compare entre elles deux adresses physiques. */ +int cmp_vmpa_by_phy(const vmpa2t *, const vmpa2t *); +/* Compare entre elles deux adresses virtuelles. */ +int cmp_vmpa_by_virt(const vmpa2t *, const vmpa2t *); +#define are_equal(a, b) \ + (cmp_vmpa_by_phy(a, b) == 0 && cmp_vmpa_by_virt(a, b) == 0) -#define get_phy_addr(a) a->physical -#define get_virt_addr(a) a->virtual +#define get_phy_addr(a) (a)->physical +#define get_virt_addr(a) (a)->virtual +#define dup_vmpa(src) \ + make_vmpa(get_phy_addr(src), get_virt_addr(src)) +/* Décalle une position d'une certaine quantité. */ +void advance_vmpa(vmpa2t *, off_t); +/* Calcule au mieux la distance entre deux coordonnées. */ +off_t compute_vmpa_diff(const vmpa2t *, const vmpa2t *); /* Lit la définition d'une adresse depuis un flux réseau. */ bool recv_vmpa(vmpa2t *, int, int); @@ -121,11 +95,10 @@ bool recv_vmpa(vmpa2t *, int, int); bool send_vmpa(const vmpa2t *, int, int); /* Transforme une adresse physique en chaîne de caractères. */ -const char *vmpa2_phys_to_string(vmpa2t *, MemoryDataSize, size_t *); +char *vmpa2_phys_to_string(const vmpa2t *, MemoryDataSize, char [VMPA_MAX_LEN], size_t *); /* Transforme une adresse virtuelle en chaîne de caractères. */ -const char *vmpa2_virt_to_string(vmpa2t *, MemoryDataSize, size_t *); - +char *vmpa2_virt_to_string(const vmpa2t *, MemoryDataSize, char [VMPA_MAX_LEN], size_t *); |