Skip to content

Commit 85a53ba

Browse files
linusgnico
authored andcommitted
Kernel+LibC: Remove emuctl syscall
This is a leftover from UserspaceEmulator which was removed in 3f9d0c7 and fd31672.
1 parent 222acc9 commit 85a53ba

File tree

9 files changed

+3
-94
lines changed

9 files changed

+3
-94
lines changed

Kernel/API/Syscall.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ enum class NeedsBigProcessLock {
6969
S(disown, NeedsBigProcessLock::No) \
7070
S(dump_backtrace, NeedsBigProcessLock::No) \
7171
S(dup2, NeedsBigProcessLock::No) \
72-
S(emuctl, NeedsBigProcessLock::No) \
7372
S(execve, NeedsBigProcessLock::Yes) \
7473
S(exit, NeedsBigProcessLock::Yes) \
7574
S(exit_thread, NeedsBigProcessLock::Yes) \

Kernel/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ set(KERNEL_SOURCES
310310
Syscalls/debug.cpp
311311
Syscalls/disown.cpp
312312
Syscalls/dup2.cpp
313-
Syscalls/emuctl.cpp
314313
Syscalls/execve.cpp
315314
Syscalls/exit.cpp
316315
Syscalls/faccessat.cpp

Kernel/Syscalls/emuctl.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

Kernel/Tasks/Process.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ class Process final
348348
void stop_tracing();
349349
void tracer_trap(Thread&, RegisterState const&);
350350

351-
ErrorOr<FlatPtr> sys$emuctl();
352351
ErrorOr<FlatPtr> sys$yield();
353352
ErrorOr<FlatPtr> sys$sync();
354353
ErrorOr<FlatPtr> sys$beep(int tone);

Meta/gn/secondary/Kernel/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,6 @@ executable("Kernel_bin") {
724724
"Syscalls/debug.cpp",
725725
"Syscalls/disown.cpp",
726726
"Syscalls/dup2.cpp",
727-
"Syscalls/emuctl.cpp",
728727
"Syscalls/execve.cpp",
729728
"Syscalls/exit.cpp",
730729
"Syscalls/faccessat.cpp",

Tests/Kernel/fuzz-syscalls.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static bool is_unfuzzable_syscall(int fn)
3030

3131
static bool is_nosys_syscall(int fn)
3232
{
33-
return fn == SC_futex || fn == SC_emuctl;
33+
return fn == SC_futex;
3434
}
3535

3636
static bool is_bad_idea(int fn, size_t const* direct_sc_args, size_t const* fake_sc_params, char const* some_string)

Userland/Libraries/LibC/malloc.cpp

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -53,44 +53,6 @@ static bool s_log_malloc = false;
5353
static bool s_scrub_malloc = true;
5454
static bool s_scrub_free = true;
5555
static bool s_profiling = false;
56-
static bool s_in_userspace_emulator = false;
57-
58-
ALWAYS_INLINE static void ue_notify_malloc(void const* ptr, size_t size)
59-
{
60-
if (s_in_userspace_emulator)
61-
syscall(SC_emuctl, 1, size, (FlatPtr)ptr);
62-
}
63-
64-
ALWAYS_INLINE static void ue_notify_free(void const* ptr)
65-
{
66-
if (s_in_userspace_emulator)
67-
syscall(SC_emuctl, 2, (FlatPtr)ptr, 0);
68-
}
69-
70-
ALWAYS_INLINE static void ue_notify_realloc(void const* ptr, size_t size)
71-
{
72-
if (s_in_userspace_emulator)
73-
syscall(SC_emuctl, 3, size, (FlatPtr)ptr);
74-
}
75-
76-
ALWAYS_INLINE static void ue_notify_chunk_size_changed(void const* block, size_t chunk_size)
77-
{
78-
if (s_in_userspace_emulator)
79-
syscall(SC_emuctl, 4, chunk_size, (FlatPtr)block);
80-
}
81-
82-
struct MemoryAuditingSuppressor {
83-
ALWAYS_INLINE MemoryAuditingSuppressor()
84-
{
85-
if (s_in_userspace_emulator)
86-
syscall(SC_emuctl, 7);
87-
}
88-
ALWAYS_INLINE ~MemoryAuditingSuppressor()
89-
{
90-
if (s_in_userspace_emulator)
91-
syscall(SC_emuctl, 8);
92-
}
93-
};
9456

9557
struct MallocStats {
9658
size_t number_of_malloc_calls;
@@ -348,20 +310,15 @@ static ErrorOr<void*> malloc_impl(size_t size, size_t align, CallerWillInitializ
348310
new (block) BigAllocationBlock(real_size);
349311
}
350312

351-
void* ptr = reinterpret_cast<void*>(round_up_to_power_of_two(reinterpret_cast<uintptr_t>(&block->m_slot[0]), align));
352-
353-
ue_notify_malloc(ptr, size);
354-
return ptr;
313+
return reinterpret_cast<void*>(round_up_to_power_of_two(reinterpret_cast<uintptr_t>(&block->m_slot[0]), align));
355314
}
356315
}
357316
#endif
358317
auto* block = (BigAllocationBlock*)TRY(os_alloc(real_size, "malloc: BigAllocationBlock"));
359318
g_malloc_stats.number_of_big_allocs++;
360319
new (block) BigAllocationBlock(real_size);
361320

362-
void* ptr = reinterpret_cast<void*>(round_up_to_power_of_two(reinterpret_cast<uintptr_t>(&block->m_slot[0]), align));
363-
ue_notify_malloc(ptr, size);
364-
return ptr;
321+
return reinterpret_cast<void*>(round_up_to_power_of_two(reinterpret_cast<uintptr_t>(&block->m_slot[0]), align));
365322
}
366323

367324
ChunkedBlock* block = nullptr;
@@ -381,7 +338,6 @@ static ErrorOr<void*> malloc_impl(size_t size, size_t align, CallerWillInitializ
381338
block = s_hot_empty_blocks[--s_hot_empty_block_count];
382339
if (block->m_size != good_size) {
383340
new (block) ChunkedBlock(good_size);
384-
ue_notify_chunk_size_changed(block, good_size);
385341
char buffer[64];
386342
snprintf(buffer, sizeof(buffer), "malloc: ChunkedBlock(%zu)", good_size);
387343
set_mmap_name(block, ChunkedBlock::block_size, buffer);
@@ -407,7 +363,6 @@ static ErrorOr<void*> malloc_impl(size_t size, size_t align, CallerWillInitializ
407363
if (this_block_was_purged)
408364
g_malloc_stats.number_of_cold_empty_block_purge_hits++;
409365
new (block) ChunkedBlock(good_size);
410-
ue_notify_chunk_size_changed(block, good_size);
411366
}
412367
allocator->usable_blocks.append(*block);
413368
}
@@ -438,7 +393,6 @@ static ErrorOr<void*> malloc_impl(size_t size, size_t align, CallerWillInitializ
438393
if (s_scrub_malloc && caller_will_initialize_memory == CallerWillInitializeMemory::No)
439394
memset(ptr, MALLOC_SCRUB_BYTE, block->m_size);
440395

441-
ue_notify_malloc(ptr, size);
442396
return ptr;
443397
}
444398

@@ -538,7 +492,6 @@ static void free_impl(void* ptr)
538492
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html
539493
void* malloc(size_t size)
540494
{
541-
MemoryAuditingSuppressor suppressor;
542495
auto ptr_or_error = malloc_impl(size, 16, CallerWillInitializeMemory::No);
543496

544497
if (ptr_or_error.is_error()) {
@@ -555,17 +508,14 @@ void* malloc(size_t size)
555508
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html
556509
void free(void* ptr)
557510
{
558-
MemoryAuditingSuppressor suppressor;
559511
if (s_profiling)
560512
perf_event(PERF_EVENT_FREE, reinterpret_cast<FlatPtr>(ptr), 0);
561-
ue_notify_free(ptr);
562513
free_impl(ptr);
563514
}
564515

565516
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/calloc.html
566517
void* calloc(size_t count, size_t size)
567518
{
568-
MemoryAuditingSuppressor suppressor;
569519
if (Checked<size_t>::multiplication_would_overflow(count, size)) {
570520
errno = ENOMEM;
571521
return nullptr;
@@ -585,7 +535,6 @@ void* calloc(size_t count, size_t size)
585535
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_memalign.html
586536
int posix_memalign(void** memptr, size_t alignment, size_t size)
587537
{
588-
MemoryAuditingSuppressor suppressor;
589538
auto ptr_or_error = malloc_impl(size, alignment, CallerWillInitializeMemory::No);
590539

591540
if (ptr_or_error.is_error())
@@ -597,7 +546,6 @@ int posix_memalign(void** memptr, size_t alignment, size_t size)
597546

598547
void* aligned_alloc(size_t alignment, size_t size)
599548
{
600-
MemoryAuditingSuppressor suppressor;
601549
auto ptr_or_error = malloc_impl(size, alignment, CallerWillInitializeMemory::No);
602550

603551
if (ptr_or_error.is_error()) {
@@ -610,7 +558,6 @@ void* aligned_alloc(size_t alignment, size_t size)
610558

611559
size_t malloc_size(void const* ptr)
612560
{
613-
MemoryAuditingSuppressor suppressor;
614561
if (!ptr)
615562
return 0;
616563
void* page_base = (void*)((FlatPtr)ptr & ChunkedBlock::block_mask);
@@ -632,7 +579,6 @@ size_t malloc_good_size(size_t size)
632579

633580
void* realloc(void* ptr, size_t size)
634581
{
635-
MemoryAuditingSuppressor suppressor;
636582
if (!ptr)
637583
return malloc(size);
638584
if (!size) {
@@ -643,7 +589,6 @@ void* realloc(void* ptr, size_t size)
643589
auto existing_allocation_size = malloc_size(ptr);
644590

645591
if (size <= existing_allocation_size) {
646-
ue_notify_realloc(ptr, size);
647592
return ptr;
648593
}
649594
auto* new_ptr = malloc(size);
@@ -656,14 +601,6 @@ void* realloc(void* ptr, size_t size)
656601

657602
void __malloc_init()
658603
{
659-
s_in_userspace_emulator = (int)syscall(SC_emuctl, 0) != -ENOSYS;
660-
if (s_in_userspace_emulator) {
661-
// Don't bother scrubbing memory if we're running in UE since it
662-
// keeps track of heap memory anyway.
663-
s_scrub_malloc = false;
664-
s_scrub_free = false;
665-
}
666-
667604
if (secure_getenv("LIBC_NOSCRUB_MALLOC"))
668605
s_scrub_malloc = false;
669606
if (secure_getenv("LIBC_NOSCRUB_FREE"))

Userland/Libraries/LibC/serenity.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ u16 internet_checksum(void const* ptr, size_t count)
147147
return htons(~checksum);
148148
}
149149

150-
int emuctl(uintptr_t command, uintptr_t arg0, uintptr_t arg1)
151-
{
152-
return syscall(SC_emuctl, command, arg0, arg1);
153-
}
154-
155150
int serenity_open(char const* path, size_t path_length, int options, ...)
156151
{
157152
if (!path) {

Userland/Libraries/LibC/serenity.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ int setkeymap(char const* name, uint32_t const* map, uint32_t* const shift_map,
6868

6969
uint16_t internet_checksum(void const* ptr, size_t count);
7070

71-
int emuctl(uintptr_t command, uintptr_t arg0, uintptr_t arg1);
72-
7371
int serenity_open(char const* path, size_t path_length, int options, ...);
7472

7573
__END_DECLS

0 commit comments

Comments
 (0)