Commit Graph

6744 Commits

Author SHA1 Message Date
Alexander von Gluck IV
b3d3ee5a2f libroot/ppc: Stub out emitted GCC atomics on ppc32
* gcc will emit 64-bit (_8) atomic functions on 32-bit
  powerpc architectures. This stubs them out for now
  with a warning.
* We could do more here, but i'm just getting PPC
  bootstrapped to get the nightly builds going again.
* We could also just completely drop PPC.. but it was
  pretty close pre-pm... so I'd hate to lose that work.
2017-07-03 13:05:47 -05:00
Alexander von Gluck IV
9c8119e02c kernel/smp: Add a comment for some obsecure knowledge
* I was ready to rip this out until PulkoMandy set me stright.
* Add a comment so others understand the impact here.
2017-07-03 09:43:07 -05:00
Alexander von Gluck IV
7f47ae44c2 openfirmware: Fix build post get_boot_partitions changes
* Thanks jessicah!
2017-07-02 22:57:53 -05:00
Pedro Pinto
856da1f3ff Add missing include with Partition class definition
* Fixes a compilation error while compiling the u-boot loader for
  the ARM platform.

Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
2017-06-23 17:30:27 -04:00
Augustin Cavalier
6ad3d25212 real_time_clock: Change _user_{get|set}_timezone argument to int32.
Both the user-mode syscalls.h and the kernel-mode one define it
as an int32, not a time_t, and as it's a timezone offset not
an actual time, there's no reason it needs to be one.
2017-06-06 17:38:17 -04:00
Augustin Cavalier
affb4e25fe runtime_loader: Remove EXEMODE hack.
This reverts commit 6af29d4f83.
I'll have a look at our buildbot config and see if it needs fixing.
2017-05-28 12:42:12 -04:00
Augustin Cavalier
6af29d4f83 runtime_loader: Ensure EXEMODE is set.
Stopgap solution for #12373.
2017-05-26 15:31:55 -04:00
James Woodcock
d7b12f71ea kernel/fs: Fix permissions on symlinks in root directory.
Various symbolic links (/bin, for example) in the root directory have
no read, write or execute permissions. This prevents non-privileved users
from logging in.

Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
Fixes #13530.
2017-05-26 15:10:18 -04:00
Rahul Jain
7ce3cbfbe8 "fail-safe video mode" is confusing.
The same wording was used for two unrelated things: using the VESA
driver, and forcing a specific resolution. Relabel the menu items to
make it clear that they are not related.

fixes #8887

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
2017-05-25 11:46:02 +02:00
Alexander von Gluck IV
d8219f96da bootloader/bios: Add tracing of real-mode bios interrupt calls 2017-05-24 08:18:54 -05:00
Alexander von Gluck IV
9d9f76edff bootloader/hpet: Fix tracing on x86_64 2017-05-23 21:54:10 -05:00
Jessica Hamilton
f286626cd0 pxe_ia32: add missing include for boot::Partition 2017-05-17 23:21:40 +12:00
Jessica Hamilton
e888217124 loader: fetch all potential boot partitions for boot device.
This allows the loader to skip BFS partitions that don't contain
a bootable system. Useful when you have a BFS data partition that
comes before the system partition when iterated over.

Currently, only the UEFI loader actually returns more than one
possible partition.
2017-05-17 12:51:09 +12:00
Axel Dörfler
655aae6a79 KPathTest: Fix build for GCC 5.
* Also fixed a warning in KPath.
* Sorry, again!
2017-04-30 18:17:51 +02:00
Axel Dörfler
16825fd976 VFS: Pass on NULL for NULL paths, if allowed.
* Uses the new KPath::LAZY_ALLOC feature.
* This closes ticket #9625.
2017-04-30 17:37:17 +02:00
Axel Dörfler
e9843da357 KPath: Added LAZY_ALLOC flag.
* This allows KPath to not allocate a buffer when initialized
  without path.
* Added test cases for this.
* Added test for LockBuffer().
* Enhanced tests to allow building them in debug mode.
* Moved calling vfs_normalize_path() into own private method.
* Improved error codes; B_NO_MEMORY is now only returned if the
  allocation actually failed.
* If used with LAZY_ALLOC, Path() and LockBuffer() are now allowed
  to return a NULL path.
2017-04-30 17:14:45 +02:00
Axel Dörfler
f94671c33d KPath.Adopt(): Fixed path length.
* Issue was hidden due to inappropriate test values; changed test
  to uncover it.
2017-04-30 17:13:45 +02:00
Axel Dörfler
eac83fb33e KPath: Replaced booleans with flags field.
* No functional change intended; I chose the flags in a way that it
  should still work even if I missed a reference.
2017-04-30 17:13:39 +02:00
Axel Dörfler
e1b4aed0cb KPath: Fixed Normalize() return code, changed Leaf().
* Normalize() now returns the error code that vfs_normalize_path()
  returns.
* Leaf() now returns "" instead of "/" for the root. It's not used
  outside of KPath.
* Adapted RemoveLeaf() to deal with this correctly.
* "KPath = string" no longer changes the buffer size.
* Added missing operator tests for =, ==, and !=.
2017-04-30 17:13:33 +02:00
Axel Dörfler
4be518758d KPath.Adopt() fixed incorrect path/buffer length.
* The other object was left in an inconsistent state.
* This lets the unit test for Adopt() pass.
2017-04-29 19:03:16 +02:00
Axel Dörfler
3582d4fe85 Minor style cleanup. 2017-04-29 14:37:56 +02:00
Jessica Hamilton
10a1d9102e bootloader/efi: use B_PAGE_SIZE 2017-04-25 00:06:01 +00:00
Augustin Cavalier
17f5ac9149 libroot: Restore exit() call after debugger().
Thanks PulkoMandy for the review.
2017-04-14 18:29:29 -04:00
Augustin Cavalier
a5d208c7d6 libroot: abort() should behave like a crash, not just a 'failure' exit.
Calling debugger() means that the crash dialog will be shown, and so
users will not be left wondering why an app just spontenously disappeared.
2017-04-14 16:07:02 -04:00
Adrien Destugues
743088d40b Fix users of PAGE_SIZE
- Replaced by B_PAGE_SIZE where possible
- Enabled the _XOPEN_SOURCE feature define otherwise
2017-04-13 21:32:08 +02:00
Axel Dörfler
99ccb18d97 Kernel IOBuffer: Fixed potential memory leak.
* IOBuffer::FreeVirtualVecCookie() did not put the last physical page
  back. This was only an issue in case GetNextVirtualVec() wasn't
  iterated through the end, for example in case of an error.
* Fixed the condition when to put back a physical page; the current
  solution will also work with the generic page mapper implementation.
* This fixes the low hanging fruits of Ingo's comment in #5777.
2017-04-06 23:31:48 +02:00
Axel Dörfler
742b85c1f1 vfs: Let new_vnode() and publish_vnode() wait for busy vnodes.
* Both functions need to wait when encountering a busy vnode, in order
  not to create a race condition in combination with get_vnode().
* This should fix both #5262, and #9839.
* I did not implement Ingo's suggestion to burden the file systems with
  solving the problem for the following reasons:
  - I think the file system interface should be as simple as possible.
  - I can't think of a possible locking issue at least for BFS.
  - The solution on the file system side would look pretty similar to
    what the VFS already does or has to do (minus controlling the locking
    directly), so it would cause quite a functional duplication.
2017-04-02 14:30:45 +02:00
Alexander von Gluck IV
d8ce1a9fad x86/irq_routing: Convert panic into warning. Solves #13388
* Solves #13388 and likely a bunch of other bug reports.
* While this *is* an issue that can potentially be serious,
  there really isn't a risk of data loss or a system
  instability, only broken PCI devices. Show warning and
  keep going.
2017-03-20 14:10:14 -05:00
Alexander von Gluck IV
8eee7007cf x86/irq_routing: More tracing around fill_pci_info_for_entry 2017-03-19 17:44:11 -05:00
Alexander von Gluck IV
acdfec1189 x86/irq_routing: Improve trace information 2017-03-19 16:29:11 -05:00
Augustin Cavalier
59bdca5dd4 kernel/x86/arch_int: Style fixes.
Thanks Axel for the review.
2017-02-27 18:14:26 -05:00
Augustin Cavalier
0414166a29 kernel/x86/arch_int: Move cast after NULL check.
Spotted by Lioncash (via IRC). No functional change intended.
2017-02-25 15:28:25 -05:00
Lioncash
7c6caa8939 load_driver_settings: Add missing kernel_args_free() call to load_driver_settings_file()
Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
2017-02-25 15:16:07 -05:00
Jérôme Duval
85566e032d posix: add _POSIX_SEM_NSEMS_MAX.
* have _SC__SEM_NSEMS_MAX return _POSIX_SEM_NSEMS_MAX, a per team limit
instead of the global limit.
2017-02-21 20:17:16 +01:00
Jérôme Duval
0bec83a85a pthread: add const for pthread_mutex*_get*()
according to the spec. Fixes #13324.
* code style clean up.
2017-02-21 20:05:02 +01:00
Jérôme Duval
4f10ef40b9 pthread: check parameters for pthread_barrierattr_*pshared().
* fixes #13323.
2017-02-21 20:05:02 +01:00
Jérôme Duval
90acbbfecb pthread: have pthread_setschedparam return 0 on success.
* fixes #13299.
2017-02-14 20:48:43 +01:00
Augustin Cavalier
b6f76ebe71 s/OpenBeOS License/MIT License/ universally, as they're the same thing.
Fixes #8681.
2017-02-09 22:09:56 -05:00
Freeman Lou
aa3083e086 Style fixes to various parts of the system.
Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

This patch was never applied after GSoC 2012. Rebase the parts that
still apply so we can close the ticket.

Fixes #9490.
2017-01-29 22:47:28 +01:00
Andrew Aldridge
f31b1a2faf Implement scrypt-based password hashing
Signed-off-by: Axel Dörfler <axeld@pinc-software.de>
2017-01-17 23:09:04 +01:00
Jessica Hamilton
92b9c8649b MultibyteToWchar: correctly handle UTF-16 surrogate pairs.
* Whilst in WcharToMultibyte, we correctly convert our UTF-32
  wchar characters to multibyte, the same wasn't done in
  MultibyteToWchar. Now, if we detect a leading surrogate,
  we'll re-read the multibyte sequence with space for a UTF-16
  pair, which allows U16_GET to correctly convert the UTF-16
  byte sequence into the needed UTF-32 codepoint.

Fixes #13184.
2017-01-12 06:39:55 +13:00
Jessica Hamilton
d2423e4b3c ICUCtypeData.cpp: format string fixes for tracing. 2017-01-12 03:33:11 +13:00
Jessica Hamilton
079ab7f0b1 ICU add-on: validate mbState->converter before attempting to close.
This resolves crashes in gawk with multibyte support.

Fixes #12515, #13103.
2017-01-12 03:33:04 +13:00
Jessica Hamilton
3d870da3cb UEFI: leave runtime memory identity mapped.
* We don't have kernel/userspace access to UEFI at this point
  either, and with some firmware, if we don't keep the
  runtime memory identity mapped, then the loader dies. This
  will fix booting on such machines, and shouldn't have any
  impact on already working machines.
2017-01-08 21:43:53 +13:00
Jessica Hamilton
6b4cbec040 UEFI: identify the boot partition to check that it's valid.
* Also modified EFI::Header to return the efi_table_header so
  that we can compare it to boot device partition table.
2017-01-07 21:26:25 +13:00
Jessica Hamilton
42e718f041 UEFI: improve boot support in devices.cpp
* Maintain a list of all MESSAGING_DEVICE_PATH and
  MEDIA_DEVICE_PATH handles, so we can avoid adding devices
  multiple times.
* Split up platform_add_boot_device() into separate functions
  for better readability (add_cd_devices, add_boot_device_for_image,
  etc.).
2017-01-07 21:26:23 +13:00
Jessica Hamilton
35b38c392e loader: get_boot_file_system() iterate over all devices found.
* This is useful for UEFI, as we can then add the device that
  contains the UEFI loader, as well as all CD devices. As a
  result, if the device with the UEFI loader doesn't contain
  a bootable BFS partition, it will then attempt the same for
  CD devices.
2017-01-07 21:25:23 +13:00
Jessica Hamilton
445b080ea3 UEFI: support selecting video resolution & vesa settings file. 2017-01-07 15:39:35 +13:00
Fredrik Holmqvist
1d8306654a Rewrote device handling in EFI boot-loader
This allows me to find and boot disks and cds(*)
platform_add_boot_device tries to find the disk of the EFI partition
As on other platforms if boot disk isn't found platform_add_block_devices
will be called.
platform_add_block_devices will find all block devices that arn't partitions as
they are handled by Haiku already.
Currently first found suitable partition will be selected.

TODO:
 * pass in partition UUID's as boot-loader arg to setup boot for
any partition.
 * Better cd detection
 * Better disk_identifier

*) vfs_boot.cpp is very restrictive when it comes to booting cds.
It either do very Anyboot check where boot partition should be at offset 0,
which isn't true for EFI. In my case it's not even on that disk.
Or it only allow data session partition types.
This is currently failing as the Anyboot partition type is BFS.
2017-01-06 19:43:08 +01:00
Fredrik Holmqvist
57b59d47c5 memset was done twice 2017-01-06 19:39:58 +01:00
Murai Takashi
57db30a752 find_paths.cpp: fix memory leak
Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

fixes #13136
2017-01-01 11:38:13 +01:00
Dmytro Shynkevych
0e0f49e799 libroot: Implemented pthread barriers
This is an implementation of pthread barriers pursuant to the relevant specification.

