LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // cgo glue for initializing the Go runtime in shared library mode | 5 // cgo glue for initializing the Go runtime in shared library mode |
6 | 6 |
7 #include <pthread.h> | 7 #include <pthread.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 #include <string.h> // strerror | 10 #include <string.h> // strerror |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 x_cgo_lib_init_once(void) | 63 x_cgo_lib_init_once(void) |
64 { | 64 { |
65 pthread_attr_t attr; | 65 pthread_attr_t attr; |
66 pthread_t p; | 66 pthread_t p; |
67 int err; | 67 int err; |
68 long ps; | 68 long ps; |
69 void *map; | 69 void *map; |
70 void *guard_addr; | 70 void *guard_addr; |
71 | 71 |
72 ps = sysconf(_SC_PAGESIZE); | 72 ps = sysconf(_SC_PAGESIZE); |
73 » if (ps == -1) { | 73 » if(ps == -1) { |
74 fprintf(stderr, "runtime/cgo: failed to query page size\n"); | 74 fprintf(stderr, "runtime/cgo: failed to query page size\n"); |
75 abort(); | 75 abort(); |
76 } | 76 } |
77 if(sizeof(void *) > 4) | 77 if(sizeof(void *) > 4) |
78 guard_addr = (void*)(0x00d0ULL<<32); | 78 guard_addr = (void*)(0x00d0ULL<<32); |
79 else | 79 else |
80 guard_addr = (void*)(0xa0000000); | 80 guard_addr = (void*)(0xa0000000); |
81 map = mmap(guard_addr, ps, PROT_READ, MAP_ANON|MAP_PRIVATE, -1, 0); | 81 map = mmap(guard_addr, ps, PROT_READ, MAP_ANON|MAP_PRIVATE, -1, 0); |
82 » if (map == MAP_FAILED || map != guard_addr) { | 82 » if(map == MAP_FAILED || map != guard_addr) { |
83 fprintf(stderr, "runtime/cgo: failed to map guard page (%p) (mul
tiple go shared libraries in the same process is not supported)\n", guard_addr); | 83 fprintf(stderr, "runtime/cgo: failed to map guard page (%p) (mul
tiple go shared libraries in the same process is not supported)\n", guard_addr); |
84 abort(); | 84 abort(); |
85 } | 85 } |
86 | 86 |
87 pthread_attr_init(&attr); | 87 pthread_attr_init(&attr); |
88 err = pthread_create(&p, &attr, lib_init_entry, runtime_main); | 88 err = pthread_create(&p, &attr, lib_init_entry, runtime_main); |
89 if(err != 0) { | 89 if(err != 0) { |
90 fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", stre
rror(err)); | 90 fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", stre
rror(err)); |
91 abort(); | 91 abort(); |
92 } | 92 } |
(...skipping 22 matching lines...) Expand all Loading... |
115 { | 115 { |
116 runtime_main = main_func; | 116 runtime_main = main_func; |
117 } | 117 } |
118 | 118 |
119 void | 119 void |
120 x_cgo_lib_init(void) | 120 x_cgo_lib_init(void) |
121 { | 121 { |
122 int err; | 122 int err; |
123 | 123 |
124 err = pthread_once(&init_once, x_cgo_lib_init_once); | 124 err = pthread_once(&init_once, x_cgo_lib_init_once); |
125 » if (err != 0) { | 125 » if(err != 0) { |
126 fprintf(stderr, "runtime/cgo: pthread_once failed: %s\n", strerr
or(err)); | 126 fprintf(stderr, "runtime/cgo: pthread_once failed: %s\n", strerr
or(err)); |
127 abort(); | 127 abort(); |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
LEFT | RIGHT |