[haiku-commits] haiku: hrev52830 - headers/os/kernel src/system/libnetwork src/kits/network/libnetapi headers/private/system src/kits/app

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 1 Feb 2019 20:34:30 -0500 (EST)

hrev52830 adds 5 changesets to branch 'master'
old head: a396188f230b33cece34dd850251c05e842ec0ac
new head: 67ef9f72fc35c7a3b11b9013962ce65cbdaf68c5
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=67ef9f72fc35+%5Ea396188f230b

----------------------------------------------------------------------------

04b9fbfdfad0: headers/kernel: Clean up image.h.
  
   * Add missing whitespace.
   * Remove definition of the now-gone __haiku_init_before.
  
  No functional change intended.

475172337b21: headers/kernel: Move B_WAIT_TILL_LOADED to a syscall header.
  
  It is only used as an argument to _kern_load_image directly, not to
  any of the load_image functions in image.h, so it belongs in a syscall-
  specific header like other such constants.
  
  No functional change intended.

d545ad17ce0f: headers/kernel: Define B_CURRENT_IMAGE_SYMBOL via __func__.
  
  Previously, __haiku_init_before was a symbol that was included in
  each (shared) object, and so it could be used to determine what
  one we were in. Now, there are no such universal symbols that
  are declared private to only the object, so we have to use
  a different approach.
  
  __func__ is defined as a const char* at the very beginning of
  every function it's used in, set to a string of the function name
  only, i.e., the arguments and return type are left off. So while
  including that is perhaps not quite optimal, in practice this
  definition is used extremely rarely (it was introduced by Haiku,
  and it is used in only 2 applications at all that I could find --
  WebKit and Canna.)
  
  There really isn't any other way to get a pointer that we know
  for certain is within the current object besides this one
  without inserting one, but that really isn't merited just for this.
  (__builtin_return_address() has problematic semantics wrt. inlining,
  including linker-inlining.) So this will have to do.

c5e4e4ffb4a9: headers/kernel: Include declarations of initialization functions 
in image.h.
  
  No "real" functional change, but this causes GCC7 to throw errors when
  these functions are declared without the image_id argument, which
  in some files they were (as this commit repairs.)
  
  This change is largely inconsequential on x86, but on callee-cleanup-args
  targets, leaving out the argument would probably cause stack corruption.

67ef9f72fc35: network: Utilize image_id argument to initialize_before.
  
  We don't need to search for our own image_id, we already have it now,
  so just use it.

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

11 files changed, 63 insertions(+), 55 deletions(-)
headers/os/kernel/image.h                   | 44 ++++++++++++-------------
headers/private/system/syscall_load_image.h | 19 +++++++++++
src/bin/debug/debug_utils.cpp               |  1 +
src/kits/app/InitTerminateLibBe.cpp         |  6 ++--
src/kits/debug/TeamDebugger.cpp             |  1 +
src/kits/network/libnetapi/init.cpp         | 20 ++++-------
src/kits/tracker/FSUtils.cpp                |  1 +
src/system/kernel/team.cpp                  |  1 +
src/system/libnetwork/init.cpp              | 21 ++++--------
src/system/libroot/libroot_init.c           |  3 --
src/system/libroot/os/image.cpp             |  1 +

############################################################################

Commit:      04b9fbfdfad0a4f22d60ac9fe27f1a683eb5693d
URL:         https://git.haiku-os.org/haiku/commit/?id=04b9fbfdfad0
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Sat Feb  2 00:19:38 2019 UTC

headers/kernel: Clean up image.h.

 * Add missing whitespace.
 * Remove definition of the now-gone __haiku_init_before.

No functional change intended.

----------------------------------------------------------------------------

diff --git a/headers/os/kernel/image.h b/headers/os/kernel/image.h
index 76c748a4df..3bef07cba9 100644
--- a/headers/os/kernel/image.h
+++ b/headers/os/kernel/image.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007-2009, Haiku, Inc. All Rights Reserved.
+ * Copyright 2007-2019, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT license.
  */
 #ifndef _IMAGE_H
@@ -39,29 +39,34 @@ typedef struct {
        int32           abi;                    /* the Haiku ABI used by the 
image */
 } image_info;
 
