Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(950)

Unified Diff: third_party/android_crazy_linker/src/tests/test_two_shared_relros.cpp

Issue 322433006: Fork of the Android NDK crazy linker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a required license header to a cpp module, missing in the original. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/android_crazy_linker/src/tests/test_two_shared_relros.cpp
diff --git a/third_party/android_crazy_linker/src/tests/test_two_shared_relros.cpp b/third_party/android_crazy_linker/src/tests/test_two_shared_relros.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9af0eee6a9c0bcb1ae4cdd428a76a4698a3fd31c
--- /dev/null
+++ b/third_party/android_crazy_linker/src/tests/test_two_shared_relros.cpp
@@ -0,0 +1,122 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Same as test_relro_sharing.cpp, but uses two libraries at the same
+// time (libfoo_with_relro.so and libbar_with_relro.so), each one of
+// them gets its own shared RELRO.
+
+#include <errno.h>
+#include <pthread.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include <crazy_linker.h>
+
+#include "test_util.h"
+
+typedef void (*FunctionPtr)();
+
+int main() {
+
+ if (!crazy_system_can_share_relro()) {
+ fprintf(stderr, "WARNING: Test ignored due to broken kernel!!\n");
+ return 0;
+ }
+
+ crazy_context_t* context = crazy_context_create();
+
+ RelroLibrary foo;
+ RelroLibrary bar;
+
+ crazy_context_add_search_path_for_address(context, (void*)&main);
+
+ // Load libfoo_with_relro.so
+ crazy_context_set_load_address(context, 0x20000000);
+ foo.Init("libfoo_with_relro.so", context);
+
+ crazy_context_set_load_address(context, 0x20800000);
+ bar.Init("libbar_with_relro.so", context);
+
+ printf("Libraries loaded\n");
+
+ int pipes[2];
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipes) < 0)
+ Panic("Could not create socket pair: %s", strerror(errno));
+
+ pid_t child = fork();
+ if (child < 0)
+ Panic("Could not fork test program!");
+
+ if (child == 0) {
+ // In the child.
+ printf("Child waiting for foo relro fd\n");
+
+ foo.ReceiveRelroInfo(pipes[0]);
+ foo.UseSharedRelro(context);
+
+ printf("Child waiting for bar relro fd\n");
+ bar.ReceiveRelroInfo(pipes[0]);
+ bar.UseSharedRelro(context);
+
+ printf("RELROs used in child process\n");
+
+ CheckRelroMaps(2);
+
+ FunctionPtr bar_func;
+ if (!crazy_library_find_symbol(
+ bar.library, "Bar", reinterpret_cast<void**>(&bar_func)))
+ Panic("Could not find 'Bar' in library");
+
+ printf("Calling Bar()\n");
+ (*bar_func)();
+
+ printf("Bar() called, exiting\n");
+
+ exit(0);
+
+ } else {
+ // In the parent.
+
+ printf("Parent enabling foo RELRO sharing\n");
+
+ foo.EnableSharedRelro(context);
+ foo.SendRelroInfo(pipes[1]);
+
+ printf("Parent enabling bar RELRO sharing\n");
+
+ bar.EnableSharedRelro(context);
+ bar.SendRelroInfo(pipes[1]);
+
+ printf("RELROs enabled and sent to child\n");
+
+ CheckRelroMaps(2);
+
+ printf("Parent waiting for child\n");
+
+ // Wait for child to complete.
+ int status;
+ waitpid(child, &status, 0);
+
+ if (WIFSIGNALED(status))
+ Panic("Child terminated by signal!!\n");
+ else if (WIFEXITED(status)) {
+ int child_status = WEXITSTATUS(status);
+ if (child_status != 0)
+ Panic("Child terminated with status=%d\n", child_status);
+ } else
+ Panic("Child exited for unknown reason!!\n");
+ }
+
+ printf("Closing libraries\n");
+ bar.Close();
+ foo.Close();
+
+ crazy_context_destroy(context);
+ return 0;
+}

Powered by Google App Engine
This is Rietveld 408576698