OSDN Git Service

Make `union semun` usable.
authorElliott Hughes <enh@google.com>
Thu, 18 May 2017 22:05:26 +0000 (15:05 -0700)
committerElliott Hughes <enh@google.com>
Thu, 18 May 2017 22:05:26 +0000 (15:05 -0700)
This is a bit bogus because it's been removed from glibc (though not
thoroughly) and is never useful on Android (because the system calls
in question are compiled out of Android kernels, and SELinux would
disallow them even if you weren't running an Android kernel). This
also means that on glibc you need to include <linux/sem.h> for this
and on bionic you need <sys/sem.h> (and for either if you #include
the other file, you won't get this union).

Bug: https://github.com/android-ndk/ndk/issues/400
Test: added new test
Change-Id: I47f721da77515531f616d6ad8479bfbc9b60ee47

libc/include/sys/sem.h
libc/kernel/tools/defaults.py
libc/kernel/uapi/linux/sem.h
tests/sys_sem_test.cpp

index 904c334..be0e22d 100644 (file)
 
 #include <linux/sem.h>
 
+__BEGIN_DECLS
+
 #define semid_ds semid64_ds
 
-__BEGIN_DECLS
+union semun {
+  int val;
+  struct semid_ds* buf;
+  unsigned short* array;
+  struct seminfo* __buf;
+  void* __pad;
+};
 
 int semctl(int, int, int, ...) __INTRODUCED_IN(26);
 int semget(key_t, int, int) __INTRODUCED_IN(26);
index c22f684..5198dbe 100644 (file)
@@ -70,6 +70,8 @@ kernel_token_replacements = {
     "semid_ds": "__kernel_legacy_semid_ds",
     "shmid_ds": "__kernel_legacy_shmid_ds",
     "ipc_perm": "__kernel_legacy_ipc_perm",
+    # The kernel semun isn't usable (https://github.com/android-ndk/ndk/issues/400).
+    "semun": "__kernel_legacy_semun",
     # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside.
     "_NSIG": "_KERNEL__NSIG",
     "NSIG": "_KERNEL_NSIG",
index 6916556..df815db 100644 (file)
@@ -52,7 +52,7 @@ struct sembuf {
   short sem_flg;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
-union semun {
+union __kernel_legacy_semun {
   int val;
   struct __kernel_legacy_semid_ds __user * buf;
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
index d8d83c5..eaf2b8f 100644 (file)
@@ -98,3 +98,19 @@ TEST(sys_sem, semtimedop_failure) {
   ASSERT_EQ(-1, semtimedop(-1, nullptr, 0, nullptr));
   ASSERT_TRUE(errno == EINVAL || errno == ENOSYS);
 }
+
+TEST(sys_sem, union_semun) {
+  // https://github.com/android-ndk/ndk/issues/400
+#if defined(__BIONIC__)
+  semun arg;
+  semid_ds i1;
+  seminfo i2;
+  unsigned short a[] = { 1u, 2u };
+  arg.val = 123;
+  arg.buf = &i1;
+  arg.array = a;
+  arg.__buf = &i2;
+#else
+  // glibc already mostly removed this cruft (although it's still in <linux/sem.h>).
+#endif
+}