Barriers are essentially a special case of conditional variables,
such that all threads waiting on one are woken up when the number of
waiters reaches a number provided at the initialization of the barrier.
In view of that, this implementation mimics the implementation of pthread_cond,
except it is more specialized and self-contained.

Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>
2016-12-30 11:32:04 +01:00
Jessica Hamilton
d2e18d6462 efi/video.cpp: style fix. 2016-12-23 18:58:26 +13:00
Jessica Hamilton
4419d699ec partitioning: pass along reference to parent when uninitializing.
* Fixes problems with setting the partition name after uninitializing
  a partition in DriveSetup. Previously, UninitializeJob() was
  followed by SetStringJob(), but the kernel was updating the
  change counter for the parent partition when uninitializing a
  partition, leading to SetStringJob() having an incorrect change
  counter for the parent partition. Now the parent change counter
  will be correct when SetStringJob() runs.
2016-12-23 18:53:15 +13:00
Jessica Hamilton
4ff3f10852 UEFI: improve setting up of the framebuffer.
* Even if we get dropped into the boot menu, we still want
  to have the framebuffer enabled, else we never switch
  back into graphics mode.
2016-12-19 20:18:31 +13:00
Jérôme Duval
9969137ced fork(): Follow-up fix to 17b2a3cfc.
* Ingo rightly noticed that the defer_signals counter is reinitialized on
  thread's user area creation. Setting the flag THREAD_CREATION_FLAG_DEFER_SIGNALS
  indeed gives the expected behavior, deferring signals until undefer_signals() is
  called in the child thread. Thanks for the review and fix suggestion.
* Added a simple test showing the values of the defer_signals counter after fork().
2016-12-18 09:44:03 +01:00
Jessica Hamilton
941c240ab0 libroot/fork: fix gcc2 compilation. 2016-12-18 14:42:06 +13:00
Fredrik Holmqvist
9e487d8d74 UEFI: serial debugging support.
Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
2016-12-18 14:41:54 +13:00
Jérôme Duval
17b2a3cfcb fork(): Defer signals and lock the heaps while _kern_fork().
* Also defer signals while registering fork hooks.
* While malloc provides fork heap hooks which lock the heaps and unlock/reinit,
  malloc_debug provides empty hooks.
* Ideas suggested by Ingo, patch reviewed by him. Thanks a lot!
* Also call fork parent hooks on failure.
* Solve locks-up when combining multithreading and process forking, should help
  with #13111.
2016-12-17 21:11:15 +01:00
Henry Harrington
e2b610b4b3 UEFI: CR0.WP must be set before entering the kernel.
If WP is not enabled then the kernel can freely write to read-only user
pages, which breaks copy-on-write.

Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
2016-12-14 06:02:19 +13:00
Jessica Hamilton
b521a45ec2 Revert "vm: Try harder to allocate early physical pages."
This reverts commit 21e3ac6cf5,
which was accidentally applied twice, missed during rebase.

Originally applied in 601b2f7eda.
2016-12-13 22:24:12 +13:00
Jessica Hamilton
48494219eb Add a dumb framebuffer driver.
This is separate to the VESA driver, as the VESA driver requires
using the VBE BIOS. Under UEFI, we don't have the VBE BIOS, nor
are we able to switch modes after leaving UEFI Boot Services, so
a dumb framebuffer driver seemed like the easier way to approach
the problem.

The framebuffer & vesa drivers now test for the presence of the
VESA_MODES_BOOT_INFO boot item to distinguish between which driver
to use. Also added check for the VESA mode count to determine
whether to add the VESA_MODES_BOOT_INFO item.

UEFI video updated to explicitly zero out the VESA and EDID
boot data.
2016-12-13 21:41:10 +13:00
Michael Lotz
1f7e5bde38 kernel: Fix NULL dereference in ThreadTimeUserTimer::Schedule().
The SpinLocker was always initialized to fThread->time_lock even though
fThread may be NULL. This looks like a simple oversight as the rest of
the method handles fThread being NULL and the team variants of these
timers have very similar logic and do the NULL check as well.

This fixes the last remaining KDL in the posixtestsuite.
2016-12-12 11:55:06 +01:00
Jessica Hamilton
25fa3b1b8a loader: fix defines affecting elf.cpp for other platforms 2016-11-14 23:46:10 +13:00
Jessica Hamilton
04f0d02a8f Jamfiles: fix TARGET_BOOT_PLATFORM tests to use = efi 2016-11-14 23:45:22 +13:00
Jessica Hamilton
f4ff9cb02c Merge branch 'uefi-support' 2016-11-14 03:21:59 +13:00
Nick Smallbone
a99a0c003d EFI: add support for SMP.
Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
2016-11-14 03:21:41 +13:00
Jessica Hamilton
ec239abcf5 EFI: implement mmu_map_physical_memory & mmu_free.
Also move cpu, acpi, hpet init into platform_start_kernel, as we
need an initialised heap for alllocating memory for recording
the mapped regions.
2016-11-14 03:21:41 +13:00
Jessica Hamilton
a7142a5037 EFI: add cpu.cpp from bios_ia32 2016-11-14 03:21:40 +13:00
Jessica Hamilton
a1d0102ee4 EFI: add support for HPET 2016-11-14 03:21:40 +13:00
Jessica Hamilton
6e6efaecdc EFI: add ACPI support
Also add support in the kernel to get the ACPI RSDP from the
bootloader, and pass onto the ACPI driver using get_boot_item.
2016-11-14 03:21:36 +13:00
Henry Harrington
82dcc31606 bootloader: Translate kernel args before adding them to kernel_args_range.
Chunks may be physically contiguous, but virtually disjoint. Adding
physical addresses may cause ranges to be merged incorrectly.

Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
2016-11-14 01:00:00 +13:00
Henry Harrington
21e3ac6cf5 vm: Try harder to allocate early physical pages.
Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
2016-11-14 01:00:00 +13:00
Henry Harrington
34a6dd6728 EFI: Initialize/load the GDT.
Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
2016-11-14 00:59:59 +13:00
Henry Harrington
b3215a6275 EFI: preliminary support for starting the kernel.
Enough to let the kernel to print hello, but not much beyond that.

Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
2016-11-14 00:59:56 +13:00
Jérôme Duval
33e68be479 Update libroot stubs. 2016-11-01 08:44:04 +01:00
Adrien Destugues
b5c858aa75 strptime: allow dates before 1900.
While struct tm makes things more confusing than they need to be,
nothing in the API prevents handling those. So let's just accept them.

Fixes some strange cases in the cookie test suite (with a cookie set to
expire in year 101 B.C.)
2016-10-30 20:23:43 +01:00
Adrien Destugues
4bc43f4368 style fix. 2016-10-30 09:17:00 +01:00
Jérôme Duval
58fb6344ae libroot: getlogin_r(): 32 is a valid length.
* also use LOGIN_NAME_MAX for the max length.
2016-10-29 22:39:32 +02:00
Adrien Destugues
61987fe7a2 runtime_loader: allow the ABI version symbol to be local.
Some libraries buildsystems (eg. zlib) somehow prevent the symbol from
being exported. We should fix that, but binaries with missing symbols
are already out there, so we need to handle them in any case.
2016-10-29 10:16:29 +02:00
Adrien Destugues
09c4bc5bd3 runtime_loader: fix getting ABI from gcc .comment
The format for the .comment string changed at some point, and this
fallback code would always fail for files built only with "new" versions
of gcc.

Also consider gcc 5 to be ABI version 4, since it is still compatible
with the old ABI (and provides a new one side by side).

See https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
for infos on GCC ABI changes in GCC 5.
2016-10-23 22:23:06 +02:00
Ulrich Drepper
d2bd05420a glibc: (_IO_cleanup): Do not use locking when flushing ...
the buffers. Some thread might be using a stream.
2016-10-23 20:30:45 +02:00
François Revol
b1e2427d75 glibc: replace extern __inline with __extern_always_inline for ppc
As was done for x86 in hrev49774.
2016-10-22 15:53:57 +02:00
François Revol
72ddc912a6 PPC: make arch_framebuffer.h more like ARM version
Now the only difference is the physical address, which is returned as
phys_addr_t as should be.
2016-10-22 15:53:52 +02:00
François Revol
f4dc609dbe U-Boot: PPC: dump the start of the board_data struct
Not so useful but just in case...

