History log of /haiku/src/system/kernel/elf.cpp
Revision Date Author Comments
# f83058d1 24-Sep-2023 X512 <danger_mail@list.ru>

elf: add PT_RISCV_ATTRIBUTES program header

Attribute is ignored for now.

It is supposed to check ABI compatiblity and reject loading incompatible images.
Haiku currently do not use multiple ABIs for RISC-V so it is safe to ignore attributes.

PT_RISCV_ATTRIBUTES program header is produced by default in GCC 13 and Clang 17.

Change-Id: I4659e9bacbf34a2a0bc16b34c2aaa37232d700fa
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6948
Reviewed-by: David Karoly <karolyd577@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>


# b6bfd9b7 09-Mar-2022 Augustin Cavalier <waddlesplash@gmail.com>

kernel/elf: Use Deleters and get rid of gotos in elf_load_user_image.

Briefly tested: system boots and applications launch as before.


# 264451d9 25-Oct-2021 David Karoly <karolyd577@gmail.com>

kernel: fix loading kernel add-ons on arm

Change-Id: I60cc1c1aa9d4298453aece0456ce7ee74fc95a34
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4659
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: X512 <danger_mail@list.ru>
Reviewed-by: Fredrik Holmqvist <fredrik.holmqvist@gmail.com>


# e41c35ae 25-Nov-2019 Andrej Antunovikj <tunas@cryptolab.net>

kernel/elf: Replace sprintf with snprintf

In two places in elf.cpp, sprintf is used which does not check for buffer overflows. This could potentially lead to malicious executables trying to reach memory
they are not supposed to. Instead, it's possible to use snprintf with a sizeof() call.
I'm not very well-versed into C/C++, so this is just based on what I've learned. Please do provide feedback, I would like to get into more useful contributions :)

Change-Id: I9c36a9938f9c99b3849e77aa9cd2eab313f5bb95
Reviewed-on: https://review.haiku-os.org/c/haiku/+/1975
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# 1b312d7f 23-Feb-2019 PulkoMandy <pulkomandy@pulkomandy.tk>

kernel/elf: use BytePointer

Change-Id: I3a40921854540d78dec025b2a349e3a153f91d55
Reviewed-on: https://review.haiku-os.org/c/1083
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# 03d1fd2b 21-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

kernel/elf: Ignore PT_EH_FRAME for kernel add-ons.

We do the same thing in runtime_loader. Silences a lot
of warnings.


# 36f72031 14-Jan-2019 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Obey "load_symbols" kernel setting.

Somehow this was never implemented...


# ef593f61 24-Nov-2018 Augustin Cavalier <waddlesplash@gmail.com>

ELF: Ignore PT_EH_FRAME and PT_STACK.

This allows Clang builds (linked with our cross binutils) to
at least start runtime_loader and then try to load launch_daemon.
That fails with an infinite loop somewhere...


# a553e95d 04-May-2018 Jérôme Duval <jerome.duval@gmail.com>

kernel: support elf32 on x86_64.

* define ELF32_COMPAT to enable ELF32 macros.
* add a flag ELF_LOAD_USER_IMAGE_TEST_EXECUTABLE to only check the format.
It will be used by load_image_internal() to check which mode to use when
loading an image.
* in arch_elf_relocate_rel(), switch to elf_addr instead of addr_t, which
would be the wrong size for elf32 on x86_64.
* the ELF compat loader reuses the relevant parts of elf.cpp and arch_elf.cpp,
excluding for instance load_kernel_add_on() or dump functions.

Change-Id: Ifa47334e5adefd45405a823a3accbd12eee5b116


# bec80c1c 10-Feb-2018 Jérôme Duval <jerome.duval@gmail.com>

white space cleanup


# 9dd4d2dd 03-Jan-2018 Jérôme Duval <jerome.duval@gmail.com>

kernel: support for Intel SMAP and SMEP on x86_64.

SMAP will generated page faults when the kernel tries to access user pages unless overriden.
If SMAP is enabled, the override instructions are written where needed in memory with
binary "altcodepatches".
Support is enabled by default, might be disabled per safemode setting.

Change-Id: Ife26cd765056aeaf65b2ffa3cadd0dcf4e273a96


# 8efb6db7 06-Aug-2016 Adrien Destugues <pulkomandy@gmail.com>

elf.h: rename ELF_MAGIC to ELFMAG

- This is how it is named in other versions of elf.h (Linux, glibc, possibly more)
- ELF_MAGIC is used by libelf for the same thing, and the defines conflicts,
breaking libelf build on Haiku.


# 90f57186 22-May-2016 Ingo Weinhold <ingo_weinhold@gmx.de>

kernel: Add elf_read_kernel_image_symbols()

Refactor new function out of _user_read_kernel_image_symbols(). Can be
used to get a kernel image's symbols from within the kernel as well.


# 9266cd66 29-Apr-2016 Ingo Weinhold <ingo_weinhold@gmx.de>

extended_image_info: Add text_delta field

Needed to offset a symbol address read from the symbol table to the
actual load address.


# 8c6cb8af 26-Apr-2016 Ingo Weinhold <ingo_weinhold@gmx.de>

runtime loader: Register extended image info with kernel

Add structure extended_image_info which extends image_info by the
fields symbol_table, symbol_hash, string_table.


# c73d1301 08-Nov-2015 Michael Lotz <mmlr@mlotz.ch>

kernel: Use anonymous namespaces to avoid type collisions.

The anonymous namespace makes type definitions local to the translation
unit (like static does for objects). For pretty much any type not shared
across multiple files this is what one wants to happen (and might
erroneously expect to happen automatically).

This commit solves some actual collisions that were present:

* The VFS and the rootfs both used an incompatible VnodeHash struct for
their BOpenHashTable.
* XSI semaphores and message queues both used queued_thread, Ipc and
IpcHashTableDefinition.

For release builds these did not cause problems as the types were fully
inlined. Debug builds would crash at boot however because parts of a
BOpenHashTable<VnodeHash> from the rootfs meant to operate on struct
rootfs_vnode would be applied to one from the VFS expecting struct
vnode.

