2020-07-30 21:38:15 +00:00
|
|
|
/*
|
2021-02-08 19:14:33 +00:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-07-30 21:38:15 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-30 21:38:15 +00:00
|
|
|
*/
|
|
|
|
|
2021-08-06 08:45:34 +00:00
|
|
|
#include <Kernel/Memory/Region.h>
|
2020-07-30 21:38:15 +00:00
|
|
|
#include <Kernel/Process.h>
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
ErrorOr<FlatPtr> Process::sys$get_stack_bounds(Userspace<FlatPtr*> user_stack_base, Userspace<size_t*> user_stack_size)
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2021-08-06 12:21:08 +00:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
2021-06-26 12:56:28 +00:00
|
|
|
auto& regs = Thread::current()->get_register_dump_from_stack();
|
2021-07-18 23:50:08 +00:00
|
|
|
FlatPtr stack_pointer = regs.userspace_sp();
|
2022-08-23 15:58:05 +00:00
|
|
|
return address_space().with([&](auto& space) -> ErrorOr<FlatPtr> {
|
|
|
|
auto* stack_region = space->find_region_containing(Memory::VirtualRange { VirtualAddress(stack_pointer), 1 });
|
2021-02-14 10:44:21 +00:00
|
|
|
|
2022-08-23 15:58:05 +00:00
|
|
|
// The syscall handler should have killed us if we had an invalid stack pointer.
|
|
|
|
VERIFY(stack_region);
|
2020-07-30 21:38:15 +00:00
|
|
|
|
2022-08-23 15:58:05 +00:00
|
|
|
FlatPtr stack_base = stack_region->range().base().get();
|
|
|
|
size_t stack_size = stack_region->size();
|
|
|
|
TRY(copy_to_user(user_stack_base, &stack_base));
|
|
|
|
TRY(copy_to_user(user_stack_size, &stack_size));
|
|
|
|
return 0;
|
|
|
|
});
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|