| 1 |
/* |
| 2 |
getcpuflags_arm: get cpuflags for ARM |
| 3 |
|
| 4 |
copyright 1995-2024 by the mpg123 project - free software under the terms of the LGPL 2.1 |
| 5 |
see COPYING and AUTHORS files in distribution or http://mpg123.org |
| 6 |
initially written by Taihei Momma |
| 7 |
*/ |
| 8 |
|
| 9 |
// For sigsetjmp, we need POSIX 2001 |
| 10 |
#define _POSIX_C_SOURCE 200112L |
| 11 |
// For SA_RESTART, XSI is needed (or POSIX 2008). |
| 12 |
// This here should include the above, keeping that for clarity. |
| 13 |
#define _XOPEN_SOURCE 600 |
| 14 |
|
| 15 |
#include <setjmp.h> |
| 16 |
#include <signal.h> |
| 17 |
#include "mpg123lib_intern.h" |
| 18 |
#include "getcpuflags.h" |
| 19 |
|
| 20 |
extern void INT123_check_neon(void); |
| 21 |
|
| 22 |
#ifndef _M_ARM |
| 23 |
static sigjmp_buf jmpbuf; |
| 24 |
#else |
| 25 |
static jmp_buf jmpbuf; |
| 26 |
#endif |
| 27 |
|
| 28 |
static void mpg123_arm_catch_sigill(int sig) |
| 29 |
{ |
| 30 |
#ifndef _M_ARM |
| 31 |
siglongjmp(jmpbuf, 1); |
| 32 |
#else |
| 33 |
longjmp(jmpbuf, 1); |
| 34 |
#endif |
| 35 |
} |
| 36 |
|
| 37 |
unsigned int INT123_getcpuflags(struct cpuflags* cf) |
| 38 |
{ |
| 39 |
#ifndef _M_ARM |
| 40 |
struct sigaction act, act_old; |
| 41 |
act.sa_handler = mpg123_arm_catch_sigill; |
| 42 |
act.sa_flags = SA_RESTART; |
| 43 |
sigemptyset(&act.sa_mask); |
| 44 |
sigaction(SIGILL, &act, &act_old); |
| 45 |
|
| 46 |
cf->has_neon = 0; |
| 47 |
|
| 48 |
if(!sigsetjmp(jmpbuf, 1)) { |
| 49 |
INT123_check_neon(); |
| 50 |
cf->has_neon = 1; |
| 51 |
} |
| 52 |
|
| 53 |
sigaction(SIGILL, &act_old, NULL); |
| 54 |
#else |
| 55 |
cf->has_neon = 0; |
| 56 |
|
| 57 |
if (!setjmp(jmpbuf)) { |
| 58 |
signal(SIGILL, mpg123_arm_catch_sigill); |
| 59 |
INT123_check_neon(); |
| 60 |
cf->has_neon = 1; |
| 61 |
} |
| 62 |
|
| 63 |
signal(SIGILL, SIG_DFL); |
| 64 |
#endif |
| 65 |
|
| 66 |
return 0; |
| 67 |
} |