As such collisions are violations of the one definition rule, the code
is at fault and unfortunatley the compiler isn't required to diagnose
such problems across translation units (which isn't actually trivial).
This can lead to subtle and hard to debug problems and it's therefore
best to avoid leaking types into the global namespace whenever possible.


# 6c009cde 28-Oct-2015 Jérôme Duval <jerome.duval@gmail.com>

kernel: avoid dprintf messages for known header types we don't use.

* fix a typo in runtime_loader/count_regions().


# 459e651f 11-Apr-2015 Michael Lotz <mmlr@mlotz.ch>

syscalls: Remove lookup_symbol syscall again.

This partially reverts b959d46dbd2f9087ae860dbced40440c28596a6e.


# f4bd3825 10-Apr-2015 Michael Lotz <mmlr@mlotz.ch>

Whitespace cleanup only.


# b959d46d 10-Apr-2015 Michael Lotz <mmlr@mlotz.ch>

syscalls: Add get_stack_trace and lookup_symbol syscalls.

The get_stack_trace syscall generates a stack trace using the kernel
debugging facilities and copies the resulting return address array to
the preallocated buffer from userland. It is only possible to get a
stack trace of the current thread.

The lookup_symbol syscall can be used to look up the symbol and image
name corresponding to an address. It can be used to resolve symbols
from a stack trace generated by the get_stack_trace syscall. Only
symbols of the current team can be looked up. Note that this uses
the symbol lookup of the kernel debugger which does not support lookup
of all symbols (static functions are missing for example).

This is meant to be used in situations where more elaborate stack trace
generation, like done in the userland debugging helpers, is not possible
due to constraints.


# c4718ea9 12-Jan-2015 Adrien Destugues <pulkomandy@gmail.com>

Missing std::nothrow on new

Forgot to add this when migrating to BOpenHashTable.


# 6e970417 09-Jan-2015 Rene Gollent <rene@gollent.com>

kernel: Style fix.


# d05a5a70 09-Jan-2015 Rene Gollent <anevilyak@gmail.com>

kernel: Fix ELF hashtable iterator handling.

As a result of the refactoring for OpenHashTable, the iterator semantics
have changed a bit, such that the end of the table is no longer signalled
by the iterator returning NULL. This wasn't taken into account during
refactoring, which would lead to various places returning the last item
in the list in the case where no matching item was found, causing e.g.
drivers not to be loaded properly. This fixes the boot hang regressions
introduced in hrev48640.


# 3b3cad84 09-Jan-2015 Adrien Destugues <pulkomandy@gmail.com>

kernel elf: Fix Compare function

I forgot to change the function to return true on equality, instead of
returning the difference as khash required. Fixes a panic on boot.


# 69ff01cb 08-Jan-2015 Adrien Destugues <pulkomandy@gmail.com>

Migrate image hash table to BOpenHashTable.

For #9552.


# 8614737f 15-Apr-2013 Pawel Dziepak <pdziepak@quarnos.org>

elf: restore correct region protection after relocation


# db1ca605 15-Apr-2013 Pawel Dziepak <pdziepak@quarnos.org>

runtime_loader: randomize position of runtime_loader
* make runtime_loader a dynammically linked object
* add kernel support for loading user images that need to be relocated
* load runtime_loader at random address


# e85e399f 17-Mar-2013 Pawel Dziepak <pdziepak@quarnos.org>

commpage: randomize position of commpage

This patch introduces randomization of commpage position. From now on commpage
table contains offsets from begining to of the commpage to the particular
commpage entry. Similary addresses of symbols in ELF memory image "commpage"
are just offsets from the begining of the commpage.

This patch also updates KDL so that commpage entries are recognized and shown
correctly in stack trace. An update of Debugger is yet to be done.


# d1f280c8 01-Apr-2012 Hamish Morrison <hamishm53@gmail.com>

Add support for pthread_attr_get/setguardsize()

* Added the aforementioned functions.
* create_area_etc() now takes a guard size parameter.
* The thread_info::stack_base/end range now refers to the usable range
only.


# 8a190335 07-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Implemented user debugging support for x86_64.

Reused x86 arch_user_debugger.cpp, with a few minor changes to make
the code work for both 32 and 64 bit. Something isn't quite working
right, if a breakpoint is hit the kernel will hang. Other than that
everything appears to work correctly.


# f4294645 05-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

User symbol lookup works now on x86_64.


# 59ae45c1 21-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Fixed commpage for x86_64.

Since the commpage is at a kernel address, changed 64-bit paging code
to match x86's behaviour of allowing user-accessible mappings to be
created in the kernel portion of the address space. This is also
required by some drivers.


# 0cbce9aa 18-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

A few 64-bit fixes for ELF/module code.


# c3f0fd28 12-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Fixed formatting of output in some debugger commands.

Currently all debugger commands assume 32-bit pointers when formatting their
output. This means that on x86_64 the output is incorrectly formatted. Fixed
this by adding a B_PRINTF_POINTER_WIDTH definition (16 on 64-bit, 8 on
32-bit), and using this to correctly format the output. Not all commands have
been fixed yet, but all VM, slab, VFS, team, thread and image commands should
be correct.


# 3b802628 09-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Support ELF64 in the kernel.

This has been done by adding typedefs in elf_common.h to the correct ELF
structures for the architecture, and changing all Elf32_* uses to those
types. I don't know whether image loading works as I cannot test it yet,
there may be some 64-bit safety issues around. However, symbol lookup for
the kernel is working correctly.


# f1244978 22-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Added an ELF64 version of preloaded_image.

* There is now 2 structures, preloaded_elf32_image and preloaded_elf64_image,
which both inherit from preloaded_image.
* For now I've just hardcoded in use of preloaded_elf32_image, but the
bootloader ELF code will shortly be converted to use templates which use
the appropriate structure. The kernel will be changed later when I add
ELF64 support to it.
* All kernel_args data is now compatible between 32-bit and 64-bit kernels.


# 0e88a887 13-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

First round of 64-bit safety fixes in the kernel.

* Most of this is incorrect printf format strings. Changed all strings
causing errors to use the B_PRI* format string definitions, which
means the strings should be correct across all platforms.
* Some other fixes for errors, casts required, etc.


# d817520f 29-Oct-2011 Axel Dörfler <axeld@pinc-software.de>

* Removed some dead code by applying a patch by lucian from ticket #6275,
thanks!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42970 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 24df6592 11-Jun-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged signals-merge branch into trunk with the following changes:
* Reorganized the kernel locking related to threads and teams.
* We now discriminate correctly between process and thread signals. Signal
handlers have been moved to teams. Fixes #5679.
* Implemented real-time signal support, including signal queuing, SA_SIGINFO
support, sigqueue(), sigwaitinfo(), sigtimedwait(), waitid(), and the addition
of the real-time signal range. Closes #1935 and #2695.
* Gave SIGBUS a separate signal number. Fixes #6704.
* Implemented <time.h> clock and timer support, and fixed/completed alarm() and
[set]itimer(). Closes #5682.
* Implemented support for thread cancellation. Closes #5686.
* Moved send_signal() from <signal.h> to <OS.h>. Fixes #7554.
* Lots over smaller more or less related changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42116 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4535495d 10-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged the signals branch into trunk, with these changes:
* The team and thread kernel structures have been renamed to Team and Thread
respectively and moved into the new BKernel namespace.
* Several (kernel add-on) sources have been converted from C to C++ since
private kernel headers are included that are no longer C compatible.

Changes after merging:
* Fixed gcc 2 build (warnings mainly in the scary firewire bus manager).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0068f3c8 03-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed uint32 underflow in backwards loop (CID 2601).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40095 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c07db2ec 26-Nov-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* elf_find_symbol(): Skip undefined symbols and symbols with the wrong binding.
* Implemented missing handling of symbolically linked images and of weak
symbols.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39646 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 25dc253d 22-Nov-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Merged weak-symbols branch.
* Fixed trivial merge conflict in src/system/libroot/posix/locale/nl_langinfo.cpp
* Fixed gcc 2 compilation of src/system/glue/init_term_dyn.c.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39571 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 55748110 14-Aug-2010 Stefano Ceccherini <stefano.ceccherini@gmail.com>

CID 1653. symbolTable could be leaked in certain error cases.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38116 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f75e014c 06-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Patch by Lucian Adrian Grijincu: Added support for loading kernel modules
with only a single readable/writable/executable text+data segment.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37415 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4d7859f0 06-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

elf_resolve_symbol(): If a weak undefined symbol could not be resolved,
return 0 as its address.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37412 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 45bd7bb3 25-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Removed unnecessary inclusions of <boot/kernel_args.h> in private kernel
headers and respectively added includes in source files.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37259 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a8ad734f 14-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Introduced structures {virtual,physical}_address_restrictions, which specify
restrictions for virtual/physical addresses.
* vm_page_allocate_page_run():
- Fixed conversion of base/limit to array indexes. sPhysicalPageOffset was not
taken into account.
- Takes a physical_address_restrictions instead of base/limit and also
supports alignment and boundary restrictions, now.
* map_backing_store(), VM[User,Kernel]AddressSpace::InsertArea()/
ReserveAddressRange() take a virtual_address_restrictions parameter, now. They
also support an alignment independent from the range size.
* create_area_etc(), vm_create_anonymous_area(): Take
{virtual,physical}_address_restrictions parameters, now.
* Removed no longer needed B_PHYSICAL_BASE_ADDRESS.
* DMAResources:
- Fixed potential overflows of uint32 when initializing from device node
attributes.
- Fixed bounce buffer creation TODOs: By using create_area_etc() with the
new restrictions parameters we can directly support physical high address,
boundary, and alignment.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37131 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c3676b54 13-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added vm_debug_copy_page_memory() which copies memory from a potentially not
mapped page.
* debug_{mem,strl}cpy():
- Added "team" parameter for specifying the address space the address are
to be interpreted in.
- When the standard memcpy() (with fault handler) fails, fall back to
vm_debug_copy_page_memory().
* Added debug_is_debugged_team(): Predicate returning true, if the supplied
team_id refers to the same team debug_get_debugged_thread() belongs to.
* Added DebuggedThreadSetter class for scope-based debug_set_debugged_thread().
Made use of it in several debugger functions.
* print_demangled_call() (x86): Fixed unsafe memory access.

Allows KDL stack traces to work correctly again, even if the page daemon has
already unmapped the concerned pages.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36230 a95241bf-73f2-0310-859d-f6bbb57e9c96


# cee04e80 08-Feb-2010 Artur Wyszynski <aljen-mlists@o2.pl>

Fixed various errors/warnings reported by cppcheck:
* memory leaks
* resource leaks
* added const's to getters
* removed a few reundant conditions


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35433 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 38a97b2c 04-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Moved all knowledge of reserved areas from vm.cpp to VMAddressSpace. It's a
pure address space feature, so it should be handled there.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34491 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bbd97b4b 03-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Made the VMArea fields base and size private and added accessors instead.
This makes it more explicit where the fields are modified.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34464 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 35d94001 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed the address space area list to doubly linked. The reason is to
simplify migration of the area management, but as a side effect, it also
makes area deletion O(1) (instead of O(n), n == number of areas in the
address space).
* Moved more area management functionality from vm.cpp to VMAddressSpace and
VMArea structure creation to VMArea. Made the list and list link members
itself private.
* VMAddressSpace tracks its amount of free space, now. This also replaces
the previous mechanism to do that only for the kernel address space. It
was broken anyway, since delete_area() subtracted the area size instead of
adding it.
* vm_free_unused_boot_loader_range():
- lastEnd could be set to a value < start, which could cause memory
outside of the given range to be unmapped. Haven't checked whether this
could happen in practice -- if so, it would be seriously unhealthy.
- The range between the end of the last area in the range and the end of
the range would never be freed.
- Fixed potential integer overflows when computing addresses.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34459 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f34a1dd5 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Created VMArea.{h,cpp} and moved VMArea and the global area hash table (new
class VMAreaHash) there.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34450 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e50cf876 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Moved the VM headers into subdirectory vm/.
* Renamed vm_cache.h/vm_address_space.h to VMCache.h/VMAddressSpace.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34449 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 90d870c1 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Moved VMAddressSpace definition to vm_address_space.h.
* "Classified" VMAddressSpace, i.e. turned the vm_address_space_*() functions
into methods, made all attributes (but "areas") private, and added
accessors.
* Also turned the vm.cpp functions vm_area_lookup() and
remove_area_from_address_space() into VMAddressSpace methods. The rest of
the area management functionality will follow soon.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34447 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a99eb6b5 01-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

vm_area -> VMArea


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34423 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e0aad96f 22-Oct-2009 Axel Dörfler <axeld@pinc-software.de>

* Allow to use symbols as variables (prefixed with '@'). Now only tab completion
for variable names is missing B-}


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33723 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c51d6579 30-Sep-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed incorrect uses of user_{strl,mem}cpy() in the kernel debugger. This could
break stack traces.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33381 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ea2abd11 02-Aug-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed the ROUNDOWN macro to ROUNDDOWN. Also changed the implementation of
ROUNDUP to use '*' and '/' -- the compiler will optimize that for powers of
two anyway and this implementation works for other numbers as well.
* The thread::fault_handler use in C[++] code was broken with gcc 4. At least
when other functions were invoked. Trying to trick the compiler wasn't a
particularly good idea anyway, since the next compiler version could break
the trick again. So the general policy is to use the fault handlers only in
assembly code where we have full control. Changed that for x86 (save for the
vm86 mode, which has a similar mechanism), but not for the other
architectures.
* Introduced fault_handler, fault_handler_stack_pointer, and fault_jump_buffer
fields in the cpu_ent structure, which must be used instead of
thread::fault_handler in the kernel debugger. Consequently user_memcpy() must
not be used in the kernel debugger either. Introduced a debug_memcpy()
instead.
* Introduced debug_call_with_fault_handler() function which calls a function
in a setjmp() and fault handler context. The architecture specific backend
arch_debug_call_with_fault_handler() has only been implemented for x86 yet.
* Introduced debug_is_kernel_memory_accessible() for use in the kernel
debugger. It determines whether a range of memory can be accessed in the
way specified. The architecture specific back end
arch_vm_translation_map_is_kernel_page_accessible() has only been implemented
for x86 yet.
* Added arch_debug_unset_current_thread() (only implemented for x86) to unset
the current thread pointer in the kernel debugger. When entering the kernel
debugger we do some basic sanity checks of the currently set thread structure
and unset it, if they fail. This allows certain commands (most importantly
the stack trace command) to avoid accessing the thread structure.
* x86: When handling a double fault, we do now install a special handler for
page faults. This allows us to gracefully catch faulting commands, even if
e.g. the thread structure is toast.

