avutil/cpu_internal: Provide ff_getauxval() wrapper for getauxvaul()

Initially used for getauxval() but will be used to add support for
other API, such as elf_aux_info().

Signed-off-by: Brad Smith <brad@comstyle.com>
This commit is contained in:
Brad Smith 2024-09-09 06:20:11 -04:00
parent 5e9845f11e
commit fe4b9ef69f
7 changed files with 22 additions and 6 deletions

View File

@ -31,8 +31,8 @@ static int detect_flags(void)
{
int flags = 0;
unsigned long hwcap = getauxval(AT_HWCAP);
unsigned long hwcap2 = getauxval(AT_HWCAP2);
unsigned long hwcap = ff_getauxval(AT_HWCAP);
unsigned long hwcap2 = ff_getauxval(AT_HWCAP2);
if (hwcap & HWCAP_AARCH64_ASIMDDP)
flags |= AV_CPU_FLAG_DOTPROD;

View File

@ -55,7 +55,7 @@
static int get_auxval(uint32_t *hwcap)
{
#if HAVE_GETAUXVAL
unsigned long ret = getauxval(AT_HWCAP);
unsigned long ret = ff_getauxval(AT_HWCAP);
if (ret == 0)
return -1;
*hwcap = ret;

View File

@ -49,6 +49,10 @@
#include <unistd.h>
#endif
#if HAVE_GETAUXVAL
#include <sys/auxv.h>
#endif
static atomic_int cpu_flags = -1;
static atomic_int cpu_count = -1;
@ -283,3 +287,13 @@ size_t av_cpu_max_align(void)
return 8;
}
unsigned long ff_getauxval(unsigned long type)
{
#if HAVE_GETAUXVAL
return getauxval(type);
#else
errno = ENOSYS;
return 0;
#endif
}

View File

@ -59,4 +59,6 @@ size_t ff_get_cpu_max_align_ppc(void);
size_t ff_get_cpu_max_align_x86(void);
size_t ff_get_cpu_max_align_loongarch(void);
unsigned long ff_getauxval(unsigned long type);
#endif /* AVUTIL_CPU_INTERNAL_H */

View File

@ -28,7 +28,7 @@
static int cpu_flags_getauxval(void)
{
int flags = 0;
int flag = (int)getauxval(AT_HWCAP);
int flag = (int)ff_getauxval(AT_HWCAP);
if (flag & LA_HWCAP_LSX)
flags |= AV_CPU_FLAG_LSX;

View File

@ -34,7 +34,7 @@
static int cpucfg_available(void)
{
return getauxval(AT_HWCAP) & HWCAP_LOONGSON_CPUCFG;
return ff_getauxval(AT_HWCAP) & HWCAP_LOONGSON_CPUCFG;
}
/* Most toolchains have no CPUCFG support yet */

View File

@ -86,7 +86,7 @@ int ff_get_cpu_flags_riscv(void)
}
#elif HAVE_GETAUXVAL
{
const unsigned long hwcap = getauxval(AT_HWCAP);
const unsigned long hwcap = ff_getauxval(AT_HWCAP);
if (hwcap & HWCAP_RV('I'))
ret |= AV_CPU_FLAG_RVI;