Files
haiku-beta6/src/kits/network/init.cpp
T
Axel Dörfler bcb0dd2b3b The R5 compatibility is now turned off when the socket functions are used
within the library - theoretically, this mechanism could be extended to
turn the compatibility layer on and off based on the images that call the
functions (allowing to mix R5 and BONE network add-ons in a single executable).
This change fixes R5 networking apps such as Vision, and NetworkTime (both
now seem to work fine under Haiku).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19431 a95241bf-73f2-0310-859d-f6bbb57e9c96
2006-12-05 03:03:15 +00:00

82 lines
1.8 KiB
C++

/*
* Copyright 2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler, [email protected]
*/
#include <libroot_private.h>
#include <OS.h>
#include <image.h>
#include <string.h>
bool __gR5Compatibility = false;
addr_t __gNetworkStart;
addr_t __gNetworkEnd;
static void
find_own_image()
{
int32 cookie = 0;
image_info info;
while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
if (((uint32)info.text <= (uint32)find_own_image
&& (uint32)info.text + (uint32)info.text_size > (uint32)find_own_image)) {
// found us
__gNetworkStart = (addr_t)min_c(info.text, info.data);
__gNetworkEnd = min_c((addr_t)info.text + info.text_size,
(addr_t)info.data + info.data_size);
break;
}
}
}
extern "C" void
initialize_before()
{
// determine if we have to run in R5 compatibility mode
// get image of executable
image_info info;
uint32 cookie = 0;
if (get_next_image_info(B_CURRENT_TEAM, (int32 *)&cookie, &info) != B_OK)
return;
if (get_image_symbol(info.id, "__gHaikuStartupCode", B_SYMBOL_TYPE_DATA,
NULL) == B_OK) {
// we were linked on/for Haiku
return;
}
// We're using the BeOS startup code, check if BONE libraries are in
// use, and if not, enable the R5 compatibility layer.
const char *name;
cookie = 0;
int enable = 0;
while (__get_next_image_dependency(info.id, &cookie, &name) == B_OK) {
if (!strcmp(name, "libbind.so")
|| !strcmp(name, "libsocket.so")
|| !strcmp(name, "libbnetapi.so")
|| !strcmp(name, "libnetwork.so"))
enable -= 2;
else if (!strcmp(name, "libnet.so")
|| !strcmp(name, "libnetapi.so"))
enable++;
}
if (enable > 0) {
__gR5Compatibility = true;
find_own_image();
debug_printf("libnetwork.so running in R5 compatibility mode.\n");
}
}