+
 /* flags for clear_caches() */
 #define B_FLUSH_DCACHE                         0x0001  /* data cache */
 #define B_FLUSH_ICACHE                         0x0004  /* instruction cache */
 #define B_INVALIDATE_DCACHE                    0x0002
 #define B_INVALIDATE_ICACHE                    0x0008
 
+
 /* symbol types */
-#define        B_SYMBOL_TYPE_DATA                      0x1
-#define        B_SYMBOL_TYPE_TEXT                      0x2
+#define B_SYMBOL_TYPE_DATA                     0x1
+#define B_SYMBOL_TYPE_TEXT                     0x2
 #define B_SYMBOL_TYPE_ANY                      0x5
 
+
 /* initialization/termination functions of shared objects */
-#define        B_INIT_BEFORE_FUNCTION_NAME     "initialize_before"
+#define B_INIT_BEFORE_FUNCTION_NAME    "initialize_before"
 #define B_INIT_AFTER_FUNCTION_NAME     "initialize_after"
-#define        B_TERM_BEFORE_FUNCTION_NAME     "terminate_before"
+#define B_TERM_BEFORE_FUNCTION_NAME    "terminate_before"
 #define B_TERM_AFTER_FUNCTION_NAME     "terminate_after"
 
+
 #define B_APP_IMAGE_SYMBOL             ((void*)(addr_t)0)
        /* value that can be used instead of a pointer to a symbol in the 
program
           image. */
 #define B_CURRENT_IMAGE_SYMBOL ((void*)&__haiku_init_before)
        /* pointer to a symbol in the callers image */
 
+
 /* flags for _kern_load_image() (private API) */
 enum {
        B_WAIT_TILL_LOADED      = 0x01,
@@ -72,10 +77,12 @@ enum {
                   doesn't exist. */
 };
 
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+
 thread_id load_image(int32 argc, const char **argv, const char **environ);
 image_id load_add_on(const char *path);
 status_t unload_add_on(image_id image);
@@ -95,11 +102,10 @@ status_t _get_image_info(image_id image, image_info *info, 
size_t size);
 status_t _get_next_image_info(team_id team, int32 *cookie, image_info *info,
                                size_t size);
 
-/* private */
-void __haiku_init_before(image_id id);
 
 #ifdef __cplusplus
 }
 #endif
 
+
 #endif /* _IMAGE_H */

############################################################################

Commit:      475172337b217fc506feeec8d9fd8258c2d7c97c
URL:         https://git.haiku-os.org/haiku/commit/?id=475172337b21
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Sat Feb  2 00:45:56 2019 UTC

headers/kernel: Move B_WAIT_TILL_LOADED to a syscall header.

It is only used as an argument to _kern_load_image directly, not to
any of the load_image functions in image.h, so it belongs in a syscall-
specific header like other such constants.

No functional change intended.

----------------------------------------------------------------------------

diff --git a/headers/os/kernel/image.h b/headers/os/kernel/image.h
index 3bef07cba9..8a712c8a74 100644
--- a/headers/os/kernel/image.h
+++ b/headers/os/kernel/image.h
@@ -1,6 +1,6 @@
 /*
- * Copyright 2007-2019, Haiku, Inc. All Rights Reserved.
- * Distributed under the terms of the MIT license.
+ * Copyright 2007-2019, Haiku, Inc. All rights reserved.
+ * Distributed under the terms of the MIT License.
  */
 #ifndef _IMAGE_H
 #define        _IMAGE_H