Sadly, this struct is both compile-time and arch dependent :-(
2016-10-22 15:53:47 +02:00
François Revol
9e66f03165 U-Boot: PPC: Try to enable unaligned transfers
This however doesn't help with the 64bit float operations that
gcc emits when assigning the physical framebuffer address in kernel_args,
which is a packed struct...
2016-10-22 15:53:38 +02:00
François Revol
e57c83d9e4 U-Boot: PPC: make the shift calculation more obvious
It's the 11th bit, counting from the MSB, on the top 16 bits.
2016-10-22 15:53:24 +02:00
François Revol
1fe7e6711f PPC: call debug_uart_from_fdt with C++ linkage 2016-10-22 15:53:20 +02:00
François Revol
11642b7f2c PPC: arch_asm.S: style fix
Capitalize TODO & FIXME, gedit prefers those
2016-10-22 15:53:15 +02:00
François Revol
33c594f0c7 PPC: U-Boot: fix gUBootOS offset
Since the removal of some other variables we were overwriting some random function.
2016-10-22 15:53:07 +02:00
François Revol
ffb9ffb68d PPC: Use FUNCTION_END in arch_asm.S 2016-10-22 15:52:51 +02:00
François Revol
9d0098ec04 ppc/paging: Convert to new-style CPU management
* Aka, post-scheduler changes
* Luckily PPC paging code is very similar to x86 paging now
2016-10-22 15:52:46 +02:00
François Revol
f5f6d7e600 PPC: compile arch_exception*.S in cpu-specific objects 2016-10-22 15:52:38 +02:00
François Revol
8dc55498fa PPC: rename arch_exceptions_44x.S to arch_exceptions_440.S 2016-10-22 15:52:29 +02:00
François Revol
094525151d PPC: Split cpu-specific files into separate objects 2016-10-22 15:52:16 +02:00
François Revol
d66182742f PPC: Stub out 460 paging classes 2016-10-22 15:52:08 +02:00
François Revol
62caef87ce PPC: Restructure paging stuff to match other platforms
First attempt.

Totally untested.
2016-10-22 15:51:57 +02:00
Julian Harnath
b2ef1767a7 x86 kernel stack trace: make sure memcpy stays in bounds
* Commit 337c4ccf introduced usage of plain memcpy in
  get_next_frame_no_debugger(), when the frame is already
  known to be on the kernel stack. However, it also needs
  to check that the end of the frame is still within the
  stack bounds. Otherwise this can cause a KDL if bp does
  not point to a valid complete frame anymore and is
  near a page boundary. Although with commit e477b10c such
  cases should already be avoided, it's still safer to
  check this here in case of e.g. analyzing broken stacks.
2016-10-17 22:27:04 +02:00
Julian Harnath
e477b10cef x86 kernel stack trace: break when return address is zero
* No need to continue walking the stack when a zero return
  address is found, only bogus frames will follow

* Fixes KDLs seen when using the system profiler, due to
  a bug that will be fixed in the next commit...
2016-10-17 22:26:02 +02:00
Andreas Faerber
51777fe86c Revert r25895: Undo ppc linkhack workaround #6210 2016-10-16 12:52:02 -05:00
Jérôme Duval
e340f717a4 runtime_loader: add support for ELF init/term routine arrays.
* binutils 2.27 defaults to DT_INIT_ARRAY instead of DT_INIT.
2016-10-11 22:26:06 +02:00
Sergei Reznikov
766191919d Added stub for get_nth_pci_info.
BeRometer works now.

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

This is a private API, but some apps used it anyway. We don't need a
complete implementation to at least make BeRoMeter run.

Fixes #5146.
2016-09-26 21:44:21 +02:00
Adrien Destugues
ed1b81b72b Boot loader VFS: fix string termination error.
The code was resetting the pointer to NULL, instead of setting the
pointed char to null-terminate the string. The result was resolving the
current directory later on, instead of the parent as requested.

This only happened when calling open_from with O_CREAT, and a name with
sub-directories inside it. The boot loader never does that, so the code
wasn't used until now.

Fixes #12941.

Thanks to mt for spotting the problem.
2016-09-17 11:15:00 +02:00
Jessica Hamilton
2da1cb75a4 EFI: device support for anyboot CDs.
I have tried to get normal ISOs working, but the bootloader doesn't
seem to detect any bootable partitions.
2016-09-03 01:58:41 +12:00
Jessica Hamilton
325b1e3787 EFI: add support for graphics mode output
* We can now switch between graphics and text modes, and display
  the splash screen
2016-09-02 19:02:35 +12:00
Jessica Hamilton
dbf1363b41 EFI: naive platform_allocate_region() implementation 2016-09-02 19:02:35 +12:00
Jessica Hamilton
96f4d68b2b EFI: check for boot keys
* Only supports spacebar for the boot menu, and escape for
  enabling debug output. Shift keys will not work.
2016-09-02 19:02:34 +12:00
Jessica Hamilton
c0bdc8bef5 bootloader: build objects in $(TARGET_BOOT_PLATFORM)
This separates the objects required for the various boot
loaders, allowing the build system to be able to build
for different targets alongside each other. Currently
only done for bios_ia32 vs efi, as both loaders will be
needed for the x86_64 images.
2016-09-02 19:02:34 +12:00
Jessica Hamilton
c0002a79e7 EFI: Implement heap 2016-09-02 19:02:33 +12:00
Jessica Hamilton
e2e1558a02 EFI: stub functions so we can call loader's main() function. 2016-09-02 19:02:33 +12:00
François Revol
495efc382b loader: Drop the HashMap for partition lookup by id
The HashMap constructor was called before the heap is initialized,
ending up calling malloc from the OpenHashMap constructor.

Oddly it was still working on x86 but broke other platforms.

Instead we add a Lookup() static method to Partition,
which by default walks gPartitions for the id,
and recursively calls itself on the children lists.

This means we must add a partition even temporarily to gPartitions
before Scan()ing it though.

Signed-off-by: François Revol <revol@free.fr>
2016-09-02 19:02:33 +12:00
Fredrik Holmqvist
735f1daee9 EFI: Implement console code. 2016-09-02 19:02:32 +12:00
Fredrik Holmqvist
bd0604764e Setup -fno-pic or -fpic in Architecture Rules.
EFI boot needs -fpic but all boot code was built with -fno-pic.
This is now set accordingly in HAIKU_BOOT_CCFLAGS and
HAIKU_BOOT_C++FLAGS.

Also setup compile flags for EFI platform.
2016-09-02 19:02:32 +12:00
Fredrik Holmqvist
211483cb51 EFI: Initial test EFI application
* Only set HAIKU_BOOT_PLATFORM to bios_ia32 if not defined
* Add gnuefi build feature
* Introduce BOOT_LDFLAGS, and move options for passing to linker
  into ArchitectureSetup
* x86_64 compile fixes for warnings in boot loader
* loader/elf.cpp: don't include ELF32 support when targeting EFI
* relocation_func.cpp: copy of the relocation code from gnuefi
  to make _relocate extern "C", and avoid including <efilib.h>
* boot_loader_efi.ld: copy of gnuefi's elf_x86_64_efi.lds,
  modified to include support for C++ constructors, etc. Keep in
  sync with the gnuefi package

Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
2016-09-02 19:02:29 +12:00
Adrien Destugues
2080509cb0 Fix some missing parentheses
* Problem found by gcc4.
2016-08-27 09:31:16 +02:00
Adrien Destugues
c92f19c6e8 Fix definition of _setjmp
The #pragma weak does not work, the symbol is not defined and when
already defined, it is not made weak. Moreover, it does not make the
symbol global so we need to declare it with a FUNCTION.

If we want the symbol to be weak, then we should use .weak to do so. The
_longjmp symbol should also be changed to match, in that case.

Fixes #12912.
2016-08-14 09:18:07 +02:00
Augustin Cavalier
4fecb09f14 libroot: Ship empty libpthread.a and libm.a for POSIX and general compatibility.
A few weeks back, I spotted in the Musl FAQ that they apparently ship
empty libm.a and libpthread.a files (https://www.musl-libc.org/faq.html),
which they said was for POSIX compatibility. A bit of digging got me to
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/c99.html which
says:

> It is unspecified whether the libraries libc.a, libl.a, libm.a, libpthread.a,
> librt.a, [OB] [Option Start] libtrace.a, [Option End] libxnet.a, or liby.a
> exist as regular files. The implementation may accept as -l option-arguments
> names of objects that do not exist as regular files.

So to follow the letter of the law, we only need to have the "c99" command
accept these; however, it appears all Linux and BSD cstdlibs accept them
no matter what compliance mode is in effect.

Discussed with PulkoMandy. This will make HaikuPorts' job a lot easier...
2016-08-13 11:16:06 -04:00
Adrien Destugues
8efb6db7b9 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.
2016-08-06 20:32:47 +02:00
Adrien Destugues
766f682338 Fix build and first runtime problem in network boot
The boot still crashes some time later, but at least it is easier to
test now.

- PackageFS included in the net boot archive
- Tell the system it is booted "from image" when netbooting
2016-08-06 20:29:08 +02:00
François Revol
02283e080c M68K: drop the custom C arch_cpu_user_mem*() for the default impl
I didn't notice there was a C++ version that didn't require writing asm.

I'll have to write them anyway for speed someday.
2016-07-20 21:57:19 +02:00
François Revol
169349c98f M68K: more SMP stubbing
We'll very much likely never support SMP on M68K...
(unless someone has an SMP machine to donate? :D)
2016-07-20 21:56:15 +02:00
François Revol
ad4b06aa75 m68k/paging: Convert to new-style CPU management
* Aka, post-scheduler changes
* Luckily M68K paging code is very simular to x86 paging
2016-07-20 21:28:56 +02:00
François Revol
9df4533caa M68K: use the updated atomic semantics
* Use atomic_get_and_set to return the old value
* Atomics are no longer volatile
2016-07-20 21:26:32 +02:00
François Revol
a462159ce3 M68K: Update to new system_info structures 2016-07-20 21:26:12 +02:00
François Revol
7cd7ba758c M68K: fix implicit casts of fault handler 2016-07-20 21:07:26 +02:00
François Revol
830fd19eb5 M68K: Fix spinlock initialization 2016-07-20 21:06:38 +02:00
François Revol
d26fd5f68d M68K: drop the platform_type field, the enum is gone from OS.h 2016-07-20 20:31:14 +02:00
François Revol
c094f04537 M68K: dos2unix some files
For some reason they used CR-LF.
2016-07-20 20:27:08 +02:00
François Revol
990d34efdd M68K: add arch_cpu_idle and arch_cpu_pause inline stubs
Remove the stub from arch_cpu.cpp

We might want to implement a 040 CPU module providing idle using LPSTOP.
2016-07-20 20:26:29 +02:00
François Revol
181391c106 ARM: Add TODO on barrier calls, we might need to do more here
They look suspiciously empty.
2016-07-20 18:53:24 +02:00
Ingo Weinhold
c60453fd79 Core dump: Add symbols for commpage to core file 2016-05-22 22:10:48 +02:00
Ingo Weinhold
90f571868e 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.
2016-05-22 22:10:47 +02:00
Ingo Weinhold
a689b8f22e kernel: team_create_thread_start_internal(): Set text_delta
The commpage's symbol table entries are commpage start relative.
2016-05-22 22:09:53 +02:00
Jérôme Duval
f022c304b0 readdir_r(): uses the logic of readdir()...
to retrieve more than one entry.
* readdir_r() is now affected by rewinddir(), thus fixing #12755.
* extends dirent_test with readdir_r().
2016-05-07 16:40:53 +02:00
Jérôme Duval
ab7c65d33d arm: remove duplicate arch_get_thread_debug_cpu_state(). 2016-05-02 21:25:05 +02:00
Ingo Weinhold
a0c364c70d Core file images note: Add text delta field 2016-04-29 22:32:15 +02:00
Ingo Weinhold
9266cd66c7 extended_image_info: Add text_delta field
Needed to offset a symbol address read from the symbol table to the
actual load address.
2016-04-29 22:32:14 +02:00
Ingo Weinhold
5cde7a856d Add symbol and string table addresses to core file 2016-04-27 02:16:54 +02:00
Ingo Weinhold
8c6cb8af01 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.
2016-04-27 02:16:09 +02:00
Ingo Weinhold
82185a52e2 Future proofing core file format
* The Haiku specific notes contain a structure size field, now.
* Change the type of the count and size fields in the Haiku specific
  notes to uint32 also for 64 bit ELF. The size field for a note is a
  uint32 anyway.
2016-04-27 00:55:23 +02:00
Ingo Weinhold
467fe4ca0c kernel: Add core dump facility
* Add function core_dump_write_core_file(). It writes a core file for
  the current thread's team. The file format is similar to that of
  other OSs (i.e. ELF with PT_LOAD segments and a PT_NOTE segment), but
  most of the notes are Haiku specific (infos for team, areas, images,
  threads). More data will probably need to be added.
* Add team flag TEAM_FLAG_DUMP_CORE, thread flag
  THREAD_FLAGS_TRAP_FOR_CORE_DUMP, and Team property coreDumpCondition,
  a condition variable available while a core dump is progress. A
  thread that finds its flag THREAD_FLAGS_TRAP_FOR_CORE_DUMP set before
  exiting the kernel to userland calls core_dump_trap_thread(), which
  blocks on the condition variable until the core dump has finished. We
  need the team's threads to stop so we can get their CPU state (and
  have a generally unchanging team state while writing the core file).
* Add user debugger message B_DEBUG_WRITE_CORE_FILE. It causes
  core_dump_write_core_file() to be called for the team.
* Dumping core as an immediate effect of a terminal signal has not been
  implemented yet, but that should be fairly straight forward.
2016-04-24 18:22:14 +02:00
Ingo Weinhold
ac1f1a926e kernel: +image_iterate_through_team_images()
Like image_iterate_through_images(), but iterates though the images of
the given team only.
2016-04-24 17:30:52 +02:00
Ingo Weinhold
99f00556a4 kernel: +arch_get_thread_debug_cpu_state()
Similar to arch_get_debug_cpu_state(), but the thread whose CPU state
to retrieve is specified. Works only for threads that aren't running,
and on x86-64 we can get the FPU state only when the thread was
interrupted in userland.
Not implemented for the incomplete architecture ports.
2016-04-24 17:29:28 +02:00
Ingo Weinhold
7a187cd629 _user_debug_thread(): Use new signal SIGNAL_DEBUG_THREAD
This resolves a TODO: We used thread_interrupt() to wake up the thread
from an interruptable wait. However, if the thread was already in the
kernel and about to start waiting, that would have no effect and the
thread would wait anyway. Now there's the new non-blockable signal
SIGNAL_DEBUG_THREAD, which is sent to the thread instead, making sure
that thread doesn't start waiting.
2016-04-24 11:54:17 +02:00
Fredrik Holmqvist
20e11028aa Don't use partition pointer as id, as it only works on 32bit platforms.
Use a counter to generate the partition id, and store the id to partition
lookup in a hashmap instead.
2016-04-14 19:18:21 +12:00
Dario Casalinuovo
2b05e191ce Revert "Force runtime_loader permissions during build"
This reverts commit f45b1ff242.
2016-04-06 12:12:25 +02:00
Dario Casalinuovo
f45b1ff242 Force runtime_loader permissions during build
* Fixes #12373.
2016-04-06 00:29:38 +02:00
Axel Dörfler
67988f501a NodeMonitor: Resolve mount points for B_WATCH_CHILDREN.
* When a watched directory contains a mount point, we need to resolve
  the actual parent directory of the mount point in the file system to
  serve the monitor.
2016-03-28 14:31:27 +02:00
Axel Dörfler
6f7fc2204b NodeMonitor: Added B_WATCH_CHILDREN flag.
* Added a directory argument for notify_{stat/attribute}_changed().
* This allows to watch only a directory, and get the notifications for
  all of its files, not just add/remove entry notifications.
2016-03-28 14:31:27 +02:00
Michael Lotz
3108c9bed0 ioapic: Fix 64 bit build with tracing enabled, some cleanup.
* Use print format macros to fix the 64 bit build.
* Correct a typo in the shift of the trigger mode definition. As the
  value is 0 either way, this does not make a functional difference.
* Use macros instead of values in comparisons.
2016-03-12 13:34:01 +01:00
Adrien Destugues
3b4f50d3fb Style fix.
Thanks to axel for watching!
2016-03-04 20:01:58 +01:00
Adrien Destugues
93ea83e53d Allow custom baud rates for FTDI serial ports
- Termios: cf{get,set}{i,o}speed can handle arbitrary speed values.
- The value is stored in the appropriate fields of the termios structure
  in this case. The old constants (stored in the flags) are preserved
  for BeOS binary compatibility.
- Adjust the FTDI FT232* driver to accept custom rates, by replacing the
  hardcoded regster values with a function that will compute it
  according to FTDI documentation (confirmed giving the same values for
  the existing baudrates).
2016-02-27 19:08:53 +01:00
François Revol
e89ef1fef7 U-Boot: TRACE fdt_serial instead of dprintf
and disable it by default (it would hang on some platforms anyway).
2016-02-26 22:59:33 +01:00
François Revol
c82af4bebe U-Boot: try to use virtual-reg to get the UART
XXX: possibly only for _BOOT_MODE?
2016-02-26 22:58:45 +01:00
François Revol
14cfccd011 U-Boot: add a 'physical' arg to fdt_get_device_reg()
If false, try to use the virtual-reg property first.
2016-02-26 22:58:17 +01:00
François Revol
73ef47f70a loader: TRACE undefined symbols
While the kernel shouldn't have any, it happens on platforms missing new features.

Make it explicit.
2016-02-26 22:57:06 +01:00
Alexander von Gluck IV
4e7b05cca2 platform/bios_ia32: Fix regression introduced in hrev48326
* Reverts f3e381dd
* Details in #12633
* For some unknown reason, this change breaks an Intel Core 2
  system from booting (Dell Optiplex 960, E8400)
* If anyone has any ideas on why, let me know :-)
2016-02-02 18:48:19 -06:00
Adrien Destugues
9ec8a1e4d9 Kernel POSIX: add stpcpy.
- Required by new GCC versions, which are able to optimize string
  appends using it.
- Fixes build of ACPICA for x86/gcc4.
2015-12-29 10:24:06 +01:00
Michael Lotz
28d3c8ca50 runtime_loader: Resync heap impl with the one of the bootloader.
The heap implementation of the runtime_loader was switched to the one
of the bootloader in 6f0994d but was since updated independently.

To keep the diff between the two implementations as small as possible,
the bootloader implementation was first copied to the runtime_loader
and then some features not relevant in the runtime_loader (like the
special large allocation handling) have been removed and the
runtime_loader specific features (grow_heap, add_area) have been
reintegrated. But basically this applies 96689a5..HEAD of
src/system/boot/loader/heap.cpp to the runtime_loader heap.

