Commit Graph

6484 Commits

Author SHA1 Message Date
Jérôme Duval
34cdda1dd5 kernel: x86: enable writes before patching.
Follow up for commit a2021292d4.
Binary patching would otherwise fail after the kernel text area
becomes read-only.
2018-01-23 17:59:41 +01:00
Jérôme Duval
483c45843d kernel: x86: add some more cpuid flags. 2018-01-15 20:18:43 +01:00
Jérôme Duval
a2021292d4 kernel: Binary code patches on x86.
This will be used to support SMAP.

Sponsored-by:	https://liberapay.com/korli
2018-01-14 13:20:38 +01:00
Jérôme Duval
9409021432 kernel: x86: add cpuid feature 7 flags. 2018-01-13 09:33:47 +01:00
Andrew Aldridge
f6d25a3a81 strtod: Do not consume "x" in incomplete hex input
Adapted from upstream glibc commits:
* 405698e946dbed472491f85867eb511eb080e05a
* 43b9d657408fbf47a47934f9e7c84ed87f7f5a18

Fixes #13949
2018-01-12 16:45:14 +00:00
Jérôme Duval
bbb5a50f9b kernel: debug: map the frame_buffer for the kernel only. 2018-01-11 19:59:10 +01:00
Jérôme Duval
51051c56d3 kernel: wait_for_objects: read the user sigmask with user_memcpy() 2018-01-08 22:19:07 +01:00
Jérôme Duval
9fbffea6f4 kernel: vfs: don't use the attribute name user buffer directly.
instead copy the name on the stack.
2018-01-07 23:33:04 +01:00
Jérôme Duval
ff678dd91b kernel: image: _get_next_image_info shouldn't use a user buffer directly
_user_get_next_image_info() now copies the cookie on the stack, calls
_get_next_image_info() and copy back the cookie to the user buffer.
2018-01-07 22:57:41 +01:00
Jérôme Duval
6e28d80927 kernel: port: check USE_USER_COPY flag before masking it.
writev_port_etc() used memcpy() instead of user_memcpy() for user buffers.
The branch was even left out silently as an optimization on gcc5.
2018-01-07 22:41:39 +01:00
Jérôme Duval
da8f9c86bd kernel: disk_device_manager: no return in method returning void 2018-01-06 21:38:16 +01:00
Jérôme Duval
4644c7cc92 kernel: disk_device_manager: clean user interface
* avoid assignment in if statements
* use boolean conditions
* use copy_from_user_value/copy_to_user_value instead of user_memcpy
* no functional changes except user buffer addresses check in:
_user_get_next_disk_device_id(), _user_get_disk_system_info(),
_user_get_next_disk_system_info(), _user_find_disk_system()
* remove TODO "Add user address checks and check return values of user_memcpy()!".
2018-01-06 21:38:16 +01:00
Jérôme Duval
9572fa7340 kernel: signal: check user buffer addresses...
in _user_set_signal_mask(), _user_sigaction(), _user_sigsuspend(), _user_set_signal_stack().
2018-01-06 17:15:18 +01:00
Jérôme Duval
b68d872bdb kernel: apm: check buffer parameter in apm_control syscall 2018-01-06 16:11:32 +01:00
Jérôme Duval
9c18398fe4 kernel: system_info: correctly check the user buffer...
before writing.
2018-01-06 12:05:20 +01:00
François Revol
4069b740e5 pthread: assign handle argument before resuming the created thread
It's not specified by POSIX:
http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_create.html
"There is no requirement on the implementation that the ID of the
created thread be available before the newly created thread starts executing."

However I've run into it with MPD which assumed this, probably because
of Linux:
https://github.com/MusicPlayerDaemon/MPD/issues/188

It doesn't hurt anyway.
2018-01-06 05:07:43 +01:00
Michael Lotz
0a7f661ae2 kernel: Fix scheduler tracing formats and priority field type.
* Use format macros for printing to fix priting on 64 bit.
* Use int32 for all priority fields, some of them were truncated.
2018-01-05 22:48:56 +01:00
Michael Lotz
3084a7000f Cleanup: Remove one trailing whitespace. 2018-01-05 22:48:56 +01:00
Jérôme Duval
e46e9fee6b vfs: check userland buffers before reading them. 2018-01-03 21:15:30 +01:00
ohnx
7766c048b3 libroot: Fix possible typo in printf_size.c
It appears as if there is a typo in printf_size.c; it makes
no sense to compare an unitialized variable in such a way.
Since `info->width` is referenced later on in the variable
assignment, it seems possible that the intended statement
was to place the larger of the values between `info->width`
and `info->prec` into `width`.

Fixes CID 609431.

