diff --git a/kernel/src/binfmt/BinaryFormat.cpp b/kernel/src/binfmt/BinaryFormat.cpp index 6388d023..3979a70a 100644 --- a/kernel/src/binfmt/BinaryFormat.cpp +++ b/kernel/src/binfmt/BinaryFormat.cpp @@ -1,6 +1,7 @@ #include "binfmt/BinaryFormat.h" #include "binfmt/ELF.h" #include "binfmt/Script.h" +#include "lib/Mutex.h" struct BinaryFormatDescriptor { @@ -10,6 +11,8 @@ struct BinaryFormatDescriptor Vector g_binary_formats; +static Mutex g_lock; + Result BinaryFormat::init() { TRY(register_binary_format(ELFLoader::create, nullptr)); @@ -20,6 +23,7 @@ Result BinaryFormat::init() Result BinaryFormat::register_binary_format(binfmt_loader_creator_t creator, void* arg) { + ScopedMutexLock lock(g_lock); return g_binary_formats.try_append({ creator, arg }); } @@ -27,6 +31,8 @@ Result> BinaryFormat::create_loader(SharedPtr= 8) return err(ELOOP); + ScopedMutexLock lock(g_lock); + for (const auto& format : g_binary_formats) { auto loader = TRY(format.creator(inode, format.arg, recursion_level)); diff --git a/kernel/src/fs/devices/DeviceRegistry.cpp b/kernel/src/fs/devices/DeviceRegistry.cpp index 0a6d8ad9..d3eccbda 100644 --- a/kernel/src/fs/devices/DeviceRegistry.cpp +++ b/kernel/src/fs/devices/DeviceRegistry.cpp @@ -12,6 +12,7 @@ #include "fs/devices/UARTDevice.h" #include "fs/devices/ZeroDevice.h" #include "fs/tmpfs/FileSystem.h" +#include "lib/Mutex.h" #include "thread/Thread.h" #include @@ -26,10 +27,14 @@ struct DeviceDescriptor Vector g_available_devices = {}; +static Mutex g_lock; + namespace DeviceRegistry { Result> fetch_special_device(u32 major, u32 minor) { + ScopedMutexLock lock(g_lock); + for (const auto& descriptor : g_available_devices) { if (descriptor.major == major && descriptor.minor == minor) return descriptor.device; @@ -38,7 +43,7 @@ namespace DeviceRegistry return err(ENODEV); } - Result create_special_device_inode(SharedPtr fs, const DeviceDescriptor& descriptor) + static Result create_special_device_inode(SharedPtr fs, const DeviceDescriptor& descriptor) { auto inode = TRY(fs->create_device_inode(descriptor.major, descriptor.minor, descriptor.mode)); TRY(fs->root_inode()->add_entry(inode, descriptor.name)); @@ -48,6 +53,8 @@ namespace DeviceRegistry Result register_special_device(u32 major, u32 minor, SharedPtr device, mode_t mode) { + ScopedMutexLock lock(g_lock); + for (const auto& descriptor : g_available_devices) { if (descriptor.major == major && descriptor.minor == minor) return err(EEXIST); @@ -82,7 +89,7 @@ namespace DeviceRegistry dev_t next_null_device_id() { - static u32 next_minor = 0; + static Atomic next_minor = 0; return luna_dev_makedev(0, next_minor++); }