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