goldfish_sync: detect when running on a 64-bit kernel

bug: 71861550

The goldfish sync ioctl cmd for QUEUE_WORK is different when running a
64-bit kernel. Use that magic number instead if we get a negative return
code and ENOTTY from ioctl.

Change-Id: I23b1f6d0d8be9e97f3d14105882d4c8d9c4435df
Merged-In: I23b1f6d0d8be9e97f3d14105882d4c8d9c4435df
diff --git a/system/egl/goldfish_sync.h b/system/egl/goldfish_sync.h
index 6b30fe5..5dcc449 100644
--- a/system/egl/goldfish_sync.h
+++ b/system/egl/goldfish_sync.h
@@ -47,6 +47,11 @@
     return close(sync_fd);
 }
 
+static unsigned int sQueueWorkIoctlCmd = GOLDFISH_SYNC_IOC_QUEUE_WORK;
+
+// If we are running on a 64-bit kernel.
+static unsigned int sQueueWorkIoctlCmd64Kernel = 0xc0184000;
+
 static __inline__ int goldfish_sync_queue_work(int goldfish_sync_fd,
                                                 uint64_t host_glsync,
                                                 uint64_t host_thread,
@@ -59,7 +64,15 @@
     info.host_syncthread_handle_in = host_thread;
     info.fence_fd_out = -1;
 
-    err = ioctl(goldfish_sync_fd, GOLDFISH_SYNC_IOC_QUEUE_WORK, &info);
+    err = ioctl(goldfish_sync_fd, sQueueWorkIoctlCmd, &info);
+
+    if (err < 0 && errno == ENOTTY) {
+        sQueueWorkIoctlCmd = sQueueWorkIoctlCmd64Kernel;
+        err = ioctl(goldfish_sync_fd, sQueueWorkIoctlCmd, &info);
+        if (err < 0) {
+            sQueueWorkIoctlCmd = GOLDFISH_SYNC_IOC_QUEUE_WORK;
+        }
+    }
 
     if (fd_out) *fd_out = info.fence_fd_out;