This brings in the switch from a linked list to a splay tree based
free chunk management. Since the allocation counts in the runtime_loader
are rather small, this does not perceptibly affect performance in either
direction though.
2015-12-27 13:54:48 +01:00
Michael Lotz
8bbfae7b05 runtime_loader: Fix endless rld heap grow loop in edge case.
The needed storage space for tracking the allocation size was not
accounted for when growing the heap. Since the growth size is always
rounded up to a multiple of 32KiB, this did almost never matter as the
new allocation wouldn't need the full size. If the allocation did
happen to need the full size however, the newly added area would always
be too small. As the allocation attempt was simply restarted after each
successful growth, this lead to an endless loop creating small new
areas, which would then quickly starve the system for memory.
2015-12-27 13:54:47 +01:00
Augustin Cavalier
6984b8554c Revert "libroot: Undefine constants for unsupported POSIX features"
This reverts commit 7aebec8db1.
As per the discussion on the mailing list.
2015-12-21 12:16:33 -05:00
Simon South
7aebec8db1 libroot: Undefine constants for unsupported POSIX features
Haiku does not yet support certain features related to POSIX threads.
Constants used to test for the presence of these features should
therefore be left undefined, according to the POSIX spec, but are
currently set to -1. This can cause software built on Haiku to
incorrectly detect the presence of these features.

* unistd.h: Undefine _POSIX_THREAD_ATTR_STACKADDR,
  _POSIX_THREAD_PRIORITY_SCHEDULING feature constants.
* conf.cpp: __sysconf: Return -1 for unsupported features.

Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
2015-12-21 11:09:34 -05:00
Simon South
dbf060a3f7 libroot: Add brk() and sbrk().
This commit replaces the placeholder implementation of sbrk(), which
operated on a process' heap, with real implementations of brk() and
sbrk() that adjust a process' program break.

* unistd.h: Add standard definitions of brk() and sbrk(); include
  stdint.h for intptr_t.
* thread.cpp: Recognize RLIMIT_AS and RLIMIT_DATA resource limits
  (both currently unlimited); order limit identifiers alphabetically.
* arch-specific.cpp: Remove sbrk_hook().
* malloc_debug_api.cpp: Remove sbrk_hook().
* unistd/Jamfile: Build brk.c instead of sbrk.c.
* unistd/brk.c: Add.
* unistd/sbrk.c: Delete (placeholder implementation).
* libroot_stubs.c: Remove sbrk_hook().
* libroot_stubs_legacy.c: Remove sbrk_hook().
* src/tests/.../posix/Jamfile: Build brk_test.c.
* brk_test.c: Add (simple unit test that demonstrates behaviour of
  sbrk()).

Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>
2015-11-22 17:59:22 +01:00
Michael Lotz
ba307a12db vfs: Cleanup: Move functions around for more logical grouping.
Move static internal functions out of the API functions block and drop
their vfs_ prefix and move an API function into the API functions block.
2015-11-08 22:31:56 +01:00
Michael Lotz
c73d13015d 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.
2015-11-08 22:31:56 +01:00
Jonathan Schleifer
f7ededa623
shell.S: Add .section .bss to make Clang happy 2015-11-08 16:30:40 +01:00
Jonathan Schleifer
50a1d86c88
byteorder.S: Use flds instead of fld
Clang refuses to guess.
2015-11-08 16:27:31 +01:00
François Revol
c518435bb1 VFS: pass correct vnode to fs calls in default get_vnode_name
The opendir and closedir/free_dircookie hooks were called with
mismatched vnode. It seems only googlefs is actually affected by this,
since all other fs without a get_vnode_name just don't are about the
passed vnode arg to closedir and free_dircookie.

Now I should really get some sleep!
2015-11-08 04:32:57 +01:00
François Revol
8f4a653ca6 VFS: typo 2015-11-08 04:32:57 +01:00
Jonathan Schleifer
93bcaf3650
arm/arch_exceptions.S: Replace spsr_all with spsr
After a quick look at binutils, they seem to be equal, however, Clang
does not accept the _all one.
2015-11-08 00:59:18 +01:00
Jonathan Schleifer
15d594cccd
ARM: Add __aeabi_memset and __aeabi_memmove alias 2015-11-08 00:54:32 +01:00
Jonathan Schleifer
d8548e00aa
Fix some more type mismatches with std::{min,max} 2015-11-08 00:44:18 +01:00
Jérôme Duval
6c4cca34c2 glibc: replace extern __inline with __extern_always_inline for x86.
* also update __atan2l for x86, update __FAST_MATH sections.
2015-11-08 00:38:20 +01:00
Jérôme Duval
b49dd60c46 Drop namespace std after 95d4ed6778. 2015-11-08 00:38:19 +01:00
Jonathan Schleifer
c7624537a3
ARM: Alias __aeabi_memcpy to memcpy 2015-11-07 23:11:14 +01:00
Jonathan Schleifer
55de0addd5
arm/arch_string.S: Only use sane insns for Clang 2015-11-07 18:29:50 +01:00
Jonathan Schleifer
ed6dfed2a0
Fix a type mismatch for std::min() 2015-11-07 18:16:40 +01:00
Jonathan Schleifer
71e0324992
Move new / delete kernel_cpp.h -> kernel_cpp.cpp
new and delete may not be defined as inline, as Clang loudly complains.
The same is true for static.
2015-11-07 18:16:23 +01:00
Jonathan Schleifer
b310316956
Fix arm/arch_string.S for Clang 2015-11-07 18:08:01 +01:00
Jonathan Schleifer
95d4ed6778
Add missing "using std::nothrow" 2015-11-07 18:08:01 +01:00
Simon South
75c31ae28d system: Build using public elf.h header
Reduce duplication of code by

* Removing from elf_common.h definitions available in os/kernel/elf.h
* Deleting elf32.h and elf64.h
* Renaming elf_common.h to elf_private.h
* Updating source to build using public and private ELF header files
  together

Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
2015-11-07 11:49:56 +13:00
Simon South
874e9521b2 x86_64: Glue code: Keep stack 16-byte-aligned
Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>
2015-10-28 21:24:34 +01:00
Jérôme Duval
6c009cde0b kernel: avoid dprintf messages for known header types we don't use.
* fix a typo in runtime_loader/count_regions().
2015-10-28 21:21:56 +01:00
Simon South
d5447eb9c0 runtime_loader: Do not assume executable has dynamic segment
This prevents a crash when loading a statically linked executable.

Fixes #12287.

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
2015-10-26 21:23:30 +01:00
Simon South
078b88b12d runtime_loader: Randomly position only relocatable code
The use of an unreliable test for relocatability effectively broke
runtime_loader's support for non-position-independent executables, as it
would insist on randomly positioning these files' segments in memory
anyway causing the program to quickly crash.

With this change runtime_loader uses the object type specified in the
file's header to determine whether its segments can be safely relocated,
restoring support for non-PI executables.

Fixes #12427.

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
2015-10-26 21:19:25 +01:00
Murai Takashi
1e6dd3feed Fix GCC 5 maybe-uninitialized warnings.
Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

Fixes #12020
2015-10-26 21:13:24 +01:00
Murai Takashi
949cf6ac85 Fix GCC 5 build.
* Add -fgnu89-inline flag for libroot/posix/glibc
* Change __GNUC__ == 4 to __GNUC__ >= 4

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

Fixes #11990, most of the changes had already been done.
2015-10-26 19:05:24 +01:00
Adrien Destugues
1388211503 Implement stat.st_rdev for block and character devices.
* devfs: set st_rdev to the inode number of the node being queried. This
  may not be the best thing to do, as it does not match what is set in
  st_dev for other files, so it can't be used to find which device
  stores a particular file. I'm not sure if st_rdev is actually used that
  way anywhere, however.
* vfs: do not clobber st_rdev with -1 for "special" (device) files.
  Refactor the code a little so setting the common attributes is done in
  a single place.

Fixes #12390.
2015-10-11 18:26:21 +02:00
Simon South
5df5223b4b kernel: Don't send SIGTTOU if calling thread is blocking it
POSIX requires SIGTTOU to be sent to a process in a background process
group that tries to change the foreground process group ID associated
with its controlling terminal, unless the process is ignoring SIGTTOU or
the calling thread is blocking it. Previously the code checked the
former condition but not the latter, making it possible for calls to
tcsetpgrp() to get stuck in a loop and never return.

Should fix #3417.

Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
2015-10-08 19:25:31 -04:00
François Revol
594187ade2 glibc/ppc: add missing math stuff
hopefully fixing the build for the 53rd time...
2015-09-18 03:59:56 +02:00
François Revol
bbdf4c27fa glibc: avoid linking long double math stuff on PPC and M68K 2015-09-18 03:59:56 +02:00
François Revol
dab2aa8189 complex.h: fix __NO_LONG_DOUBLE_MATH test
PPC doesn't support long double yet...
2015-09-18 03:59:55 +02:00
Jessica Hamilton
8927348ef1 Boot menu: change colours of sub-menu headers. Fixes #12371.
Changed from white on red background, to yellow on black
(neutral) background. Red on black made it look like a
warning, whereas yellow feels more informative.
2015-09-15 01:32:07 +00:00
Axel Dörfler
eb62d3337b VFS: Slight rework of the FD disconnect feature.
* This should fix ticket #4157, although I probably have missed
  something.
* In any case, it no longer messes with the ref counts of the
  file descriptor, and the race condition in put_fd() should be
  gone.
* It's still rather messy all in all.
2015-09-11 17:25:01 +02:00
Axel Dörfler
6adf7a0c75 VFS: prevent FD inheritance for the kernel completely.
* Each io_context now has a "inherit_fds" member that decides whether
  or not this context allows to inherit FDs to its children.
* This replaces the former O_CLOEXEC mechanism.
2015-09-11 17:08:35 +02:00
Axel Dörfler
e668e80db0 VFS: Always open kernel FDs with O_CLOEXEC.
* Avoids leaking them into userland.
2015-09-11 08:57:15 +02:00
Michael Lotz
d64c7086d5 Various whitespace cleanup only. 2015-09-05 16:09:33 +02:00
Michael Lotz
8b9bb054f4 libroot_debug: Replace two more uses of printf in guarded heap.
Use the internal print_stdout() instead as done when printing the
stack traces.
2015-08-23 13:19:12 +02:00
Michael Lotz
5dbea46970 libroot_debug: Track freeing thread in guarded heap separatley.
Previously the thread member was overwritten with the freeing thread
when a page was freed, leading to confusion when hitting unallocated
pages due to the debugger message still stating "allocated by thread".

Track the freeing thread separately as it might be interesting to know
both, which thread initially allocated and which thread eventually freed
an allocation.
2015-08-23 13:10:12 +02:00
Michael Lotz
c4a9344a11 libroot_debug: Support alignments > B_PAGE_SIZE in guarded heap.
These are always allocated using an area. The allocation size is
increased as to guarantee the availability of a suitable address. The
pages between the allocation info and the actual, aligned start address
and the pages past the allocation end are then protected.

This commit also fixes corruption of the allocation info for large
allocations that used areas. The alignment wasn't taken into account
when calculating the amount of space needed. The alignment could then
lead to rounding down the allocation start such that it would overlap
with the allocation info.
2015-08-20 21:59:41 +02:00
Michael Lotz
5d4501aa01 Assorted whitespace cleanup and typo fixes. 2015-08-20 21:54:41 +02:00
Michael Lotz
efb0a3a853 EntryCache: Add entry_cache_add_missing() for negative caching.
It provides a way for filesystems to cache a lookup failure and
therefore prevents repeated lookups of missing entries. This is a
common scenario for example in command lookup and compiling, where
each directory in PATH or each include directory is searched for the
given entry.
2015-08-20 21:25:56 +02:00
Alexander von Gluck IV
5d91a421b9 glibc/arm: More generic math functions 2015-08-15 00:00:26 -05:00
Alexander von Gluck IV
76cc2d8f45 glibc/arm: Filling in more ARM gaps 2015-08-14 21:06:40 -05:00
Alexander von Gluck IV
17ddd6c09d libroot/arm: Add in some missing math functions
* Using native assembly functions would be a lot faster,
  but would require quite a bit of changes to glibc.
* This gets arm linking for now... I'd personally like
  to see musl in here in the future for gcc4 images. (pre-R2)
2015-08-14 13:46:05 -05:00
Alexander von Gluck IV
ab341b9d63 kernel/arm: Correct platform id on ARM 2015-08-14 12:50:05 -05:00
Michael Lotz
1748116d1c libroot_debug.so: Fix missing alignment in guarded realloc. 2015-08-13 22:33:55 +02:00
Michael Lotz
8fa441bf5c libroot_debug: Revert to a legacy default alignment of 8.
This reverts the legacy default alignment (in absence of max_align_t)
to 8, as it was before.
2015-08-13 22:12:19 +02:00
Michael Lotz
f474606ee9 libroot_debug: Merge guarded heap into libroot_debug.
The individual debug heap implementations are now exposed via a
structure of function pointers and a common frontend dispatches the
malloc and malloc_debug APIs through them.

The MALLOC_DEBUG environment variable can be used to select the guarded
heap by adding 'g', otherwise the debug heap is used as the default.
Consequently the separate libroot_guarded is not needed anymore and has
been removed.

To allow the use of environment variables this early, init_env_post_heap
has been added and the heap dependent atfork() moved there. This allowed
to fold the code of init_heap_post_env into init_heap so the former has
been removed.
2015-08-13 22:12:18 +02:00
Rene Gollent
422b0ec754 libroot: Fix issue reported in ticket #12291.
fts.c:
- Our fts functions were imported from FreeBSD and consequently did not
  use the same weak alias methodology that most of our glibc-derived
  POSIX functions do. These subsequently wound up clashing with the
  implementation of said functions in current versions of coreutils,
  resulting in assertion failures when e.g. running a program through
  stdbuf, since the BSD-derived functions had different flag constraints
  than their GNU peers. Consequently, this change adjusts the fts_*
  family of functions to similarly be exported as weak symbols so they
  can be preempted.