korli: Patch applied in cddfcf2f87
was incomplete. This patch completes with what upstream did in 2004:
fa5753eede.patch

Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>
2018-01-03 19:42:55 +01:00
Michael Lotz
36ef138ce5 kernel: Implement WEXITED for waitid.
Previously dead teams were always returned (as needed for wait/waitpid).
Using waitid it should however be possible to omit the WEXITED flag to
only get stopped (WUNTRACED | WSTOPPED) or continued (WCONTINUED) teams.

Adjust the other caller of the _kern_wait_for_child syscall, used by the
various less specific wait* functions, to always include WEXITED. This
avoids having to special case waitid in the syscall interface or with an
extra flag.

Add a check to ensure that any of these flags is set to avoid the now
possible case of nothing being specified. This fails with B_BAD_VALUE
(EINVAL) as on other systems.
2018-01-03 01:52:52 +01:00
Michael Lotz
63e2d20137 kernel: Treat WSTOPPED synonymous to WUNTRACED.
On other systems their values are usually aliased. We defined them as
two different values, but didn't handle WSTOPPED anywhere. The check
is now simply extended to cover both bits.
2018-01-03 01:22:53 +01:00
Michael Lotz
afe8d6621d kernel: Avoid double lock in wait_for_child with child == team.
When wait_for_child was called with a child argument equal to the
current team, the team was locked again to check if it was a child of
itself.

This is now handled the same way as on other systems, where this case
results in ECHILD (and not EINVAL).
2018-01-03 01:10:29 +01:00
Fredrik Holmqvist
1446507ce3 Remove the code to force ACPI to shutdown on CPU0
It was discussed and introduced based on docs that some systems
need this to shutdown properly. I can find no mention of this in
ACPICA or ACPI docs.
This needs to be re-evalutad, as all my shutdowns been successful
after disabling it and I can't locate where this info came from
or if it actually helped.

See 1316462ab0 for original commit
and bug 12306 on current shutdown issue.
2017-12-31 17:43:31 +01:00
Augustin Cavalier
04c3bd6cf1 Team: Defer adding the team to parent and hash until just before starting.
Previously I had intended to take the simpler route and just lock the
already-inserted team before setting the io_context (as in prior commits),
but after hearing some reports from users that some other seemingly
unrelated KDLs had possibly cleared up after the first iteration of
that fix, I decided to go with this route instead.

Now we do not insert the team into the parent and hash and send the
notification until just before the team's main thread is actually started;
i.e. we now initialize not only io_context but also the team's args, VM
address space, and user data (and if creation of any of these fails
we do not inset the team into the hash at all.)

Since the team structure was not locked at all while this initialization
was taking place, any number of race-dependent bugs could have been
caused by this on multicore systems.
2017-12-19 22:47:31 -05:00
Augustin Cavalier
4ecdf1e195 team: Only lock while actually setting io_context, not while creating it.
Thanks Ingo for the review!
2017-12-19 20:51:01 -05:00
Augustin Cavalier
11b65332b4 kernel/team: Lock the team while modifying the io_context.
Second part of the fix for #13861. Thanks Ingo for the review!
2017-12-17 22:27:44 -05:00
Augustin Cavalier
019828aba7 VFS: Add proper locking of the team structure in disconnect_mount_or_vnode_fds.
The KDL in #13861 was apparently caused by a NULL io_context. I read over
the Team code and have applied the following fixes here as a result:

  1. A NULL io_context is entirely possible, as implied by the NULL check
     before deinitializing it in Team's destructor, so account for that.

  2. Team objects have a class-wide lock which must be acquired before
     directly accessing class members, so use that here.

