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-02-14 09:49:16 +00:00
|
|
|
#include <Kernel/Panic.h>
|
2020-07-30 21:38:15 +00:00
|
|
|
#include <Kernel/Process.h>
|
2021-02-08 19:14:33 +00:00
|
|
|
#include <Kernel/VM/Region.h>
|
2020-07-30 21:38:15 +00:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-06-28 18:59:35 +00:00
|
|
|
KResultOr<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-06-26 12:56:28 +00:00
|
|
|
auto& regs = Thread::current()->get_register_dump_from_stack();
|
|
|
|
FlatPtr stack_pointer;
|
|
|
|
#if ARCH(I386)
|
|
|
|
stack_pointer = regs.userspace_esp;
|
|
|
|
#else
|
|
|
|
stack_pointer = regs.userspace_rsp;
|
|
|
|
#endif
|
2021-02-08 19:14:33 +00:00
|
|
|
auto* stack_region = space().find_region_containing(Range { VirtualAddress(stack_pointer), 1 });
|
2021-02-14 10:44:21 +00:00
|
|
|
|
|
|
|
// The syscall handler should have killed us if we had an invalid stack pointer.
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(stack_region);
|
2020-07-30 21:38:15 +00:00
|
|
|
|
|
|
|
FlatPtr stack_base = stack_region->range().base().get();
|
|
|
|
size_t stack_size = stack_region->size();
|
2020-09-12 03:11:07 +00:00
|
|
|
if (!copy_to_user(user_stack_base, &stack_base))
|
2021-03-01 12:49:16 +00:00
|
|
|
return EFAULT;
|
2020-09-12 03:11:07 +00:00
|
|
|
if (!copy_to_user(user_stack_size, &stack_size))
|
2021-03-01 12:49:16 +00:00
|
|
|
return EFAULT;
|
2020-07-30 21:38:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|