2015-08-10 17:01:35 -04:00
Michael Lotz
f9a8f3e727 Clean up various whitespace and fix one header guard. 2015-08-02 23:19:07 +02:00
Rene Gollent
27dec4bb1e user_debugger: Adjust handling of continue request.
- B_DEBUG_MESSAGE_CONTINUE_THREAD now checks if the thread in question
  is in a suspended state rather than waiting on the debug nub port, and
  if so, handles resuming it automatically. This allows the continue message
  to be used on the main thread of a team that was freshly created under
  debug control without the API user having to be cognizant of the distinction.
2015-07-31 17:28:00 -04:00
Jérôme Duval
2a868d7645 glibc: replace extern __inline with __extern_inline.
* this helps to comply with C99. As a reminder, some of these headers
are also used by x86_gcc2 src/libs/stdc++.
2015-07-26 10:09:22 +02:00
Rene Gollent
410b38b5c5 libroot: Fix strto{i,u}max.
- According to POSIX, these functions should map to whatever's appropriate
  for the platform's intmax_t size, which in our case is a 64-bit integer.
  Our (2004) implementation, however, was calling the 32-bit variations of
  strto*(), leading to truncation for larger values.
2015-07-24 21:57:11 -04:00
Axel Dörfler
34671d601a Added execvpe().
* This closes #12114 again; while not POSIX, it's just a line away.
* Removed exect() from the header -- not sure where this came from.
  but I can't find anything about it on the net.
* Consolidated use of asterisk style in exec.cpp.
2015-07-23 13:30:30 +02:00
Axel Dörfler
463d38e40b Fixed exec*(), and __flatten_process_args() with NULL env.
* Not sure if it's following any standard, but environ can be NULL
  (either by manually setting it to NULL, or by calling clearenv()).
2015-07-22 20:44:12 +02:00
Axel Dörfler
7987907008 launch_daemon: We can now talk to the authentication manager.
* When creating the port of the registrar's authentication manager, we
  now set it manually, so that the user/group functions work.
* This allows LaunchDaemon::_StartSession() to set up the user, and
  groups as needed.
2015-07-22 20:43:26 +02:00
Axel Dörfler
ef462ab57f libroot: ensure that the launch_daemon doesn't wait for itself.
* The launch_daemon might indirectly call get_launch_daemon_port()
  which may cause a deadlock. Just fail in this case.
2015-07-22 20:41:09 +02:00
Axel Dörfler
1f374c8b2a libroot: hardcode find_directory() to /home/boot for root.
* This is a work-around to allow the registrar, and the launch_daemon
  to call find_directory() without worries.
2015-07-22 20:41:05 +02:00
Axel Dörfler
bea38cb711 registrar: implemented auth port via launch_daemon.
* get_roster_port_name() is no longer needed.
* This also removes the app_server restart code from the debug
  server -- this will be done by the launch_daemon in the future.
2015-07-22 20:41:01 +02:00
Axel Dörfler
4bf862e368 syslog_daemon: Converted to BServer.
* Instead of letting the kernel search for the syslog port, the
  daemon now registers itself with the kernel (which even solves
  a TODO).
* A port is created for the actual log messages from the launch_daemon,
  and used on start.
* However, the SyslogTest does not yet work, due to the BMessage <->
  KMessage communication problems.
2015-07-22 20:40:47 +02:00
Axel Dörfler
9d69dc097d libroot: added ability to communicate with the launch_daemon.
* These methods don't really work yet, as BMessage doesn't support
  replying with a KMessage; the request is received, but the reply
  never gets to the target.
2015-07-22 20:40:42 +02:00
Axel Dörfler
89168ad8b9 Boot the system via launch_daemon.
* This is actually working already, although we cannot reproduce all
  the features of the former Bootscript yet. This is without any
  dependency support in launch_daemon.
* All shell activity like cleaning out /tmp, setting up the environment,
  setting the time, etc. is not yet working.
2015-07-22 20:40:33 +02:00
Axel Dörfler
035e3e77ed kernel: profile system when SYSTEM_PROFILER is defined.
* This enables a mechanism to profile almost the complete boot process
  (starting with main2()), if SYSTEM_PROFILER is defined to 1.
* You can access the profiling data using "profile -r".
2015-07-22 20:39:52 +02:00
Jérôme Duval
a83446983d libroot: added a complex.h header based on ...
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/complex.h.html
* added missing parts from glibc.
* x86_64 was already complete, x86 was missing a few functions.
* should help with #12202, provided that the gcc4 buildtools are rebuilt.
2015-07-10 22:39:21 +02:00
Ingo Weinhold
fb29004aaf disk device manager: Remove obsolete include path
virtualdrive hasn't been used for a long time. Should help with #12162.
2015-07-05 09:40:13 +02:00
Augustin Cavalier
6eafb4b041 Replace a few references to Subversion with Git.
There are a whole bunch more of these around, but these were the
ones I was confident replacing.
2015-06-19 15:36:52 -04:00
Jérôme Duval
0dc6b011fe malloc: implement malloc_usable_size().
* Fix #12132
2015-06-13 14:29:11 +02:00
François Revol
78b7298197 u-boot: PPC: Fix warnings 2015-06-12 23:18:33 +02:00
Hamish Morrison
b092f872b3 fork: update the thread id in the pthread struct after forking
Otherwise the child process's main thread will inherit the thread id
of its parent and pthread operations will be directed at the wrong
thread.
2015-06-04 13:36:29 +01:00
Hamish Morrison
9afa331102 chown: leave owner and group unchanged when values of -1 are passed 2015-06-02 16:54:40 +01:00
Hamish Morrison
d6d439f3f7 Reimplement unnamed POSIX semaphores using user_mutex
* Fixes sharing semantics, so non-shared semaphores in non-shared
  memory do not become shared after a fork.
* Adds two new system calls: _user_mutex_sem_acquire/release(),
  which reuse the user_mutex address-hashed wait mechanism.
* Named semaphores continue to use traditional sem_id semaphores.
2015-05-24 14:03:40 +01:00
Axel Dörfler
748c0f3021 kernel: Fixed broken port tracing.
* Broken since the scheduler merge.
2015-05-11 22:55:41 +02:00
Hamish Morrison
fb67dbf0a4 user mutex: dequeue waiters when waking them up
* This prevents the same waiter being woken multiple times, before it
  has a chance to run and dequeue itself.
2015-05-07 23:20:54 +01:00
Hamish Morrison
10b4fed24f Add support for pthread_condattr_get/setclock()
* Allows use of either CLOCK_REALTIME or CLOCK_MONOTONIC as the time
  base for pthread_cond_timedwait().
2015-05-02 20:55:57 +01:00
Humdinger
040029e0b8 Have B_FIND_PATH_LIB_DIRECTORY return the architecture.
Fixes #12028.
2015-04-28 08:07:22 +02:00
François Revol
a2ddc1c06e Fix CompileDTS rule to locate the device tree blob properly
This avoids having to call it from the BoardSetup files.
2015-04-24 02:27:55 +02:00
Michael Lotz
5d05694ad6 kernel guarded heap: Implement allocations debugger command.
It can be used to dump the current heap allocations with their details
and stack traces if enabled.
2015-04-23 23:04:38 +02:00
Michael Lotz
453ee84e23 kernel guarded heap: Also store team id for allocations. 2015-04-23 23:01:53 +02:00
Michael Lotz
337c4ccf01 kernel debugger: Use memcpy for stack trace on kernel stack.
If it was already determined that the memory is within the kernel
stack, a simple memcpy is enough.

This allows capturing kernel stack traces in situations where a fault
handler cannot be installed (i.e. where one is already installed).
2015-04-23 22:54:45 +02:00
François Revol
5c2425a61e PPC: fix COFF bootloader entry point
The concept of entry point in COFF is actually different than in ELF.

In COFF, the entry point is actually a "descriptor" (pointer) to the actual
start code. So we patch the entry point address when calling objcopy.

Now my old Performa 5400/180 actually starts the loader correctly \o/
2015-04-22 02:43:35 +02:00
François Revol
ade89bf38e PPC: simplify the bootloader linker script
the OF 2.0 COFF loader skips sections other than
.text .data and .bss, so merge others into those three.
2015-04-22 02:43:34 +02:00
François Revol
c3bffc88c9 fix warnings 2015-04-21 00:25:30 +02:00
François Revol
10e57f6e58 PPC: fix handler type cast 2015-04-20 17:19:33 +02:00
Alexander von Gluck IV
f178e4a248 arm: bcm2835 framebuffer
* Drop some messy mmu externs
* Set proper page flags
2015-04-19 20:13:24 -05:00
Alexander von Gluck IV
f427a82d48 arm: Add debug function to dump mmu state
* We don't change the data cache (and other) settings.
  Interesting to know their state on each platform.
* Not used by default as it needs called after
  serial-init in u-boot
2015-04-19 20:13:23 -05:00
Michael Lotz
9bf9ee3806 Whitespace and style cleanup only. 2015-04-12 18:50:01 +02:00
PulkoMandy
7d82b5d4ab arm/mmu: Fix boot on beagle-xm
* The changes for pi2 support led to the virtual addresses overlapping
with the page table again on the beagle, because the kernel address
space overlaps with the physical RAM identity mapped. Try to find a
memory range in a way that will work in both cases.
2015-04-12 17:52:24 +02:00
Alexander von Gluck IV
9c5e234cb3 arm: Initial Cubieboard4 work
* SD cards are "blessed" with a boot0 spl and boot1 u-boot
  at fixed locations.
* Allwinner's u-boot is lacking a lot.
* Upstream u-boot should be better at some point. WIP:
  http://lists.denx.de/pipermail/u-boot/2015-January/201537.html
2015-04-11 16:53:04 -05:00
Michael Lotz
97ebc043a6 Remove empty file probably accidentally added in hrev47198. 2015-04-11 23:37:55 +02:00
Michael Lotz
8f9d4cad45 syscalls: Remove get_stack_trace syscall again.
This reverts the other half of b959d46dbd.
2015-04-11 23:37:55 +02:00
Michael Lotz
3dfbe1a12d guarded_heap: Use __arch_get_stack_trace() instead of syscall.
The stack base and end addresses are stored in TLS slots that are
prepared when enabling stack traces and filled in lazily on use for
each thread. This avoids the need of calling get_thread_info to get
these values.

Also simplifies the code somewhat due to proper frame skipping support.
2015-04-11 23:37:54 +02:00
Michael Lotz
c012e7e930 libroot: Add private __arch_get_stack_trace().
It can be used to get a stack trace of the current thread. Note that
this works by walking frame pointers and will not produce anything
useful if an application is compiled with the frame pointers omitted.

The stack base and end addresses have to be provided as arguments and
are used to check that the frame pointers fall within that range. These
values are thread specific and can be retrieved with get_thread_info().
No other sanity checks (like checking for loops in the linked list) are
done.

This is a simplified rewrite of the stack trace code from the kernel
debugger.

As this code is common to x86 and x86_64 but is not generic across
architectures I introduced x86_common as a directory to put such
sources.
2015-04-11 23:37:54 +02:00
Michael Lotz
459e651fd5 syscalls: Remove lookup_symbol syscall again.
This partially reverts b959d46dbd.
2015-04-11 11:18:51 +02:00
Michael Lotz
bd5dea318a guarded_heap: Replace symbol lookup syscall with runtime_loader.
Use the private runtime_loader API to do the symbol lookup instead of
using the syscall.
2015-04-11 11:18:51 +02:00
Michael Lotz
ebdc1d480e runtime_loader: Add imageName and exactMatch to symbol lookup.
Extend the get_nearest_symbol_at_address() private runtime_loader
export to include imageName and exactMatch arguments.

The imageName holds the SONAME of the image, if available, so cannot
neccessarily be extracted from the image path.

Whether or not there was an exact match, i.e. the symbol with its size
contains the address, is now returned in exactMatch.
2015-04-11 11:18:50 +02:00
Michael Lotz
0cf3d62115 Make guarded heap accessible through its own libroot_guarded.so.
This adds libroot_guarded.so to the HaikuDevel package. It is the same
as libroot_debug with the debug heap swapped out for the guarded heap.
The guarded heap has some useful features that make it desirable to use
while having the disadvantage of a large memory and address space
overhead which make it unusable in some situations. Therefore the
guarded heap cannot simply replace the debug heap but should still be
made available. As the heap init needs to happen even before having
environment variables, the heap to use can not be chosen dynamically.
Exposing them through their own libraries is the next best thing.
2015-04-11 09:41:25 +02:00
Michael Lotz
74c284545b malloc_debug: Remove condition that is always true. 2015-04-10 17:11:56 +02:00
Michael Lotz
ec0190adb0 malloc_debug: Implement allocation dump on exit in guarded heap.
When enabled (using heap_debug_dump_allocations_on_exit(true) or
MALLOC_DEBUG=e) this causes a dump of all remaining allocations when
libroot_debug is unloaded. It uses terminate_after to be called as
late as possible.