We are now in much better shape to deal with double faults. Hopefully avoiding
the triple faults that some people have been experiencing on their hardware
and ideally even allowing to use the kernel debugger normally.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32073 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d3b44ccb 29-Jul-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Added explicit physical address parameter to vm_create_anonymous_area() and
create_area_etc(). 0 for the default behavior.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31941 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 82db8a9e 19-Jun-2009 Axel Dörfler <axeld@pinc-software.de>

* Added an "unmapAddressRange" argument to the file mapping syscall. This is
the first part of making the runtime loader behave itself; it should already
make Clockwerk run okay with any number of translators (even if not all of
them will work yet).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31113 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f2d4d6f6 24-May-2009 Michael Lotz <mmlr@mlotz.ch>

Invalidate the elfHeader variable when the image struct is deleted on error, as
they share the same pointer. Should fix bug #3955.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30848 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9bf61a0e 21-May-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added GNU style ELF symbol versioning support in the kernel, too.
* Fixed memory leak in insert_preloaded_image() in error case.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30820 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6a1e04b1 13-May-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Symbol resolution functions in the kernel: Removed the unused parameter
allowing optional prepending of a string to the symbol names.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30750 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 593ee7bb 12-May-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Extended image_info by fields for the Haiku version and ABI. The runtime loader
and the kernel read those values from the shared object (if available). In the
runtime loader this should eventually replace the gcc version guessing method
currently used (at least for shared objects built for Haiku). The optional
packages need to be rebuilt first, though.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30729 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b36c8ba2 08-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Added elf_get_kernel_image() returning the image for the kernel.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30036 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4acbaafd 25-Mar-2009 Jérôme Duval <korli@users.berlios.de>

