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-02-14 12:49:16 +03:00
|
|
|
#include <Kernel/Panic.h>
|
2020-07-31 00:38:15 +03:00
|
|
|
#include <Kernel/Process.h>
|
2021-02-08 22:14:33 +03:00
|
|
|
#include <Kernel/VM/Region.h>
|
2020-07-31 00:38:15 +03:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-03-01 16:50:36 +03:00
|
|
|
KResultOr<int> Process::sys$get_stack_bounds(Userspace<FlatPtr*> user_stack_base, Userspace<size_t*> user_stack_size)
|
2020-07-31 00:38:15 +03:00
|
|
|
{
|
|
|
|
FlatPtr stack_pointer = Thread::current()->get_register_dump_from_stack().userspace_esp;
|
2021-02-08 22:14:33 +03:00
|
|
|
auto* stack_region = space().find_region_containing(Range { 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();
|
2020-09-12 06:11:07 +03:00
|
|
|
if (!copy_to_user(user_stack_base, &stack_base))
|
2021-03-01 15:49:16 +03:00
|
|
|
return EFAULT;
|
2020-09-12 06:11:07 +03:00
|
|
|
if (!copy_to_user(user_stack_size, &stack_size))
|
2021-03-01 15:49:16 +03:00
|
|
|
return EFAULT;
|
2020-07-31 00:38:15 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|