mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 05:27:20 +00:00
[porthole] make the segments private and add a method to obtain the ptr
This commit is contained in:
parent
453b8e6a4d
commit
76007092d5
@ -22,18 +22,10 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
unsigned int size;
|
|
||||||
void * data;
|
|
||||||
}
|
|
||||||
PortholeSegment;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
unsigned int num_segments;
|
unsigned int num_segments;
|
||||||
PortholeSegment segments[0];
|
|
||||||
}
|
}
|
||||||
PortholeMap;
|
PortholeMap;
|
@ -52,3 +52,11 @@ void porthole_copy_map_to_mem(PortholeMap * src, void * dst, size_t len, off_t o
|
|||||||
* @param dst_off The offset into the dst PortholeMap
|
* @param dst_off The offset into the dst PortholeMap
|
||||||
*/
|
*/
|
||||||
void porthole_copy_map_to_map(PortholeMap * src, PortholeMap * dst, size_t len, off_t src_off, off_t dst_off);
|
void porthole_copy_map_to_map(PortholeMap * src, PortholeMap * dst, size_t len, off_t src_off, off_t dst_off);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the pointer to the base of a PortholeMap
|
||||||
|
*
|
||||||
|
* @param map The map to get the pointer for
|
||||||
|
* @return The base address of the mapping, or NULL if the mapping is not contiguous
|
||||||
|
*/
|
||||||
|
void * porthole_get_map_ptr(PortholeMap *map);
|
||||||
|
@ -17,6 +17,7 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|||||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
#include "porthole/util.h"
|
#include "porthole/util.h"
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ void porthole_copy_mem_to_map(void * src, PortholeMap * dst, size_t len, off_t o
|
|||||||
DEBUG_FATAL("Attempt to write beyond the length of destination mapping");
|
DEBUG_FATAL("Attempt to write beyond the length of destination mapping");
|
||||||
|
|
||||||
/* find the start segment */
|
/* find the start segment */
|
||||||
PortholeSegment * seg = &dst->segments[0];
|
PortholeSegment * seg = PH_SEGMENTS(dst);
|
||||||
while(off)
|
while(off)
|
||||||
{
|
{
|
||||||
if (seg->size > off)
|
if (seg->size > off)
|
||||||
@ -62,7 +63,7 @@ void porthole_copy_map_to_mem(PortholeMap * src, void * dst, size_t len, off_t o
|
|||||||
DEBUG_FATAL("Attempt to read beyond the length of the source mapping");
|
DEBUG_FATAL("Attempt to read beyond the length of the source mapping");
|
||||||
|
|
||||||
/* find the start segment */
|
/* find the start segment */
|
||||||
PortholeSegment * seg = &src->segments[0];
|
PortholeSegment * seg = PH_SEGMENTS(src);
|
||||||
while(off)
|
while(off)
|
||||||
{
|
{
|
||||||
if (seg->size > off)
|
if (seg->size > off)
|
||||||
@ -99,7 +100,7 @@ void porthole_copy_map_to_map(PortholeMap * src, PortholeMap * dst, size_t len,
|
|||||||
DEBUG_FATAL("Attempt to write beyond the length of the destination mapping");
|
DEBUG_FATAL("Attempt to write beyond the length of the destination mapping");
|
||||||
|
|
||||||
/* find the start segments */
|
/* find the start segments */
|
||||||
PortholeSegment * src_seg = &src->segments[0];
|
PortholeSegment * src_seg = PH_SEGMENTS(src);
|
||||||
while(src_off)
|
while(src_off)
|
||||||
{
|
{
|
||||||
if (src_seg->size > src_off)
|
if (src_seg->size > src_off)
|
||||||
@ -109,7 +110,7 @@ void porthole_copy_map_to_map(PortholeMap * src, PortholeMap * dst, size_t len,
|
|||||||
++src_seg;
|
++src_seg;
|
||||||
}
|
}
|
||||||
|
|
||||||
PortholeSegment * dst_seg = &dst->segments[0];
|
PortholeSegment * dst_seg = PH_SEGMENTS(dst);
|
||||||
while(dst_off)
|
while(dst_off)
|
||||||
{
|
{
|
||||||
if (dst_seg->size > dst_off)
|
if (dst_seg->size > dst_off)
|
||||||
@ -150,3 +151,11 @@ void porthole_copy_map_to_map(PortholeMap * src, PortholeMap * dst, size_t len,
|
|||||||
len -= avail;
|
len -= avail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void * porthole_get_map_ptr(PortholeMap *map)
|
||||||
|
{
|
||||||
|
if (map->num_segments != 1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return PH_SEGMENTS(map)[0].data;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user