* added help for image KDL command


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29710 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c33667d4 01-Feb-2009 Michael Lotz <mmlr@mlotz.ch>

Fixing warnings under GCC4 in preparation to enable -Werror there as well:
* Replaced the use of offsetof() for structs that aren't PODs. Add a
offset_of_member() macro to util/khash.h because that's what it's used for
in our cases.
* Change the signature of add_debugger_command()/remove_debugger_command() on
GCC > 2 to avoid the depricated conversion from string constants to char *.
* Adding some "suggested" parenthesis. I know that not everyone likes that, but
it pointed out at least one bug that is fixed here as well.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29113 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e6e76e14 11-Nov-2008 Axel Dörfler <axeld@pinc-software.de>

* elf_find_symbol() now checks if the hashtable section is greater than 0.
* Whatever is the cause of #2733, this should at least not make it crash.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28615 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b50e6202 02-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed various warnings.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27841 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 99409ebb 28-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Generate a debug event for a loaded user image. When a debugged team
exec*()ed, the debugger never got notified that a runtime loader image
was created.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27773 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fec47a57 24-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added functions elf_create_memory_image() and
elf_add_memory_image_symbol(). The former creates and registers a new
image that has not been loaded from a file. The latter adds a symbol to
its symbol table. This is mainly a debug feature, allowing to name code
or data in memory regions that aren't associated with loaded ELF
objects.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27721 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 52d0d5e5 23-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

elf_load_user_image() does now register the loaded image. That is every
team does have a runtime loader image. The "profile" tool can thus
translate addresses in the runtime loader correctly.
Note that this change will break code that assumes that the application
image is the first image returned by get_next_image_info().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27715 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8839d592 22-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added syscall _kern_read_kernel_image_symbols() for reading a kernel
image's symbol and string tables.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27687 a95241bf-73f2-0310-859d-f6bbb57e9c96


# dd1c278d 03-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added elf_get_image_info_for_address() to get an image info for a kernel
image.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27300 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 98241371 22-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Improved the "ls" command:
* It can now also lookup userland symbols.
* By respecting the currently debugged thread it smoothly cooperates
with the "in_context" command. IOW it can lookup symbols in any team.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27167 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1e906305 21-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added a "flags" parameter to vm_create_anonymous_area() and
create_area_etc().
* When the new flag CREATE_AREA_DONT_WAIT is specified, the functions
don't wait for memory or pages to become available. They fail
immediately instead.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27117 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4a40451d 20-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

The "symbol" command does now set its return value to the symbol
address, so it can be used in expressions.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27098 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 70ce6a9a 02-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Don't allow the kernel team to be passed to
elf_debug_lookup_user_symbol_address().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26747 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5c99d639 22-Jul-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged branch haiku/branches/developer/bonefish/vm into trunk. This
introduces the following relevant changes:
* VMCache:
- Renamed vm_cache to VMCache, merged it with vm_store and made it a
C++ class with virtual methods (replacing the store operations).
Turned the different store implementations into subclasses.
- Introduced MergeStore() callback, changed semantics of Commit().
- Changed locking and referencing semantics. A reference can only be
acquired/released with the cache locked. An unreferenced cache is
deleted and a mergeable cache merged when it is unlocked. This
removes the "busy" state of a cache and simplifies the page fault
code.
* Added VMAnonymousCache, which will implement swap support (work by
Zhao Shuai). It is not integrated and used yet, though.
* Enabled the mutex/recursive lock holder asserts.
* Fixed DoublyLinkedList::Swap().
* Generalized the low memory handler to a low resource handler. And made
semaphores and reserved memory handled resources. Made
vm_try_resource_memory() optionally wait (with timeout), and used that
feature to reserve memory for areas.
...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26572 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 467acc16 22-Jul-2008 Axel Dörfler <axeld@pinc-software.de>

* Cleanup, no functional change.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26568 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 736352dc 16-Jul-2008 Axel Dörfler <axeld@pinc-software.de>

* Added [un]lock_memory_etc() versions that accept a team_id as first argument.
This allows drivers to lock the memory outside of the original team context.
* create_area_etc() got a struct team as first argument, but that should have
been a team_id.
* Removed delete_area_etc() - there is already vm_delete_area() doing the same
thing.
* Renamed vm_get_address_space_by_id() to vm_get_address_space(), as there is
no other method of getting an address space.
* Removed erroneous white space.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26455 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fa0a5cd0 09-Jul-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

insert_preloaded_image() now copies the debug symbols and string table
over to the kernel heap. This allows us to simply free them in
unload_elf_image(). Now we no longer leak the memory for non-preloaded
images. On my T61 this amounted to more than 10 MB of kernel heap after
booting.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26343 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d1d7044e 08-Jul-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added TODO regarding memory leak. Too tired ATM to solve it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26335 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f5b3a6a7 05-Jun-2008 Michael Lotz <mmlr@mlotz.ch>

* Initialize all static mutexes in the kernel through a MUTEX_INITIALIZER()
and remove the then unneeded mutex_init() for them.
* Remove the workaround for allowing uninitialized mutexes on kernel startup.
As they are all initialized statically through the MUTEX_INITIALIZER() now
this is not needed anymore.
* An uninitialized mutex will now cause a panic when used to find possibly
remaining cases.
* Remove now unnecessary driver_settings_init_post_sem() function.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25812 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3cf7ecd1 13-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* 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


# 5dafcc2b 26-Mar-2008 Axel Dörfler <axeld@pinc-software.de>

* Added new "symbol" command which is able to search for a symbol that
matches the specified pattern in all loaded kernel images.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24592 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 890c615a 03-Mar-2008 Axel Dörfler <axeld@pinc-software.de>

* unload_elf_image() never unloaded any image because the ref_count
check was wrong (never gets below zero if everything goes as
intended).
* Removed erroneous white space.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24232 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d4d25a55 18-Feb-2008 Michael Lotz <mmlr@mlotz.ch>

We should lock around register_elf_image() as we modify the image hash in there.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24010 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7bb85c7b 31-Jan-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Clarifying comment.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23806 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2477bce5 19-Jan-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added support for userland symbol lookup in "sc" and "call". Having
used it for an hour or so, I really wonder how we could live without it.
:-)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23640 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4063db92 06-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

