From af2da315dc9a699849a86a5c6f3b2ddb79632e83 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Tue, 10 May 2011 15:35:04 +0000 Subject: [PATCH] Fix the larger problem that was hiding behind the build problem of set_haiku_revsion on FreeBSD: * the length of the sHaikuRevision character array symbol needs to be set explicitly, as using either _SYS_NAMELEN or sizeof(utsname::version) will only return the values for the host, which may not match ours, thus potentially causing problems when using sHaikuRevision * add headers/private/system_revision.h which defines SYSTEM_REVISION_LENGTH to 128 * adjust definitions of sHaikuRevision in libroot and kernel accordingly utsname::version is shorter than SYSTEM_REVISION_LENGTH, but that doesn't cause any harm until we have indeed switched to a DVCS (in which case longer revision strings will be cut off by 'uname'). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41421 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/system/system_revision.h | 14 ++++++++++++++ src/system/kernel/system_info.cpp | 4 ++-- src/system/libroot/posix/sys/uname.c | 4 +++- src/tools/Jamfile | 1 + src/tools/set_haiku_revision.cpp | 5 +++-- 5 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 headers/private/system/system_revision.h diff --git a/headers/private/system/system_revision.h b/headers/private/system/system_revision.h new file mode 100644 index 0000000000..c1c612b26b --- /dev/null +++ b/headers/private/system/system_revision.h @@ -0,0 +1,14 @@ +/* + * Copyright 2011, Oliver Tappe . + * Distributed under the terms of the MIT License. + */ +#ifndef _SYSTEM_SYSTEM_REVISION_H +#define _SYSTEM_SYSTEM_REVISION_H + + +/** The length of the system revision character array symbol living in libroot + and the kernel */ +#define SYSTEM_REVISION_LENGTH 128 + + +#endif /* _SYSTEM_SYSTEM_REVISION_H */ diff --git a/src/system/kernel/system_info.cpp b/src/system/kernel/system_info.cpp index e35ba006e7..3823355ffc 100644 --- a/src/system/kernel/system_info.cpp +++ b/src/system/kernel/system_info.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -31,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -45,7 +45,7 @@ const static char *kKernelName = "kernel_" HAIKU_ARCH; // Haiku SVN revision. Will be set when copying the kernel to the image. // Lives in a separate section so that it can easily be found. -static char sHaikuRevision[_SYS_NAMELEN] +static char sHaikuRevision[SYSTEM_REVISION_LENGTH] __attribute__((section("_haiku_revision"))); diff --git a/src/system/libroot/posix/sys/uname.c b/src/system/libroot/posix/sys/uname.c index c4e1d08f93..cc81e61dd2 100644 --- a/src/system/libroot/posix/sys/uname.c +++ b/src/system/libroot/posix/sys/uname.c @@ -13,10 +13,12 @@ #include +#include + // Haiku SVN revision. Will be set when copying libroot.so to the image. // Lives in a separate section so that it can easily be found. -static char sHaikuRevision[_SYS_NAMELEN] +static char sHaikuRevision[SYSTEM_REVISION_LENGTH] __attribute__((section("_haiku_revision"))); diff --git a/src/tools/Jamfile b/src/tools/Jamfile index 376563e117..afbff6d33d 100644 --- a/src/tools/Jamfile +++ b/src/tools/Jamfile @@ -96,6 +96,7 @@ MODE on rm_attrs = 755 ; BuildPlatformMain rmattr : rmattr.cpp : $(HOST_LIBBE) ; +UsePrivateObjectHeaders set_haiku_revision : system : : true ; BuildPlatformMain set_haiku_revision : set_haiku_revision.cpp : $(HOST_LIBSTDC++) $(HOST_LIBSUPC++) ; diff --git a/src/tools/set_haiku_revision.cpp b/src/tools/set_haiku_revision.cpp index 44f9f7f964..5022398448 100644 --- a/src/tools/set_haiku_revision.cpp +++ b/src/tools/set_haiku_revision.cpp @@ -10,12 +10,13 @@ #include #include #include -#include #include #include #include +#include + // We use htonl(), which is defined in on BeOS R5. #ifdef HAIKU_HOST_PLATFORM_BEOS #include @@ -585,7 +586,7 @@ main(int argc, const char* const* argv) // write revision string to section elfObject.Write(info.offset, revisionString, - std::min(sizeof(utsname::version), strlen(revisionString) + 1), + min((size_t)SYSTEM_REVISION_LENGTH, strlen(revisionString) + 1), "Failed to write revision."); } catch (Exception exception) {