When combined with alloc stack traces this makes for a nice if a bit
crude leak checker. Note that a lot of allocations usually remain
even at that stage due to statically, lazyly and globally allocated
stuff from the various system libraries where it isn't necessarily
worth the overhead to free them when the program terminates anyway.
2015-04-10 17:04:28 +02:00
Michael Lotz
e26a4e7b7a malloc_debug: Also print stack traces when dumping guarded heap. 2015-04-10 16:49:02 +02:00
Michael Lotz
607ac916de malloc_debug: Impl. heap_debug_dump_allocations in guarded heap. 2015-04-10 16:42:29 +02:00
Michael Lotz
158e20e60e malloc_debug: Implement alloc/free stack traces in guarded heap.
When configured to do so (using heap_debug_set_stack_trace_depth(depth)
or MALLOC_DEBUG=s<depth>) the guarded heap now captures stack traces on
alloc and free.

A crash due to hitting a guard page or an already freed page now dumps
these stack traces. In the case of use-after-free one can therefore see
both where the allocation was done and where it was freed.

Note that there is a hardcoded maximum stack trace depth of 50 and that
the alloc stack trace takes away space from the free stack trace which
uses up the rest of that maximum.
2015-04-10 16:28:42 +02:00
Michael Lotz
f4bd38257b Whitespace cleanup only. 2015-04-10 16:10:05 +02:00
Michael Lotz
b959d46dbd 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.
2015-04-10 16:00:49 +02:00
Michael Lotz
416255de4e libroot: Fix typo in static variable name. 2015-04-10 15:05:13 +02:00
Michael Lotz
abf230a9ac malloc_debug: Set default alignment to max_align_t if available.
For it to be available we build malloc_debug in C++11 mode when not
using GCC2. Note that max_align_t is not in the std namespace in GCC4
versions prior to GCC 4.9. The extra "using namespace std" is there to
be forward compatible once we update.
2015-04-08 12:56:58 +02:00
Ithamar R. Adema
efdcada6f3 BlockWriter: Do not panic on failing read/writes
These were here for debugging purposes, as often it is a sign of
inconsistencies. However, for USB disks this is a normal occurence
when someone janks out of the device without unmounting first.

Make sure we log these cases though, as it still helps debugging.

Fix sponsered by http://www.izcorp.com
2015-04-05 22:18:09 +02:00
Michael Lotz
121655e9ee malloc_debug: Add default alignment option.
This allows for something similar as was implemented in 217f090 but
makes it optional and configurable.

The MALLOC_DEBUG environment variable now can take "a<size>" to set
the default alignment to the specified size. Note that not all
alignments may be supported depending on the heap implementation.
2015-04-04 22:55:57 +02:00
Michael Lotz
b0e31a9ce3 Revert "malloc_debug: align allocations".
This reverts commit 217f090f9e.

At least for the guarded heap this completely defeats the purpose. If
software requires a certain alignment it should request it using
memalign explicitly instead of assuming it.
2015-04-04 22:55:57 +02:00
Michael Lotz
37acb83e4c libroot_debug: Fix build of guarded_heap after atomic changes. 2015-04-04 11:04:35 +02:00
Michael Lotz
ffba66060b UserlandFS: Make 64 bit clean and enable build for x86_64.
I did not bother to fix the BeOS kernel emulation, so this part is
still left out of the x86_64 build.
2015-03-29 16:25:17 +02:00
Murai Takashi
cddfcf2f87 Fix incorrect initialization.
Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>
2015-03-29 11:01:31 +02:00
Alexander von Gluck IV
3f80e2801f loader/fatfs: Fix tracing 2015-03-28 17:36:53 -05:00
Alexander von Gluck IV
115ac6bcae arm/mailbox: Load mailbox base from FDT in loader 2015-03-28 16:56:50 -05:00
Jérôme Duval
f5e61f7174 libroot.so: libc-lock.h: use a pthread mutex based impl.
* based on current glibc sysdeps/nptl/bits/libc-lock.h file.
* include missing headers which were previously included by libc-lock.h.
* This fixes #11182.
2015-03-28 22:02:53 +01:00
Alexander von Gluck IV
c6a4fee579 loader/u-boot: Use FDT serial info to create uart
* drop my fdt tests
* we have to call fdt parsing code *after* cpu_init (why?)
* pass fdt pointer to all FDT support calls to avoid confusion
  once we get into the kernel land
* look for PL011 compatible uart and use it
* Add some saftey checks to serial putc code to avoid null*
* fdt_node_check_compatible returns 0 on success not 1
* fdt_get_device_reg needs to add the SOC base to the result
* fdt_get_device_reg might need to add the second range cell
  instead of reg?
2015-03-28 15:52:16 -05:00
Michael Lotz
3384ca1a7b rootfs: Fix wrong comparison for buffer reuse on rename.
The comparison to decide whether or not to reuse the name buffer when
renaming a rootfs entry was reversed. For renames where the new name
was longer than the old one this resulted in writing beyond the name
buffer and corrupting random kernel memory.

A likely candidate for this to be triggered was when a audio cd was
renamed due to a CDDB lookup, as the placeholder "Audio CD" is quite
short and the actual CD name is usually longer.

Fixes: #10259. Possibly fixes the related #9528 and #9858.
2015-03-28 12:18:29 +01:00
Jérôme Duval
c5b66b40ab use macro instead of attributes for weak aliases. 2015-03-28 09:41:40 +01:00
Axel Dörfler
b7a87fd137 find_paths_etc(): added user/system only flags.
* B_FIND_PATHS_(USER|SYSTEM)_ONLY cause only the specified paths
  to be included in the result list.
2015-03-26 21:47:22 +00:00
Alexander von Gluck IV
40eb7121b6 arm/fdt: Start using new fdt code in mmu_man's fdt_serial logic
* Expose fdt_get_device_reg for others to use
2015-03-14 14:29:30 -05:00
Alexander von Gluck IV
fe19a9b18b arm/fdt: Add functions to get device bases by name + alias
* Move more code into fdt_support
* We now can query FDT registers based on name or alias
* Return addr_t where it makes sense
* Copyright change ok'ed by mmu_man
2015-03-14 13:03:51 -05:00
Alexander von Gluck IV
f121867b87 arm/fdt: Initial reorg of fdt support code
* Makes FDT support code useable by everyone
  without all of the externs
* Further movement to be non-u-boot centic
  may still happen.
2015-03-14 09:50:46 -05:00
Alexander von Gluck IV
de8d2d8957 arm/fdt: Clean up debugging statements
* Add some comments
2015-03-13 23:52:37 -05:00
Alexander von Gluck IV
59ef0db249 arm/fdt: Add code to navigate FDT.
* This isn't be best long-term place for this code,
  will likely move to some generic FDT support code.
* We pass a path like "/soc/gpio" and get back the
  base physical register address in memory minus
  the range offset.
2015-03-13 23:46:54 -05:00
François Revol
1a8d852f25 ARM: Fix copy-paste oversight 2015-03-14 04:11:47 +01:00
Alexander von Gluck IV
401afabd40 loader/arm/mmu: Set first available va to KERNEL_LOAD_BASE
* The existing code set the first available pa and va to
  the end of the page dirctory.
* The arm mmu code was attempting to identity map (va==pa)
  the memory, but also wanted memory to be in kernel space.
  This allocation method isn't possible on all boards
  (including the pi)
* We're adjusting the dynamic ram to KERNEL_LOAD_BASE
  plus the max size of the kernel. (which is what most
  other platforms are doing)
2015-03-13 16:25:03 -05:00
Alexander von Gluck IV
91c878846b u-boot: Improve error checking on framebuffer 2015-03-10 22:40:38 -05:00
Alexander von Gluck IV
2ac9acbba4 bcm2835: Improve framebuffer tracing and error trapping 2015-03-10 22:40:07 -05:00
Alexander von Gluck IV
2fc1ec2238 bcm2835: Adjust mailbox base register 2015-03-10 22:07:38 -05:00
Alexander von Gluck IV
f90ec6bffc bcm2835: Use mailbox calls again 2015-03-07 20:43:41 -06:00
Alexander von Gluck IV
ed9a0b70f3 u-boot/serial: Only reference pl011 on ARM
* This will likely change once we FDT.
2015-03-07 13:50:32 -06:00
Alexander von Gluck IV
deb4929b9a rpi1/rpi2: Use PL011 UART fallback in loader.
* Adjust UART base locations to reflect ARM pref base.
* We have a working haiku_loader_u-boot on Raspberry Pi 2!:q
2015-03-07 13:42:18 -06:00
Alexander von Gluck IV
196479ae96 headers/bcm283X: Don't depend on others to include board_config.h 2015-03-07 12:35:00 -06:00
Alexander von Gluck IV
427d40adb5 arm/targets: Add rpi2, rename raspberry_pi to rpi1
* The Raspberry pi 2 uses a new SoC which differs slightly
  from the Raspberry Pi 1.
* Someday these two board targets could go away when we get
  FDT support.
2015-03-07 12:31:12 -06:00
Alexander von Gluck IV
523c77e052 arm: Rename BCM2835 SoC header to bcm283X.h
* Fix a few typos in hrev48873
2015-03-07 11:11:53 -06:00
Alexander von Gluck IV
f8e19d47fb arm: Rename BCM2708 to BCM2805
* To while there was some compatibility between
  BCM2708 and BCM2805, it makes the BCM2806 changes
  more confusing. We don't have any valueable BCM2708
  targets.
2015-03-07 11:03:01 -06:00
Paweł Dziepak
91bf7d51f0 boot/arm: mailbox_bxm2708: add final and override specifiers
Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2015-03-06 19:03:59 +01:00
Paweł Dziepak
1410ffb696 boot/arm: use std::atomic<> to access bcm2708 mailbox
Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2015-03-06 19:03:59 +01:00
Paweł Dziepak
2b92ac2a70 boot/arm: enable C++14
Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2015-03-06 19:03:59 +01:00
Alexander von Gluck IV
5eeb4163fa platform/u-boot: Make bcm2708 mailbox code functional
* Functional == compiles. Needs tested :-)
2015-03-06 10:17:52 -06:00
Alexander von Gluck IV
5906dbb4d4 platform/u-boot: Work towards using arm mailbox driver
* Reference bcm2708 framebuffer when it makes sense
* Add bcm2708 define to Raspberry Pi board_config.h
2015-03-06 07:47:32 -06:00
Alexander von Gluck IV
7ddf9bcf0d boot/arm: bcm2708 cleanup; no functional change 2015-03-05 22:54:21 -06:00
Alexander von Gluck IV
c798e80b79 raspberry_pi: Move over to u-boot.
* The raspberry_pi loader wasn't in great shape anyway,
  but could still contain some valueable code.
2015-03-05 22:41:47 -06:00
Alexander von Gluck IV
8a06abf132 bcm2708: Convert framebuffer driver over to new format
* Remove from raspberry_pi bootloader (which should die soon)
* Change to use new arm device layout
* Create arch_mailbox to check arm mailboxes (WIP)
2015-03-05 22:41:47 -06:00
Adrien Destugues
1736cb1d59 driver_settings: fix allocating an empty settings
I misread the condition and broke this in 0687a01. Thanks to Axel for
reviewing!
* Refactor the code again to move all the error checking at the top of
the function, to make it easier to read.
2015-01-14 13:39:35 +01:00
Adrien Destugues
bcb793d37b Fix driver_settings in kernel mode outside of drivers.
The API allows to create driver settings which are not added to the
global list, however those were left partially uninitialized, and there
was no way to cleanly delete them.

Tag such unattached settings with a ref_count of -1, and have
delete_driver_settings check for this and handle the case correctly.

Note: #10494 comment 2 says the settings for packagefs shouldn't be
added to the kernel driver settings list, which is why I went with this
solution. An alternative would be always using the list and the
reference counting, but I don't know what the consequences are.

Fixes #10494.
2015-01-14 11:53:19 +01:00
Adrien Destugues
0687a01b53 driver_settings: don't strdup(NULL)
* This is not allowed by strdup POSIX specs and GCC may use its builtin
strdup which doesn't check for it.
* also refactor parse_driver_settings_string to create the
settings_handle using settings_new, to reduce code duplication.
2015-01-14 11:53:18 +01:00
PulkoMandy
98731302d8 fssh_api_wrapper: fix build on non-Haiku.
* I'm not sure why strings.h needs to be included before <new>, but it
wouldn't work otherwise.
2015-01-14 10:16:32 +01:00
Adrien Destugues
749bd21c45 rootfs: fs_shel build fix attempt.
Sorry, I can't test all cases when building from Haiku.

Including <new> after the fs shell wrapper makes the compiler fail
because new needs a size_t argument (not an fssh_size_t). But including
it before also fails because it includes C++ typedefs without the fssh
wrapper, leading to conflicts.

Undefining size_t just for the include of <new> isn't very clean, but
seems to work. new gets a size_t argument as it should and the other
typedefs aren't conflicting.
2015-01-13 16:21:14 +01:00
Adrien Destugues
a7d444d145 Remove old block cache implementation
This was not used anywhere except the tests written for it (which is
also removed).
2015-01-13 15:48:59 +01:00
Adrien Destugues
ace74964f1 Remove khash from the sources.
Fixes #9552.
2015-01-13 15:48:58 +01:00
Adrien Destugues
bb3092b298 rootfs: convert to BOpenHashTable.
* Add an fs-shell compatible version of BOpenHashTable in the fs_shell
to keep it working. The header is renamed to KOpenHashTable to avoid a
conflict with the OpenHashTable.h available in private/shared which is
not API compatible.
2015-01-13 15:48:58 +01:00
Adrien Destugues
9d1c3b8d4b block cache: convert to BOpenHashTable. 2015-01-13 15:48:56 +01:00
Rene Gollent
be60c04c89 modules: Fix #11746.
- When normalizing paths of the preloaded modules to their final mounted
  path, remove them from the hash table before updating their path. Otherwise,
  the remove would fail due to the hash no longer matching, which in turn
  would cause the code in question to introduce an infinite loop in the
  hash table's internal link list due to manually rewriting the next link.