* elf_resolve_symbol() no longer copies the symbol name if symbolPrepend is
NULL (it's not used anywhere yet, anyway).
* Fixed warning when compiling with tracing turned on.
* Some cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23267 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a0b6b9b9 04-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23241 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 80f54692 06-Oct-2007 Axel Dörfler <axeld@pinc-software.de>

* struct vnode is an opaque type now, removed void* where it was used incorrectly.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22461 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5c4ed86b 27-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* Moved some definitions from vm_types.h that functions in vm.h need as
arguments into vm.h.
* This should fix the broken build from earlier - thanks Stefano for the note!
* That also allowed to clean some other includes a bit.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22331 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e6dc7903 26-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* vm.h no longer includes vm_types.h - only those that actually need access
to the private VM types are including vm_types.h now.
* Removed vm_page, vm_area, vm_cache, and vm_address_space typedefs; it's
cleaner this way, and the actual types are only used in C++ files now,
anyway.
* And that caused changes in many files...
* Made commpage.h self-containing.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22329 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6e442c70 31-Mar-2007 Ingo Weinhold <ingo_weinhold@gmx.de>

Reversed locking order of sImageLoadMutex and sImageMutex in
unload_kernel_add_on(). The former one could lead to deadlocks with
load_kernel_add_on() (e.g. occasionally the boot process would hang).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20485 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0ad660a1 02-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

Remap all preloaded executables read-only and executable.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19180 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7d2fafca 26-Mar-2006 Axel Dörfler <axeld@pinc-software.de>

Forgot even more debug output...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16882 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 61106f7e 26-Mar-2006 Axel Dörfler <axeld@pinc-software.de>

Forgot to remove some debug output.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16881 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c14a34a6 26-Mar-2006 Axel Dörfler <axeld@pinc-software.de>

* Improved kernel ELF loader (and made it more similar to the one from the boot
loader): it now supports holes between segments, and accepts any segment order.
* Renamed elf.c to elf.cpp and fixed warnings.
* Renamed elf_image_info::dynamic_ptr and eheader to dynamic_section and elf_header.
* Some cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16878 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 459e651fd518aaecda9ff6079ea0385456e0be5b 11-Apr-2015 Michael Lotz <mmlr@mlotz.ch>

syscalls: Remove lookup_symbol syscall again.

This partially reverts b959d46dbd2f9087ae860dbced40440c28596a6e.


# f4bd38257bc7f485b8740770340e84ba9f8c8cea 10-Apr-2015 Michael Lotz <mmlr@mlotz.ch>

Whitespace cleanup only.


# b959d46dbd2f9087ae860dbced40440c28596a6e 10-Apr-2015 Michael Lotz <mmlr@mlotz.ch>

syscalls: Add get_stack_trace and lookup_symbol syscalls.

The get_stack_trace syscall generates a stack trace using the kernel
debugging facilities and copies the resulting return address array to
the preallocated buffer from userland. It is only possible to get a
stack trace of the current thread.

The lookup_symbol syscall can be used to look up the symbol and image
name corresponding to an address. It can be used to resolve symbols
from a stack trace generated by the get_stack_trace syscall. Only
symbols of the current team can be looked up. Note that this uses
the symbol lookup of the kernel debugger which does not support lookup
of all symbols (static functions are missing for example).

This is meant to be used in situations where more elaborate stack trace
generation, like done in the userland debugging helpers, is not possible
due to constraints.


# c4718ea973dc20d96ddf1c8b164ed5ca514b8ca5 12-Jan-2015 Adrien Destugues <pulkomandy@gmail.com>

Missing std::nothrow on new

Forgot to add this when migrating to BOpenHashTable.


# 6e9704175eef7a3adbe28f74bd0712b1b2434310 09-Jan-2015 Rene Gollent <rene@gollent.com>

kernel: Style fix.


# d05a5a70e0413af2ecea0b8c0b03d7c871973634 09-Jan-2015 Rene Gollent <anevilyak@gmail.com>

kernel: Fix ELF hashtable iterator handling.

As a result of the refactoring for OpenHashTable, the iterator semantics
have changed a bit, such that the end of the table is no longer signalled
by the iterator returning NULL. This wasn't taken into account during
refactoring, which would lead to various places returning the last item
in the list in the case where no matching item was found, causing e.g.
drivers not to be loaded properly. This fixes the boot hang regressions
introduced in hrev48640.


# 3b3cad8468437a0546d0a72ba6588d768607f4a8 09-Jan-2015 Adrien Destugues <pulkomandy@gmail.com>

kernel elf: Fix Compare function

I forgot to change the function to return true on equality, instead of
returning the difference as khash required. Fixes a panic on boot.


# 69ff01cb9ea7aacb1ac487b6a309f4bd192b5755 08-Jan-2015 Adrien Destugues <pulkomandy@gmail.com>

Migrate image hash table to BOpenHashTable.

For #9552.


# 8614737f7111ab63672b04299280005000907b81 15-Apr-2013 Pawel Dziepak <pdziepak@quarnos.org>

elf: restore correct region protection after relocation


# db1ca60528285ea0c6620a5acac93c083fbbca6a 15-Apr-2013 Pawel Dziepak <pdziepak@quarnos.org>

runtime_loader: randomize position of runtime_loader
* make runtime_loader a dynammically linked object
* add kernel support for loading user images that need to be relocated
* load runtime_loader at random address


# e85e399fd7b229b8bc92f28928a059876d7216d3 17-Mar-2013 Pawel Dziepak <pdziepak@quarnos.org>

commpage: randomize position of commpage

This patch introduces randomization of commpage position. From now on commpage
table contains offsets from begining to of the commpage to the particular
commpage entry. Similary addresses of symbols in ELF memory image "commpage"
are just offsets from the begining of the commpage.

This patch also updates KDL so that commpage entries are recognized and shown
correctly in stack trace. An update of Debugger is yet to be done.


# d1f280c80529d5f0bc55030c2934f9255bc7f6a2 01-Apr-2012 Hamish Morrison <hamishm53@gmail.com>

Add support for pthread_attr_get/setguardsize()

* Added the aforementioned functions.
* create_area_etc() now takes a guard size parameter.
* The thread_info::stack_base/end range now refers to the usable range
only.


# 8a1903353eedd95266c7241aada3a314c5d35a55 07-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Implemented user debugging support for x86_64.

Reused x86 arch_user_debugger.cpp, with a few minor changes to make
the code work for both 32 and 64 bit. Something isn't quite working
right, if a breakpoint is hit the kernel will hang. Other than that
everything appears to work correctly.


# f4294645358d2eeec007d93493f092581e9bb504 05-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

User symbol lookup works now on x86_64.


# 59ae45c1ab32476f1fa428dae22989f8387a1f9e 21-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Fixed commpage for x86_64.

Since the commpage is at a kernel address, changed 64-bit paging code
to match x86's behaviour of allowing user-accessible mappings to be
created in the kernel portion of the address space. This is also
required by some drivers.


# 0cbce9aa4732e96acd9d593cb86ca0847a61d051 18-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

A few 64-bit fixes for ELF/module code.


# c3f0fd28cda13d70a8c092003609442e4e29cf78 12-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Fixed formatting of output in some debugger commands.

Currently all debugger commands assume 32-bit pointers when formatting their
output. This means that on x86_64 the output is incorrectly formatted. Fixed
this by adding a B_PRINTF_POINTER_WIDTH definition (16 on 64-bit, 8 on
32-bit), and using this to correctly format the output. Not all commands have
been fixed yet, but all VM, slab, VFS, team, thread and image commands should
be correct.


# 3b802628b8e2aa14eb4c674d0a8cf900f522baa1 09-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Support ELF64 in the kernel.

This has been done by adding typedefs in elf_common.h to the correct ELF
structures for the architecture, and changing all Elf32_* uses to those
types. I don't know whether image loading works as I cannot test it yet,
there may be some 64-bit safety issues around. However, symbol lookup for
the kernel is working correctly.


# f1244978152350f9cc010e766d09c2e9ad34dfce 22-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

Added an ELF64 version of preloaded_image.

* There is now 2 structures, preloaded_elf32_image and preloaded_elf64_image,
which both inherit from preloaded_image.
* For now I've just hardcoded in use of preloaded_elf32_image, but the
bootloader ELF code will shortly be converted to use templates which use
the appropriate structure. The kernel will be changed later when I add
ELF64 support to it.
* All kernel_args data is now compatible between 32-bit and 64-bit kernels.


# 0e88a887b4a9ecaaf1062078d9ca9bfca78fcf3a 13-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

First round of 64-bit safety fixes in the kernel.

* Most of this is incorrect printf format strings. Changed all strings
causing errors to use the B_PRI* format string definitions, which
means the strings should be correct across all platforms.
* Some other fixes for errors, casts required, etc.


# d817520f9870f68166cbc49d0e629c681229a751 29-Oct-2011 Axel Dörfler <axeld@pinc-software.de>

* Removed some dead code by applying a patch by lucian from ticket #6275,
thanks!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42970 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 24df65921befcd0ad0c5c7866118f922da61cb96 11-Jun-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged signals-merge branch into trunk with the following changes:
* Reorganized the kernel locking related to threads and teams.
* We now discriminate correctly between process and thread signals. Signal
handlers have been moved to teams. Fixes #5679.
* Implemented real-time signal support, including signal queuing, SA_SIGINFO
support, sigqueue(), sigwaitinfo(), sigtimedwait(), waitid(), and the addition
of the real-time signal range. Closes #1935 and #2695.
* Gave SIGBUS a separate signal number. Fixes #6704.
* Implemented <time.h> clock and timer support, and fixed/completed alarm() and
[set]itimer(). Closes #5682.
* Implemented support for thread cancellation. Closes #5686.
* Moved send_signal() from <signal.h> to <OS.h>. Fixes #7554.
* Lots over smaller more or less related changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42116 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4535495d80c86e19e2610e7444a4fcefe3e0f8e6 10-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged the signals branch into trunk, with these changes:
* The team and thread kernel structures have been renamed to Team and Thread
respectively and moved into the new BKernel namespace.
* Several (kernel add-on) sources have been converted from C to C++ since
private kernel headers are included that are no longer C compatible.

Changes after merging:
* Fixed gcc 2 build (warnings mainly in the scary firewire bus manager).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0068f3c8104e65bea370767aad4b81d79b24822b 03-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed uint32 underflow in backwards loop (CID 2601).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40095 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c07db2ec3f246a20402116d8ac23a8d2f43039e6 26-Nov-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* elf_find_symbol(): Skip undefined symbols and symbols with the wrong binding.
* Implemented missing handling of symbolically linked images and of weak
symbols.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39646 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 25dc253d6ab28ce204fa4de2d3e7a27d167fc817 22-Nov-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Merged weak-symbols branch.
* Fixed trivial merge conflict in src/system/libroot/posix/locale/nl_langinfo.cpp
* Fixed gcc 2 compilation of src/system/glue/init_term_dyn.c.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39571 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 557481100897b13934d01937a2262c8558507428 14-Aug-2010 Stefano Ceccherini <stefano.ceccherini@gmail.com>

CID 1653. symbolTable could be leaked in certain error cases.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38116 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f75e014cb8f1d8de3a86cd3d8db2a2816d0acd62 06-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Patch by Lucian Adrian Grijincu: Added support for loading kernel modules
with only a single readable/writable/executable text+data segment.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37415 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4d7859f03165e18a791d65b15d3f4cbf7a08a79b 06-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

elf_resolve_symbol(): If a weak undefined symbol could not be resolved,
return 0 as its address.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37412 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 45bd7bb3db9d9e4dcb02b89a3e7c2bf382c0a88c 25-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Removed unnecessary inclusions of <boot/kernel_args.h> in private kernel
headers and respectively added includes in source files.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37259 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a8ad734f1c698917badb15e1641e0f38b3e9a013 14-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Introduced structures {virtual,physical}_address_restrictions, which specify
restrictions for virtual/physical addresses.
* vm_page_allocate_page_run():
- Fixed conversion of base/limit to array indexes. sPhysicalPageOffset was not
taken into account.
- Takes a physical_address_restrictions instead of base/limit and also
supports alignment and boundary restrictions, now.
* map_backing_store(), VM[User,Kernel]AddressSpace::InsertArea()/
ReserveAddressRange() take a virtual_address_restrictions parameter, now. They
also support an alignment independent from the range size.
* create_area_etc(), vm_create_anonymous_area(): Take
{virtual,physical}_address_restrictions parameters, now.
* Removed no longer needed B_PHYSICAL_BASE_ADDRESS.
* DMAResources:
- Fixed potential overflows of uint32 when initializing from device node
attributes.
- Fixed bounce buffer creation TODOs: By using create_area_etc() with the
new restrictions parameters we can directly support physical high address,
boundary, and alignment.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37131 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c3676b54bfd2e06b73646d1846b2ab0272cb96e2 13-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added vm_debug_copy_page_memory() which copies memory from a potentially not
mapped page.
* debug_{mem,strl}cpy():
- Added "team" parameter for specifying the address space the address are
to be interpreted in.
- When the standard memcpy() (with fault handler) fails, fall back to
vm_debug_copy_page_memory().
* Added debug_is_debugged_team(): Predicate returning true, if the supplied
team_id refers to the same team debug_get_debugged_thread() belongs to.
* Added DebuggedThreadSetter class for scope-based debug_set_debugged_thread().
Made use of it in several debugger functions.
* print_demangled_call() (x86): Fixed unsafe memory access.

Allows KDL stack traces to work correctly again, even if the page daemon has
already unmapped the concerned pages.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36230 a95241bf-73f2-0310-859d-f6bbb57e9c96


# cee04e8074ec61fd8c6dac3539c5b821c3618888 08-Feb-2010 Artur Wyszynski <aljen-mlists@o2.pl>

Fixed various errors/warnings reported by cppcheck:
* memory leaks
* resource leaks
* added const's to getters
* removed a few reundant conditions


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35433 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 38a97b2c36a42758a143aef034e0a3fc70440934 04-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Moved all knowledge of reserved areas from vm.cpp to VMAddressSpace. It's a
pure address space feature, so it should be handled there.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34491 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bbd97b4bb41cc03735528962ff53d89a2a2d7ff2 03-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Made the VMArea fields base and size private and added accessors instead.
This makes it more explicit where the fields are modified.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34464 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 35d940014e100b8ca09eaf294b86fb9ef905b1e0 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed the address space area list to doubly linked. The reason is to
simplify migration of the area management, but as a side effect, it also
makes area deletion O(1) (instead of O(n), n == number of areas in the
address space).
* Moved more area management functionality from vm.cpp to VMAddressSpace and
VMArea structure creation to VMArea. Made the list and list link members
itself private.
* VMAddressSpace tracks its amount of free space, now. This also replaces
the previous mechanism to do that only for the kernel address space. It
was broken anyway, since delete_area() subtracted the area size instead of
adding it.
* vm_free_unused_boot_loader_range():
- lastEnd could be set to a value < start, which could cause memory
outside of the given range to be unmapped. Haven't checked whether this
could happen in practice -- if so, it would be seriously unhealthy.
- The range between the end of the last area in the range and the end of
the range would never be freed.
- Fixed potential integer overflows when computing addresses.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34459 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f34a1dd5d701373687b6f3f0e6e76bd2b1ae6007 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Created VMArea.{h,cpp} and moved VMArea and the global area hash table (new
class VMAreaHash) there.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34450 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e50cf8765be50a7454c9488db38b638cf90805af 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Moved the VM headers into subdirectory vm/.
* Renamed vm_cache.h/vm_address_space.h to VMCache.h/VMAddressSpace.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34449 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 90d870c1556bdc415c7f41de5474ebebb0ceebdd 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Moved VMAddressSpace definition to vm_address_space.h.
* "Classified" VMAddressSpace, i.e. turned the vm_address_space_*() functions
into methods, made all attributes (but "areas") private, and added
accessors.
* Also turned the vm.cpp functions vm_area_lookup() and
remove_area_from_address_space() into VMAddressSpace methods. The rest of
the area management functionality will follow soon.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34447 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a99eb6b56f61bd847d246e44885618fdeaa313a1 01-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

vm_area -> VMArea


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34423 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e0aad96f945323bdabadd6a91a2cddd5985bbe5f 22-Oct-2009 Axel Dörfler <axeld@pinc-software.de>

* Allow to use symbols as variables (prefixed with '@'). Now only tab completion
for variable names is missing B-}


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33723 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c51d6579e4c15820d383b1f84247f9c2b2b3780c 30-Sep-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed incorrect uses of user_{strl,mem}cpy() in the kernel debugger. This could
break stack traces.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33381 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ea2abd110bd6a4518a954477562e2dd94a5fef9d 02-Aug-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed the ROUNDOWN macro to ROUNDDOWN. Also changed the implementation of
ROUNDUP to use '*' and '/' -- the compiler will optimize that for powers of
two anyway and this implementation works for other numbers as well.
* The thread::fault_handler use in C[++] code was broken with gcc 4. At least
when other functions were invoked. Trying to trick the compiler wasn't a
particularly good idea anyway, since the next compiler version could break
the trick again. So the general policy is to use the fault handlers only in
assembly code where we have full control. Changed that for x86 (save for the
vm86 mode, which has a similar mechanism), but not for the other
architectures.
* Introduced fault_handler, fault_handler_stack_pointer, and fault_jump_buffer
fields in the cpu_ent structure, which must be used instead of
thread::fault_handler in the kernel debugger. Consequently user_memcpy() must
not be used in the kernel debugger either. Introduced a debug_memcpy()
instead.
* Introduced debug_call_with_fault_handler() function which calls a function
in a setjmp() and fault handler context. The architecture specific backend
arch_debug_call_with_fault_handler() has only been implemented for x86 yet.
* Introduced debug_is_kernel_memory_accessible() for use in the kernel
debugger. It determines whether a range of memory can be accessed in the
way specified. The architecture specific back end
arch_vm_translation_map_is_kernel_page_accessible() has only been implemented
for x86 yet.
* Added arch_debug_unset_current_thread() (only implemented for x86) to unset
the current thread pointer in the kernel debugger. When entering the kernel
debugger we do some basic sanity checks of the currently set thread structure
and unset it, if they fail. This allows certain commands (most importantly
the stack trace command) to avoid accessing the thread structure.
* x86: When handling a double fault, we do now install a special handler for
page faults. This allows us to gracefully catch faulting commands, even if
e.g. the thread structure is toast.

