<div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default"><div class="gmail_default">Android runs all 32bit programs in a PER_LIINUX32 personality</div><div class="gmail_default">even under a 64 bit kernel, causing the machine to show up as</div><div class="gmail_default">"i686". Check for and correct this case so tests use the correct</div><div class="gmail_default">kernel_bits value.</div><div class="gmail_default"><br></div><div class="gmail_default">Signed-off-by: Kenneth Magic <<a href="mailto:kmagic@google.com">kmagic@google.com</a>></div><div class="gmail_default">---</div><div class="gmail_default"> lib/tst_kernel.c | 47 +++++++++++++++++++++++++++++++++++++++++------</div><div class="gmail_default"> 1 file changed, 41 insertions(+), 6 deletions(-)</div><div class="gmail_default"><br></div><div class="gmail_default">diff --git a/lib/tst_kernel.c b/lib/tst_kernel.c</div><div class="gmail_default">index 42d64cbdc..8edafb8ff 100644</div><div class="gmail_default">--- a/lib/tst_kernel.c</div><div class="gmail_default">+++ b/lib/tst_kernel.c</div><div class="gmail_default">@@ -15,21 +15,28 @@</div><div class="gmail_default">  * along with this program. If not, see <<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>>.</div><div class="gmail_default">  */</div><div class="gmail_default"> </div><div class="gmail_default">+#include <linux/personality.h></div><div class="gmail_default"> #include <sys/utsname.h></div><div class="gmail_default"> #include "test.h"</div><div class="gmail_default"> #include "tst_kernel.h"</div><div class="gmail_default"> </div><div class="gmail_default">-int tst_kernel_bits(void)</div><div class="gmail_default">+static int get_kernel_bits_from_uname(struct utsname *buf)</div><div class="gmail_default"> {</div><div class="gmail_default">-<span style="white-space:pre"> </span>struct utsname buf;</div><div class="gmail_default">-<span style="white-space:pre">  </span>int kernel_bits;</div><div class="gmail_default">-</div><div class="gmail_default">-<span style="white-space:pre">     </span>if (uname(&buf)) {</div><div class="gmail_default">+<span style="white-space:pre">       </span>if (uname(buf)) {</div><div class="gmail_default"> <span style="white-space:pre">           </span>tst_brkm(TBROK | TERRNO, NULL, "uname()");</div><div class="gmail_default"> <span style="white-space:pre">                </span>return -1;</div><div class="gmail_default"> <span style="white-space:pre">  </span>}</div><div class="gmail_default"> </div><div class="gmail_default">-<span style="white-space:pre">   </span>kernel_bits = strstr(buf.machine, "64") ? 64 : 32;</div><div class="gmail_default">+<span style="white-space:pre"> </span>return strstr(buf->machine, "64") ? 64 : 32;</div><div class="gmail_default">+}</div><div class="gmail_default">+</div><div class="gmail_default">+int tst_kernel_bits(void)</div><div class="gmail_default">+{</div><div class="gmail_default">+<span style="white-space:pre"> </span>struct utsname buf;</div><div class="gmail_default">+<span style="white-space:pre">  </span>int kernel_bits = get_kernel_bits_from_uname(&buf);</div><div class="gmail_default">+</div><div class="gmail_default">+<span style="white-space:pre">      </span>if (kernel_bits == -1)</div><div class="gmail_default">+<span style="white-space:pre">               </span>return -1;</div><div class="gmail_default"> </div><div class="gmail_default"> <span style="white-space:pre"> </span>/*</div><div class="gmail_default"> <span style="white-space:pre">  </span> * ARM64 (aarch64) defines 32-bit compatibility modes as</div><div class="gmail_default">@@ -40,6 +47,34 @@ int tst_kernel_bits(void)</div><div class="gmail_default"> <span style="white-space:pre">                 </span>|| !strcmp(buf.machine, "s390x"))</div><div class="gmail_default"> <span style="white-space:pre">         </span>kernel_bits = 64;</div><div class="gmail_default"> </div><div class="gmail_default">+#ifdef __ANDROID__</div><div class="gmail_default">+<span style="white-space:pre"> </span>/* Android's bionic libc sets the PER_LINUX32 personality for all 32-bit</div><div class="gmail_default">+<span style="white-space:pre"> </span> * programs. This will cause buf.machine to report as i686 even though</div><div class="gmail_default">+<span style="white-space:pre">       </span> * the kernel itself is 64-bit.</div><div class="gmail_default">+<span style="white-space:pre">      </span> */</div><div class="gmail_default">+<span style="white-space:pre">  </span>if (!strcmp(buf.machine, "i686") &&</div><div class="gmail_default">+<span style="white-space:pre">                        </span>(personality(0xffffffff) & PER_MASK) == PER_LINUX32) {</div><div class="gmail_default">+<span style="white-space:pre">           </span>/* Set the personality back to the default. */</div><div class="gmail_default">+<span style="white-space:pre">               </span>if (personality(PER_LINUX) == -1) {</div><div class="gmail_default">+<span style="white-space:pre">                  </span>tst_brkm(TBROK | TERRNO, NULL, "personality()");</div><div class="gmail_default">+<span style="white-space:pre">                   </span>return -1;</div><div class="gmail_default">+<span style="white-space:pre">           </span>}</div><div class="gmail_default">+</div><div class="gmail_default">+<span style="white-space:pre">            </span>/* Redo the uname check without the PER_LINUX32 personality to</div><div class="gmail_default">+<span style="white-space:pre">               </span> * determine the actual kernel bits value.</div><div class="gmail_default">+<span style="white-space:pre">           </span> */</div><div class="gmail_default">+<span style="white-space:pre">          </span>kernel_bits = get_kernel_bits_from_uname(&buf);</div><div class="gmail_default">+<span style="white-space:pre">          </span>if (kernel_bits == -1)</div><div class="gmail_default">+<span style="white-space:pre">                       </span>return -1;</div><div class="gmail_default">+</div><div class="gmail_default">+<span style="white-space:pre">           </span>/* Set the personality back to PER_LINUX32. */</div><div class="gmail_default">+<span style="white-space:pre">               </span>if (personality(PER_LINUX32) == -1) {</div><div class="gmail_default">+<span style="white-space:pre">                        </span>tst_brkm(TBROK | TERRNO, NULL, "personality()");</div><div class="gmail_default">+<span style="white-space:pre">                   </span>return -1;</div><div class="gmail_default">+<span style="white-space:pre">           </span>}</div><div class="gmail_default">+<span style="white-space:pre">    </span>}</div><div class="gmail_default">+#endif  /* __ANDROID__ */</div><div class="gmail_default">+</div><div class="gmail_default"> <span style="white-space:pre"> </span>tst_resm(TINFO, "uname.machine=%s kernel is %ibit",</div><div class="gmail_default"> <span style="white-space:pre">       </span>         buf.machine, kernel_bits);</div><div class="gmail_default"> </div><div class="gmail_default">-- </div><div class="gmail_default">2.19.0.397.gdd90340f6a-goog</div><div style="font-size:small"><br></div></div></div></div></div>