First part of the fix for #13861.
2017-12-17 22:27:44 -05:00
Mason X
8a4744fbe4 Catch integer overflow in calloc (Fixes #13820)
calloc, when multiplying to find the true size of memory desired
by a user, will occasionally overflow if the numbers are too
large. This commit makes calloc ensure that the multiplication
does not overflow by dividing the result by one of the numbers,
and checking to ensure that the result is equal to the other
number. If there is overflow, it is treated as an OOM error.

Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
2017-12-17 17:02:09 -05:00
Augustin Cavalier
bfc37fd122 libroot/posix/stdio: Remove unused portions.
We use glibc's versions of these functions.
2017-12-17 13:55:13 -05:00
Augustin Cavalier
efdaac9c08 kernel/convertutf: Fix file mode. 2017-12-10 12:07:23 -05:00
hyche
1750cd1e92 block_cache: Implement cache_has_block_in_transaction function that will check the existence of block in one specific transaction.
Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
2017-12-10 11:02:56 -05:00
Adrien Destugues
6a028821b6 x86 glue code: keep stack aligned.
The glue code pushed 12 bytes to the stack, breaking the 16-byte stack
alignment requirement. This would be fixed by the main() prologue from
gcc, but all "init" and "fini" code (static/global constructors/ destructors)
would run with a misaligned stack.

This was already fixed for x86_64 in hrev49731. Note that the fix here
is slightly different, the pointer is realigned after it is saved to EBP
and the function epilogue restores it from EBP, so no changes to crtn.S are
needed.
2017-12-10 09:23:22 +01:00
Augustin Cavalier
8b222e6272 IORequest: NULL check does not belong in method body.
Found by Clang's -Wtautological-undefined-compare.
2017-12-03 13:44:16 -05:00
Augustin Cavalier
bf77c15232 kernel/vm: Correct virtual function declarations.
The base VMCache class changed to the generic_ types with their
introduction in in *2011* (435c43f591),
but these classes were never properly adapted. These functions should not
be called here (they panic() -- but the base class only returns B_ERROR,
so that is a difference at least.)

Found by Clang's -Woverloaded-virtual.
2017-12-02 21:42:50 -05:00
Rene Gollent
dfc46d83b7 runtime_loader: Fix #13799.
- Don't remove .eh_frame in the linker scripts, as this saves little
  space in practice, and results in debug binaries of the runtime loader
  not being properly debuggable due to missing canonical frame
  information.
2017-12-02 15:41:41 -05:00
Augustin Cavalier
30c9d3c0cc kernel: Correct class/struct mixups.
Almost certainly harmless. Spotted by Clang.
2017-12-01 20:27:15 -05:00
Jérôme Duval
6ac3a280f4 Add ZstdCompressionAlgorithm.
* kernel lib is decompress only (like zlib).
* expand compression_test for zstd.
2017-11-24 21:35:49 +01:00
Julian Harnath
5c821d1200 SystemProfiler: prevent nested wake-up of profiler thread
* When SystemProfiler::_MaybeNotifyProfilerThreadLocked() is called
  and the conditions are right, it will lock the thread's scheduler
  spinlock and unblock it. Internally, the unblock will enqueue the
  thread into the run queue, which causes a ThreadEnqueuedInRunQueue
  event for SystemProfiler. Since the conditions haven't changed, it
  now went into _MaybeNotifyProfilerThreadLocked again (this time
  from the profiler thread context). In there, it will try to lock
  the profiler thread's scheduling spinlock, which is already locked
  by the other thread (which is firmly sleeping). Deadlock, KDL.

* Before unblocking the profiler thread, unset fWaitingProfilerThread
  so that further events will not try to unblock it again.
2017-11-24 18:22:14 +01:00
Alexander von Gluck IV
eb81dec460 kernel/u-boot: Add a few missed fdt compat's for omap uart 2017-11-23 10:25:18 -06:00
Augustin Cavalier
df9bc792e0 runtime_loader: Set sSearchPathSubDir on first image, not on app image.
Under normal conditions this will behave identically. But when using LD_PRELOAD
or the like, some shared objects (and dependencies) are loaded before the
app image is, and on the secondary arch on hybrid builds, will fail to load
any of their dependencies due to sSearchPathSubDir not being set.

Fixes #12214, which had plagued users of libroot_debug for a long time now.
2017-11-22 17:55:36 +01:00
François Revol
dd1454bd96 Defer calling arch_debug_console_init_settings
when we can actually read driver settings :-)
2017-11-20 18:16:54 +01:00
Alexander von Gluck IV
2dce5eecef build/arm: Correct missing sources in search
* Group into local var to prevent recurrence.
2017-11-20 09:36:56 -06:00
Alexander von Gluck IV
a42249db2d arm: Add 8250 omap variant uart driver
* Untested, someone with an omap3,4,5 could though.
2017-11-20 09:16:58 -06:00
François Revol
0835170c80 Actually use the serial port and speed from the kernel settings
Turns out we just reused the already set values, disregarding the new ones.
2017-11-20 11:44:43 +01:00
Alexander von Gluck IV
f6c47144a6 kernel/uart: Refinements to irq and FIFO management 2017-11-18 13:20:53 -06:00
Jérôme Duval
f57e467bd8 Update libroot stubs. 2017-11-18 17:28:06 +01:00
Jérôme Duval
edfefa187b libroot/posix: remove useless keyword extern. 2017-11-18 17:28:06 +01:00
Alexander von Gluck IV
1d3d336a97 libbsd: Move lutimes to bsd compat
* Rework be149e8ccf since lutimes isn't posix
2017-11-17 14:27:26 -06:00
Augustin Cavalier
7d8eb4d7f9 time: Address review comments.
* Use ENOSYS not B_DONT_DO_THAT (thanks korli)
 * Use unsigned long not uint64 (thanks axeld)
2017-11-16 20:53:14 +01:00