We are now in much better shape to deal with double faults. Hopefully avoiding
the triple faults that some people have been experiencing on their hardware
and ideally even allowing to use the kernel debugger normally.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32073 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d3b44ccb1470db823a443d0f9b32e09bfa0d0a9c 29-Jul-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Added explicit physical address parameter to vm_create_anonymous_area() and
create_area_etc(). 0 for the default behavior.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31941 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 82db8a9e159b60e775b4cab31d54ac40fe95de53 19-Jun-2009 Axel Dörfler <axeld@pinc-software.de>

* Added an "unmapAddressRange" argument to the file mapping syscall. This is
the first part of making the runtime loader behave itself; it should already
make Clockwerk run okay with any number of translators (even if not all of
them will work yet).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31113 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f2d4d6f6765e3a6dd63f28876f6fb4254b53b555 24-May-2009 Michael Lotz <mmlr@mlotz.ch>

Invalidate the elfHeader variable when the image struct is deleted on error, as
they share the same pointer. Should fix bug #3955.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30848 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9bf61a0eccc21ebe33d90186064ee70c195abab9 21-May-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added GNU style ELF symbol versioning support in the kernel, too.
* Fixed memory leak in insert_preloaded_image() in error case.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30820 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6a1e04b121921344eec3e7314fafa8796e14cfaf 13-May-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Symbol resolution functions in the kernel: Removed the unused parameter
allowing optional prepending of a string to the symbol names.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30750 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 593ee7bbc334e3ca6ecf6553543ad8037bd7b58a 12-May-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Extended image_info by fields for the Haiku version and ABI. The runtime loader
and the kernel read those values from the shared object (if available). In the
runtime loader this should eventually replace the gcc version guessing method
currently used (at least for shared objects built for Haiku). The optional
packages need to be rebuilt first, though.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30729 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b36c8ba26ad642c712987f68e7b8ca9bccaa19bb 08-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Added elf_get_kernel_image() returning the image for the kernel.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30036 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4acbaafd89a8a61f4e26043d396c71f0449e0e2d 25-Mar-2009 Jérôme Duval <korli@users.berlios.de>

