github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/mobile/app/android_x86.c (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build android,x86 6 7 #include <android/log.h> 8 #include <dlfcn.h> 9 #include <errno.h> 10 #include <fcntl.h> 11 #include <stdlib.h> 12 #include <stdint.h> 13 #include <string.h> 14 #include "_cgo_export.h" 15 16 void build_auxv(uint32_t *xauxv, size_t xauxv_len) { 17 char* auxv = (char*)xauxv; 18 size_t auxv_len = xauxv_len*sizeof(uint32_t); 19 20 // TODO(crawshaw): determine if we can read /proc/self/auxv on 21 // x86 android release builds. 22 int fd = open("/proc/self/auxv", O_RDONLY, 0); 23 if (fd == -1) { 24 __android_log_print(ANDROID_LOG_FATAL, "Go", "cannot open /proc/self/auxv: %s", strerror(errno)); 25 } 26 int n = read(fd, &auxv, auxv_len); 27 if (n < 0) { 28 __android_log_print(ANDROID_LOG_FATAL, "Go", "error reading /proc/self/auxv: %s", strerror(errno)); 29 } 30 if (n == auxv_len) { // auxv should be more than plenty. 31 __android_log_print(ANDROID_LOG_FATAL, "Go", "/proc/self/auxv too big"); 32 } 33 close(fd); 34 35 for (; n < auxv_len; n++) { 36 auxv[n] = 0; 37 } 38 }