2015-01-12 19:08:24 -05:00
Adrien Destugues
3395fdcd6a gcc4 build fix.
* offsetof is not allowed on non-POD types so we need to use
offset_of_member (gcc2 accepts offsetof, and C++11 relaxed the
constraints on where it is allowed so it should work there too)
* we have offset_of_member as a workaround until we switch to C++11,
move it from khash (which is soon to be removed) to list.h which is the
other place where it is used (for this one single call in our whole
codebase)

Also fix a typo in vfs.cpp.
2015-01-12 19:04:33 +01:00
Adrien Destugues
f9defd4526 VFS: migrate to BOpenHashTable. 2015-01-12 18:23:45 +01:00
Adrien Destugues
6235b4967b More useless inclusions of khash.h 2015-01-12 18:23:45 +01:00
Adrien Destugues
79b12613f5 legacy_drivers: convert to BOpenHashTable. 2015-01-12 18:23:44 +01:00
Adrien Destugues
887be0ac6a kernel/module: fully convert to BOpenHashTable 2015-01-12 18:23:44 +01:00
Adrien Destugues
c4718ea973 Missing std::nothrow on new
Forgot to add this when migrating to BOpenHashTable.
2015-01-12 09:46:40 +01:00
Rene Gollent
6e9704175e kernel: Style fix. 2015-01-09 19:49:52 -05:00
Rene Gollent
d05a5a70e0 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.
2015-01-09 14:42:13 -05:00
Adrien Destugues
3b3cad8468 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.
2015-01-09 21:31:34 +01:00
Adrien Destugues
271ac910a4 Remove useless includes of khash.h
* These files were already converted to BOpenHashTable.
* For #9552.
2015-01-09 18:09:12 +01:00
Adrien Destugues
6a89f8040f devfs: migrate to BOpenHashTable
For #9552.
2015-01-09 18:09:10 +01:00
Adrien Destugues
69ff01cb9e Migrate image hash table to BOpenHashTable.
For #9552.
2015-01-09 18:09:09 +01:00
Adrien Destugues
57f933d348 CID603224: missing break in parsedate.
Could lead to wrongly setting the TYPE_MINUTE flag for an invalid (>59)
number of minutes. Harmless, as that flag is never used.
For completeness, also set the flag for seconds (also never used).

Fixes #11552.
2014-12-18 15:55:47 +01:00
Puck Meerburg
c038f26da8 Import div.c patch by Tri-Edge AI
Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>
2014-12-14 18:06:21 +01:00
Puck Meerburg
a5f30beaad Fix #7008: Add a64l and l64a from glibc, and add some missing definitions in wchar.h and stdlib.h
Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>
2014-12-14 18:06:09 +01:00
Adrien Destugues
38ec030ace FileDevice: implement icon ioctls
Fixes #9320.
2014-12-02 09:04:56 +01:00
Adrien Destugues
56abf4aa37 Fix std::isnan and friends for gcc2.
gcc2 was relying on the c99 functions being there, but they are not in
the std namespace.
* Disable the C99 functions and macros in C++ mode
* Redefine them as inline functions in cmath in the std namespace.

Fixes #7396.
2014-11-27 10:58:49 +01:00
Jérôme Duval
f3e381dd0c bios_ia32: for correctness, add clobber memory for asm invlpg.
* generated code is the same for x86_gcc2 and x86_64.
* fixed TRACE build for mmu.cpp.
2014-11-17 20:17:30 +01:00
PulkoMandy
8068b64b5c Fix build with guarded heap on x86_64
* Type mismatch.
2014-11-14 12:55:50 +01:00
Adrien Destugues
db214549c5 guarded_heap: fix build (volatile + atomic ops)
Unfortunately, the package manager uses more kernel memory and it's not
possible to boot to the desktop with the guarded heap anymore.
2014-11-12 16:20:24 +01:00
Adrien Destugues
7b4084f717 reject partitions with negative offset
I had a KDL when trying to read an audio CD which apparently uses this
as a copy protection scheme.
I don't know if this is the right place to do this, the KDL would happen
further down when the intel partitionning system or bfs would try to
read data from the disk at offset -2048.
2014-11-11 17:13:03 +01:00
Alexander von Gluck IV
57bc65034a Everything: Update lots of code to use B_COUNT_OF macro
* Likely not everything, but the obvious uses of B_COUNT_OF
2014-11-09 14:52:19 -06:00
Michael Lotz
9a6331459f kernel: Fix build with KDEBUG_LEVEL < 2.
The lock caller info isn't available in such a configuration.
2014-11-04 23:00:59 +01:00
François Revol
76b8f002e1 Implement lseek(SEEK_END) on devices
While the partitioning system does publish partitions as block
devices and report their size in stat(), the old BeOS-style
drivers have no means of reporting it this way.
So we fall back to ioctl(B_GET_GEOMETRY) to find out the size.
2014-11-04 20:47:04 +01:00
François Revol
b7ff6340ae U-Boot: always initialize args.arguments_count 2014-11-04 16:01:16 +01:00
François Revol
361f5a857f ARM: OMAP3: dynamically allocate the framebuffer
It seems to work on overo at least, which has only 128MB by default in QEMU.
2014-11-03 21:06:20 +01:00
François Revol
1cac4300c3 ARM: Add an mmu_get_virtual_mapping() call to bootloader
Will be needed to figure out the framebuffer address
once we allocate it properly instead of hardcoding.
2014-11-03 20:49:01 +01:00
François Revol
cb3ea122d3 U-Boot: delay checking /chosen:bootargs after remapping FDT
This avoids having to copy the strings.
For now we disregard argv[] as it is not remapped before
being used in add_stage2_driver_settings() and is not used
by the linux entry point.

This makes the overo loader panic at the same place as
the beagle xm one now, even though it fails to display
anything with the default RAM size since we allocate
the framebuffer beyond 128MB...
2014-11-03 19:41:38 +01:00
Michael Lotz
eac94f5db9 kernel: Also push lock caller in acquire_spinlock_nocheck. 2014-11-02 00:04:28 +01:00
Michael Lotz
41418981f4 kernel: Sync panic messages across acquire_spinlock versions.
* Always include last caller and lock value on both UP and MP path.
* Change lock value printing to hex format, as 0xdeadbeef is more
  obvious than its decimal counterpart.
2014-11-02 00:04:27 +01:00
Jessica Hamilton
22ea34153f access: fix to be POSIX compliant 2014-11-02 08:51:24 +13:00
François Revol
564a073b01 ARM: move uEnv.txt content to BoardSetup file
That's really where it belongs. Not all boards will need it,
but for now it's always created.
2014-11-01 19:57:48 +01:00
François Revol
95e9515c4b U-Boot: drop the bind on the flash image action 2014-11-01 19:08:57 +01:00
François Revol
92fcf262ff ARM: Check for RAM size in FDT
We skip the check when we already have ranges inserted,
like from the raspberry Pi start code, and we fall back to
32MB at SDRAM_BASE is not found.
2014-11-01 18:53:48 +01:00
François Revol
8d8bda071f U-Boot: generate a separate uImage for the boot tgz as well
We need this when using the linux entry point.
2014-11-01 17:11:01 +01:00
François Revol
d1ebf9716d U-Boot: ARM: Add a linux entry point to asm shell code
While the NetBSD entry point is handy as we can use a single uImage
with all 3 blobs, it bypasses U-Boot's own patching of the FDT since
it's not visible to it, so we won't get the RAM size and other things
through it.
2014-11-01 17:09:09 +01:00
François Revol
5de5d59d78 U-Boot: move gUImage and gFDT back to BSS section
No need for this trick anymore.
2014-11-01 16:39:44 +01:00
François Revol
909a14bb55 U-Boot: introduce a start_gen() catch-all entry
So we can pass it all the optional stuff instead of playing tricks
to initialize them outside of BSS.
2014-11-01 16:39:44 +01:00
Michael Lotz
bf685cdf2e kernel: Fix missing reference release in CreateThreadEvent.
CreateThreadEvent::DoDPC() missed a reference release to balance the
acquired reference before queuing the DPC, resulting in the
CreateThreadEvent objects being leaked.

This also removes the destructor that tried to cancel the DPC. Since
the class is reference counted and only destroyed when the DPC has
run and released the last reference, this didn't make much sense.
2014-11-01 16:32:04 +01:00
François Revol
1309cdade9 U-Boot: rework flash image rule to be more flexible
We can now specify arbitrary content and offsets for each.

Change the default block size to 1k.
2014-11-01 05:37:06 +01:00
François Revol
f680a1a723 U-Boot: skip flash-image targets if no U-Boot image is passed
When building flash images we want a U-Boot binary for now.
Testing for it avoids dd waiting for input on stdin
instead leaving no clue.
2014-11-01 02:15:09 +01:00
François Revol
88d51506d0 Move ARM device tree files to an arch-specific subfolder
FDT are also used on PPC at least, and at least skeleton.dtsi
might clash since there is a different one for PPC.
2014-10-31 16:28:48 +01:00
Michael Lotz
6a80e6889a kernel: Fix missing reference to team/thread in signal events.
The signal to the team/thread is only actually sent in a deferred
procedure. To ensure that the team/thread stays valid between the DPC
being queued and it actually running, we need to acquire a reference.

Fixes #11390, where the DPC was run after the team was already
destroyed.
2014-10-31 16:16:37 +01:00
Ithamar R. Adema
5d8ce4733c ARM: u-boot: Generate DTB and include in uImage 2014-10-31 12:08:03 +01:00
Ithamar R. Adema
a52dd58d2d ARM: kernel: introduce SoC abstraction
This introduces InterruptController and HardwareTimer classes to
handle the SoC specific implementations of timers and ints for
the ARM platform.

These could be improved and moved to a more 'generic' level once
we're confident they are 'good enough'.

NOTE: The OMAP timer implementation is fully untested and probably
      completely non-functional....
2014-10-31 11:37:02 +01:00
Ithamar R. Adema
1628632584 ARM: u-boot: fixup FDT handling
If we find an FDT (either from uImage or otherwise) we make sure
we map it after mmu_init() and use kernel_args to pass it to the
kernel (so it is available at all times there).
2014-10-31 11:21:38 +01:00
Ithamar R. Adema
b794d1f947 ARM: platform: grab the FDT from the bootloader 2014-10-31 11:19:00 +01:00
Ithamar R. Adema
f4c28fe71f loader: make sure bfs debug output ends up in log
Use dprintf instead of printf so any debug output ends up in
bootloader log instead of only being displayed on-screen.
2014-10-31 10:53:28 +01:00
Henry Harrington
601b2f7eda vm: Try harder to allocate early physical pages.
* On UEFI, pages are allocated top-down; previously,
  VM would fail to allocate early pages due to
  running into pages allocated at the top and
  assume it had run out of pages to map.

Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
2014-10-31 13:42:48 +13:00
Ingo Weinhold
dfb13a8716 Increase the size of the kernel FD table
With packagefs potentially opening quite a few packages the default of
256 slots is a bit tight. It's 4096 now, which should be safe for a
while, but we might want to consider resizing the table dynamically and
probably even switching to another algorithm for allocating the slots.

Should fix #11328.
2014-10-29 21:07:03 +01:00
Ingo Weinhold
6bbd25f071 Make vfs_resize_fd_table() accessible in the kernel
Also update some types from int to uint32.
2014-10-29 21:07:02 +01:00
Ingo Weinhold
7ca277b9ca vm_soft_fault(): remove unused wiredRange parameter 2014-10-29 12:37:25 +01:00
Ingo Weinhold
078a965f65 vm_soft_fault(): Avoid deadlock waiting for wired ranges
* VMArea::AddWaiterIfWired(): Replace the ignoreRange argument by a
flags argument and introduce (currently only) flag
IGNORE_WRITE_WIRED_RANGES. If specified, ranges wired for writing
are ignored. Ignoring just a single specified range doesn't cut it
in vm_soft_fault(), and there aren't any other users of that feature.
* vm_soft_fault(): When having to unmap a page of a lower cache, this
page cannot be wired for writing. So we can safely ignore all
writed-wired ranges, instead of just our own. We even have to do that
in case there's another thread that concurrently tries to write-wire
the same page, since otherwise we'd deadlock waiting for each other.
2014-10-29 12:37:25 +01:00
Adrien Destugues
f26118f286 Change error code for already mounted partition to B_BAD_VALUE.
As Axel pointed out, B_BAD_DATA is not the correct code here. B_BUSY
could be used but I wantd a code different from the existing one for
"partition already being initialized".
2014-10-29 08:44:52 +01:00
Ingo Weinhold
8ef857d85c vm_soft_fault(): Avoid inconsistent state when seeing wired page
When we encounter a wired page that we'd have to unmap to map our newly
allocated one, we need to get rid of the latter before unlocking
everything and waiting for the wired page. Otherwise we'd leave things
in an inconsistent state (a page from an upper cache shadowing a mapped
page from a lower cache).
2014-10-29 02:36:09 +01:00
Ingo Weinhold
699b57307e VMAnonymousCache::_MergePagesSmallerConsumer(): Add ASSERT 2014-10-29 02:36:08 +01:00
Ingo Weinhold
9da590f73e Add vm_page_free_etc()
It additionally gets a vm_page_reservation* argument. If not NULL, the
page count of the reservation is incremented for the freed page.
2014-10-29 02:36:08 +01:00
Ingo Weinhold
70d3bd5592 vm_soft_fault(): Missing DEBUG_PAGE_ACCESS_END()
... in case we'd need to unmap a page that is wired.

