selftests/powerpc: Refactor the AUXV routines
Refactor the AUXV routines so they are more composable. In a future test we want to look for many AUXV entries and we don't want to have to read /proc/self/auxv each time. Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
This commit is contained in:
@@ -24,7 +24,11 @@ typedef uint8_t u8;
|
|||||||
|
|
||||||
void test_harness_set_timeout(uint64_t time);
|
void test_harness_set_timeout(uint64_t time);
|
||||||
int test_harness(int (test_function)(void), char *name);
|
int test_harness(int (test_function)(void), char *name);
|
||||||
extern void *get_auxv_entry(int type);
|
|
||||||
|
int read_auxv(char *buf, ssize_t buf_size);
|
||||||
|
void *find_auxv_entry(int type, char *auxv);
|
||||||
|
void *get_auxv_entry(int type);
|
||||||
|
|
||||||
int pick_online_cpu(void);
|
int pick_online_cpu(void);
|
||||||
|
|
||||||
static inline bool have_hwcap(unsigned long ftr)
|
static inline bool have_hwcap(unsigned long ftr)
|
||||||
|
|||||||
@@ -19,45 +19,64 @@
|
|||||||
|
|
||||||
static char auxv[4096];
|
static char auxv[4096];
|
||||||
|
|
||||||
void *get_auxv_entry(int type)
|
int read_auxv(char *buf, ssize_t buf_size)
|
||||||
{
|
{
|
||||||
ElfW(auxv_t) *p;
|
|
||||||
void *result;
|
|
||||||
ssize_t num;
|
ssize_t num;
|
||||||
int fd;
|
int rc, fd;
|
||||||
|
|
||||||
fd = open("/proc/self/auxv", O_RDONLY);
|
fd = open("/proc/self/auxv", O_RDONLY);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
perror("open");
|
perror("open");
|
||||||
return NULL;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = NULL;
|
num = read(fd, buf, buf_size);
|
||||||
|
|
||||||
num = read(fd, auxv, sizeof(auxv));
|
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
perror("read");
|
perror("read");
|
||||||
|
rc = -EIO;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num > sizeof(auxv)) {
|
if (num > buf_size) {
|
||||||
printf("Overflowed auxv buffer\n");
|
printf("overflowed auxv buffer\n");
|
||||||
|
rc = -EOVERFLOW;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = 0;
|
||||||
|
out:
|
||||||
|
close(fd);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *find_auxv_entry(int type, char *auxv)
|
||||||
|
{
|
||||||
|
ElfW(auxv_t) *p;
|
||||||
|
|
||||||
p = (ElfW(auxv_t) *)auxv;
|
p = (ElfW(auxv_t) *)auxv;
|
||||||
|
|
||||||
while (p->a_type != AT_NULL) {
|
while (p->a_type != AT_NULL) {
|
||||||
if (p->a_type == type) {
|
if (p->a_type == type)
|
||||||
result = (void *)p->a_un.a_val;
|
return p;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
out:
|
|
||||||
close(fd);
|
return NULL;
|
||||||
return result;
|
}
|
||||||
|
|
||||||
|
void *get_auxv_entry(int type)
|
||||||
|
{
|
||||||
|
ElfW(auxv_t) *p;
|
||||||
|
|
||||||
|
if (read_auxv(auxv, sizeof(auxv)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
p = find_auxv_entry(type, auxv);
|
||||||
|
if (p)
|
||||||
|
return (void *)p->a_un.a_val;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pick_online_cpu(void)
|
int pick_online_cpu(void)
|
||||||
|
|||||||
Reference in New Issue
Block a user