* added help for image KDL command


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29710 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c33667d400856680a8e0122300861eda77d1847a 01-Feb-2009 Michael Lotz <mmlr@mlotz.ch>

Fixing warnings under GCC4 in preparation to enable -Werror there as well:
* Replaced the use of offsetof() for structs that aren't PODs. Add a
offset_of_member() macro to util/khash.h because that's what it's used for
in our cases.
* Change the signature of add_debugger_command()/remove_debugger_command() on
GCC > 2 to avoid the depricated conversion from string constants to char *.
* Adding some "suggested" parenthesis. I know that not everyone likes that, but
it pointed out at least one bug that is fixed here as well.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29113 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e6e76e14dd6dc1c59ff2018bf5ce7b4b98300881 11-Nov-2008 Axel Dörfler <axeld@pinc-software.de>

* elf_find_symbol() now checks if the hashtable section is greater than 0.
* Whatever is the cause of #2733, this should at least not make it crash.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28615 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b50e620202c4faf76869721957973c0f72e83155 02-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed various warnings.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27841 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 99409ebb19488238a93624df727b537aba89c93d 28-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Generate a debug event for a loaded user image. When a debugged team
exec*()ed, the debugger never got notified that a runtime loader image
was created.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27773 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fec47a570239d9505c56b680fb3c2564c9988c14 24-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added functions elf_create_memory_image() and
elf_add_memory_image_symbol(). The former creates and registers a new
image that has not been loaded from a file. The latter adds a symbol to
its symbol table. This is mainly a debug feature, allowing to name code
or data in memory regions that aren't associated with loaded ELF
objects.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27721 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 52d0d5e53e69a54f4138b0301d574591307a5292 23-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

elf_load_user_image() does now register the loaded image. That is every
team does have a runtime loader image. The "profile" tool can thus
translate addresses in the runtime loader correctly.
Note that this change will break code that assumes that the application
image is the first image returned by get_next_image_info().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27715 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8839d592bce4b8ffebdb440ed50085fbf397975b 22-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added syscall _kern_read_kernel_image_symbols() for reading a kernel
image's symbol and string tables.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27687 a95241bf-73f2-0310-859d-f6bbb57e9c96


# dd1c278d4b64ef9c143903384a85d4c5aabc2770 03-Sep-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added elf_get_image_info_for_address() to get an image info for a kernel
image.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27300 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 982413718d43f9a992698d4cb9f3e2181addd1d0 22-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Improved the "ls" command:
* It can now also lookup userland symbols.
* By respecting the currently debugged thread it smoothly cooperates
with the "in_context" command. IOW it can lookup symbols in any team.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27167 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1e90630527225143d9321738152bba9194f5ef3f 21-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added a "flags" parameter to vm_create_anonymous_area() and
create_area_etc().
* When the new flag CREATE_AREA_DONT_WAIT is specified, the functions
don't wait for memory or pages to become available. They fail
immediately instead.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27117 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4a40451dd9991da4bb053ca25329968af51865ba 20-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

