kernel: Rename set/clear_ac to arch_cpu_enable/disable_user_access.
These are architecture-specific routines, so they deserve proper architecture-specific naming. The user memory access routines are already under arch_cpu (arch_cpu_user_memcpy, etc.), and the methods usually change a CPU flag, so it makes sense to put these there too. RISC-V had get_ac but nothing else defined or used it, so it's removed. No functional change intended. Change-Id: Id4715214e32f73d4a93bc7ba8249411a0878d174 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8106 Reviewed-by: waddlesplash <[email protected]> Reviewed-by: X512 X512 <[email protected]> Reviewed-by: Jérôme Duval <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
dadc497fbc
commit
6f88de113d
@@ -16,8 +16,8 @@
|
||||
#define dmb() __asm__ __volatile__("dmb" : : : "memory")
|
||||
#define wfi() __asm__ __volatile__("wfi" : : : "memory")
|
||||
|
||||
#define set_ac()
|
||||
#define clear_ac()
|
||||
#define arch_cpu_enable_user_access()
|
||||
#define arch_cpu_disable_user_access()
|
||||
|
||||
|
||||
#ifndef _ASSEMBLER
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#define CACHE_LINE_SIZE 64
|
||||
|
||||
// TODO: These will require a real implementation when PAN is enabled
|
||||
#define set_ac()
|
||||
#define clear_ac()
|
||||
#define arch_cpu_enable_user_access()
|
||||
#define arch_cpu_disable_user_access()
|
||||
|
||||
#include <kernel/arch/arm64/arm_registers.h>
|
||||
|
||||
|
||||
@@ -65,12 +65,12 @@ bool user_access(Function function)
|
||||
// destructor.
|
||||
auto fail = setjmp(thread_get_current_thread()->fault_handler_state);
|
||||
if (fail == 0) {
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
function();
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
return true;
|
||||
}
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
#define CACHE_LINE_SIZE 16
|
||||
|
||||
|
||||
#define set_ac()
|
||||
#define clear_ac()
|
||||
#define arch_cpu_enable_user_access()
|
||||
#define arch_cpu_disable_user_access()
|
||||
|
||||
|
||||
#define SR_IP_MASK 0x0700
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
// 128 Byte lines on PPC970
|
||||
|
||||
|
||||
#define set_ac()
|
||||
#define clear_ac()
|
||||
#define arch_cpu_enable_user_access()
|
||||
#define arch_cpu_disable_user_access()
|
||||
|
||||
|
||||
struct iframe {
|
||||
|
||||
@@ -16,22 +16,15 @@
|
||||
#define CACHE_LINE_SIZE 64
|
||||
|
||||
|
||||
static inline bool
|
||||
get_ac()
|
||||
{
|
||||
return SstatusReg{.val = Sstatus()}.sum;
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
set_ac()
|
||||
arch_cpu_enable_user_access()
|
||||
{
|
||||
SetBitsSstatus(SstatusReg{.sum = 1}.val);
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
clear_ac()
|
||||
arch_cpu_disable_user_access()
|
||||
{
|
||||
ClearBitsSstatus(SstatusReg{.sum = 1}.val);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
// 128 Byte lines on PPC970
|
||||
|
||||
|
||||
#define set_ac()
|
||||
#define clear_ac()
|
||||
#define arch_cpu_enable_user_access()
|
||||
#define arch_cpu_disable_user_access()
|
||||
|
||||
|
||||
typedef struct arch_cpu_info {
|
||||
|
||||
@@ -64,10 +64,10 @@ x86_write_cr3(size_t value)
|
||||
#define wbinvd() \
|
||||
__asm__ volatile ("wbinvd" : : : "memory")
|
||||
|
||||
#define set_ac() \
|
||||
#define arch_cpu_enable_user_access() \
|
||||
__asm__ volatile (ASM_STAC : : : "memory")
|
||||
|
||||
#define clear_ac() \
|
||||
#define arch_cpu_disable_user_access() \
|
||||
__asm__ volatile (ASM_CLAC : : : "memory")
|
||||
|
||||
#define xgetbv(reg) ({ \
|
||||
|
||||
@@ -136,7 +136,7 @@ arch_vm_translation_map_init(kernel_args *args,
|
||||
dprintf("physMemBase: %#" B_PRIxADDR "\n", args->physical_memory_range[0].start);
|
||||
gVirtFromPhysOffset = args->arch_args.physMap.start - args->physical_memory_range[0].start;
|
||||
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
|
||||
*_physicalPageMapper = new(&sPhysicalPageMapperData)
|
||||
RISCV64VMPhysicalPageMapper();
|
||||
|
||||
@@ -286,10 +286,10 @@ arch_thread_enter_userspace(Thread* thread, addr_t entry, void* args1,
|
||||
// entry function returns to the top of the stack to act as the return
|
||||
// address. The stub is inside commpage.
|
||||
addr_t commPageAddress = (addr_t)thread->team->commpage_address;
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
codeAddr = ((addr_t*)commPageAddress)[COMMPAGE_ENTRY_X86_THREAD_EXIT]
|
||||
+ commPageAddress;
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
if (user_memcpy((void*)stackTop, (const void*)&codeAddr, sizeof(codeAddr))
|
||||
!= B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
@@ -406,10 +406,10 @@ arch_setup_signal_frame(Thread* thread, struct sigaction* action,
|
||||
// stack. First argument points to the frame data.
|
||||
addr_t* commPageAddress = (addr_t*)thread->team->commpage_address;
|
||||
frame->user_sp = (addr_t)userStack;
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
frame->ip = commPageAddress[COMMPAGE_ENTRY_X86_SIGNAL_HANDLER]
|
||||
+ (addr_t)commPageAddress;
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
frame->di = (addr_t)userSignalFrameData;
|
||||
frame->flags &= ~(uint64)(X86_EFLAGS_TRAP | X86_EFLAGS_DIRECTION);
|
||||
|
||||
|
||||
@@ -27,10 +27,10 @@
|
||||
#else
|
||||
#define mutex_lock(...)
|
||||
#define mutex_unlock(...)
|
||||
#undef set_ac
|
||||
#undef clear_ac
|
||||
#define set_ac()
|
||||
#define clear_ac()
|
||||
#undef arch_cpu_enable_user_access
|
||||
#undef arch_cpu_disable_user_access
|
||||
#define arch_cpu_enable_user_access()
|
||||
#define arch_cpu_disable_user_access()
|
||||
#endif
|
||||
|
||||
#include "font.h"
|
||||
@@ -153,7 +153,7 @@ render_glyph(int32 column, int32 row, uint8 glyph, uint8 attr)
|
||||
uint8* color = get_palette_entry(foreground_color(attr));
|
||||
uint8* backgroundColor = get_palette_entry(background_color(attr));
|
||||
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
for (int y = 0; y < sConsole.font->glyphHeight; y++) {
|
||||
uint16_t bits = get_font_data(glyph, y);
|
||||
for (int x = 0; x < sConsole.font->glyphWidth; x++) {
|
||||
@@ -170,8 +170,7 @@ render_glyph(int32 column, int32 row, uint8 glyph, uint8 attr)
|
||||
|
||||
base += sConsole.bytes_per_row;
|
||||
}
|
||||
clear_ac();
|
||||
|
||||
arch_cpu_disable_user_access();
|
||||
} else {
|
||||
// VGA mode will be treated as monochrome
|
||||
// (ie. only the first plane will be used)
|
||||
@@ -181,7 +180,7 @@ render_glyph(int32 column, int32 row, uint8 glyph, uint8 attr)
|
||||
+ column * sConsole.font->glyphWidth / 8);
|
||||
uint8 baseOffset = (column * sConsole.font->glyphWidth) & 0x7;
|
||||
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
for (int y = 0; y < sConsole.font->glyphHeight; y++) {
|
||||
uint16_t bits = get_font_data(glyph, y);
|
||||
uint8 offset = baseOffset;
|
||||
@@ -204,7 +203,7 @@ render_glyph(int32 column, int32 row, uint8 glyph, uint8 attr)
|
||||
|
||||
base += sConsole.bytes_per_row;
|
||||
}
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,14 +225,14 @@ draw_cursor(int32 x, int32 y)
|
||||
endY /= 8;
|
||||
}
|
||||
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
for (; y < endY; y++) {
|
||||
for (int32 x2 = x; x2 < endX; x2++)
|
||||
base[x2] = ~base[x2];
|
||||
|
||||
base += sConsole.bytes_per_row;
|
||||
}
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
}
|
||||
|
||||
|
||||
@@ -318,14 +317,14 @@ console_blit(int32 srcx, int32 srcy, int32 width, int32 height, int32 destx,
|
||||
destx = destx * sConsole.font->glyphWidth / 8;
|
||||
}
|
||||
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
for (int32 y = 0; y < height; y++) {
|
||||
memmove((void*)(sConsole.frame_buffer + (desty + y)
|
||||
* sConsole.bytes_per_row + destx),
|
||||
(void*)(sConsole.frame_buffer + (srcy + y) * sConsole.bytes_per_row
|
||||
+ srcx), width);
|
||||
}
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
}
|
||||
|
||||
|
||||
@@ -335,7 +334,7 @@ console_clear(uint8 attr)
|
||||
if (!frame_buffer_console_available())
|
||||
return;
|
||||
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
switch (sConsole.bytes_per_pixel) {
|
||||
case 1:
|
||||
if (sConsole.depth >= 8) {
|
||||
@@ -364,8 +363,8 @@ console_clear(uint8 attr)
|
||||
break;
|
||||
}
|
||||
}
|
||||
arch_cpu_disable_user_access();
|
||||
|
||||
clear_ac();
|
||||
sConsole.cursor_x = -1;
|
||||
sConsole.cursor_y = -1;
|
||||
}
|
||||
|
||||
@@ -1988,9 +1988,9 @@ elf_load_user_image(const char *path, Team *team, uint32 flags, addr_t *entry)
|
||||
size_t amount = fileUpperBound
|
||||
- (programHeaders[i].p_vaddr % B_PAGE_SIZE)
|
||||
- (programHeaders[i].p_filesz);
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
memset((void *)start, 0, amount);
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
|
||||
// Check if we need extra storage for the bss - we have to do this if
|
||||
// the above region doesn't already comprise the memory size, too.
|
||||
@@ -2050,20 +2050,20 @@ elf_load_user_image(const char *path, Team *team, uint32 flags, addr_t *entry)
|
||||
// modify the dynamic ptr by the delta of the regions
|
||||
image->dynamic_section += image->text_region.delta;
|
||||
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
status = elf_parse_dynamic_section(image);
|
||||
if (status != B_OK) {
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
return status;
|
||||
}
|
||||
|
||||
status = elf_relocate(image, image);
|
||||
if (status != B_OK) {
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
return status;
|
||||
}
|
||||
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
|
||||
// set correct area protection
|
||||
for (int i = 0; i < elfHeader.e_phnum; i++) {
|
||||
|
||||
@@ -83,9 +83,9 @@ user_atomic_or(int32* value, int32 orValue, bool isWired)
|
||||
{
|
||||
int32 result;
|
||||
if (isWired) {
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
result = atomic_or(value, orValue);
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -100,9 +100,9 @@ user_atomic_and(int32* value, int32 andValue, bool isWired)
|
||||
{
|
||||
int32 result;
|
||||
if (isWired) {
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
result = atomic_and(value, andValue);
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -117,9 +117,9 @@ user_atomic_get(int32* value, bool isWired)
|
||||
{
|
||||
int32 result;
|
||||
if (isWired) {
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
result = atomic_get(value);
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -135,9 +135,9 @@ user_atomic_test_and_set(int32* value, int32 newValue, int32 testAgainst,
|
||||
{
|
||||
int32 result;
|
||||
if (isWired) {
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
result = atomic_test_and_set(value, newValue, testAgainst);
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -942,17 +942,17 @@ handle_signals(Thread* thread)
|
||||
sigset_t nonBlockedMask = ~thread->sig_block_mask;
|
||||
sigset_t signalMask = thread->AllPendingSignals() & nonBlockedMask;
|
||||
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
if (thread->user_thread->defer_signals > 0
|
||||
&& (signalMask & NON_DEFERRABLE_SIGNALS) == 0
|
||||
&& thread->sigsuspend_original_unblocked_mask == 0) {
|
||||
thread->user_thread->pending_signals = signalMask;
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
return;
|
||||
}
|
||||
|
||||
thread->user_thread->pending_signals = 0;
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
|
||||
// determine syscall restart behavior
|
||||
uint32 restartFlags = atomic_and(&thread->flags,
|
||||
|
||||
@@ -651,14 +651,14 @@ enter_userspace(Thread* thread, UserThreadEntryArguments* args)
|
||||
|
||||
// init the thread's user_thread
|
||||
user_thread* userThread = thread->user_thread;
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
userThread->pthread = args->pthread;
|
||||
userThread->flags = 0;
|
||||
userThread->wait_status = B_OK;
|
||||
userThread->defer_signals
|
||||
= (args->flags & THREAD_CREATION_FLAG_DEFER_SIGNALS) != 0 ? 1 : 0;
|
||||
userThread->pending_signals = 0;
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
|
||||
// initialize default TLS fields
|
||||
addr_t tls[TLS_FIRST_FREE_SLOT];
|
||||
@@ -674,12 +674,12 @@ enter_userspace(Thread* thread, UserThreadEntryArguments* args)
|
||||
// This is a fork()ed thread.
|
||||
|
||||
// Update select TLS values, do not clear the whole array.
|
||||
set_ac();
|
||||
arch_cpu_enable_user_access();
|
||||
addr_t* userTls = (addr_t*)thread->user_local_storage;
|
||||
ASSERT(userTls[TLS_BASE_ADDRESS_SLOT] == thread->user_local_storage);
|
||||
userTls[TLS_THREAD_ID_SLOT] = tls[TLS_THREAD_ID_SLOT];
|
||||
userTls[TLS_USER_THREAD_SLOT] = tls[TLS_USER_THREAD_SLOT];
|
||||
clear_ac();
|
||||
arch_cpu_disable_user_access();
|
||||
|
||||
// Copy the fork args onto the stack and free them.
|
||||
arch_fork_arg archArgs = *args->forkArgs;
|
||||
|
||||
Reference in New Issue
Block a user