Revert "Omit calls to set composing region when pasting image."
[chromium-blink-merge.git] / third_party / android_crazy_linker / src / tests / test_relocated_shared_relro.cpp
blob3ab297ed63b13dd93822c1bd0c6d91a2e1c5e632
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <errno.h>
6 #include <stdarg.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sys/socket.h>
10 #include <sys/uio.h>
11 #include <sys/wait.h>
12 #include <unistd.h>
14 #include <crazy_linker.h>
16 #include "test_util.h"
18 #define PARENT_ADDRESS 0x20000000
19 #define CHILD_ADDRESS 0x20134000
21 typedef void (*FunctionPtr)();
23 int main() {
24 crazy_context_t* context = crazy_context_create();
26 RelroLibrary foo;
28 int pipes[2];
29 if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipes) < 0)
30 Panic("Could not create socket pair: %s", strerror(errno));
32 pid_t child = fork();
33 if (child < 0)
34 Panic("Could not fork test program!");
36 if (child == 0) {
37 // In the child.
38 crazy_context_set_load_address(context, CHILD_ADDRESS);
39 foo.Init("libfoo_with_relro.so", context);
41 printf("Child waiting for foo relro fd\n");
43 foo.ReceiveRelroInfo(pipes[0]);
44 foo.UseSharedRelro(context);
46 printf("RELRO used in child process\n");
48 CheckRelroMaps(1);
50 FunctionPtr foo_func;
51 if (!crazy_library_find_symbol(
52 foo.library, "Foo", reinterpret_cast<void**>(&foo_func)))
53 Panic("Could not find 'Foo' in library");
55 printf("Calling Foo()\n");
56 (*foo_func)();
58 printf("Foo called, exiting\n");
60 exit(0);
62 } else {
63 // In the parent.
65 // Load at fixed address to simplify testing.
66 crazy_context_set_load_address(context, PARENT_ADDRESS);
67 foo.Init("libfoo_with_relro.so", context);
69 printf("Library loaded\n");
71 printf("Parent enabling foo RELRO sharing\n");
73 foo.CreateSharedRelro(context, CHILD_ADDRESS);
74 foo.SendRelroInfo(pipes[1]);
76 printf("Relocated RELRO sent to child\n");
78 CheckRelroMaps(0);
80 printf("Parent waiting for child\n");
82 // Wait for child to complete.
83 int status;
84 waitpid(child, &status, 0);
86 if (WIFSIGNALED(status))
87 Panic("Child terminated by signal!!\n");
88 else if (WIFEXITED(status)) {
89 int child_status = WEXITSTATUS(status);
90 if (child_status != 0)
91 Panic("Child terminated with status=%d\n", child_status);
92 } else
93 Panic("Child exited for unknown reason!!\n");
96 crazy_context_destroy(context);
97 return 0;