summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2008-11-18 16:01:11 -0500
committerDan Williams <dcbw@redhat.com>2008-11-18 16:01:11 -0500
commitcd2a79ab81045aa7e35bc901081e57dea6ac4845 (patch)
tree60c73cb761dd2036af98c6ca43d4d7cc76c430fa
parentb1b0507c24d7a3afb1ee09fc23783fa22cd0e56e (diff)
Less fragile Linux altivec detection
Instead of using really fragile SIGILL trapping, use a more reliable detection method by checking what the CPU really supports. https://bugzilla.redhat.com/show_bug.cgi?id=472000 https://bugzilla.redhat.com/show_bug.cgi?id=451831
-rw-r--r--pixman/pixman-pict.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/pixman/pixman-pict.c b/pixman/pixman-pict.c
index e2fd235..1388517 100644
--- a/pixman/pixman-pict.c
+++ b/pixman/pixman-pict.c
@@ -1987,7 +1987,59 @@ pixman_bool_t pixman_have_vmx (void) {
return have_vmx;
}
-#else
+#elif defined (__linux__)
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <linux/auxvec.h>
+#include <asm/cputable.h>
+
+pixman_bool_t pixman_have_vmx (void)
+{
+ if (!initialized) {
+ char fname[64];
+ unsigned long buf[64];
+ ssize_t count = 0;
+ pid_t pid;
+ int fd, i;
+
+ pid = getpid();
+ snprintf(fname, sizeof(fname)-1, "/proc/%d/auxv", pid);
+
+ fd = open(fname, O_RDONLY);
+ if (fd >= 0) {
+ for (i = 0; i <= (count / sizeof(unsigned long)); i += 2) {
+ /* Read more if buf is empty... */
+ if (i == (count / sizeof(unsigned long))) {
+ count = read(fd, buf, sizeof(buf));
+ if (count <= 0)
+ break;
+ i = 0;
+ }
+
+ if (buf[i] == AT_HWCAP) {
+ have_vmx = !!(buf[i+1] & PPC_FEATURE_HAS_ALTIVEC);
+ initialized = TRUE;
+ break;
+ } else if (buf[i] == AT_NULL) {
+ break;
+ }
+ }
+ close(fd);
+ }
+ }
+ if (!initialized) {
+ /* Something went wrong. Assume 'no' rather than playing
+ fragile tricks with catching SIGILL. */
+ have_vmx = FALSE;
+ initialized = TRUE;
+ }
+
+ return have_vmx;
+}
+#else /* !__APPLE__ && !__linux__ */
#include <signal.h>
#include <setjmp.h>