Fixes the immediate issue of #10977. There's a problem remaining (as
discussed in comment 1): If two threads want to wire the same page at
the same time (which led to the assertion being triggered), they will
now deadlock, waiting for each other to remove the pre-registered
VMAreaWiredRange.
2014-10-29 02:36:08 +01:00
Michael Lotz
52d500e5b4 kernel: Workaround for double lock of spinlock in user timers.
The thread that is being [un]scheduled already has its time_lock locked
in {stop|continue}_cpu_timers(). When updating the TeamTimeUserTimer,
the team is asked for its cpu time. Team::CPUTime() then iterates the
threads of the team and locks the time_lock of the thread again.

This workaround passes a possibly locked thread through the relevant
functions so Team::CPUTime() can decide whether or not a thread it
iterates needs to be locked or not.

This works around #11032 and its duplicates #11314 and #11344.
2014-10-29 00:25:37 +01:00
Adrien Destugues
4ed39e6a62 disk device manager: check that partitions are unmounted before uninitializing.
when uninitializing a partition or a disk (removing the partition
table), check that all partitions from that table are unmounted, as they
are about to become invalid.

Fixes #8827.
2014-10-28 23:52:57 +01:00
PulkoMandy
6879e9df77 Tarfs: fix traces 2014-10-28 08:49:05 +01:00
Ithamar R. Adema
ed04ffb598 ARM: keep all pages we've mapped during kernel startup
Don't just keep the page directory, but also the actual allocates
pages for the pagetables we've created.
2014-10-26 23:43:35 +01:00
Ithamar R. Adema
a17ff8279b ARM: make sure we cleanup after the bootloader
The "2nd" assert that we always ran into was due to bootloader mappings
still being active after VM init. Turns out we missed a call in the
architecture specific code for cleaning this up.

Many thanks to Ingo for spending the time to figure this out!
2014-10-26 23:23:30 +01:00
Ingo Weinhold
4ce1f197fa x86 boot loader: check gKernelArgs.arch_args.pgtables overflow 2014-10-26 22:34:52 +01:00
Michael Lotz
831abecd6a kernel: Fix unbalanced release of sync object in FD select race.
When a file descriptor is closed between being selected and adding the
select info to its IO context, the select info needs to be cleaned up.
This is done by deselect_select_infos() which unconditionally also put
the select_sync associated with the infos. In this special case we do
not yet hold a reference to the select_sync however, so avoid putting
the corresponding sync object.

Fixes #11098, #10763 and #10230.
2014-10-26 00:30:08 +02:00
Ithamar R. Adema
9c71c67140 ARM: Fix OMAP3 framebuffer divider setting
QEMU was crashing since when setting the DSS divider we were _clearing_
the TV divider, and QEMU did not check for a divide by zero.

This "fixes" the QEMU crash and gets us a working framebuffer on Beagle ;)
2014-10-25 14:49:51 -07:00
Axel Dörfler
5a95af70a2 vfs/{b|btr|package|b}fs/ext2/exfat: common access check.
* Added VFS helper function check_access_permissions() that combines
  several partially correct versions to the one true version (tm).
* All but BFS (since recently) missed the S_IXOTH for root on directories,
  and all but packagefs missed proper group handling.
2014-10-25 18:47:15 +02:00
Ithamar R. Adema
2ce0d69a7e ARM: fix bootloader's mmu_map_physical_memory size
When the address is not page aligned, not only adjust the address
to start mapping, but also take the "overflow" on the last page
into account.

This makes the bootloader boot again ;)
2014-10-25 09:43:15 -07:00
Axel Dörfler
8efd5b7613 vfs: check the X permission on set cwd.
* When you change the current working directory, you actually
  should have the permission to enter that directory.
* This gives us a 0.04% better score on the perl test suite :-)
2014-10-25 15:57:38 +02:00
Michael Lotz
e9922e775f haiku_loader: Fix wrong size of gBootGDT on x86_64.
The BOOT_GDT_SEGMENT_COUNT was based on USER_DATA_SEGMENT on both
x86 and x86_64. However, on x86_64 the order of the segments is
different, leading to a too small gBootGDT array. Move the define to
the arch specific headers so they can be setup correctly in either case.
Also add a STATIC_ASSERT() to check that the descriptors fit into the
array.

Pointed out by CID 1210898.
2014-10-22 21:06:07 +02:00
Michael Lotz
368dd37798 runtime_loader: Fix missing include of util/kernel_cpp.h.
Due to the missing include, the builtin new and delete operators were
used in those two files instead of the ones from the include used
everywhere else in the runtime_loader.
2014-10-18 21:58:08 +02:00
Michael Lotz
8ea3e9126d Typo: Fix doubled "not" in comment. 2014-10-18 19:32:33 +02:00
Adrien Destugues
7554bc9a19 wctype: out of bound access in POSIX locale.
The POSIX locale has gLocaleRoster = NULL and relies on the non-wide
version of the implementation. However it doesn't check that the
characters are actually in range which leads to out of bound access and
crashes in __isctype.

Fixes #11322.
2014-10-06 16:54:31 +02:00
Lioncash
a4a9dade68 boot: Fix some always false conditions 2014-09-26 20:56:04 +02:00
Paweł Dziepak
9c5c599041 kernel: pagecache: provided buffers are not always in user memory
Source or destination buffers passed to pagecache functions may belong
to kernel memory (e.g. when the caller is packagefs). Because of that
we should tell vm_memcpy_{from, to}_physical() truth, not assume that all
buffers are in user memory. That's important because user memory page fault
handlers cannot be nested and these functions may be used while handling
a page fault.

With high probability fixes #11246.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-25 21:57:32 +02:00
Jérôme Duval
c8990b0907 _user_wait_for_objects: remove redundant check. 2014-09-17 21:04:14 +02:00
Jessica Hamilton
f0b0d6578b Undo accidental file mode changes. 2014-09-15 16:38:30 +12:00
Paweł Dziepak
95e97463d2 kernel: add generic wrapper for accessing user memory
This patch adds user_access() which can be used to gracefully handle
page faults that may happen when accessing user memory. It is used
by arch_cpu_user{memcpy, memset, strlcpy}() to allow using optimized
functions from the standard library.

Currently only x64 uses this, but nothing really is arch specific here.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 22:39:07 +02:00
Paweł Dziepak
4582b6e3a3 libroot/x86_64: new memcpy implementation
This patch introduces new memcpy() implementation that improves the
performance when the buffer is small. It was written for processors that
support ERMSB, but performs reasonably well on older CPUs as well.

The following benchmarks were done on Haswell i7 running Debian Jessie
with Linux 3.16.1. In each iteration 64MB buffer was copied, the
parameter "size" is the size of the buffer passed in a single call (i.e.
for "size: 2" memcpy() was called ~32 million times to copy the whole
64MB).

f - original implementation, g - new implementation, all buffers 16 byte
aligned

cpy, size:        8, f:    79971 µs, g:    20419 µs, ∆:   74.47%
cpy, size:       32, f:    42068 µs, g:    12159 µs, ∆:   71.10%
cpy, size:      128, f:    13408 µs, g:    10359 µs, ∆:   22.74%
cpy, size:      512, f:    10634 µs, g:    10433 µs, ∆:    1.89%
cpy, size:     1024, f:    10474 µs, g:    10536 µs, ∆:   -0.59%
cpy, size:     4096, f:     9419 µs, g:     8630 µs, ∆:    8.38%

f - glibc 2.19 implementation, g - new implementation, all buffers 16 byte
aligned

cpy, size:        8, f:    26299 µs, g:    20919 µs, ∆:   20.46%
cpy, size:       32, f:    11146 µs, g:    12159 µs, ∆:   -9.09%
cpy, size:      128, f:    10778 µs, g:    10354 µs, ∆:    3.93%
cpy, size:      512, f:    12291 µs, g:    10426 µs, ∆:   15.17%
cpy, size:     1024, f:    13923 µs, g:    10571 µs, ∆:   24.08%
cpy, size:     4096, f:    11770 µs, g:     8671 µs, ∆:   26.33%

f - glibc 2.19 implementation, g - new implementation, all buffers unaligned

cpy, size:       16, f:    13376 µs, g:    13009 µs, ∆:    2.74%
cpy, size:       32, f:    11130 µs, g:    12171 µs, ∆:   -9.35%
cpy, size:       64, f:    11017 µs, g:    11231 µs, ∆:   -1.94%
cpy, size:      128, f:    10884 µs, g:    10407 µs, ∆:    4.38%
cpy, size:      256, f:    10826 µs, g:    10106 µs, ∆:    6.65%
cpy, size:      512, f:    12354 µs, g:    10396 µs, ∆:   15.85%

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
1d7b716f84 libroot/x86_64: new memset implementation
This patch introduces new memset() implementation that improves the
performance when the buffer is small. It was written for processors that
support ERMSB, but performs reasonably well on older CPUs as well.

The following benchmarks were done on Haswell i7 running Debian Jessie
with Linux 3.16.1. In each iteration 64MB buffer was memset()ed, the
parameter "size" is the size of the buffer passed in a single call (i.e.
for "size: 2" memset() was called ~32 million times to memset the whole
64MB).

f - original implementation, g - new implementation, all buffers 16 byte
aligned

set, size:        8, f:    66885 µs, g:    17768 µs, ∆:   73.44%
set, size:       32, f:    17123 µs, g:     9163 µs, ∆:   46.49%
set, size:      128, f:     6677 µs, g:     6919 µs, ∆:   -3.62%
set, size:      512, f:    11656 µs, g:     7715 µs, ∆:   33.81%
set, size:     1024, f:     9156 µs, g:     7359 µs, ∆:   19.63%
set, size:     4096, f:     4936 µs, g:     5159 µs, ∆:   -4.52%

f - glibc 2.19 implementation, g - new implementation, all buffers 16 byte
aligned

set, size:        8, f:    19631 µs, g:    17828 µs, ∆:    9.18%
set, size:       32, f:     8545 µs, g:     9047 µs, ∆:   -5.87%
set, size:      128, f:     8304 µs, g:     6874 µs, ∆:   17.22%
set, size:      512, f:     7373 µs, g:     7486 µs, ∆:   -1.53%
set, size:     1024, f:     9007 µs, g:     7344 µs, ∆:   18.46%
set, size:     4096, f:     8169 µs, g:     5146 µs, ∆:   37.01%

Apparently, glibc uses SSE even for large buffers and therefore does not
takes advantage of ERMSB:

set, size:    16384, f:     7007 µs, g:     3223 µs, ∆:   54.00%
set, size:    32768, f:     6979 µs, g:     2930 µs, ∆:   58.02%
set, size:    65536, f:     6907 µs, g:     2826 µs, ∆:   59.08%
set, size:   131072, f:     6919 µs, g:     2752 µs, ∆:   60.23%

The new implementation handles unaligned buffers quite well:

f - glibc 2.19 implementation, g - new implementation, all buffers unaligned

set, size:       16, f:    10045 µs, g:    10498 µs, ∆:   -4.51%
set, size:       32, f:     8590 µs, g:     9358 µs, ∆:   -8.94%
set, size:       64, f:     8618 µs, g:     8585 µs, ∆:    0.38%
set, size:      128, f:     8393 µs, g:     6893 µs, ∆:   17.87%
set, size:      256, f:     8042 µs, g:     7621 µs, ∆:    5.24%
set, size:      512, f:     9661 µs, g:     7738 µs, ∆:   19.90%

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
718fd007a6 kernel/x86_64: clear xmm0-15 registers on syscall exit
As Alex pointed out we can leak possibly sensitive data in xmm registers
when returning from the kernel. To prevent that xmm0-15 are zeroed
before sysret or iret. The cost is negligible.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
396b74228e kernel/x86_64: save fpu state at interrupts
The kernel is allowed to use fpu anywhere so we must make sure that
user state is not clobbered by saving fpu state at interrupt entry.
There is no need to do that in case of system calls since all fpu
data registers are caller saved.

We do not need, though, to save the whole fpu state at task swich
(again, thanks to calling convention). Only status and control
registers are preserved. This patch actually adds xmm0-15 register
to clobber list of task swich code, but the only reason of that is
to make sure that nothing bad happens inside the function that
executes that task swich. Inspection of the generated code shows
that no xmm registers are actually saved.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
b41f281071 boot/x86_64: enable sse early
Enable SSE as a part of the "preparation of the environment to run any
C or C++ code" in the entry points of stage2 bootloader.

SSE2 is going to be used by memset() and memcpy().

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
acad7bf64a kernel/x86_64: make sure stack is properly aligned in syscalls
Just following the path of least resistance and adding andq $~15, %rsp
where appropriate. That should also make things harder to break
when changing the amount of stuff placed on stack before calling the
actual syscall routine.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
f2f91078bd kernel/x86_64: remove memset and memcpy from commpage
There is absolutely no reason for these functions to be in commpage,
they don't do anything that involves the kernel in any way.

Additionaly, this patch rewrites memset and memcpy to C++, current
implementation is quite simple (though it may perform surprisingly
well when dealing with large buffers on cpus with ermsb). Better
versions are coming soon.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:52 +02:00
Paweł Dziepak
6156a508ad kernel/x86[_64]: remove get_optimized_functions from cpu modules
The possibility to specify custom memcpy and memset implementations
in cpu modules is currently unused and there is generally no point
in such feature.

There are only 2 x86 vendors that really matter and there isn't
very big difference in performance of the generic optmized versions
of these funcions across different models. Even if we wanted different
versions of memset and memcpy depending on the processor model or
features much better solution would be to use STT_GNU_IFUNC and save
one indirect call.

Long story short, we don't really benefit in any way from
get_optimized_functions and the feature it implements and it only adds
unnecessary complexity to the code.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2014-09-14 19:16:51 +02:00