New problem, same library, might as well post here.
Hitting a segfault but I'm not seeing what I did wrong, I'm assuming I miss-allocated but I rather than just throw memory at the problem to shut it up I'd rather understand it 1st, here's the relevant code:
Code:
PAW_HIDDEN int paw_compare_maps( void const * _one, void const * _two )
{
struct paw_map const *one = _one, *two = _two;
int ret = (one->first > two->final) - (two->first > one->final);
if ( ret )
return ret;
ret = (two->first < one->first) - (two->first > one->first);
if ( ret )
return ret;
ret = (two->final < one->final) - (two->final > one->final);
if ( ret )
return ret;
ret = (one->perm[0] == 'r') - (two->perm[0] == 'r');
if ( ret )
return ret;
ret = (one->perm[0] == 'w') - (two->perm[0] == 'w');
if ( ret )
return ret;
return (one->perm[0] == 'x') - (two->perm[0] == 'x');
}
PAW_SHARED int paw_load_maps_text( void *ud, struct paw_text *text, struct paw_maps *maps )
{
struct paw_text *sources = &(maps->sources);
struct paw_map *_maps = maps->buff, *map;
size_t want = 0, done = 0;
char *line = text->buff, *source, *_sources = sources->buff, *temp;
want = (text->size / sizeof(struct paw_map)) * sizeof(struct paw_map);
if ( maps->size < want )
{
_maps = paw.alloc( ud, _maps, maps->size, want );
if ( !_maps )
return ENOMEM;
maps->buff = _maps;
maps->size = want;
}
memset( _maps, 0, want );
if ( sources->size < text->size )
{
_sources = paw.alloc( ud, _sources, sources->size, text->size );
if ( !_sources )
return ENOMEM;
sources->buff = _sources;
sources->size = text->size;
}
sources->used = 0;
memset( _sources, 0, sources->size );
for ( maps->used = 0; *line; maps->used++ )
{
map = _maps + maps->used;
sscanf
(
line
, "%jx-%jx %s %jx %u:%u %lu%n"
, &(map->first)
, &(map->final)
, map->perm
, &(map->faddr)
, &(map->major)
, &(map->minor)
, &(map->inode)
, &done
);
for ( source = line + done; *source == ' '; ++source );
for ( line = source; *line && *line != '\n' && *line != '\r'; ++line );
temp = _sources + sources->used;
map->index = sources->used;
map->count = (size_t)(line - source);
if ( map->count )
(void)memcpy( temp, source, map->count );
sources->used += map->count + 1;
}
/* Downsize now we no longer need the optimization */
sources->buff = paw.alloc( ud, _sources, sources->size, sources->used );
sources->size = sources->used;
/* Same with mappings */
want = maps->used * sizeof(struct paw_map);
maps->buff = paw.alloc( ud, _maps, maps->size, want );
maps->size = want;
qsort( maps->buff, maps->size, sizeof(struct paw_map), paw_compare_maps );
return 0;
}
The text parameter only has the 3 members you can see so skip that question, it's preloaded by another function with the contents of /proc/<PID>/maps, in this case it's actually /proc/self/maps (The function that loads app details just fills in the directory to use as an optimization)
According to gede the segfault occured in paw_compare_apps() but only after successfully comparing a number of them so the error is surely with what I hand qsort(), I gave the rest of paw_load_maps_text() for context, the main area I'm looking at is at the bottom of that function