The "symbol" command does now set its return value to the symbol
address, so it can be used in expressions.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27098 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 70ce6a9ade79bd43b0cccab87da21e2f00979d28 02-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Don't allow the kernel team to be passed to
elf_debug_lookup_user_symbol_address().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26747 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5c99d639708df9b4e2cc847b38d510149d19ec78 22-Jul-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged branch haiku/branches/developer/bonefish/vm into trunk. This
introduces the following relevant changes:
* VMCache:
- Renamed vm_cache to VMCache, merged it with vm_store and made it a
C++ class with virtual methods (replacing the store operations).
Turned the different store implementations into subclasses.
- Introduced MergeStore() callback, changed semantics of Commit().
- Changed locking and referencing semantics. A reference can only be
acquired/released with the cache locked. An unreferenced cache is
deleted and a mergeable cache merged when it is unlocked. This
removes the "busy" state of a cache and simplifies the page fault
code.
* Added VMAnonymousCache, which will implement swap support (work by
Zhao Shuai). It is not integrated and used yet, though.
* Enabled the mutex/recursive lock holder asserts.
* Fixed DoublyLinkedList::Swap().
* Generalized the low memory handler to a low resource handler. And made
semaphores and reserved memory handled resources. Made
vm_try_resource_memory() optionally wait (with timeout), and used that
feature to reserve memory for areas.
...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26572 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 467acc16f5abd2ecfe4e512b4accba5377b410c6 22-Jul-2008 Axel Dörfler <axeld@pinc-software.de>

* Cleanup, no functional change.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26568 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 736352dcf58f1855db8dc09c456d420ca91596ef 16-Jul-2008 Axel Dörfler <axeld@pinc-software.de>

* Added [un]lock_memory_etc() versions that accept a team_id as first argument.
This allows drivers to lock the memory outside of the original team context.
* create_area_etc() got a struct team as first argument, but that should have
been a team_id.
* Removed delete_area_etc() - there is already vm_delete_area() doing the same
thing.
* Renamed vm_get_address_space_by_id() to vm_get_address_space(), as there is
no other method of getting an address space.
* Removed erroneous white space.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26455 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fa0a5cd0e867824fdc375da59860db7423d2e054 09-Jul-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

insert_preloaded_image() now copies the debug symbols and string table
over to the kernel heap. This allows us to simply free them in
unload_elf_image(). Now we no longer leak the memory for non-preloaded
images. On my T61 this amounted to more than 10 MB of kernel heap after
booting.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26343 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d1d7044ed199d0a1698b4fce89092a9dcd41cea0 08-Jul-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added TODO regarding memory leak. Too tired ATM to solve it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26335 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f5b3a6a7968b849c8cb3d06ffe6d19acccf910a8 05-Jun-2008 Michael Lotz <mmlr@mlotz.ch>

* Initialize all static mutexes in the kernel through a MUTEX_INITIALIZER()
and remove the then unneeded mutex_init() for them.
* Remove the workaround for allowing uninitialized mutexes on kernel startup.
As they are all initialized statically through the MUTEX_INITIALIZER() now
this is not needed anymore.
* An uninitialized mutex will now cause a panic when used to find possibly
remaining cases.
* Remove now unnecessary driver_settings_init_post_sem() function.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25812 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3cf7ecd1e49db0ad531a6d81ad1945c4a6235010 13-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* 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


# 5dafcc2b1b258a02efb4636e99b03e09316a8dd7 26-Mar-2008 Axel Dörfler <axeld@pinc-software.de>

* Added new "symbol" command which is able to search for a symbol that
matches the specified pattern in all loaded kernel images.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24592 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 890c615aee357f4123a597faef098291f0a73288 03-Mar-2008 Axel Dörfler <axeld@pinc-software.de>

* unload_elf_image() never unloaded any image because the ref_count
check was wrong (never gets below zero if everything goes as
intended).
* Removed erroneous white space.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24232 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d4d25a55bd390c6ede98b168c98d0ac231a0759f 18-Feb-2008 Michael Lotz <mmlr@mlotz.ch>

We should lock around register_elf_image() as we modify the image hash in there.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24010 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7bb85c7b5502a2b6662b4b521a5e70af6c32b01c 31-Jan-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Clarifying comment.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23806 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2477bce5046dba76204a8c8b75ea773be4ae9748 19-Jan-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added support for userland symbol lookup in "sc" and "call". Having
used it for an hour or so, I really wonder how we could live without it.
:-)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23640 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4063db92d046d7a878f659e13b07be5f732ee0e5 06-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

* elf_resolve_symbol() no longer copies the symbol name if symbolPrepend is
NULL (it's not used anywhere yet, anyway).
* Fixed warning when compiling with tracing turned on.
* Some cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23267 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a0b6b9b9e62fbdf91fd1e432a31cc745275a846d 04-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23241 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 80f54692912d728f5780e9d78d7643828edaaa2a 06-Oct-2007 Axel Dörfler <axeld@pinc-software.de>

* struct vnode is an opaque type now, removed void* where it was used incorrectly.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22461 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5c4ed86b56868e2584298c05792a6e65d4d3fa78 27-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* Moved some definitions from vm_types.h that functions in vm.h need as
arguments into vm.h.
* This should fix the broken build from earlier - thanks Stefano for the note!
* That also allowed to clean some other includes a bit.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22331 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e6dc7903e4277bf6e22527ed611df619c7e645f1 26-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* vm.h no longer includes vm_types.h - only those that actually need access
to the private VM types are including vm_types.h now.
* Removed vm_page, vm_area, vm_cache, and vm_address_space typedefs; it's
cleaner this way, and the actual types are only used in C++ files now,
anyway.
* And that caused changes in many files...
* Made commpage.h self-containing.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22329 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6e442c70cbeb658dc0dd446c72c5e817dfe16b9b 31-Mar-2007 Ingo Weinhold <ingo_weinhold@gmx.de>

Reversed locking order of sImageLoadMutex and sImageMutex in
unload_kernel_add_on(). The former one could lead to deadlocks with
load_kernel_add_on() (e.g. occasionally the boot process would hang).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20485 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0ad660a168b87946b2bfed03603790119f53dc39 02-Nov-2006 Axel Dörfler <axeld@pinc-software.de>

Remap all preloaded executables read-only and executable.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19180 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7d2fafcac538f09519b02c3d0021e31480060a5d 26-Mar-2006 Axel Dörfler <axeld@pinc-software.de>

Forgot even more debug output...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16882 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 61106f7e86d5c5256de9fae2ca23d022fecc4452 26-Mar-2006 Axel Dörfler <axeld@pinc-software.de>

Forgot to remove some debug output.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16881 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c14a34a65f69bbccfca75a0c9cd44bab21ab25d5 26-Mar-2006 Axel Dörfler <axeld@pinc-software.de>

* Improved kernel ELF loader (and made it more similar to the one from the boot
loader): it now supports holes between segments, and accepts any segment order.
* Renamed elf.c to elf.cpp and fixed warnings.
* Renamed elf_image_info::dynamic_ptr and eheader to dynamic_section and elf_header.
* Some cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16878 a95241bf-73f2-0310-859d-f6bbb57e9c96