Skip to content

Commit

Permalink
Add tool to dump /proc/cpuinfo under AArch32 on AArch64 systems
Browse files Browse the repository at this point in the history
  • Loading branch information
Marat Dukhan committed Apr 19, 2018
1 parent dca6828 commit cb9ae9c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,10 @@ IF(CPUINFO_SUPPORTED_PLATFORM AND CPUINFO_BUILD_TOOLS)
CPUINFO_TARGET_ENABLE_C99(auxv-dump)
CPUINFO_TARGET_RUNTIME_LIBRARY(auxv-dump)
TARGET_LINK_LIBRARIES(auxv-dump PRIVATE ${CMAKE_DL_LIBS})

ADD_EXECUTABLE(cpuinfo-dump tools/cpuinfo-dump.c)
CPUINFO_TARGET_ENABLE_C99(cpuinfo-dump)
CPUINFO_TARGET_RUNTIME_LIBRARY(cpuinfo-dump)
ENDIF()

IF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|AMD64|x86_64)$")
Expand Down
6 changes: 6 additions & 0 deletions jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ LOCAL_SRC_FILES := $(LOCAL_PATH)/tools/auxv-dump.c
LOCAL_CFLAGS := -std=gnu99
include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)
LOCAL_MODULE := cpuinfo-dump
LOCAL_SRC_FILES := $(LOCAL_PATH)/tools/cpuinfo-dump.c
LOCAL_CFLAGS := -std=gnu99
include $(BUILD_EXECUTABLE)

endif # armeabi, armeabi-v7a, or arm64-v8a

ifeq ($(TARGET_ARCH_ABI),$(filter $(TARGET_ARCH_ABI),x86 x86_64))
Expand Down
45 changes: 45 additions & 0 deletions tools/cpuinfo-dump.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>
#include <fcntl.h>
#include <errno.h>


#define BUFFER_SIZE 4096
char buffer[BUFFER_SIZE];

#define CPUINFO_PATH "/proc/cpuinfo"

int main(int argc, char** argv) {
int file = open(CPUINFO_PATH, O_RDONLY);
if (file == -1) {
fprintf(stderr, "Error: failed to open %s: %s\n", CPUINFO_PATH, strerror(errno));
exit(EXIT_FAILURE);
}

/* Only used for error reporting */
size_t position = 0;
char* data_start = buffer;
ssize_t bytes_read;
do {
bytes_read = read(file, buffer, BUFFER_SIZE);
if (bytes_read < 0) {
fprintf(stderr, "Error: failed to read file %s at position %zu: %s\n",
CPUINFO_PATH, position, strerror(errno));
exit(EXIT_FAILURE);
}

position += (size_t) bytes_read;
if (bytes_read > 0) {
fwrite(buffer, 1, (size_t) bytes_read, stdout);
}
} while (bytes_read != 0);

if (close(file) != 0) {
fprintf(stderr, "Error: failed to close %s: %s\n", CPUINFO_PATH, strerror(errno));
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}

0 comments on commit cb9ae9c

Please sign in to comment.