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

Side by Side Diff: tests/pnacl_ld_experiments/hello1.c

Issue 10268028: Intial experiment for building dynamic images without glibc under pnacl (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /* Copyright 2012 The Native Client Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can
3 * be found in the LICENSE file.
4 */
5
6 /* This is highly experimental code to test shared/dynamic images
7 * with pnacl.
8 * Currently, only x86-32 is tested.
9 */
10
11 #include <unistd.h>
12 #include <stdlib.h>
13 #include <bits/nacl_syscalls.h>
14
15 /* ====================================================================== */
16 #define NACL_INSTR_BLOCK_SHIFT 5
17 #define NACL_PAGESHIFT 12
18 #define NACL_SYSCALL_START_ADDR (16 << NACL_PAGESHIFT)
19 #define NACL_SYSCALL_ADDR(syscall_number) \
20 (NACL_SYSCALL_START_ADDR + (syscall_number << NACL_INSTR_BLOCK_SHIFT))
21
22 #define NACL_SYSCALL(s) ((TYPE_nacl_ ## s) NACL_SYSCALL_ADDR(NACL_sys_ ## s))
23
24 /* ====================================================================== */
25 /* proto-types for nacl syscalls */
26
27 typedef int (*TYPE_nacl_write) (int desc, void const *buf, int count);
28 typedef void (*TYPE_nacl_null) (void);
29 typedef void (*TYPE_nacl_exit) (int status);
30
31 /* ====================================================================== */
32 /* proto-types for functions inside ld.so */
33 extern void _dl_get_tls_static_info(int *static_tls_size,
34 int *static_tls_align);
35 extern int __tls_get_addr();
36 /* ====================================================================== */
37 int mystrlen(const char* s) {
38 int count = 0;
39 while (*s++) ++count;
40 return count;
41 }
42
43
44 void myhextochar(int n, char buffer[9]) {
45 int i;
46 buffer[8] = 0;
47
48 for (i = 0; i < 8; ++i) {
49 int nibble = 0xf & (n >> (4 * (7 - i)));
50 if (nibble <= 9) {
51 buffer[i] = nibble + '0';
52 } else {
53 buffer[i] = nibble - 10 + 'A';
54 }
55 }
56 }
57
58 #define myprint(s) NACL_SYSCALL(write)(1, s, mystrlen(s))
59
60 __thread int tdata1 = 1;
61 __thread int tdata2 = 3;
62
63
64 ssize_t write(int l, const void* buf, size_t n) {
65 return NACL_SYSCALL(write)(l, buf, n);
66 }
67
68 void exit(int ret) {
69 NACL_SYSCALL(exit)(ret);
70 }
71
72 void __deregister_frame_info(const void *begin) {
73 myprint("__deregister_frame_info\n");
74 }
75
76 void __register_frame_info(void *begin, void *ob) {
77 myprint("__register_frame_info\n");
78 }
79
80
81 int main(int argc, char** argv, char** envp) {
82 myprint("hello world\n");
83 char buffer[9];
84
85 myhextochar(tdata1, buffer);
86 myprint(buffer);
87 myprint("\n");
88
89 myhextochar(tdata2, buffer);
90 myprint(buffer);
91 myprint("\n");
92
93 int static_tls_size;
94 int static_tls_align;
95
96 #if 0
97 /* will be enabled soon */
98 int x = (int) & __tls_get_addr;
99 myhextochar(x, buffer);
100 myprint(buffer);
101 myprint("\n");
102 _dl_get_tls_static_info (&static_tls_size, &static_tls_align);
103 #endif
104
105 return 0;
106 }
107
108 char message_init[] = "init\n";
109
110 int __libc_csu_init (int argc, char **argv, char **envp) {
111 write(1, message_init, sizeof(message_init));
112 return 0;
113 }
114
115 char message_fini[] = "fini\n";
116 void __libc_csu_fini (void) {
117 write(1, message_fini, sizeof(message_fini));
118 }
119
120 void __libc_start_main (int (*main) (int argc, char **argv, char **envp),
121 int argc, char **argv,
122 int (*init) (int argc, char **argv, char **envp),
123 void (*fini) (void),
124 void (*rtld_fini) (void),
125 void *stack_end) {
126
127 exit(main(0, 0, 0));
128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698