tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / kits / network / init.cpp
blob983c2dc3f18413d92b5c096353f9e3083435390f
1 /*
2 * Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Axel Dörfler, axeld@pinc-software.de
7 * Oliver Tappe, zooey@hirschkaefer.de
8 */
11 #include <libroot_private.h>
13 #include <OS.h>
14 #include <image.h>
16 #include <string.h>
19 bool __gR5Compatibility = false;
20 addr_t __gNetworkStart;
21 addr_t __gNetworkEnd;
22 addr_t __gNetAPIStart;
23 addr_t __gNetAPIEnd;
26 static void
27 find_own_image()
29 int32 cookie = 0;
30 image_info info;
31 while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
32 if (((addr_t)info.text <= (addr_t)find_own_image
33 && (addr_t)info.text + (addr_t)info.text_size
34 > (addr_t)find_own_image)) {
35 // found us
36 __gNetworkStart = (addr_t)min_c(info.text, info.data);
37 __gNetworkEnd = min_c((addr_t)info.text + info.text_size,
38 (addr_t)info.data + info.data_size);
39 break;
45 extern "C" void
46 initialize_before()
48 // determine if we have to run in BeOS compatibility mode
50 // get image of executable
51 image_info info;
52 uint32 cookie = 0;
53 if (get_next_image_info(B_CURRENT_TEAM, (int32*)&cookie, &info) != B_OK)
54 return;
56 if (get_image_symbol(info.id, "__gHaikuStartupCode", B_SYMBOL_TYPE_DATA,
57 NULL) == B_OK) {
58 // we were linked on/for Haiku
59 return;
62 // We're using the BeOS startup code, check if BONE libraries are in
63 // use, and if not, enable the BeOS R5 compatibility layer.
64 // As dependencies to network libraries may be "hidden" in libraries, we
65 // may have to scan not only the executable, but every loaded image.
66 int enable = 0;
67 uint32 crumble;
68 const char *name;
69 do {
70 crumble = 0;
71 while (__get_next_image_dependency(info.id, &crumble, &name) == B_OK) {
72 if (!strcmp(name, "libbind.so")
73 || !strcmp(name, "libsocket.so")
74 || !strcmp(name, "libbnetapi.so")
75 || !strcmp(name, "libnetwork.so"))
76 enable -= 2;
77 else if (!strcmp(name, "libnet.so")
78 || !strcmp(name, "libnetapi.so"))
79 enable++;
82 if (enable > 0) {
83 __gR5Compatibility = true;
84 find_own_image();
85 debug_printf("libnetwork.so running in R5 compatibility mode.\n");
86 return;
88 } while (enable == 0
89 && get_next_image_info(B_CURRENT_TEAM, (int32*)&cookie, &info) == B_OK);