Commit Graph

102 Commits

Author SHA1 Message Date
David McPaul
2ecebae14f ignore Stack type in elf loader
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30099 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-04-10 03:28:00 +00:00
Axel Dörfler
317bd7dda3 * Changed directory structure as suggested on the mailing list.
* Made the TimeZoneView less error prone, and also actually use Haiku code (the
  previous check didn't work since it used #if, not #ifdef).
* Also took the liberty to rename our boot loader to haiku_loader, since I had
  to update the nasm binary anyway. Updated the assembly sources to nasm 2.0.
* I haven't found where the synth location in the MIDI code is specified,
  though.
* Also, NetBootArchive, and FloppyBootImage haven't been updated yet. Will do
  so next.
* Some optional packages still put their license to beos/etc/licenses. I didn't
  update them yet, as we'll probably do so anyway at some point. Also, I think
  we might want to introduce a common/data/licenses instead for those.
* If you encounter any problems, please tell!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29876 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-04-03 09:02:44 +00:00
Ingo Weinhold
a2dad9e1a9 get_library_symbol(): Simplified the RTLD_NEXT case. The caller is not bound
to search for a function with the same name as the calling function, so we
really don't need to find the calling function; the calling image suffices.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29645 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-03-22 01:39:34 +00:00
Michael Lotz
e94d1badf5 Add the name of the missing symbol to the error message that is sent via port.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29515 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-03-14 14:14:21 +00:00
Ingo Weinhold
80ece78534 Added private get_image_symbol_etc() that can recursively search for a symbol
(similar to how dlsym() works).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29356 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-02-28 18:50:40 +00:00
Ingo Weinhold
47bc666311 The assumption that the program image is not used for relocation of
dlopen()ed objects was incorrect. This should fix problems with ports of
software with a plugin/add-on interface.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29112 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-02-01 18:40:42 +00:00
Ingo Weinhold
df30098d91 unload_library() invoked from dlclose() might not have deleted images
correctly and it returned an error on success.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28578 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-11-09 18:18:51 +00:00
Ingo Weinhold
0c85bd054e * Reworked undefined symbol resolution in the runtime loader. Got rid of
the per-root-image breadth-first sorted image array. Instead we have a
  per-image hook function to resolve the symbols. The default function
  uses the sLoadedImages list directly, which is breadth-first sorted
  anyway. There's also a BeOS function for old-style symbol resolution
  and one for add-ons, which lacks a proper implementation yet (just
  uses old-style ATM).
* Made the dl*() functions POSIX compliant:
  - dlopen() does no longer use load_add_on(), but loads the object as a
    library. It also properly supports a NULL name, now -- the previous
    "_APP_" work-around did only work, if this soname was set on the
    program (unlikely for programs using this API).
  - Implemented RTLD_{GLOBAL,LOCAL}.
  - dlsym() looks up symbols properly now, i.e. not just in the given
    image, but breadth-first for an actual image or in load order for
    the global scope. It also supports the not-quite POSIX RTLD_DEFAULT
    and RTLD_NEXT extensions. Our RTLD_NEXT finds more symbols than in
    Linux (also in later dlopen()ed libraries), but that should be fine.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28568 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-11-08 22:40:56 +00:00
Ingo Weinhold
10b4b5d175 * Added an "add-on" interface for the runtime loader. Pre-loaded images
can export a structure containing callback hooks invoked by the
  runtime loader when certain image events occur (image loaded,
  relocated, initialized, etc.).
* Also added a mechanism to patch image symbols. For an image callback
  functions can be installed that patch symbols exported or imported by
  the image.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28475 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-11-03 13:27:14 +00:00
Ingo Weinhold
ca618b2259 * Changed the way symbols are resolved. For each root image (program,
add-on) we create a breadth-first sorted image list and use that to
  search for symbols.
* Added support for preloading libraries. The environment variable
  LD_PRELOAD can contain a whitespace-separated list of shared objects
  that will be loaded before the program. This allows to replace
  symbols without changing the executable or libraries.
* Resolved TODO in load_program() regarding the order of remapping the
  images and initializing the dependencies (problem fixed in r28453).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28455 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-11-02 03:16:30 +00:00
Ingo Weinhold
f68fa9d364 Implemented realloc().
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28454 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-11-02 02:59:15 +00:00
Axel Dörfler
0982317bea * Workaround for bug #2273 - not pretty but works for now.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28310 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-10-24 10:15:39 +00:00
Ingo Weinhold
02e577f99a When going to load a library also check whether the last path component
matches the program's image name. This is a special case for add-ons
that link against the application, with the application not having a
soname set. The concerned Pe add-ons (HeaderHeader and others) work now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28294 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-10-23 12:11:24 +00:00
Ingo Weinhold
b2568a30b1 Patch by romain: Fixed FD leak after opening an image that has already
been loaded.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28246 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-10-20 11:42:14 +00:00
Ingo Weinhold
c73aeac11e We need to let the runtime loader call shared object termination hooks
from exit().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27991 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-10-12 12:26:27 +00:00
François Revol
85f9771aec Avoid crashing if gccPlatform is NULL, thanks Axel!
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27968 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-10-11 08:41:54 +00:00
Axel Dörfler
2716cfd3d7 * Threw away the broken stat() vs. _stat() mechanism to allow for more fields
in struct stat.
* Instead, I followed Marcus' great idea and added a compatibility check in
  the runtime loader: now, R5 binaries (also shared libraries) are detected,
  and they get special versions for stat(), fstat(), and lstat() that return
  the smaller stat struct.
* However, I've disabled (in src/system/libroot/posix/sys/stat.c) using the
  larger stat field for now, as this breaks some of our optional packages.
  So until we rebuild them all, this shouldn't be enabled.
* This should now also be used for BeOS compatibility in libnetwork.so.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27961 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-10-10 22:13:05 +00:00
Ingo Weinhold
b18c9b97ae * Implemented x86 assembly version of memset().
* memset() is now available through the commpage.
* CPU modules can provide a model-optimized memset().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27952 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-10-10 18:43:46 +00:00
Ingo Weinhold
379ad6d037 * Moved the arch specific stuff in src/system/kernel/lib into arch/...
subdirectories. Also moved the x86 kernel arch_string.S there.
* Moved memcpy.c from src/system/libroot/posix/string into the
  arch/generic subdirectory.
* Dealt with the consequences of moving things around. Affected are also
  the boot loader and runtime loader builds.

Adjust the m68k and ppc parts, too, but only the x86 build is tested.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27947 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-10-09 23:47:01 +00:00
Axel Dörfler
0555803a41 Applied patch by Romain, thanks!:
* get_nth_symbol() did not correctly iterate over the symbol hash, causing it
  to return the same symbols more than once, and omit others.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27896 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-10-06 21:03:58 +00:00
Axel Dörfler
e73923b0c2 * Renamed static recursive lock variables to match our coding style guidelines.
* Renamed runtime loader semphore to something clearer.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27623 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-09-18 14:01:29 +00:00
Axel Dörfler
9a6072a35f * Resolved TODO added by Ingo: the runtime loader now lazily updates its
image IDs when needed.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27611 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-09-18 08:04:29 +00:00
Ingo Weinhold
cbc456de3b Added TODO regarding updating the image ID's after fork().
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27604 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-09-17 22:56:18 +00:00
Axel Dörfler
320bd2bd5a * More specific error message when relocating fails.
* Whitespace cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27031 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-08-18 11:03:50 +00:00
Axel Dörfler
b5753dd7c9 * Added a __swap_int32() function to the runtime_loader - this fixes the build,
since KMessage needs it now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26366 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-07-10 11:52:57 +00:00
Ingo Weinhold
2965c99fea * Changed the _kern_exec() and _kern_load_image() syscalls. They expect
a flattened argument/environment buffer now. This simplifies the work
  for the kernel a bit, since it can just copy the buffer and check
  whether it looks OK instead of messing around with individual strings.
  The runtime loader also gets a flattened array.
* Set the maximum size of the arguments/environment buffer to 128 KB.
  When more arguments are passed, we fail with a proper error code
  (instead of just truncating the arguments as before).
* On exec*() the first argument was silently replaced by the given path
  name, which is not correct.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26119 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-06-24 03:37:07 +00:00
François Revol
7e60c269dc m68k runtime loader code, not sure it works.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26103 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-06-23 15:31:51 +00:00
Ingo Weinhold
2a33a944e5 Don't spam to the standard output when not finding a symbol.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25784 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-06-03 15:05:16 +00:00
Ingo Weinhold
61b37794a4 Added explicit support for loading executables compiled with the
respectively other gcc version on a Haiku compiled with gcc 2 or gcc 4.
The libraries for such an executable are first searched in "gcc4"
respectively "gcc2" subdirectories of the standard search path
directories. If not found there, we try again with the standard paths.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25532 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-05-17 23:25:17 +00:00
Ingo Weinhold
6b202f4e3d * Introduced new header directory headers/private/system which is supposed
to contain headers shared by kernel and userland (mainly libroot).
* Moved quite a few private kernel headers to the new location. Split
  several kernel headers into a shared part and one that is still kernel
  private. Adjusted all affected Jamfiles and source in the standard x86
  build accordingly. The build for other architectures and for test code
  may be broken.
* Quite a bit of userland code still includes private kernel headers.
  Mostly those are <util/*> headers. The ones that aren't strictly
  kernel-only should be moved to some other place (maybe
  headers/private/shared/util).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25486 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-05-14 03:55:16 +00:00
Ingo Weinhold
3560b757c2 Fixed warning.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25438 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-05-10 22:22:08 +00:00
Ingo Weinhold
5d0638bf88 Changed FATAL macro to always dprintf() the error. Additionally it still
prints to stdout, but only until the program and its dependencies are
loaded. Failed attempts to load add-ons and the like doesn't pollute
stdout anymore.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25437 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-05-10 22:21:52 +00:00
Ingo Weinhold
6bf15ffcdc * Changed macros that enable tracing for individual components from
defined/undefined to numeric values (0 for undefined). This allows for
  trace levels.
* Set SYSCALL_TRACING_IGNORE_KTRACE_OUTPUT default to 1, since this is
  what one usually wants.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25213 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-04-27 14:24:18 +00:00
Ingo Weinhold
0efc7a1ed7 Temporarily added the /boot/home/config/* paths to the executable,
library, and add-on search paths. Can be removed again, when certain
optional packages have been moved to /boot/common.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25194 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-04-26 20:28:20 +00:00
Ingo Weinhold
3cf7ecd1e4 * Added <sys/mman.h> header. It declares only mmap() and munmap() yet
and defines the macros needed by them.
* Renamed syscall sys_vm_map_file() to _kern_map_file() and changed the
  path to an FD parameter. Changed vm_map_file() accordingly and
  adjusted the kernel ELF loader and the runtime loader.
* Added syscall _kern_unmap_memory().
* Added bool unmapAddressRange parameter to vm_create_anonymous_area()
  and map_backing_store(). If true and the address specification is
  B_EXACT_ADDRESS, all areas in the specified address range will be
  deleted (unless an area is covered only partially).
* Introduced B_SHARED_AREA flag, which is set on areas that have been
  created by {vm,_user}_map_file() with REGION_NO_PRIVATE_MAP. When
  fork()ing those areas won't be copied CoW, but rather be cloned. This
  is needed for mmap() MAP_SHARED.
* {vm,_user}_map_file() also accept an FD argument < 0, in which case an
  anonymous area is created.
* Implemented mmap() and munmap(). Currently there's the restriction
  that we can't partially unmap areas. Otherwise the functions should be
  rather compliant. We also support the non-POSIX extension
  MAP_ANONYMOUS.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24964 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-04-13 22:52:11 +00:00
Ingo Weinhold
071f9c3aa2 Build configurations shouldn't be done in svn controlled files, so I
finally created a solution to avoid that: Header files that contain
configuration settings (and nothing else) go to build/config_headers.
To change settings, create a directory build/user_config_headers (which
is ignored by svn), copy the respective header there and modify it at
your leisure. Currently only tracing_config.h has been moved to the new
location, but more files will follow eventually. It is also recommended
to move optional macro definitions in Jamfile (as for BFS) to a config
header instead; the build system will then automatically rebuild on
changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24611 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-03-27 22:01:38 +00:00
Ingo Weinhold
92af28df98 Turned the note into a TODO, adding a thought how to implement it.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24546 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-03-24 02:31:20 +00:00
Ingo Weinhold
5fd6637b4d * Decide whether to use BeOS style symbol resolution at run time
depending on the gcc version of the executable.
* Adjusted non-BeOS-style symbol resolution so that add-ons and
  dynamically loaded libraries find symbols in the executable.

This change re-enables support for undefined symbols.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24537 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-03-23 19:43:41 +00:00
Ingo Weinhold
3498280968 The runtime loader now reads a part of the .comment section of each
shared object to find out the GCC version it has been compiled with.
This is not an exact science, since we've got the version string for
every single object file that has been linked in, but my heuristic seems
to be good enough.

Having the gcc version at hand will allow for two features: Enabling
work-arounds for old executables (like the type info problem in BeOS
apps), and automatically selecting the right set of libraries in a mixed
gcc 2/gcc 4 environment.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24534 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-03-23 17:01:42 +00:00
Ingo Weinhold
dd76bc97f5 Fixed NULL related warnings.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24484 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-03-20 01:45:29 +00:00
Ingo Weinhold
8560d1885b * The runtime_loader's test_executable() no longer analyzes the
executable permissions of the file by hand. We use _kern_access()
  instead, which also handles the root case correctly.
* The user and group arguments of test_executable() aren't needed any
  longer.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24483 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-03-20 01:45:00 +00:00
Ingo Weinhold
c57db7d007 _kern_read_link() no longer null-terminates the read string. Fixes
loading of symlinked libraries.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24467 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-03-19 14:09:03 +00:00
Axel Dörfler
12a5e9a4a2 bonefish+axeld:
The runtime loader did not correctly resolve %A correctly with the
actual normalized program path. IOW it would not work correctly with
symlinks to applications that had their own lib directory.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23986 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 16:38:07 +00:00
Ingo Weinhold
2dd86b93a6 axeld + bonefish:
Adjusted PATH, LIBRARY_PATH, and the paths built into the runtime loader
to included the /boot/common tree.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23974 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 13:59:29 +00:00
Ingo Weinhold
6918dbf421 Normalize the given image path in load_container(). Just constructing
some absolute path was not enough to always recognize a library as
already loaded. This fixes problems with Perl where loading an add-on
would cause another instance of libperl.so to be loaded, which would
lead to crashes due to uninitialized static vars in the new instance.
Perl builds now and the tests run, but quite a few do fail.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23930 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-08 03:18:26 +00:00
Ingo Weinhold
7486b72dd1 Added some kernel tracing to the runtime loader.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23921 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-07 19:22:39 +00:00
Michael Lotz
3be509a228 Fix the static cleanup mechanism introduced to the runtime_loader/libroot:
* Fixed wrong start and size used in the runtime_loader
* Fixed off by one error in the matching loop of the cleanup hook
* Make sure we successfully acquire the locking sem of the exit stack

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23493 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-01-13 18:49:27 +00:00
Michael Lotz
8c2a9d7433 bonefish+mmlr:
As (our) gcc unfortunately uses atexit() to clean up lazily initialized static
variables inside functions we have to ensure that we do the right thing with
unloadable shared objects. In case a shared object was unloaded that installed
an atexit() hook the application would crash on exit. We now implement a
callback into libroot that is used to call all the atexit() hooks of a
component that is to be unloaded. Most prominently this fixes the media_server
crash at shutdown.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23486 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-01-13 12:08:34 +00:00
Ingo Weinhold
7ca40195ba Don't overwrite the last read byte with the null-terminator. Fixes bug
#1536.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22452 a95241bf-73f2-0310-859d-f6bbb57e9c96
2007-10-05 19:01:18 +00:00
Axel Dörfler
4421183286 * Changed Ld rule to allow adding resource files.
* Changed ResAttr rule to allow not deleting the file before writing the
  attributes.
* Added application signatures for the runtime_loader and zbeos, just so that
  they may have an icon, too (hint, hint) :-)
* As a side effect, this also let's FileTypes handle these two as apps (even
  though they aren't), so that I can close bug #606.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22412 a95241bf-73f2-0310-859d-f6bbb57e9c96
2007-10-02 15:22:13 +00:00