@@ -67,17 +67,6 @@ typedef struct {
        /* pointer to a symbol in the callers image */
 
 
-/* flags for _kern_load_image() (private API) */
-enum {
-       B_WAIT_TILL_LOADED      = 0x01,
-               /* Wait till the loader has loaded and relocated (but not yet
-                  initialized) the application image and all dependencies. If 
not
-                  supplied, the function returns before the loader started to 
do
-                  anything at all, i.e. it returns success, even if the 
executable
-                  doesn't exist. */
-};
-
-
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/headers/private/system/syscall_load_image.h 
b/headers/private/system/syscall_load_image.h
new file mode 100644
index 0000000000..b9c862a6c7
--- /dev/null
+++ b/headers/private/system/syscall_load_image.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2019, Haiku, Inc. All rights reserved.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef _SYSTEM_SYSCALL_LOAD_IMAGE_H
+#define _SYSTEM_SYSCALL_LOAD_IMAGE_H
+
+
+enum {
+       B_WAIT_TILL_LOADED      = 0x01,
+               /* Wait till the loader has loaded and relocated (but not yet
+                  initialized) the application image and all dependencies. If 
not
+                  supplied, the function returns before the loader started to 
do
+                  anything at all, i.e. it returns success, even if the 
executable
+                  doesn't exist. */
+};
+
+
+#endif /* _SYSTEM_SYSCALL_LOAD_IMAGE_H */
diff --git a/src/bin/debug/debug_utils.cpp b/src/bin/debug/debug_utils.cpp
index 4bfc361297..a40da76ebc 100644
--- a/src/bin/debug/debug_utils.cpp
+++ b/src/bin/debug/debug_utils.cpp
@@ -17,6 +17,7 @@
 
 #include <libroot_private.h>
 #include <syscalls.h>
+#include <syscall_load_image.h>
 
 
 extern const char* __progname;
diff --git a/src/kits/debug/TeamDebugger.cpp b/src/kits/debug/TeamDebugger.cpp
index eb0abe65e9..0933412f0c 100644
--- a/src/kits/debug/TeamDebugger.cpp
+++ b/src/kits/debug/TeamDebugger.cpp
@@ -17,6 +17,7 @@
 
 #include <libroot_private.h>
 #include <syscalls.h>
+#include <syscall_load_image.h>
 
 
 BTeamDebugger::BTeamDebugger()
diff --git a/src/kits/tracker/FSUtils.cpp b/src/kits/tracker/FSUtils.cpp
index b2bd4c6933..19dbe280d9 100644
--- a/src/kits/tracker/FSUtils.cpp
+++ b/src/kits/tracker/FSUtils.cpp
@@ -75,6 +75,7 @@ respective holders. All rights reserved.
 #include <AutoLocker.h>
 #include <libroot/libroot_private.h>
 #include <system/syscalls.h>
+#include <system/syscall_load_image.h>
 
 #include "Attributes.h"
 #include "Bitmaps.h"
diff --git a/src/system/kernel/team.cpp b/src/system/kernel/team.cpp
index ae60bd016f..3a1f918403 100644
--- a/src/system/kernel/team.cpp
+++ b/src/system/kernel/team.cpp
@@ -45,6 +45,7 @@
 #include <posix/xsi_semaphore.h>
 #include <sem.h>
 #include <syscall_process_info.h>
+#include <syscall_load_image.h>
 #include <syscall_restart.h>
 #include <syscalls.h>
 #include <tls.h>
diff --git a/src/system/libroot/os/image.cpp b/src/system/libroot/os/image.cpp
index b59a6d4117..8edba44348 100644
--- a/src/system/libroot/os/image.cpp
+++ b/src/system/libroot/os/image.cpp
@@ -19,6 +19,7 @@
 #include <libroot_private.h>
 #include <runtime_loader.h>
 #include <syscalls.h>
+#include <syscall_load_image.h>
 #include <user_runtime.h>
 
 

############################################################################

Commit:      d545ad17ce0f7368391fd8798ba58a9e2ad8e55b
URL:         https://git.haiku-os.org/haiku/commit/?id=d545ad17ce0f
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Sat Feb  2 00:50:29 2019 UTC

headers/kernel: Define B_CURRENT_IMAGE_SYMBOL via __func__.

Previously, __haiku_init_before was a symbol that was included in
each (shared) object, and so it could be used to determine what
one we were in. Now, there are no such universal symbols that
are declared private to only the object, so we have to use
a different approach.

__func__ is defined as a const char* at the very beginning of
every function it's used in, set to a string of the function name
only, i.e., the arguments and return type are left off. So while
including that is perhaps not quite optimal, in practice this
definition is used extremely rarely (it was introduced by Haiku,
and it is used in only 2 applications at all that I could find --
WebKit and Canna.)

There really isn't any other way to get a pointer that we know
for certain is within the current object besides this one
without inserting one, but that really isn't merited just for this.
(__builtin_return_address() has problematic semantics wrt. inlining,
including linker-inlining.) So this will have to do.

----------------------------------------------------------------------------

diff --git a/headers/os/kernel/image.h b/headers/os/kernel/image.h
index 8a712c8a74..e20b49a1dc 100644
--- a/headers/os/kernel/image.h
+++ b/headers/os/kernel/image.h
@@ -40,6 +40,11 @@ typedef struct {
 } image_info;
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
 /* flags for clear_caches() */
 #define B_FLUSH_DCACHE                         0x0001  /* data cache */
 #define B_FLUSH_ICACHE                         0x0004  /* instruction cache */
@@ -63,15 +68,10 @@ typedef struct {
 #define B_APP_IMAGE_SYMBOL             ((void*)(addr_t)0)
        /* value that can be used instead of a pointer to a symbol in the 
program
           image. */
-#define B_CURRENT_IMAGE_SYMBOL ((void*)&__haiku_init_before)
+#define B_CURRENT_IMAGE_SYMBOL ((void*)&__func__)
        /* pointer to a symbol in the callers image */
 
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
 thread_id load_image(int32 argc, const char **argv, const char **environ);
 image_id load_add_on(const char *path);
 status_t unload_add_on(image_id image);

############################################################################

Commit:      c5e4e4ffb4a974bd0c1803701f51f73409d85433
URL:         https://git.haiku-os.org/haiku/commit/?id=c5e4e4ffb4a9
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Sat Feb  2 01:30:39 2019 UTC

headers/kernel: Include declarations of initialization functions in image.h.

No "real" functional change, but this causes GCC7 to throw errors when
these functions are declared without the image_id argument, which
in some files they were (as this commit repairs.)

This change is largely inconsequential on x86, but on callee-cleanup-args
targets, leaving out the argument would probably cause stack corruption.

----------------------------------------------------------------------------

diff --git a/headers/os/kernel/image.h b/headers/os/kernel/image.h
index e20b49a1dc..69a29b4899 100644
--- a/headers/os/kernel/image.h
+++ b/headers/os/kernel/image.h
@@ -64,6 +64,11 @@ extern "C" {
 #define B_TERM_BEFORE_FUNCTION_NAME    "terminate_before"
 #define B_TERM_AFTER_FUNCTION_NAME     "terminate_after"
 
+void initialize_before(image_id);
+void initialize_after(image_id);
+void terminate_before(image_id);
+void terminate_after(image_id);
+
 
 #define B_APP_IMAGE_SYMBOL             ((void*)(addr_t)0)
        /* value that can be used instead of a pointer to a symbol in the 
program
diff --git a/src/kits/app/InitTerminateLibBe.cpp 
b/src/kits/app/InitTerminateLibBe.cpp
index 03f4a02e42..3b77adb2e2 100644
--- a/src/kits/app/InitTerminateLibBe.cpp
+++ b/src/kits/app/InitTerminateLibBe.cpp
@@ -43,7 +43,7 @@ initialize_forked_child()
 
 
 extern "C" void
-initialize_before()
+initialize_before(image_id)
 {
        DBG(OUT("initialize_before()\n"));
 
@@ -57,7 +57,7 @@ initialize_before()
 
 
 extern "C" void
-initialize_after()
+initialize_after(image_id)
 {
        DBG(OUT("initialize_after()\n"));
 
@@ -68,7 +68,7 @@ initialize_after()
 
 
 extern "C" void
-terminate_after()
+terminate_after(image_id)
 {
        DBG(OUT("terminate_after()\n"));
 
diff --git a/src/kits/network/libnetapi/init.cpp 
b/src/kits/network/libnetapi/init.cpp
index c311573fdd..cbe1fe0366 100644
--- a/src/kits/network/libnetapi/init.cpp
+++ b/src/kits/network/libnetapi/init.cpp
@@ -33,7 +33,7 @@ find_own_image()
 
 
 extern "C" void
-initialize_before()
+initialize_before(image_id)
 {
        // If in compatibility mode get our code address range.
        if (__gR5Compatibility)
diff --git a/src/system/libnetwork/init.cpp b/src/system/libnetwork/init.cpp
index 983c2dc3f1..357f756235 100644
--- a/src/system/libnetwork/init.cpp
+++ b/src/system/libnetwork/init.cpp
@@ -43,7 +43,7 @@ find_own_image()
 
 
 extern "C" void
-initialize_before()
+initialize_before(image_id)
 {
        // determine if we have to run in BeOS compatibility mode
 
diff --git a/src/system/libroot/libroot_init.c 
b/src/system/libroot/libroot_init.c
index 893833eea7..6da22d4bbd 100644
--- a/src/system/libroot/libroot_init.c
+++ b/src/system/libroot/libroot_init.c
@@ -19,9 +19,6 @@
 #include <pthread_private.h>
 
 
-void initialize_before(image_id imageID);
-void terminate_after(image_id imageID);
-
 struct rld_export *__gRuntimeLoader = NULL;
        // This little bugger is set to something meaningful by the runtime 
loader
        // Ugly, eh?

############################################################################

Revision:    hrev52830
Commit:      67ef9f72fc35c7a3b11b9013962ce65cbdaf68c5
URL:         https://git.haiku-os.org/haiku/commit/?id=67ef9f72fc35
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Sat Feb  2 01:33:10 2019 UTC

network: Utilize image_id argument to initialize_before.

We don't need to search for our own image_id, we already have it now,
so just use it.

----------------------------------------------------------------------------

diff --git a/src/kits/network/libnetapi/init.cpp 
b/src/kits/network/libnetapi/init.cpp
index cbe1fe0366..a554f90b0a 100644
--- a/src/kits/network/libnetapi/init.cpp
+++ b/src/kits/network/libnetapi/init.cpp
@@ -15,27 +15,21 @@
 
 
 static void
-find_own_image()
+find_own_image(image_id id)
 {
-       int32 cookie = 0;
        image_info info;
-       while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
-               if (((addr_t)info.text <= (addr_t)find_own_image
-                       && (addr_t)info.text + (size_t)info.text_size > 
(addr_t)find_own_image)) {
-                       // found us
-                       __gNetAPIStart = (addr_t)min_c(info.text, info.data);
-                       __gNetAPIEnd = min_c((addr_t)info.text + info.text_size,
-                               (addr_t)info.data + info.data_size);
-                       break;
-               }
+       if (get_image_info(id, &info) == B_OK) {
+               __gNetAPIStart = (addr_t)min_c(info.text, info.data);
+               __gNetAPIEnd = min_c((addr_t)info.text + info.text_size,
+                       (addr_t)info.data + info.data_size);
        }
 }
 
 
 extern "C" void
-initialize_before(image_id)
+initialize_before(image_id id)
 {
        // If in compatibility mode get our code address range.
        if (__gR5Compatibility)
-               find_own_image();
+               find_own_image(id);
 }
diff --git a/src/system/libnetwork/init.cpp b/src/system/libnetwork/init.cpp
index 357f756235..983208ca82 100644
--- a/src/system/libnetwork/init.cpp
+++ b/src/system/libnetwork/init.cpp
@@ -24,26 +24,19 @@ addr_t __gNetAPIEnd;
 
 
 static void
-find_own_image()
+find_own_image(image_id id)
 {
-       int32 cookie = 0;
        image_info info;
-       while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
-               if (((addr_t)info.text <= (addr_t)find_own_image
-                       && (addr_t)info.text + (addr_t)info.text_size
-                               > (addr_t)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;
-               }
+       if (get_image_info(id, &info) == B_OK) {
+               __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);
        }
 }
 
 
 extern "C" void
-initialize_before(image_id)
+initialize_before(image_id our_image)
 {
        // determine if we have to run in BeOS compatibility mode
 
@@ -81,7 +74,7 @@ initialize_before(image_id)
 
                if (enable > 0) {
                        __gR5Compatibility = true;
-                       find_own_image();
+                       find_own_image(our_image);
                        debug_printf("libnetwork.so running in R5 compatibility 
mode.\n");
                        return;
                }


Other related posts: