Skip to content

Commit

Permalink
Kernel: Mark compilation-unit-only functions as static
Browse files Browse the repository at this point in the history
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.

I found these places by using -Wmissing-declarations.

The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
	No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
	Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
	Not sure how to tell the compiler that the compiler is already using them.
	Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
	Could maybe go into a new header. This would also provide type-checking for new modules.
  • Loading branch information
BenWiederhake authored and awesomekling committed Aug 12, 2020
1 parent b1e8807 commit 42b057b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Kernel/FileSystem/FIFO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

namespace Kernel {

Lockable<HashTable<FIFO*>>& all_fifos()
static Lockable<HashTable<FIFO*>>& all_fifos()
{
static Lockable<HashTable<FIFO*>>* s_table;
if (!s_table)
Expand Down
2 changes: 1 addition & 1 deletion Kernel/FileSystem/Inode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Kernel {

static SpinLock s_all_inodes_lock;

InlineLinkedList<Inode>& all_inodes()
static InlineLinkedList<Inode>& all_inodes()
{
ASSERT(s_all_inodes_lock.is_locked());

Expand Down
58 changes: 29 additions & 29 deletions Kernel/FileSystem/ProcFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ ProcFS::~ProcFS()
{
}

Optional<KBuffer> procfs$pid_fds(InodeIdentifier identifier)
static Optional<KBuffer> procfs$pid_fds(InodeIdentifier identifier)
{
KBufferBuilder builder;
JsonArraySerializer array { builder };
Expand Down Expand Up @@ -296,7 +296,7 @@ Optional<KBuffer> procfs$pid_fds(InodeIdentifier identifier)
return builder.build();
}

Optional<KBuffer> procfs$pid_fd_entry(InodeIdentifier identifier)
static Optional<KBuffer> procfs$pid_fd_entry(InodeIdentifier identifier)
{
auto process = Process::from_pid(to_pid(identifier));
if (!process)
Expand All @@ -308,7 +308,7 @@ Optional<KBuffer> procfs$pid_fd_entry(InodeIdentifier identifier)
return description->absolute_path().to_byte_buffer();
}

Optional<KBuffer> procfs$pid_vm(InodeIdentifier identifier)
static Optional<KBuffer> procfs$pid_vm(InodeIdentifier identifier)
{
auto process = Process::from_pid(to_pid(identifier));
if (!process)
Expand Down Expand Up @@ -357,7 +357,7 @@ Optional<KBuffer> procfs$pid_vm(InodeIdentifier identifier)
return builder.build();
}

Optional<KBuffer> procfs$pci(InodeIdentifier)
static Optional<KBuffer> procfs$pci(InodeIdentifier)
{
KBufferBuilder builder;
JsonArraySerializer array { builder };
Expand All @@ -379,7 +379,7 @@ Optional<KBuffer> procfs$pci(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$interrupts(InodeIdentifier)
static Optional<KBuffer> procfs$interrupts(InodeIdentifier)
{
KBufferBuilder builder;
JsonArraySerializer array { builder };
Expand All @@ -396,7 +396,7 @@ Optional<KBuffer> procfs$interrupts(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$keymap(InodeIdentifier)
static Optional<KBuffer> procfs$keymap(InodeIdentifier)
{
KBufferBuilder builder;
JsonObjectSerializer<KBufferBuilder> json { builder };
Expand All @@ -405,7 +405,7 @@ Optional<KBuffer> procfs$keymap(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$devices(InodeIdentifier)
static Optional<KBuffer> procfs$devices(InodeIdentifier)
{
KBufferBuilder builder;
JsonArraySerializer array { builder };
Expand All @@ -426,22 +426,22 @@ Optional<KBuffer> procfs$devices(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$uptime(InodeIdentifier)
static Optional<KBuffer> procfs$uptime(InodeIdentifier)
{
KBufferBuilder builder;
builder.appendf("%u\n", (g_uptime / 1000));
return builder.build();
}

Optional<KBuffer> procfs$cmdline(InodeIdentifier)
static Optional<KBuffer> procfs$cmdline(InodeIdentifier)
{
KBufferBuilder builder;
builder.append(kernel_command_line().string());
builder.append('\n');
return builder.build();
}

Optional<KBuffer> procfs$modules(InodeIdentifier)
static Optional<KBuffer> procfs$modules(InodeIdentifier)
{
extern HashMap<String, OwnPtr<Module>>* g_modules;
KBufferBuilder builder;
Expand All @@ -461,7 +461,7 @@ Optional<KBuffer> procfs$modules(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$profile(InodeIdentifier)
static Optional<KBuffer> procfs$profile(InodeIdentifier)
{
InterruptDisabler disabler;
KBufferBuilder builder;
Expand Down Expand Up @@ -493,7 +493,7 @@ Optional<KBuffer> procfs$profile(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$net_adapters(InodeIdentifier)
static Optional<KBuffer> procfs$net_adapters(InodeIdentifier)
{
KBufferBuilder builder;
JsonArraySerializer array { builder };
Expand All @@ -519,7 +519,7 @@ Optional<KBuffer> procfs$net_adapters(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$net_arp(InodeIdentifier)
static Optional<KBuffer> procfs$net_arp(InodeIdentifier)
{
KBufferBuilder builder;
JsonArraySerializer array { builder };
Expand All @@ -533,7 +533,7 @@ Optional<KBuffer> procfs$net_arp(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$net_tcp(InodeIdentifier)
static Optional<KBuffer> procfs$net_tcp(InodeIdentifier)
{
KBufferBuilder builder;
JsonArraySerializer array { builder };
Expand All @@ -555,7 +555,7 @@ Optional<KBuffer> procfs$net_tcp(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$net_udp(InodeIdentifier)
static Optional<KBuffer> procfs$net_udp(InodeIdentifier)
{
KBufferBuilder builder;
JsonArraySerializer array { builder };
Expand All @@ -570,7 +570,7 @@ Optional<KBuffer> procfs$net_udp(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$net_local(InodeIdentifier)
static Optional<KBuffer> procfs$net_local(InodeIdentifier)
{
KBufferBuilder builder;
JsonArraySerializer array { builder };
Expand All @@ -588,7 +588,7 @@ Optional<KBuffer> procfs$net_local(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$pid_vmobjects(InodeIdentifier identifier)
static Optional<KBuffer> procfs$pid_vmobjects(InodeIdentifier identifier)
{
auto process = Process::from_pid(to_pid(identifier));
if (!process)
Expand Down Expand Up @@ -623,7 +623,7 @@ Optional<KBuffer> procfs$pid_vmobjects(InodeIdentifier identifier)
return builder.build();
}

Optional<KBuffer> procfs$pid_unveil(InodeIdentifier identifier)
static Optional<KBuffer> procfs$pid_unveil(InodeIdentifier identifier)
{
auto process = Process::from_pid(to_pid(identifier));
if (!process)
Expand All @@ -648,7 +648,7 @@ Optional<KBuffer> procfs$pid_unveil(InodeIdentifier identifier)
return builder.build();
}

Optional<KBuffer> procfs$tid_stack(InodeIdentifier identifier)
static Optional<KBuffer> procfs$tid_stack(InodeIdentifier identifier)
{
auto thread = Thread::from_tid(to_tid(identifier));
if (!thread)
Expand All @@ -659,7 +659,7 @@ Optional<KBuffer> procfs$tid_stack(InodeIdentifier identifier)
return builder.build();
}

Optional<KBuffer> procfs$pid_exe(InodeIdentifier identifier)
static Optional<KBuffer> procfs$pid_exe(InodeIdentifier identifier)
{
auto process = Process::from_pid(to_pid(identifier));
if (!process)
Expand All @@ -669,23 +669,23 @@ Optional<KBuffer> procfs$pid_exe(InodeIdentifier identifier)
return custody->absolute_path().to_byte_buffer();
}

Optional<KBuffer> procfs$pid_cwd(InodeIdentifier identifier)
static Optional<KBuffer> procfs$pid_cwd(InodeIdentifier identifier)
{
auto process = Process::from_pid(to_pid(identifier));
if (!process)
return {};
return process->current_directory().absolute_path().to_byte_buffer();
}

Optional<KBuffer> procfs$pid_root(InodeIdentifier identifier)
static Optional<KBuffer> procfs$pid_root(InodeIdentifier identifier)
{
auto process = Process::from_pid(to_pid(identifier));
if (!process)
return {};
return process->root_directory_relative_to_global_root().absolute_path().to_byte_buffer();
}

Optional<KBuffer> procfs$self(InodeIdentifier)
static Optional<KBuffer> procfs$self(InodeIdentifier)
{
char buffer[16];
sprintf(buffer, "%d", Process::current()->pid().value());
Expand All @@ -712,7 +712,7 @@ Optional<KBuffer> procfs$mm(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$dmesg(InodeIdentifier)
static Optional<KBuffer> procfs$dmesg(InodeIdentifier)
{
InterruptDisabler disabler;
KBufferBuilder builder;
Expand All @@ -721,7 +721,7 @@ Optional<KBuffer> procfs$dmesg(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$mounts(InodeIdentifier)
static Optional<KBuffer> procfs$mounts(InodeIdentifier)
{
// FIXME: This is obviously racy against the VFS mounts changing.
KBufferBuilder builder;
Expand All @@ -740,7 +740,7 @@ Optional<KBuffer> procfs$mounts(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$df(InodeIdentifier)
static Optional<KBuffer> procfs$df(InodeIdentifier)
{
// FIXME: This is obviously racy against the VFS mounts changing.
KBufferBuilder builder;
Expand All @@ -767,7 +767,7 @@ Optional<KBuffer> procfs$df(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$cpuinfo(InodeIdentifier)
static Optional<KBuffer> procfs$cpuinfo(InodeIdentifier)
{
KBufferBuilder builder;
JsonArraySerializer array { builder };
Expand Down Expand Up @@ -815,7 +815,7 @@ Optional<KBuffer> procfs$memstat(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$all(InodeIdentifier)
static Optional<KBuffer> procfs$all(InodeIdentifier)
{
KBufferBuilder builder;
JsonArraySerializer array { builder };
Expand Down Expand Up @@ -898,7 +898,7 @@ Optional<KBuffer> procfs$all(InodeIdentifier)
return builder.build();
}

Optional<KBuffer> procfs$inodes(InodeIdentifier)
static Optional<KBuffer> procfs$inodes(InodeIdentifier)
{
extern InlineLinkedList<Inode>& all_inodes();
KBufferBuilder builder;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/KSyms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static void load_kernel_sybols_from_data(const KBuffer& buffer)
g_kernel_symbols_available = true;
}

NEVER_INLINE void dump_backtrace_impl(FlatPtr base_pointer, bool use_ksyms)
NEVER_INLINE static void dump_backtrace_impl(FlatPtr base_pointer, bool use_ksyms)
{
SmapDisabler disabler;
#if 0
Expand Down
2 changes: 2 additions & 0 deletions Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ void Process::dump_regions()
MM.dump_kernel_regions();
}

// Make sure the compiler doesn't "optimize away" this function:
extern void signal_trampoline_dummy(void);
void signal_trampoline_dummy(void)
{
// The trampoline preserves the current eax, pushes the signal code and
Expand Down
2 changes: 1 addition & 1 deletion Kernel/RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static unsigned days_in_years_since_epoch(unsigned year)
return days;
}

u8 bcd_to_binary(u8 bcd)
static u8 bcd_to_binary(u8 bcd)
{
return (bcd & 0x0F) + ((bcd >> 4) * 10);
}
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Syscalls/futex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@

namespace Kernel {

void compute_relative_timeout_from_absolute(const timeval& absolute_time, timeval& relative_time)
static void compute_relative_timeout_from_absolute(const timeval& absolute_time, timeval& relative_time)
{
// Convert absolute time to relative time of day.
timeval_sub(absolute_time, kgettimeofday(), relative_time);
}

void compute_relative_timeout_from_absolute(const timespec& absolute_time, timeval& relative_time)
static void compute_relative_timeout_from_absolute(const timespec& absolute_time, timeval& relative_time)
{
timeval tv_absolute_time;
timespec_to_timeval(absolute_time, tv_absolute_time);
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ enum class DefaultSignalAction {
Continue,
};

DefaultSignalAction default_signal_action(u8 signal)
static DefaultSignalAction default_signal_action(u8 signal)
{
ASSERT(signal && signal < NSIG);

Expand Down
2 changes: 1 addition & 1 deletion Kernel/kprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ extern "C" int kernelputstr(const char* characters, int length)
return 0;
}

extern "C" int vdbgprintf(const char* fmt, va_list ap)
static int vdbgprintf(const char* fmt, va_list ap)
{
ScopedSpinLock lock(s_log_lock);
color_on();
Expand Down

0 comments on commit 42b057b

Please sign in to comment.