diff --git a/include/kernel/cpu/ipi.h b/include/kernel/cpu/ipi.h index 98c85d3d4..bf6a0c2f1 100644 --- a/include/kernel/cpu/ipi.h +++ b/include/kernel/cpu/ipi.h @@ -56,7 +56,7 @@ typedef struct ipi_chip */ typedef struct { - void* private; + void* data; } ipi_func_data_t; /** @@ -73,7 +73,7 @@ typedef void (*ipi_func_t)(ipi_func_data_t* data); typedef struct ipi { ipi_func_t func; - void* private; + void* data; } ipi_t; /** @@ -158,7 +158,7 @@ uint64_t ipi_chip_amount(void); * @param cpu The specified CPU, check `ipi_flags_t`. * @param flags The flags for how to send the IPI. * @param func The function to execute on target CPU(s). - * @param private The private data to pass to the function, will be found in `irq_func_data_t->private`. + * @param private The private data to pass to the function, will be found in `irq_func_data_t->data`. * @return On success, `0`. On failure, `ERR` and `errno` is set to: * - `EINVAL`: Invalid parameters. * - `ENODEV`: No IPI chip is registered. @@ -166,7 +166,7 @@ uint64_t ipi_chip_amount(void); * - `EBUSY`: The target CPU's IPI queue is full, some or all IPIs could not be sent. * - Other errors returned by the IPI chip's `notify` function. */ -uint64_t ipi_send(cpu_t* cpu, ipi_flags_t flags, ipi_func_t func, void* private); +uint64_t ipi_send(cpu_t* cpu, ipi_flags_t flags, ipi_func_t func, void* data); /** * @brief Wake up one or more CPUs. diff --git a/include/kernel/cpu/irq.h b/include/kernel/cpu/irq.h index 6166d1f21..c818d01a5 100644 --- a/include/kernel/cpu/irq.h +++ b/include/kernel/cpu/irq.h @@ -64,7 +64,7 @@ typedef struct { interrupt_frame_t* frame; irq_virt_t virt; - void* private; + void* data; } irq_func_data_t; /** @@ -79,7 +79,7 @@ typedef struct { list_entry_t entry; irq_func_t func; - void* private; + void* data; irq_virt_t virt; } irq_handler_t; @@ -127,7 +127,7 @@ typedef struct irq_domain { list_entry_t entry; irq_chip_t* chip; - void* private; + void* data; irq_phys_t start; ///< Inclusive irq_phys_t end; ///< Exclusive } irq_domain_t; @@ -222,14 +222,14 @@ uint64_t irq_virt_set_affinity(irq_virt_t virt, cpu_t* cpu); * @param chip The IRQ chip to register. * @param start The start of the physical IRQ range. * @param end The end of the physical IRQ range. - * @param private Private data for the IRQ chip, will be found in `irq_t->domain->private`. + * @param private Private data for the IRQ chip, will be found in `irq_t->domain->data`. * @return On success, `0`. On failure, `ERR` and `errno` is set to: * - `EINVAL`: Invalid parameters. * - `EEXIST`: A chip with a domain overlapping the given range is already registered. * - `ENOMEM`: Memory allocation failed. * - Other errors as returned by the IRQ chip's `enable` function. */ -uint64_t irq_chip_register(irq_chip_t* chip, irq_phys_t start, irq_phys_t end, void* private); +uint64_t irq_chip_register(irq_chip_t* chip, irq_phys_t start, irq_phys_t end, void* data); /** * @brief Unregister all instances of the given IRQ chip within the specified range. @@ -265,7 +265,7 @@ uint64_t irq_chip_amount(void); * - `ENOMEM`: Memory allocation failed. * - Other errors as returned by the IRQ chip's `enable` function. */ -uint64_t irq_handler_register(irq_virt_t virt, irq_func_t func, void* private); +uint64_t irq_handler_register(irq_virt_t virt, irq_func_t func, void* data); /** * @brief Unregister an IRQ handler. diff --git a/include/kernel/cpu/regs.h b/include/kernel/cpu/regs.h index 25f96a0ca..01c38773c 100644 --- a/include/kernel/cpu/regs.h +++ b/include/kernel/cpu/regs.h @@ -11,7 +11,7 @@ #define XCR0_ZMM16_32_ENABLE (1 << 7) #define MSR_LAPIC 0x1B -#define MSR_IA32_TSC_AUX 0xC0000103 +#define MSR_TSC_AUX 0xC0000103 #define MSR_EFER 0xC0000080 #define MSR_STAR 0xC0000081 #define MSR_LSTAR 0xC0000082 diff --git a/include/kernel/drivers/abstract/fb.h b/include/kernel/drivers/abstract/fb.h index a7847819e..9cb44c6a2 100644 --- a/include/kernel/drivers/abstract/fb.h +++ b/include/kernel/drivers/abstract/fb.h @@ -76,7 +76,7 @@ typedef struct fb { char name[MAX_PATH]; const fb_ops_t* ops; - void* private; + void* data; dentry_t* dir; list_t files; } fb_t; @@ -89,7 +89,7 @@ typedef struct fb * @param private Private data for the framebuffer. * @return On success, the new framebuffer. On failure, `NULL` and `errno` is set. */ -fb_t* fb_new(const char* name, const fb_ops_t* ops, void* private); +fb_t* fb_new(const char* name, const fb_ops_t* ops, void* data); /** * @brief Frees a framebuffer. diff --git a/include/kernel/fs/dentry.h b/include/kernel/fs/dentry.h index d65d4e92c..8e8a2eaae 100644 --- a/include/kernel/fs/dentry.h +++ b/include/kernel/fs/dentry.h @@ -110,7 +110,7 @@ typedef struct dir_ctx */ bool (*emit)(dir_ctx_t* ctx, const char* name, ino_t number, itype_t type); size_t pos; ///< The current position in the directory, can be used to skip entries. - void* private; ///< Private data that the filesystem can use to conveniently pass data. + void* data; ///< Private data that the filesystem can use to conveniently pass data. size_t index; ///< An index that the filesystem can use for its own purposes. } dir_ctx_t; @@ -162,7 +162,7 @@ typedef struct dentry list_t children; superblock_t* superblock; const dentry_ops_t* ops; - void* private; + void* data; struct dentry* next; ///< Next dentry in the dentry cache hash bucket. _Atomic(uint64_t) mountCount; ///< Number of mounts targeting this dentry. rcu_entry_t rcu; ///< RCU entry for deferred cleanup. diff --git a/include/kernel/fs/devfs.h b/include/kernel/fs/devfs.h index eb611ed72..bd4f521d2 100644 --- a/include/kernel/fs/devfs.h +++ b/include/kernel/fs/devfs.h @@ -39,7 +39,7 @@ void devfs_init(void); * @param private Private data to store in the inode of the new directory, can be `NULL`. * @return On success, the new devfs directory. On failure, `NULL` and `errno` is set. */ -dentry_t* devfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* private); +dentry_t* devfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* data); /** * @brief Create a new file inside a mounted devfs instance. @@ -52,7 +52,7 @@ dentry_t* devfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* i * @return On success, the new devfs file. On failure, `NULL` and `errno` is set. */ dentry_t* devfs_file_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, const file_ops_t* fileOps, - void* private); + void* data); /** * @brief Create a new symbolic link inside a mounted devfs instance. @@ -63,7 +63,7 @@ dentry_t* devfs_file_new(dentry_t* parent, const char* name, const inode_ops_t* * @param private Private data to store in the inode of the new symbolic link, can be `NULL`. * @return On success, the new devfs symbolic link. On failure, `NULL` and `errno` is set. */ -dentry_t* devfs_symlink_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* private); +dentry_t* devfs_symlink_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* data); /** * @brief Descriptor for batch file creation. @@ -74,7 +74,7 @@ typedef struct devfs_file_desc const char* name; ///< Name of the file, `NULL` marks end of array. const inode_ops_t* inodeOps; ///< Inode operations, can be `NULL`. const file_ops_t* fileOps; ///< File operations, can be `NULL`. - void* private; ///< Private data to store in the inode of the file. + void* data; ///< Private data to store in the inode of the file. } devfs_file_desc_t; /** diff --git a/include/kernel/fs/file.h b/include/kernel/fs/file.h index 3a62d2eee..fd4587f8a 100644 --- a/include/kernel/fs/file.h +++ b/include/kernel/fs/file.h @@ -43,7 +43,7 @@ typedef struct file inode_t* inode; path_t path; const file_ops_t* ops; - void* private; + void* data; } file_t; /** diff --git a/include/kernel/fs/filesystem.h b/include/kernel/fs/filesystem.h index fdc83ced3..180aae5c5 100644 --- a/include/kernel/fs/filesystem.h +++ b/include/kernel/fs/filesystem.h @@ -65,7 +65,7 @@ typedef struct filesystem * @param private Private data for the filesystem's mount function. * @return On success, the root dentry of the mounted filesystem. On failure, `NULL` and `errno` is set. */ - dentry_t* (*mount)(filesystem_t* fs, const char* details, void* private); + dentry_t* (*mount)(filesystem_t* fs, const char* details, void* data); } filesystem_t; /**s diff --git a/include/kernel/fs/inode.h b/include/kernel/fs/inode.h index 20945a9c3..1c3be5781 100644 --- a/include/kernel/fs/inode.h +++ b/include/kernel/fs/inode.h @@ -58,7 +58,7 @@ typedef struct inode time_t modifyTime; ///< Unix time stamp for last file content alteration. time_t changeTime; ///< Unix time stamp for the last file metadata alteration. time_t createTime; ///< Unix time stamp for the inode creation. - void* private; + void* data; superblock_t* superblock; const inode_ops_t* ops; const file_ops_t* fileOps; diff --git a/include/kernel/fs/namespace.h b/include/kernel/fs/namespace.h index 379ea1758..3d496ed4b 100644 --- a/include/kernel/fs/namespace.h +++ b/include/kernel/fs/namespace.h @@ -136,7 +136,7 @@ bool namespace_rcu_traverse(namespace_t* ns, mount_t** mount, dentry_t** dentry) * - Other errors as returned by the filesystem's `mount()` operation or `mount_new()`. */ mount_t* namespace_mount(namespace_t* ns, path_t* target, filesystem_t* fs, const char* options, mode_t mode, - void* private); + void* data); /** * @brief Bind a source path to a target path in a namespace. diff --git a/include/kernel/fs/netfs.h b/include/kernel/fs/netfs.h index dff17aefc..290fc8687 100644 --- a/include/kernel/fs/netfs.h +++ b/include/kernel/fs/netfs.h @@ -132,7 +132,7 @@ typedef struct socket socket_type_t type; socket_state_t state; weak_ptr_t ownerNs; ///< A weak pointer to the namespace that created the socket. - void* private; + void* data; mutex_t mutex; } socket_t; diff --git a/include/kernel/fs/superblock.h b/include/kernel/fs/superblock.h index 26905b8ef..929a3b89c 100644 --- a/include/kernel/fs/superblock.h +++ b/include/kernel/fs/superblock.h @@ -35,7 +35,7 @@ typedef struct superblock sbid_t id; uint64_t blockSize; uint64_t maxFileSize; - void* private; + void* data; dentry_t* root; ///< Root dentry of the filesystem, should not take a reference. const superblock_ops_t* ops; const dentry_ops_t* dentryOps; diff --git a/include/kernel/fs/sysfs.h b/include/kernel/fs/sysfs.h index c57c7f23d..9657516ac 100644 --- a/include/kernel/fs/sysfs.h +++ b/include/kernel/fs/sysfs.h @@ -44,7 +44,7 @@ void sysfs_init(void); * @param private Private data to store in the inode of the new directory, can be `NULL`. * @return On success, the new sysfs directory. On failure, `NULL` and `errno` is set. */ -dentry_t* sysfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* private); +dentry_t* sysfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* data); /** * @brief Create a new file inside a mounted sysfs instance. @@ -57,7 +57,7 @@ dentry_t* sysfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* i * @return On success, the new sysfs file. On failure, `NULL` and `errno` is set. */ dentry_t* sysfs_file_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, const file_ops_t* fileOps, - void* private); + void* data); /** * @brief Create a new symbolic link inside a mounted sysfs instance. @@ -68,7 +68,7 @@ dentry_t* sysfs_file_new(dentry_t* parent, const char* name, const inode_ops_t* * @param private Private data to store in the inode of the new symbolic link, can be `NULL`. * @return On success, the new sysfs symbolic link. On failure, `NULL` and `errno` is set. */ -dentry_t* sysfs_symlink_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* private); +dentry_t* sysfs_symlink_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* data); /** * @brief Descriptor for batch file creation. @@ -79,7 +79,7 @@ typedef struct sysfs_file_desc const char* name; ///< Name of the file, `NULL` marks end of array. const inode_ops_t* inodeOps; ///< Inode operations, can be `NULL`. const file_ops_t* fileOps; ///< File operations, can be `NULL`. - void* private; ///< Private data to store in the inode of the file. + void* data; ///< Private data to store in the inode of the file. } sysfs_file_desc_t; /** diff --git a/include/kernel/mem/space.h b/include/kernel/mem/space.h index 125abe6b1..b6780e5b0 100644 --- a/include/kernel/mem/space.h +++ b/include/kernel/mem/space.h @@ -39,7 +39,7 @@ typedef enum /** * @brief Space callback function. */ -typedef void (*space_callback_func_t)(void* private); +typedef void (*space_callback_func_t)( void* data); /** * @brief Space callback structure. @@ -48,7 +48,7 @@ typedef void (*space_callback_func_t)(void* private); typedef struct { space_callback_func_t func; - void* private; + void* data; uint64_t pageAmount; } space_callback_t; @@ -261,7 +261,7 @@ uint64_t space_mapping_start(space_t* space, space_mapping_t* mapping, void* vir * @param private Private data to pass to the callback function. * @return On success, returns the callback ID. On failure, returns `PML_MAX_CALLBACK`. */ -pml_callback_id_t space_alloc_callback(space_t* space, size_t pageAmount, space_callback_func_t func, void* private); +pml_callback_id_t space_alloc_callback(space_t* space, size_t pageAmount, space_callback_func_t func, void* data); /** * @brief Free a callback. diff --git a/include/kernel/mem/vmm.h b/include/kernel/mem/vmm.h index 3f6fcac92..474993a13 100644 --- a/include/kernel/mem/vmm.h +++ b/include/kernel/mem/vmm.h @@ -195,7 +195,7 @@ void* vmm_alloc(space_t* space, void* virtAddr, size_t length, size_t alignment, * - Other values from `space_mapping_start()`. */ void* vmm_map(space_t* space, void* virtAddr, void* physAddr, size_t length, pml_flags_t flags, - space_callback_func_t func, void* private); + space_callback_func_t func, void* data); /** * @brief Maps an array of physical pages to virtual memory in a given address space. @@ -220,7 +220,7 @@ void* vmm_map(space_t* space, void* virtAddr, void* physAddr, size_t length, pml * - Other values from `space_mapping_start()`. */ void* vmm_map_pages(space_t* space, void* virtAddr, void** pages, size_t pageAmount, pml_flags_t flags, - space_callback_func_t func, void* private); + space_callback_func_t func, void* data); /** * @brief Unmaps virtual memory from a given address space. diff --git a/include/kernel/sync/rcu.h b/include/kernel/sync/rcu.h index f8151227f..b5d5c71a2 100644 --- a/include/kernel/sync/rcu.h +++ b/include/kernel/sync/rcu.h @@ -42,8 +42,8 @@ typedef struct rcu_entry rcu_entry_t; * To access RCU protected data, a read-side critical section must be created using `rcu_read_lock()` and * `rcu_read_unlock()`, or the `RCU_READ_SCOPE()` macro. * - * @see [https://en.wikipedia.org/wiki/Read-copy-update](Wikipedia) for more information about RCU. - * @see [https://www.kernel.org/doc/Documentation/RCU/whatisRCU.txt](kernel.org) for a explanation of RCU in the Linux kernel. + * @see [Wikipedia](https://en.wikipedia.org/wiki/Read-copy-update) for more information about RCU. + * @see [kernel.org](https://www.kernel.org/doc/Documentation/RCU/whatisRCU.txt) for a explanation of RCU in the Linux kernel. * * @{ */ diff --git a/include/libpatchwork/element.h b/include/libpatchwork/element.h index fa201f372..9eea29d9c 100644 --- a/include/libpatchwork/element.h +++ b/include/libpatchwork/element.h @@ -98,7 +98,7 @@ typedef struct * @return On success, a pointer to the new element. On failure, `NULL` and `errno` is set. */ element_t* element_new(element_t* parent, element_id_t id, const rect_t* rect, const char* text, element_flags_t flags, - procedure_t procedure, void* private); + procedure_t procedure, void* data); /** * @brief Deinitialize and free an element and all its children. @@ -126,7 +126,7 @@ element_t* element_find(element_t* elem, element_id_t id); * @param elem The element. * @param private Pointer to the private data. */ -void element_set_private(element_t* elem, void* private); +void element_set_private(element_t* elem, void* data); /** * @brief Get private data for an element. diff --git a/include/libpatchwork/window.h b/include/libpatchwork/window.h index d91475343..c79e112db 100644 --- a/include/libpatchwork/window.h +++ b/include/libpatchwork/window.h @@ -61,7 +61,7 @@ typedef enum window_flags * @return On success, the new window. On failure, returns `NULL` and `errno` is set. */ window_t* window_new(display_t* disp, const char* name, const rect_t* rect, surface_type_t type, window_flags_t flags, - procedure_t procedure, void* private); + procedure_t procedure, void* data); /** * @brief Free a window. diff --git a/include/libstd/_internal/clock_t.h b/include/libstd/_internal/clock_t.h index 221851036..9a36f1ace 100644 --- a/include/libstd/_internal/clock_t.h +++ b/include/libstd/_internal/clock_t.h @@ -14,6 +14,7 @@ typedef __UINT64_TYPE__ clock_t; #define CLOCKS_PER_SEC ((clock_t)1000000000ULL) #define CLOCKS_PER_MS ((clock_t)1000000ULL) +#define CLOCKS_PER_US ((clock_t)1000ULL) #define CLOCKS_NEVER ((clock_t)__UINT64_MAX__) /** diff --git a/include/libstd/sys/bitmap.h b/include/libstd/sys/bitmap.h index f5006cab7..09e06e068 100644 --- a/include/libstd/sys/bitmap.h +++ b/include/libstd/sys/bitmap.h @@ -115,7 +115,12 @@ typedef struct * @param buffer Pointer to the buffer, must be a multiple of 8 bytes. * @param length Length of the bitmap in bits. */ -void bitmap_init(bitmap_t* map, void* buffer, uint64_t length); +static inline void bitmap_init(bitmap_t* map, void* buffer, uint64_t length) +{ + map->firstZeroIdx = 0; + map->length = length; + map->buffer = (uint64_t*)buffer; +} /** * @brief Check if the bitmap is empty (all bits clear). @@ -123,7 +128,29 @@ void bitmap_init(bitmap_t* map, void* buffer, uint64_t length); * @param map The bitmap. * @return true if the bitmap is empty, false otherwise. */ -bool bitmap_is_empty(bitmap_t* map); +static inline bool bitmap_is_empty(bitmap_t* map) +{ + uint64_t fullQwords = map->length / 64; + for (uint64_t i = 0; i < fullQwords; i++) + { + if (map->buffer[i] != 0) + { + return false; + } + } + + uint64_t remainingBits = map->length % 64; + if (remainingBits != 0) + { + uint64_t mask = (1ULL << remainingBits) - 1; + if ((map->buffer[fullQwords] & mask) != 0) + { + return false; + } + } + + return true; +} /** * @brief Check if a bit is set in the bitmap. @@ -132,7 +159,17 @@ bool bitmap_is_empty(bitmap_t* map); * @param idx Index of the bit to check. * @return true if the bit is set, false otherwise. */ -bool bitmap_is_set(bitmap_t* map, uint64_t idx); +static inline bool bitmap_is_set(bitmap_t* map, uint64_t idx) +{ + if (idx >= map->length) + { + return false; + } + + uint64_t qwordIdx = idx / 64; + uint64_t bitInQword = idx % 64; + return (map->buffer[qwordIdx] & (1ULL << bitInQword)); +} /** * @brief Set a bit in the bitmap. @@ -140,7 +177,17 @@ bool bitmap_is_set(bitmap_t* map, uint64_t idx); * @param map Pointer to the bitmap. * @param index Index of the bit to set. */ -void bitmap_set(bitmap_t* map, uint64_t index); +static inline void bitmap_set(bitmap_t* map, uint64_t index) +{ + if (index >= map->length) + { + return; + } + + uint64_t qwordIdx = index / 64; + uint64_t bitInQword = index % 64; + map->buffer[qwordIdx] |= (1ULL << bitInQword); +} /** * @brief Set a range of bits in the bitmap. @@ -149,7 +196,34 @@ void bitmap_set(bitmap_t* map, uint64_t index); * @param low Low index of the range (inclusive). * @param high High index of the range (exclusive). */ -void bitmap_set_range(bitmap_t* map, uint64_t low, uint64_t high); +static inline void bitmap_set_range(bitmap_t* map, uint64_t low, uint64_t high) +{ + if (low >= high || high > map->length) + { + return; + } + + uint64_t firstQwordIdx = low / 64; + uint64_t firstBitInQword = low % 64; + uint64_t lastQwordIdx = (high - 1) / 64; + uint64_t lastBitInQword = (high - 1) % 64; + + if (firstQwordIdx == lastQwordIdx) + { + uint64_t mask = (~0ULL << firstBitInQword) & (~0ULL >> (63 - lastBitInQword)); + map->buffer[firstQwordIdx] |= mask; + return; + } + + map->buffer[firstQwordIdx] |= (~0ULL << firstBitInQword); + + for (uint64_t i = firstQwordIdx + 1; i < lastQwordIdx; i++) + { + map->buffer[i] = ~0ULL; + } + + map->buffer[lastQwordIdx] |= (~0ULL >> (63 - lastBitInQword)); +} /** * @brief Clear a bit in the bitmap. @@ -157,7 +231,18 @@ void bitmap_set_range(bitmap_t* map, uint64_t low, uint64_t high); * @param map Pointer to the bitmap. * @param index Index of the bit to clear. */ -void bitmap_clear(bitmap_t* map, uint64_t index); +static inline void bitmap_clear(bitmap_t* map, uint64_t index) +{ + if (index >= map->length) + { + return; + } + + uint64_t qwordIdx = index / 64; + uint64_t bitInQword = index % 64; + map->buffer[qwordIdx] &= ~(1ULL << bitInQword); + map->firstZeroIdx = MIN(map->firstZeroIdx, index); +} /** * @brief Clear a range of bits in the bitmap. @@ -166,7 +251,39 @@ void bitmap_clear(bitmap_t* map, uint64_t index); * @param low Low index of the range (inclusive). * @param high High index of the range (exclusive). */ -void bitmap_clear_range(bitmap_t* map, uint64_t low, uint64_t high); +static inline void bitmap_clear_range(bitmap_t* map, uint64_t low, uint64_t high) +{ + if (low >= high || high > map->length) + { + return; + } + + if (low < map->firstZeroIdx) + { + map->firstZeroIdx = low; + } + + uint64_t firstQwordIdx = low / 64; + uint64_t firstBitInQword = low % 64; + uint64_t lastQwordIdx = (high - 1) / 64; + uint64_t lastBitInQword = (high - 1) % 64; + + if (firstQwordIdx == lastQwordIdx) + { + uint64_t mask = (~0ULL << firstBitInQword) & (~0ULL >> (63 - lastBitInQword)); + map->buffer[firstQwordIdx] &= ~mask; + return; + } + + map->buffer[firstQwordIdx] &= ~(~0ULL << firstBitInQword); + + for (uint64_t i = firstQwordIdx + 1; i < lastQwordIdx; i++) + { + map->buffer[i] = 0ULL; + } + + map->buffer[lastQwordIdx] &= ~(~0ULL >> (63 - lastBitInQword)); +} /** * @brief Find the first clear bit in the bitmap. @@ -176,7 +293,39 @@ void bitmap_clear_range(bitmap_t* map, uint64_t low, uint64_t high); * @param endIdx Index to stop searching at (exclusive). * @return Index of the first clear bit, or `map->length` if none found. */ -uint64_t bitmap_find_first_clear(bitmap_t* map, uint64_t startIdx, uint64_t endIdx); +static inline uint64_t bitmap_find_first_clear(bitmap_t* map, uint64_t startIdx, uint64_t endIdx) +{ + if (map->firstZeroIdx >= map->length) + { + return map->length; + } + + startIdx = MAX(startIdx, map->firstZeroIdx); + uint64_t qwordIdx = startIdx / 64; + uint64_t bitIdx = startIdx % 64; + uint64_t endQwordIdx = BITMAP_BITS_TO_QWORDS(MIN(endIdx, map->length)); + + if (bitIdx != 0) + { + uint64_t qword = map->buffer[qwordIdx]; + uint64_t maskedQword = qword | ((1ULL << bitIdx) - 1); + if (maskedQword != ~0ULL) + { + return qwordIdx * 64 + __builtin_ctzll(~maskedQword); + } + qwordIdx++; + } + + for (uint64_t i = qwordIdx; i < endQwordIdx; ++i) + { + if (map->buffer[i] != ~0ULL) + { + return i * 64 + __builtin_ctzll(~map->buffer[i]); + } + } + + return map->length; +} /** * @brief Find the first set bit in the bitmap. @@ -186,7 +335,36 @@ uint64_t bitmap_find_first_clear(bitmap_t* map, uint64_t startIdx, uint64_t endI * @param endIdx Index to stop searching at (exclusive). * @return Index of the first set bit, or `map->length` if none found. */ -uint64_t bitmap_find_first_set(bitmap_t* map, uint64_t startIdx, uint64_t endIdx); +static inline uint64_t bitmap_find_first_set(bitmap_t* map, uint64_t startIdx, uint64_t endIdx) +{ + if (startIdx >= map->length) + { + return map->length; + } + + uint64_t startQwordIdx = startIdx / 64; + uint64_t startBitIdx = startIdx % 64; + uint64_t endQwordIdx = BITMAP_BITS_TO_QWORDS(MIN(endIdx, map->length)); + + while (startQwordIdx < endQwordIdx) + { + uint64_t qword = map->buffer[startQwordIdx]; + if (startBitIdx != 0) + { + qword &= ~((1ULL << startBitIdx) - 1); + } + + if (qword != 0) + { + return startQwordIdx * 64 + __builtin_ctzll(qword); + } + + startQwordIdx++; + startBitIdx = 0; + } + + return map->length; +} /** * @brief Find a clear region of specified length and alignment, and set it. @@ -198,8 +376,35 @@ uint64_t bitmap_find_first_set(bitmap_t* map, uint64_t startIdx, uint64_t endIdx * @param alignment Alignment of the region. * @return Starting index of the found region, or `map->length` if not found. */ -uint64_t bitmap_find_clear_region_and_set(bitmap_t* map, uint64_t minIdx, uintptr_t maxIdx, uint64_t length, - uint64_t alignment); +static inline uint64_t bitmap_find_clear_region_and_set(bitmap_t* map, uint64_t minIdx, uintptr_t maxIdx, uint64_t length, + uint64_t alignment) +{ + if (length == 0 || minIdx >= maxIdx || maxIdx > map->length) + { + return map->length; + } + + if (alignment == 0) + { + alignment = 1; + } + + uint64_t idx = MAX(minIdx, map->firstZeroIdx); + idx = ROUND_UP(idx, alignment); + + while (idx <= maxIdx - length) + { + uint64_t firstSet = bitmap_find_first_set(map, idx, idx + length); + if (firstSet >= idx + length) + { + bitmap_set_range(map, idx, idx + length); + return idx; + } + idx = ROUND_UP(firstSet + 1, alignment); + } + + return map->length; +} /** @} */ diff --git a/include/libstd/sys/elf.h b/include/libstd/sys/elf.h index 1fcaa26c0..6675836a7 100644 --- a/include/libstd/sys/elf.h +++ b/include/libstd/sys/elf.h @@ -896,7 +896,7 @@ void elf64_load_segments(const Elf64_File* elf, Elf64_Addr base, Elf64_Off offse * @return On success, `0`. On failure, `ERR`. */ uint64_t elf64_relocate(const Elf64_File* elf, Elf64_Addr base, Elf64_Off offset, - void* (*resolve_symbol)(const char* name, void* private), void* private); + void* (*resolve_symbol)(const char* name, void* data), void* data); /** * @brief Get a string from the string table section at the given offset diff --git a/src/kernel/cpu/cpu.c b/src/kernel/cpu/cpu.c index 9b8e2404d..bf3cb97f0 100644 --- a/src/kernel/cpu/cpu.c +++ b/src/kernel/cpu/cpu.c @@ -28,6 +28,7 @@ void cpu_init(cpu_t* cpu) { cpu_id_t id = _cpuAmount++; _cpus[id] = cpu; + msr_write(MSR_TSC_AUX, id); cpu->self = cpu; cpu->id = id; diff --git a/src/kernel/cpu/ipi.c b/src/kernel/cpu/ipi.c index d9652800f..5cdc10987 100644 --- a/src/kernel/cpu/ipi.c +++ b/src/kernel/cpu/ipi.c @@ -49,7 +49,7 @@ void ipi_handle_pending(interrupt_frame_t* frame) ctx->readIndex = (ctx->readIndex + 1) % IPI_QUEUE_SIZE; ipi_func_data_t ipiData = { - .private = ipi.private, + .data = ipi.data, }; ipi.func(&ipiData); } @@ -107,7 +107,7 @@ uint64_t ipi_chip_amount(void) return registeredChip != NULL ? 1 : 0; } -static uint64_t ipi_push(cpu_t* cpu, ipi_func_t func, void* private) +static uint64_t ipi_push(cpu_t* cpu, ipi_func_t func, void* data) { if (registeredChip == NULL) { @@ -132,12 +132,12 @@ static uint64_t ipi_push(cpu_t* cpu, ipi_func_t func, void* private) } ctx->queue[ctx->writeIndex].func = func; - ctx->queue[ctx->writeIndex].private = private; + ctx->queue[ctx->writeIndex].data = data; ctx->writeIndex = nextWriteIndex; return 0; } -uint64_t ipi_send(cpu_t* cpu, ipi_flags_t flags, ipi_func_t func, void* private) +uint64_t ipi_send(cpu_t* cpu, ipi_flags_t flags, ipi_func_t func, void* data) { if (func == NULL) { @@ -157,7 +157,7 @@ uint64_t ipi_send(cpu_t* cpu, ipi_flags_t flags, ipi_func_t func, void* private) return ERR; } - if (ipi_push(cpu, func, private) == ERR) + if (ipi_push(cpu, func, data) == ERR) { return ERR; } @@ -170,7 +170,7 @@ uint64_t ipi_send(cpu_t* cpu, ipi_flags_t flags, ipi_func_t func, void* private) cpu_t* cpu; CPU_FOR_EACH(cpu) { - if (ipi_push(cpu, func, private) == ERR) + if (ipi_push(cpu, func, data) == ERR) { return ERR; } @@ -195,7 +195,7 @@ uint64_t ipi_send(cpu_t* cpu, ipi_flags_t flags, ipi_func_t func, void* private) continue; } - if (ipi_push(iter, func, private) == ERR) + if (ipi_push(iter, func, data) == ERR) { return ERR; } diff --git a/src/kernel/cpu/irq.c b/src/kernel/cpu/irq.c index 98de6d507..deabc209f 100644 --- a/src/kernel/cpu/irq.c +++ b/src/kernel/cpu/irq.c @@ -155,7 +155,7 @@ void irq_dispatch(interrupt_frame_t* frame) irq_func_data_t data = { .frame = frame, .virt = frame->vector, - .private = handler->private, + .data = handler->data, }; handler->func(&data); @@ -325,7 +325,7 @@ uint64_t irq_virt_set_affinity(irq_virt_t virt, cpu_t* cpu) return 0; } -uint64_t irq_chip_register(irq_chip_t* chip, irq_phys_t start, irq_phys_t end, void* private) +uint64_t irq_chip_register(irq_chip_t* chip, irq_phys_t start, irq_phys_t end, void* data) { if (chip == NULL || chip->enable == NULL || chip->disable == NULL || start >= end) { @@ -353,7 +353,7 @@ uint64_t irq_chip_register(irq_chip_t* chip, irq_phys_t start, irq_phys_t end, v } list_entry_init(&domain->entry); domain->chip = chip; - domain->private = private; + domain->data = data; domain->start = start; domain->end = end; @@ -420,7 +420,7 @@ uint64_t irq_chip_amount(void) return list_size(&domains); } -uint64_t irq_handler_register(irq_virt_t virt, irq_func_t func, void* private) +uint64_t irq_handler_register(irq_virt_t virt, irq_func_t func, void* data) { if (func == NULL) { @@ -455,7 +455,7 @@ uint64_t irq_handler_register(irq_virt_t virt, irq_func_t func, void* private) } list_entry_init(&handler->entry); handler->func = func; - handler->private = private; + handler->data = data; handler->virt = virt; list_push_back(&irq->handlers, &handler->entry); diff --git a/src/kernel/drivers/abstract/fb.c b/src/kernel/drivers/abstract/fb.c index 9bfc611de..5a37a1d47 100644 --- a/src/kernel/drivers/abstract/fb.c +++ b/src/kernel/drivers/abstract/fb.c @@ -17,7 +17,7 @@ static dentry_t* dir = NULL; static size_t fb_name_read(file_t* file, void* buffer, size_t count, size_t* offset) { - fb_t* fb = file->inode->private; + fb_t* fb = file->inode->data; assert(fb != NULL); uint64_t length = strlen(fb->name); @@ -30,7 +30,7 @@ static file_ops_t nameOps = { static size_t fb_data_read(file_t* file, void* buffer, size_t count, size_t* offset) { - fb_t* fb = file->inode->private; + fb_t* fb = file->inode->data; assert(fb != NULL); if (fb->ops->read == NULL) @@ -44,7 +44,7 @@ static size_t fb_data_read(file_t* file, void* buffer, size_t count, size_t* off static size_t fb_data_write(file_t* file, const void* buffer, size_t count, size_t* offset) { - fb_t* fb = file->inode->private; + fb_t* fb = file->inode->data; assert(fb != NULL); if (fb->ops->write == NULL) @@ -58,7 +58,7 @@ static size_t fb_data_write(file_t* file, const void* buffer, size_t count, size static void* fb_data_mmap(file_t* file, void* addr, size_t length, size_t* offset, pml_flags_t flags) { - fb_t* fb = file->inode->private; + fb_t* fb = file->inode->data; assert(fb != NULL); if (fb->ops->mmap == NULL) @@ -78,7 +78,7 @@ static file_ops_t dataOps = { static size_t fb_info_read(file_t* file, void* buffer, size_t count, size_t* offset) { - fb_t* fb = file->inode->private; + fb_t* fb = file->inode->data; assert(fb != NULL); if (fb->ops->info == NULL) @@ -117,7 +117,7 @@ static file_ops_t infoOps = { static void fb_dir_cleanup(inode_t* inode) { - fb_t* fb = inode->private; + fb_t* fb = inode->data; if (fb->ops->cleanup != NULL) { @@ -131,7 +131,7 @@ static inode_ops_t dirInodeOps = { .cleanup = fb_dir_cleanup, }; -fb_t* fb_new(const char* name, const fb_ops_t* ops, void* private) +fb_t* fb_new(const char* name, const fb_ops_t* ops, void* data) { if (name == NULL || ops == NULL) { @@ -157,7 +157,7 @@ fb_t* fb_new(const char* name, const fb_ops_t* ops, void* private) strncpy(fb->name, name, sizeof(fb->name)); fb->name[sizeof(fb->name) - 1] = '\0'; fb->ops = ops; - fb->private = private; + fb->data = data; fb->dir = NULL; list_init(&fb->files); @@ -181,19 +181,19 @@ fb_t* fb_new(const char* name, const fb_ops_t* ops, void* private) .name = "name", .inodeOps = NULL, .fileOps = &nameOps, - .private = fb, + .data = fb, }, { .name = "info", .inodeOps = NULL, .fileOps = &infoOps, - .private = fb, + .data = fb, }, { .name = "data", .inodeOps = NULL, .fileOps = &dataOps, - .private = fb, + .data = fb, }, { .name = NULL, diff --git a/src/kernel/drivers/abstract/kbd.c b/src/kernel/drivers/abstract/kbd.c index 03bfaa33e..30d6d6231 100644 --- a/src/kernel/drivers/abstract/kbd.c +++ b/src/kernel/drivers/abstract/kbd.c @@ -24,7 +24,7 @@ static atomic_uint64_t newId = ATOMIC_VAR_INIT(0); static size_t kbd_name_read(file_t* file, void* buffer, size_t count, size_t* offset) { - kbd_t* kbd = file->inode->private; + kbd_t* kbd = file->inode->data; assert(kbd != NULL); size_t length = strlen(kbd->name); @@ -37,7 +37,7 @@ static file_ops_t nameOps = { static uint64_t kbd_events_open(file_t* file) { - kbd_t* kbd = file->inode->private; + kbd_t* kbd = file->inode->data; assert(kbd != NULL); kbd_client_t* client = calloc(1, sizeof(kbd_client_t)); @@ -53,16 +53,16 @@ static uint64_t kbd_events_open(file_t* file) list_push_back(&kbd->clients, &client->entry); lock_release(&kbd->lock); - file->private = client; + file->data = client; return 0; } static void kbd_events_close(file_t* file) { - kbd_t* kbd = file->inode->private; + kbd_t* kbd = file->inode->data; assert(kbd != NULL); - kbd_client_t* client = file->private; + kbd_client_t* client = file->data; if (client == NULL) { return; @@ -84,9 +84,9 @@ static size_t kbd_events_read(file_t* file, void* buffer, size_t count, size_t* return 0; } - kbd_t* kbd = file->inode->private; + kbd_t* kbd = file->inode->data; assert(kbd != NULL); - kbd_client_t* client = file->private; + kbd_client_t* client = file->data; assert(client != NULL); LOCK_SCOPE(&kbd->lock); @@ -110,9 +110,9 @@ static size_t kbd_events_read(file_t* file, void* buffer, size_t count, size_t* static wait_queue_t* kbd_events_poll(file_t* file, poll_events_t* revents) { - kbd_t* kbd = file->inode->private; + kbd_t* kbd = file->inode->data; assert(kbd != NULL); - kbd_client_t* client = file->private; + kbd_client_t* client = file->data; assert(client != NULL); LOCK_SCOPE(&kbd->lock); @@ -133,7 +133,7 @@ static file_ops_t eventsOps = { static void kbd_dir_cleanup(inode_t* inode) { - kbd_t* kbd = inode->private; + kbd_t* kbd = inode->data; if (kbd == NULL) { return; @@ -199,12 +199,12 @@ kbd_t* kbd_new(const char* name) { .name = "name", .fileOps = &nameOps, - .private = kbd, + .data = kbd, }, { .name = "events", .fileOps = &eventsOps, - .private = kbd, + .data = kbd, }, { .name = NULL, diff --git a/src/kernel/drivers/abstract/mouse.c b/src/kernel/drivers/abstract/mouse.c index 110325896..42edf6285 100644 --- a/src/kernel/drivers/abstract/mouse.c +++ b/src/kernel/drivers/abstract/mouse.c @@ -18,7 +18,7 @@ static atomic_uint64_t newId = ATOMIC_VAR_INIT(0); static size_t mouse_name_read(file_t* file, void* buffer, size_t count, size_t* offset) { - mouse_t* mouse = file->inode->private; + mouse_t* mouse = file->inode->data; assert(mouse != NULL); size_t length = strlen(mouse->name); @@ -31,7 +31,7 @@ static file_ops_t nameOps = { static uint64_t mouse_events_open(file_t* file) { - mouse_t* mouse = file->inode->private; + mouse_t* mouse = file->inode->data; assert(mouse != NULL); mouse_client_t* client = calloc(1, sizeof(mouse_client_t)); @@ -47,16 +47,16 @@ static uint64_t mouse_events_open(file_t* file) list_push_back(&mouse->clients, &client->entry); lock_release(&mouse->lock); - file->private = client; + file->data = client; return 0; } static void mouse_events_close(file_t* file) { - mouse_t* mouse = file->inode->private; + mouse_t* mouse = file->inode->data; assert(mouse != NULL); - mouse_client_t* client = file->private; + mouse_client_t* client = file->data; if (client == NULL) { return; @@ -78,9 +78,9 @@ static size_t mouse_events_read(file_t* file, void* buffer, size_t count, size_t return 0; } - mouse_t* mouse = file->inode->private; + mouse_t* mouse = file->inode->data; assert(mouse != NULL); - mouse_client_t* client = file->private; + mouse_client_t* client = file->data; assert(client != NULL); LOCK_SCOPE(&mouse->lock); @@ -104,9 +104,9 @@ static size_t mouse_events_read(file_t* file, void* buffer, size_t count, size_t static wait_queue_t* mouse_events_poll(file_t* file, poll_events_t* revents) { - mouse_t* mouse = file->inode->private; + mouse_t* mouse = file->inode->data; assert(mouse != NULL); - mouse_client_t* client = file->private; + mouse_client_t* client = file->data; assert(client != NULL); LOCK_SCOPE(&mouse->lock); @@ -127,7 +127,7 @@ static file_ops_t eventsOps = { static void mouse_dir_cleanup(inode_t* inode) { - mouse_t* mouse = inode->private; + mouse_t* mouse = inode->data; if (mouse == NULL) { return; @@ -193,12 +193,12 @@ mouse_t* mouse_new(const char* name) { .name = "name", .fileOps = &nameOps, - .private = mouse, + .data = mouse, }, { .name = "events", .fileOps = &eventsOps, - .private = mouse, + .data = mouse, }, { .name = NULL, diff --git a/src/kernel/fs/dentry.c b/src/kernel/fs/dentry.c index 988601cc6..3712de65f 100644 --- a/src/kernel/fs/dentry.c +++ b/src/kernel/fs/dentry.c @@ -94,7 +94,7 @@ static void dentry_free(dentry_t* dentry) { dentry->ops->cleanup(dentry); } - dentry->private = NULL; + dentry->data = NULL; if (dentry->inode != NULL) { @@ -122,7 +122,7 @@ static void dentry_ctor(void* ptr) list_init(&dentry->children); dentry->superblock = NULL; dentry->ops = NULL; - dentry->private = NULL; + dentry->data = NULL; dentry->next = NULL; atomic_init(&dentry->mountCount, 0); dentry->rcu = (rcu_entry_t){0}; diff --git a/src/kernel/fs/devfs.c b/src/kernel/fs/devfs.c index 003dc5bc3..986774023 100644 --- a/src/kernel/fs/devfs.c +++ b/src/kernel/fs/devfs.c @@ -32,10 +32,10 @@ static dentry_ops_t dentryOps = { .iterate = dentry_generic_iterate, }; -static dentry_t* devfs_mount(filesystem_t* fs, const char* options, void* private) +static dentry_t* devfs_mount(filesystem_t* fs, const char* options, void* data) { UNUSED(fs); - UNUSED(private); + UNUSED(data); if (options != NULL) { @@ -83,7 +83,7 @@ void devfs_init(void) root = dentry; } -dentry_t* devfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* private) +dentry_t* devfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* data) { if (name == NULL) { @@ -115,7 +115,7 @@ dentry_t* devfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* i return NULL; } UNREF_DEFER(inode); - inode->private = private; + inode->data = data; dentry_make_positive(dir, inode); @@ -123,7 +123,7 @@ dentry_t* devfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* i } dentry_t* devfs_file_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, const file_ops_t* fileOps, - void* private) + void* data) { if (name == NULL) { @@ -155,14 +155,14 @@ dentry_t* devfs_file_new(dentry_t* parent, const char* name, const inode_ops_t* return NULL; } UNREF_DEFER(inode); - inode->private = private; + inode->data = data; dentry_make_positive(dentry, inode); return REF(dentry); } -dentry_t* devfs_symlink_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* private) +dentry_t* devfs_symlink_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* data) { if (parent == NULL || name == NULL || inodeOps == NULL) { @@ -189,7 +189,7 @@ dentry_t* devfs_symlink_new(dentry_t* parent, const char* name, const inode_ops_ return NULL; } UNREF_DEFER(inode); - inode->private = private; + inode->data = data; dentry_make_positive(dentry, inode); @@ -220,7 +220,7 @@ uint64_t devfs_files_new(list_t* out, dentry_t* parent, const devfs_file_desc_t* uint64_t count = 0; for (const devfs_file_desc_t* desc = descs; desc->name != NULL; desc++) { - dentry_t* file = devfs_file_new(parent, desc->name, desc->inodeOps, desc->fileOps, desc->private); + dentry_t* file = devfs_file_new(parent, desc->name, desc->inodeOps, desc->fileOps, desc->data); if (file == NULL) { while (!list_is_empty(&createdList)) diff --git a/src/kernel/fs/file.c b/src/kernel/fs/file.c index 54fa7e842..110683ab8 100644 --- a/src/kernel/fs/file.c +++ b/src/kernel/fs/file.c @@ -64,7 +64,7 @@ file_t* file_new(const path_t* path, mode_t mode) file->inode = REF(path->dentry->inode); file->path = PATH_CREATE(path->mount, path->dentry); file->ops = path->dentry->inode->fileOps; - file->private = NULL; + file->data = NULL; return file; } diff --git a/src/kernel/fs/filesystem.c b/src/kernel/fs/filesystem.c index a60be820c..9fb4b28aa 100644 --- a/src/kernel/fs/filesystem.c +++ b/src/kernel/fs/filesystem.c @@ -44,7 +44,7 @@ static map_key_t filesystem_key(const char* name) static size_t superblock_read(file_t* file, void* buffer, size_t count, size_t* offset) { - superblock_t* sb = file->inode->private; + superblock_t* sb = file->inode->data; assert(sb != NULL); char info[MAX_PATH]; @@ -60,14 +60,14 @@ static size_t superblock_read(file_t* file, void* buffer, size_t count, size_t* static void superblock_cleanup(inode_t* inode) { - superblock_t* sb = inode->private; + superblock_t* sb = inode->data; if (sb == NULL) { return; } UNREF(sb); - inode->private = NULL; + inode->data = NULL; } static file_ops_t sbFileOps = { @@ -80,7 +80,7 @@ static inode_ops_t sbInodeOps = { static uint64_t filesystem_lookup(inode_t* dir, dentry_t* dentry) { - filesystem_t* fs = dir->private; + filesystem_t* fs = dir->data; assert(fs != NULL); sbid_t id; @@ -105,7 +105,7 @@ static uint64_t filesystem_lookup(inode_t* dir, dentry_t* dentry) { return ERR; } - inode->private = REF(sb); + inode->data = REF(sb); dentry_make_positive(dentry, inode); return 0; } @@ -120,7 +120,7 @@ static uint64_t filesystem_iterate(dentry_t* dentry, dir_ctx_t* ctx) return 0; } - filesystem_t* fs = dentry->inode->private; + filesystem_t* fs = dentry->inode->data; assert(fs != NULL); RWLOCK_READ_SCOPE(&fs->lock); @@ -170,7 +170,7 @@ static uint64_t filesystem_dir_lookup(inode_t* dir, dentry_t* dentry) return ERR; } UNREF_DEFER(inode); - inode->private = fs; + inode->data = fs; dentry->ops = &fsDentryOps; dentry_make_positive(dentry, inode); @@ -320,7 +320,7 @@ filesystem_t* filesystem_get_by_path(const char* path, process_t* process) return NULL; } - return target.dentry->inode->private; + return target.dentry->inode->data; } bool options_next(const char** iter, char* buffer, size_t size, char** key, char** value) diff --git a/src/kernel/fs/inode.c b/src/kernel/fs/inode.c index 57a8498e9..3ba31d3ed 100644 --- a/src/kernel/fs/inode.c +++ b/src/kernel/fs/inode.c @@ -19,7 +19,7 @@ static void inode_free(inode_t* inode) { inode->ops->cleanup(inode); } - inode->private = NULL; + inode->data = NULL; if (inode->superblock != NULL) { @@ -44,7 +44,7 @@ static void inode_ctor(void* ptr) inode->modifyTime = 0; inode->changeTime = 0; inode->createTime = 0; - inode->private = NULL; + inode->data = NULL; inode->superblock = NULL; inode->ops = NULL; inode->fileOps = NULL; diff --git a/src/kernel/fs/namespace.c b/src/kernel/fs/namespace.c index b5f5f8b57..b222ae2d5 100644 --- a/src/kernel/fs/namespace.c +++ b/src/kernel/fs/namespace.c @@ -385,7 +385,7 @@ bool namespace_rcu_traverse(namespace_t* ns, mount_t** mount, dentry_t** dentry) } mount_t* namespace_mount(namespace_t* ns, path_t* target, filesystem_t* fs, const char* options, mode_t mode, - void* private) + void* data) { if (ns == NULL || fs == NULL) { @@ -393,7 +393,7 @@ mount_t* namespace_mount(namespace_t* ns, path_t* target, filesystem_t* fs, cons return NULL; } - dentry_t* root = fs->mount(fs, options, private); + dentry_t* root = fs->mount(fs, options, data); if (root == NULL) { return NULL; diff --git a/src/kernel/fs/netfs.c b/src/kernel/fs/netfs.c index ae12bd7dd..1b019bba9 100644 --- a/src/kernel/fs/netfs.c +++ b/src/kernel/fs/netfs.c @@ -52,7 +52,7 @@ static socket_t* socket_new(netfs_family_t* family, socket_type_t type) socket->type = type; socket->state = SOCKET_NEW; weak_ptr_set(&socket->ownerNs, NULL, NULL, NULL); - socket->private = NULL; + socket->data = NULL; mutex_init(&socket->mutex); if (socket->family->init(socket) == ERR) @@ -72,16 +72,16 @@ typedef struct socket_file static uint64_t netfs_data_open(file_t* file) { - socket_t* sock = file->inode->private; + socket_t* sock = file->inode->data; assert(sock != NULL); - file->private = REF(sock); + file->data = REF(sock); return 0; } static void netfs_data_close(file_t* file) { - socket_t* sock = file->private; + socket_t* sock = file->data; if (sock == NULL) { return; @@ -92,7 +92,7 @@ static void netfs_data_close(file_t* file) static size_t netfs_data_read(file_t* file, void* buf, size_t count, size_t* offset) { - socket_t* sock = file->private; + socket_t* sock = file->data; assert(sock != NULL); if (sock->family->recv == NULL) @@ -114,7 +114,7 @@ static size_t netfs_data_read(file_t* file, void* buf, size_t count, size_t* off static size_t netfs_data_write(file_t* file, const void* buf, size_t count, size_t* offset) { - socket_t* sock = file->private; + socket_t* sock = file->data; assert(sock != NULL); if (sock->family->send == NULL) @@ -136,7 +136,7 @@ static size_t netfs_data_write(file_t* file, const void* buf, size_t count, size static wait_queue_t* netfs_data_poll(file_t* file, poll_events_t* revents) { - socket_t* sock = file->private; + socket_t* sock = file->data; assert(sock != NULL); if (sock->family->poll == NULL) @@ -160,7 +160,7 @@ static file_ops_t dataOps = { static uint64_t netfs_accept_open(file_t* file) { - socket_t* sock = file->inode->private; + socket_t* sock = file->inode->data; assert(sock != NULL); if (sock->family->accept == NULL) @@ -190,7 +190,7 @@ static uint64_t netfs_accept_open(file_t* file) } newSock->state = SOCKET_CONNECTED; - file->private = newSock; + file->data = newSock; file->ops = &dataOps; return 0; } @@ -203,7 +203,7 @@ static uint64_t netfs_ctl_bind(file_t* file, uint64_t argc, const char** argv) { UNUSED(argc); - socket_t* sock = file->inode->private; + socket_t* sock = file->inode->data; assert(sock != NULL); if (sock->family->bind == NULL) @@ -252,7 +252,7 @@ static uint64_t netfs_ctl_listen(file_t* file, uint64_t argc, const char** argv) } } - socket_t* sock = file->inode->private; + socket_t* sock = file->inode->data; assert(sock != NULL); if (sock->family->listen == NULL) @@ -282,7 +282,7 @@ static uint64_t netfs_ctl_connect(file_t* file, uint64_t argc, const char** argv { UNUSED(argc); - socket_t* sock = file->inode->private; + socket_t* sock = file->inode->data; assert(sock != NULL); if (sock->family->connect == NULL) @@ -341,7 +341,7 @@ static uint64_t netfs_socket_lookup(inode_t* dir, dentry_t* dentry) return ERR; } UNREF_DEFER(inode); - inode->private = dir->private; // No reference + inode->data = dir->data; // No reference dentry_make_positive(dentry, inode); return 0; @@ -352,7 +352,7 @@ static uint64_t netfs_socket_lookup(inode_t* dir, dentry_t* dentry) static void netfs_socket_cleanup(inode_t* inode) { - socket_t* socket = (socket_t*)inode->private; + socket_t* socket = (socket_t*)inode->data; if (socket == NULL) { return; @@ -414,7 +414,7 @@ static void socket_weak_ptr_callback(void* arg) static uint64_t netfs_factory_open(file_t* file) { - netfs_family_file_ctx_t* ctx = file->inode->private; + netfs_family_file_ctx_t* ctx = file->inode->data; assert(ctx != NULL); dentry_t* root = file->inode->superblock->root; assert(root != NULL); @@ -439,13 +439,13 @@ static uint64_t netfs_factory_open(file_t* file) weak_ptr_set(&socket->ownerNs, &ns->ref, socket_weak_ptr_callback, REF(socket)); - file->private = REF(socket); + file->data = REF(socket); return 0; } static void netfs_factory_close(file_t* file) { - socket_t* socket = file->private; + socket_t* socket = file->data; if (socket == NULL) { return; @@ -456,7 +456,7 @@ static void netfs_factory_close(file_t* file) static size_t netfs_factory_read(file_t* file, void* buffer, size_t count, size_t* offset) { - socket_t* socket = file->private; + socket_t* socket = file->data; if (socket == NULL) { return 0; @@ -473,7 +473,7 @@ static file_ops_t factoryFileOps = { static size_t netfs_addrs_read(file_t* file, void* buffer, size_t count, size_t* offset) { - netfs_family_file_ctx_t* ctx = file->inode->private; + netfs_family_file_ctx_t* ctx = file->inode->data; assert(ctx != NULL); RWMUTEX_READ_SCOPE(&ctx->family->mutex); @@ -527,14 +527,14 @@ static netfs_family_file_t familyFiles[] = { static void netfs_file_cleanup(inode_t* inode) { - netfs_family_file_ctx_t* ctx = inode->private; + netfs_family_file_ctx_t* ctx = inode->data; if (ctx == NULL) { return; } free(ctx); - inode->private = NULL; + inode->data = NULL; } static inode_ops_t familyFileInodeOps = { @@ -543,7 +543,7 @@ static inode_ops_t familyFileInodeOps = { static uint64_t netfs_family_lookup(inode_t* dir, dentry_t* dentry) { - netfs_family_t* family = dir->private; + netfs_family_t* family = dir->data; assert(family != NULL); for (size_t i = 0; i < ARRAY_SIZE(familyFiles); i++) @@ -568,7 +568,7 @@ static uint64_t netfs_family_lookup(inode_t* dir, dentry_t* dentry) } ctx->family = family; ctx->fileInfo = &familyFiles[i]; - inode->private = ctx; + inode->data = ctx; dentry_make_positive(dentry, inode); return 0; @@ -614,7 +614,7 @@ static uint64_t netfs_family_lookup(inode_t* dir, dentry_t* dentry) return ERR; } UNREF_DEFER(inode); - inode->private = REF(socket); + inode->data = REF(socket); dentry->ops = &socketDentryOps; @@ -627,7 +627,7 @@ static uint64_t netfs_family_lookup(inode_t* dir, dentry_t* dentry) static uint64_t netfs_family_iterate(dentry_t* dentry, dir_ctx_t* ctx) { - netfs_family_t* family = dentry->inode->private; + netfs_family_t* family = dentry->inode->data; assert(family != NULL); if (!dentry_iterate_dots(dentry, ctx)) @@ -718,7 +718,7 @@ static uint64_t netfs_lookup(inode_t* dir, dentry_t* dentry) return ERR; } UNREF_DEFER(inode); - inode->private = family; + inode->data = family; dentry->ops = &familyDentryOps; @@ -763,9 +763,9 @@ static dentry_ops_t netDentryOps = { .iterate = netfs_iterate, }; -static dentry_t* netfs_mount(filesystem_t* fs, const char* options, void* private) +static dentry_t* netfs_mount(filesystem_t* fs, const char* options, void* data) { - UNUSED(private); + UNUSED(data); if (options != NULL) { diff --git a/src/kernel/fs/procfs.c b/src/kernel/fs/procfs.c index 93df16f42..da3b38a4b 100644 --- a/src/kernel/fs/procfs.c +++ b/src/kernel/fs/procfs.c @@ -31,7 +31,7 @@ static uint64_t procfs_revalidate_hide(dentry_t* dentry) { process_t* current = process_current(); assert(current != NULL); - process_t* process = dentry->inode->private; + process_t* process = dentry->inode->data; assert(process != NULL); namespace_t* currentNs = process_get_ns(current); @@ -63,7 +63,7 @@ static dentry_ops_t hideDentryOps = { static size_t procfs_prio_read(file_t* file, void* buffer, size_t count, size_t* offset) { - process_t* process = file->inode->private; + process_t* process = file->inode->data; priority_t priority = atomic_load(&process->priority); @@ -76,7 +76,7 @@ static size_t procfs_prio_write(file_t* file, const void* buffer, size_t count, { UNUSED(offset); - process_t* process = file->inode->private; + process_t* process = file->inode->data; char prioStr[MAX_NAME]; if (count >= MAX_NAME) @@ -111,7 +111,7 @@ static file_ops_t prioOps = { static size_t procfs_cwd_read(file_t* file, void* buffer, size_t count, size_t* offset) { - process_t* process = file->inode->private; + process_t* process = file->inode->data; namespace_t* ns = process_get_ns(process); if (ns == NULL) @@ -137,7 +137,7 @@ static size_t procfs_cwd_write(file_t* file, const void* buffer, size_t count, s { UNUSED(offset); - process_t* process = file->inode->private; + process_t* process = file->inode->data; char cwdStr[MAX_PATH]; if (count >= MAX_PATH) @@ -193,7 +193,7 @@ static file_ops_t cwdOps = { static size_t procfs_cmdline_read(file_t* file, void* buffer, size_t count, size_t* offset) { - process_t* process = file->inode->private; + process_t* process = file->inode->data; if (process->argv == NULL || process->argc == 0) { @@ -250,7 +250,7 @@ static size_t procfs_note_write(file_t* file, const void* buffer, size_t count, return ERR; } - process_t* process = file->inode->private; + process_t* process = file->inode->data; RCU_READ_SCOPE(); @@ -289,7 +289,7 @@ static size_t procfs_notegroup_write(file_t* file, const void* buffer, size_t co errno = EINVAL; return ERR; } - process_t* process = file->inode->private; + process_t* process = file->inode->data; char string[NOTE_MAX] = {0}; memcpy_s(string, NOTE_MAX, buffer, count); @@ -307,7 +307,7 @@ static file_ops_t notegroupOps = { static uint64_t procfs_group_open(file_t* file) { - process_t* process = file->inode->private; + process_t* process = file->inode->data; group_t* group = group_get(&process->group); if (group == NULL) @@ -315,20 +315,20 @@ static uint64_t procfs_group_open(file_t* file) return ERR; } - file->private = group; + file->data = group; return 0; } static void procfs_group_close(file_t* file) { - group_t* group = file->private; + group_t* group = file->data; if (group == NULL) { return; } UNREF(group); - file->private = NULL; + file->data = NULL; } static file_ops_t groupOps = { @@ -338,7 +338,7 @@ static file_ops_t groupOps = { static size_t procfs_pid_read(file_t* file, void* buffer, size_t count, size_t* offset) { - process_t* process = file->inode->private; + process_t* process = file->inode->data; char pidStr[MAX_NAME]; uint32_t length = snprintf(pidStr, MAX_NAME, "%llu", process->id); @@ -351,7 +351,7 @@ static file_ops_t pidOps = { static size_t procfs_wait_read(file_t* file, void* buffer, size_t count, size_t* offset) { - process_t* process = file->inode->private; + process_t* process = file->inode->data; if (WAIT_BLOCK(&process->dyingQueue, atomic_load(&process->flags) & PROCESS_DYING) == ERR) { @@ -366,7 +366,7 @@ static size_t procfs_wait_read(file_t* file, void* buffer, size_t count, size_t* static wait_queue_t* procfs_wait_poll(file_t* file, poll_events_t* revents) { - process_t* process = file->inode->private; + process_t* process = file->inode->data; if (atomic_load(&process->flags) & PROCESS_DYING) { *revents |= POLLIN; @@ -383,7 +383,7 @@ static file_ops_t waitOps = { static size_t procfs_perf_read(file_t* file, void* buffer, size_t count, size_t* offset) { - process_t* process = file->inode->private; + process_t* process = file->inode->data; size_t userPages = space_user_page_count(&process->space); RCU_READ_SCOPE(); @@ -413,7 +413,7 @@ static file_ops_t perfOps = { static uint64_t procfs_ns_open(file_t* file) { - process_t* process = file->inode->private; + process_t* process = file->inode->data; namespace_t* ns = process_get_ns(process); if (ns == NULL) @@ -421,19 +421,19 @@ static uint64_t procfs_ns_open(file_t* file) return ERR; } - file->private = ns; + file->data = ns; return 0; } static void procfs_ns_close(file_t* file) { - if (file->private == NULL) + if (file->data == NULL) { return; } - UNREF(file->private); - file->private = NULL; + UNREF(file->data); + file->data = NULL; } static file_ops_t nsOps = { @@ -449,7 +449,7 @@ static uint64_t procfs_ctl_close(file_t* file, uint64_t argc, const char** argv) return ERR; } - process_t* process = file->inode->private; + process_t* process = file->inode->data; if (argc == 2) { @@ -498,7 +498,7 @@ static uint64_t procfs_ctl_dup2(file_t* file, uint64_t argc, const char** argv) return ERR; } - process_t* process = file->inode->private; + process_t* process = file->inode->data; fd_t oldFd; if (sscanf(argv[1], "%lld", &oldFd) != 1) @@ -530,7 +530,7 @@ static uint64_t procfs_ctl_bind(file_t* file, uint64_t argc, const char** argv) return ERR; } - process_t* process = file->inode->private; + process_t* process = file->inode->data; process_t* writing = process_current(); pathname_t targetName; @@ -593,7 +593,7 @@ static uint64_t procfs_ctl_mount(file_t* file, uint64_t argc, const char** argv) } process_t* writing = process_current(); - process_t* process = file->inode->private; + process_t* process = file->inode->data; pathname_t mountname; if (pathname_init(&mountname, argv[1]) == ERR) @@ -640,7 +640,7 @@ static uint64_t procfs_ctl_touch(file_t* file, uint64_t argc, const char** argv) return ERR; } - process_t* process = file->inode->private; + process_t* process = file->inode->data; pathname_t pathname; if (pathname_init(&pathname, argv[1]) == ERR) @@ -667,7 +667,7 @@ static uint64_t procfs_ctl_start(file_t* file, uint64_t argc, const char** argv) return ERR; } - process_t* process = file->inode->private; + process_t* process = file->inode->data; atomic_fetch_and(&process->flags, ~PROCESS_SUSPENDED); wait_unblock(&process->suspendQueue, WAIT_ALL, EOK); @@ -679,7 +679,7 @@ static uint64_t procfs_ctl_kill(file_t* file, uint64_t argc, const char** argv) { UNUSED(argv); - process_t* process = file->inode->private; + process_t* process = file->inode->data; if (argc == 2) { @@ -700,7 +700,7 @@ static uint64_t procfs_ctl_setns(file_t* file, uint64_t argc, const char** argv) return ERR; } - process_t* process = file->inode->private; + process_t* process = file->inode->data; fd_t fd; if (sscanf(argv[1], "%llu", &fd) != 1) @@ -722,7 +722,7 @@ static uint64_t procfs_ctl_setns(file_t* file, uint64_t argc, const char** argv) return ERR; } - namespace_t* ns = nsFile->private; + namespace_t* ns = nsFile->data; if (ns == NULL) { errno = EINVAL; @@ -741,7 +741,7 @@ static uint64_t procfs_ctl_setgroup(file_t* file, uint64_t argc, const char** ar return ERR; } - process_t* process = file->inode->private; + process_t* process = file->inode->data; fd_t fd; if (sscanf(argv[1], "%llu", &fd) != 1) @@ -763,7 +763,7 @@ static uint64_t procfs_ctl_setgroup(file_t* file, uint64_t argc, const char** ar return ERR; } - group_t* target = groupFile->private; + group_t* target = groupFile->data; if (target == NULL) { errno = EINVAL; @@ -790,7 +790,7 @@ CTL_STANDARD_OPS_DEFINE(ctlOps, static size_t procfs_env_read(file_t* file, void* buffer, size_t count, size_t* offset) { - process_t* process = file->inode->private; + process_t* process = file->inode->data; const char* value = env_get(&process->env, file->path.dentry->name); if (value == NULL) @@ -806,7 +806,7 @@ static size_t procfs_env_write(file_t* file, const void* buffer, size_t count, s { UNUSED(offset); - process_t* process = file->inode->private; + process_t* process = file->inode->data; char value[MAX_NAME]; if (count >= MAX_NAME) @@ -835,7 +835,7 @@ static uint64_t procfs_env_lookup(inode_t* dir, dentry_t* target) { UNUSED(target); - process_t* process = dir->private; + process_t* process = dir->data; assert(process != NULL); if (env_get(&process->env, target->name) == NULL) @@ -849,7 +849,7 @@ static uint64_t procfs_env_lookup(inode_t* dir, dentry_t* target) return ERR; } UNREF_DEFER(inode); - inode->private = process; // No reference + inode->data = process; // No reference dentry_make_positive(target, inode); @@ -864,7 +864,7 @@ static uint64_t procfs_env_create(inode_t* dir, dentry_t* target, mode_t mode) return ERR; } - process_t* process = dir->private; + process_t* process = dir->data; assert(process != NULL); if (env_set(&process->env, target->name, "") == ERR) @@ -878,7 +878,7 @@ static uint64_t procfs_env_create(inode_t* dir, dentry_t* target, mode_t mode) return ERR; } UNREF_DEFER(inode); - inode->private = process; // No reference + inode->data = process; // No reference dentry_make_positive(target, inode); return 0; @@ -886,7 +886,7 @@ static uint64_t procfs_env_create(inode_t* dir, dentry_t* target, mode_t mode) static uint64_t procfs_env_remove(inode_t* dir, dentry_t* target) { - process_t* process = dir->private; + process_t* process = dir->data; assert(process != NULL); if (env_unset(&process->env, target->name) == ERR) @@ -910,7 +910,7 @@ static uint64_t procfs_env_iterate(dentry_t* dentry, dir_ctx_t* ctx) return 0; } - process_t* process = dentry->inode->private; + process_t* process = dentry->inode->data; assert(process != NULL); MUTEX_SCOPE(&process->env.mutex); @@ -1046,7 +1046,7 @@ static procfs_entry_t procEntries[] = { static uint64_t procfs_pid_lookup(inode_t* dir, dentry_t* target) { - process_t* process = dir->private; + process_t* process = dir->data; assert(process != NULL); for (size_t i = 0; i < ARRAY_SIZE(pidEntries); i++) @@ -1063,7 +1063,7 @@ static uint64_t procfs_pid_lookup(inode_t* dir, dentry_t* target) return 0; } UNREF_DEFER(inode); - inode->private = process; // No reference + inode->data = process; // No reference if (pidEntries[i].dentryOps != NULL) { @@ -1079,14 +1079,14 @@ static uint64_t procfs_pid_lookup(inode_t* dir, dentry_t* target) static void procfs_pid_cleanup(inode_t* inode) { - process_t* process = inode->private; + process_t* process = inode->data; if (process == NULL) { return; } UNREF(process); - inode->private = NULL; + inode->data = NULL; } static uint64_t procfs_pid_iterate(dentry_t* dentry, dir_ctx_t* ctx) @@ -1097,7 +1097,7 @@ static uint64_t procfs_pid_iterate(dentry_t* dentry, dir_ctx_t* ctx) } process_t* current = process_current(); - process_t* process = dentry->inode->private; + process_t* process = dentry->inode->data; assert(process != NULL); for (size_t i = 0; i < ARRAY_SIZE(pidEntries); i++) @@ -1179,7 +1179,7 @@ static uint64_t procfs_lookup(inode_t* dir, dentry_t* target) return ERR; } UNREF_DEFER(inode); - inode->private = REF(process); + inode->data = REF(process); target->ops = &pidDentryOps; @@ -1237,9 +1237,9 @@ static dentry_ops_t procDentryOps = { .iterate = procfs_iterate, }; -static dentry_t* procfs_mount(filesystem_t* fs, const char* options, void* private) +static dentry_t* procfs_mount(filesystem_t* fs, const char* options, void* data) { - UNUSED(private); + UNUSED(data); if (options != NULL) { diff --git a/src/kernel/fs/superblock.c b/src/kernel/fs/superblock.c index ec2096071..f25ccb264 100644 --- a/src/kernel/fs/superblock.c +++ b/src/kernel/fs/superblock.c @@ -50,7 +50,7 @@ superblock_t* superblock_new(filesystem_t* fs, const superblock_ops_t* ops, cons superblock->id = vfs_id_get(); superblock->blockSize = PAGE_SIZE; superblock->maxFileSize = UINT64_MAX; - superblock->private = NULL; + superblock->data = NULL; superblock->root = NULL; superblock->ops = ops; superblock->dentryOps = dentryOps; diff --git a/src/kernel/fs/sysfs.c b/src/kernel/fs/sysfs.c index 7bf82cad5..a3018ee34 100644 --- a/src/kernel/fs/sysfs.c +++ b/src/kernel/fs/sysfs.c @@ -32,10 +32,10 @@ static dentry_ops_t dentryOps = { .iterate = dentry_generic_iterate, }; -static dentry_t* sysfs_mount(filesystem_t* fs, const char* options, void* private) +static dentry_t* sysfs_mount(filesystem_t* fs, const char* options, void* data) { UNUSED(fs); - UNUSED(private); + UNUSED(data); if (options != NULL) { @@ -115,7 +115,7 @@ void sysfs_init(void) LOG_INFO("sysfs mounted to '/sys'\n"); } -dentry_t* sysfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* private) +dentry_t* sysfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* data) { if (name == NULL) { @@ -147,7 +147,7 @@ dentry_t* sysfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* i return NULL; } UNREF_DEFER(inode); - inode->private = private; + inode->data = data; dentry_make_positive(dir, inode); @@ -155,7 +155,7 @@ dentry_t* sysfs_dir_new(dentry_t* parent, const char* name, const inode_ops_t* i } dentry_t* sysfs_file_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, const file_ops_t* fileOps, - void* private) + void* data) { if (name == NULL) { @@ -187,14 +187,14 @@ dentry_t* sysfs_file_new(dentry_t* parent, const char* name, const inode_ops_t* return NULL; } UNREF_DEFER(inode); - inode->private = private; + inode->data = data; dentry_make_positive(dentry, inode); return REF(dentry); } -dentry_t* sysfs_symlink_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* private) +dentry_t* sysfs_symlink_new(dentry_t* parent, const char* name, const inode_ops_t* inodeOps, void* data) { if (parent == NULL || name == NULL || inodeOps == NULL) { @@ -221,7 +221,7 @@ dentry_t* sysfs_symlink_new(dentry_t* parent, const char* name, const inode_ops_ return NULL; } UNREF_DEFER(inode); - inode->private = private; + inode->data = data; dentry_make_positive(dentry, inode); @@ -252,7 +252,7 @@ uint64_t sysfs_files_new(list_t* out, dentry_t* parent, const sysfs_file_desc_t* uint64_t count = 0; for (const sysfs_file_desc_t* desc = descs; desc->name != NULL; desc++) { - dentry_t* file = sysfs_file_new(parent, desc->name, desc->inodeOps, desc->fileOps, desc->private); + dentry_t* file = sysfs_file_new(parent, desc->name, desc->inodeOps, desc->fileOps, desc->data); if (file == NULL) { while (!list_is_empty(&createdList)) diff --git a/src/kernel/fs/tmpfs.c b/src/kernel/fs/tmpfs.c index b98826923..980aba2a1 100644 --- a/src/kernel/fs/tmpfs.c +++ b/src/kernel/fs/tmpfs.c @@ -31,7 +31,7 @@ static inode_t* tmpfs_inode_new(superblock_t* superblock, itype_t type, void* bu static void tmpfs_dentry_add(dentry_t* dentry) { - tmpfs_superblock_data_t* super = dentry->superblock->private; + tmpfs_superblock_data_t* super = dentry->superblock->data; lock_acquire(&super->lock); list_push_back(&super->dentrys, &dentry->otherEntry); @@ -41,7 +41,7 @@ static void tmpfs_dentry_add(dentry_t* dentry) static void tmpfs_dentry_remove(dentry_t* dentry) { - tmpfs_superblock_data_t* super = dentry->superblock->private; + tmpfs_superblock_data_t* super = dentry->superblock->data; lock_acquire(&super->lock); list_remove(&dentry->otherEntry); @@ -55,12 +55,12 @@ static size_t tmpfs_read(file_t* file, void* buffer, size_t count, size_t* offse { MUTEX_SCOPE(&file->inode->mutex); - if (file->inode->private == NULL) + if (file->inode->data == NULL) { return 0; } - return BUFFER_READ(buffer, count, offset, file->inode->private, file->inode->size); + return BUFFER_READ(buffer, count, offset, file->inode->data, file->inode->size); } static size_t tmpfs_write(file_t* file, const void* buffer, size_t count, size_t* offset) @@ -70,17 +70,17 @@ static size_t tmpfs_write(file_t* file, const void* buffer, size_t count, size_t size_t requiredSize = *offset + count; if (requiredSize > file->inode->size) { - void* newData = realloc(file->inode->private, requiredSize); + void* newData = realloc(file->inode->data, requiredSize); if (newData == NULL) { return ERR; } memset(newData + file->inode->size, 0, requiredSize - file->inode->size); - file->inode->private = newData; + file->inode->data = newData; file->inode->size = requiredSize; } - return BUFFER_WRITE(buffer, count, offset, file->inode->private, file->inode->size); + return BUFFER_WRITE(buffer, count, offset, file->inode->data, file->inode->size); } static file_ops_t fileOps = { @@ -110,10 +110,10 @@ static void tmpfs_truncate(inode_t* inode) { MUTEX_SCOPE(&inode->mutex); - if (inode->private != NULL) + if (inode->data != NULL) { - free(inode->private); - inode->private = NULL; + free(inode->data); + inode->data = NULL; } inode->size = 0; } @@ -132,14 +132,14 @@ static uint64_t tmpfs_readlink(inode_t* inode, char* buffer, uint64_t count) { MUTEX_SCOPE(&inode->mutex); - if (inode->private == NULL) + if (inode->data == NULL) { errno = EINVAL; return ERR; } uint64_t copySize = MIN(count, inode->size); - memcpy(buffer, inode->private, copySize); + memcpy(buffer, inode->data, copySize); return copySize; } @@ -184,10 +184,10 @@ static uint64_t tmpfs_remove(inode_t* dir, dentry_t* target) static void tmpfs_inode_cleanup(inode_t* inode) { - if (inode->private != NULL) + if (inode->data != NULL) { - free(inode->private); - inode->private = NULL; + free(inode->data); + inode->data = NULL; inode->size = 0; } } @@ -242,7 +242,7 @@ static dentry_t* tmpfs_load_file(superblock_t* superblock, dentry_t* parent, con static dentry_t* tmpfs_load_dir(superblock_t* superblock, dentry_t* parent, const char* name, const boot_dir_t* in) { - tmpfs_superblock_data_t* superData = superblock->private; + tmpfs_superblock_data_t* superData = superblock->data; dentry_t* dentry = dentry_new(superblock, parent, name); if (dentry == NULL) @@ -276,9 +276,9 @@ static dentry_t* tmpfs_load_dir(superblock_t* superblock, dentry_t* parent, cons return REF(dentry); } -static dentry_t* tmpfs_mount(filesystem_t* fs, const char* options, void* private) +static dentry_t* tmpfs_mount(filesystem_t* fs, const char* options, void* data) { - UNUSED(private); + UNUSED(data); if (options != NULL) { @@ -296,14 +296,14 @@ static dentry_t* tmpfs_mount(filesystem_t* fs, const char* options, void* privat superblock->blockSize = 0; superblock->maxFileSize = UINT64_MAX; - tmpfs_superblock_data_t* data = malloc(sizeof(tmpfs_superblock_data_t)); - if (data == NULL) + tmpfs_superblock_data_t* tmpfsData = malloc(sizeof(tmpfs_superblock_data_t)); + if (tmpfsData == NULL) { return NULL; } - list_init(&data->dentrys); - lock_init(&data->lock); - superblock->private = data; + list_init(&tmpfsData->dentrys); + lock_init(&tmpfsData->lock); + superblock->data = tmpfsData; if (!initialized) { @@ -354,17 +354,17 @@ static inode_t* tmpfs_inode_new(superblock_t* superblock, itype_t type, void* bu if (buffer != NULL) { - inode->private = malloc(size); - if (inode->private == NULL) + inode->data = malloc(size); + if (inode->data == NULL) { return NULL; } - memcpy(inode->private, buffer, size); + memcpy(inode->data, buffer, size); inode->size = size; } else { - inode->private = NULL; + inode->data = NULL; inode->size = 0; } diff --git a/src/kernel/mem/space.c b/src/kernel/mem/space.c index a9d50f638..633901b08 100644 --- a/src/kernel/mem/space.c +++ b/src/kernel/mem/space.c @@ -133,7 +133,7 @@ void space_deinit(space_t* space) uint64_t index; BITMAP_FOR_EACH_SET(&index, &space->callbackBitmap) { - space->callbacks[index].func(space->callbacks[index].private); + space->callbacks[index].func(space->callbacks[index].data); } if (space->flags & SPACE_MAP_KERNEL_BINARY) @@ -568,7 +568,7 @@ uint64_t space_mapping_start(space_t* space, space_mapping_t* mapping, void* vir return 0; // We return with the lock still acquired. } -pml_callback_id_t space_alloc_callback(space_t* space, size_t pageAmount, space_callback_func_t func, void* private) +pml_callback_id_t space_alloc_callback(space_t* space, size_t pageAmount, space_callback_func_t func, void* data) { if (space == NULL) { @@ -604,7 +604,7 @@ pml_callback_id_t space_alloc_callback(space_t* space, size_t pageAmount, space_ bitmap_set(&space->callbackBitmap, callbackId); space_callback_t* callback = &space->callbacks[callbackId]; callback->func = func; - callback->private = private; + callback->data = data; callback->pageAmount = pageAmount; return callbackId; } diff --git a/src/kernel/mem/vmm.c b/src/kernel/mem/vmm.c index 7044a919c..c128b47f0 100644 --- a/src/kernel/mem/vmm.c +++ b/src/kernel/mem/vmm.c @@ -215,7 +215,7 @@ void* vmm_alloc(space_t* space, void* virtAddr, size_t length, size_t alignment, } void* vmm_map(space_t* space, void* virtAddr, void* physAddr, size_t length, pml_flags_t flags, - space_callback_func_t func, void* private) + space_callback_func_t func, void* data) { if (physAddr == NULL || length == 0 || !(flags & PML_PRESENT)) { @@ -242,7 +242,7 @@ void* vmm_map(space_t* space, void* virtAddr, void* physAddr, size_t length, pml pml_callback_id_t callbackId = PML_CALLBACK_NONE; if (func != NULL) { - callbackId = space_alloc_callback(space, mapping.pageAmount, func, private); + callbackId = space_alloc_callback(space, mapping.pageAmount, func, data); if (callbackId == PML_MAX_CALLBACK) { return space_mapping_end(space, &mapping, ENOSPC); @@ -270,7 +270,7 @@ void* vmm_map(space_t* space, void* virtAddr, void* physAddr, size_t length, pml } void* vmm_map_pages(space_t* space, void* virtAddr, void** pages, size_t pageAmount, pml_flags_t flags, - space_callback_func_t func, void* private) + space_callback_func_t func, void* data) { if (pages == NULL || pageAmount == 0 || !(flags & PML_PRESENT)) { @@ -297,7 +297,7 @@ void* vmm_map_pages(space_t* space, void* virtAddr, void** pages, size_t pageAmo pml_callback_id_t callbackId = PML_CALLBACK_NONE; if (func != NULL) { - callbackId = space_alloc_callback(space, pageAmount, func, private); + callbackId = space_alloc_callback(space, pageAmount, func, data); if (callbackId == PML_MAX_CALLBACK) { return space_mapping_end(space, &mapping, ENOSPC); @@ -364,7 +364,7 @@ void* vmm_unmap(space_t* space, void* virtAddr, size_t length) if (callback->pageAmount == 0) { assert(index < space->callbacksLength); - space->callbacks[index].func(space->callbacks[index].private); + space->callbacks[index].func(space->callbacks[index].data); space_free_callback(space, index); } } diff --git a/src/kernel/module/module.c b/src/kernel/module/module.c index 1860bec91..7c1c80b39 100644 --- a/src/kernel/module/module.c +++ b/src/kernel/module/module.c @@ -46,7 +46,7 @@ static bool cacheValid = false; static mutex_t lock = MUTEX_CREATE(lock); -static void* module_resolve_symbol_callback(const char* name, void* private); +static void* module_resolve_symbol_callback(const char* name, void* data); #define MODULE_SYMBOL_ALLOWED(type, binding, name) \ (((type) == STT_OBJECT || (type) == STT_FUNC) && ((binding) == STB_GLOBAL) && \ @@ -909,9 +909,9 @@ static uint64_t module_load_dependency(module_load_ctx_t* ctx, const char* symbo return 0; } -static void* module_resolve_symbol_callback(const char* symbolName, void* private) +static void* module_resolve_symbol_callback(const char* symbolName, void* data) { - module_load_ctx_t* ctx = private; + module_load_ctx_t* ctx = data; symbol_info_t symbolInfo; if (symbol_resolve_name(&symbolInfo, symbolName) == ERR) diff --git a/src/libpatchwork/element.c b/src/libpatchwork/element.c index 0d7542bf6..b79cf0bc5 100644 --- a/src/libpatchwork/element.c +++ b/src/libpatchwork/element.c @@ -16,7 +16,7 @@ static uint64_t element_send_init(element_t* elem) } static element_t* element_new_raw(element_id_t id, const rect_t* rect, const char* text, element_flags_t flags, - procedure_t procedure, void* private) + procedure_t procedure, void* data) { element_t* elem = malloc(sizeof(element_t)); if (elem == NULL) @@ -29,7 +29,7 @@ static element_t* element_new_raw(element_id_t id, const rect_t* rect, const cha elem->id = id; elem->proc = procedure; elem->win = NULL; - elem->private = private; + elem->data = data; elem->rect = *rect; elem->flags = flags; elem->text = strdup(text); @@ -46,7 +46,7 @@ static element_t* element_new_raw(element_id_t id, const rect_t* rect, const cha } element_t* element_new(element_t* parent, element_id_t id, const rect_t* rect, const char* text, element_flags_t flags, - procedure_t procedure, void* private) + procedure_t procedure, void* data) { if (parent == NULL || rect == NULL || text == NULL || procedure == NULL) { @@ -54,7 +54,7 @@ element_t* element_new(element_t* parent, element_id_t id, const rect_t* rect, c return NULL; } - element_t* elem = element_new_raw(id, rect, text, flags, procedure, private); + element_t* elem = element_new_raw(id, rect, text, flags, procedure, data); if (elem == NULL) { errno = ENOMEM; @@ -74,7 +74,7 @@ element_t* element_new(element_t* parent, element_id_t id, const rect_t* rect, c } element_t* element_new_root(window_t* win, element_id_t id, const rect_t* rect, const char* text, element_flags_t flags, - procedure_t procedure, void* private) + procedure_t procedure, void* data) { if (win == NULL || rect == NULL || text == NULL || procedure == NULL) { @@ -82,7 +82,7 @@ element_t* element_new_root(window_t* win, element_id_t id, const rect_t* rect, return NULL; } - element_t* elem = element_new_raw(id, rect, text, flags, procedure, private); + element_t* elem = element_new_raw(id, rect, text, flags, procedure, data); if (elem == NULL) { errno = ENOMEM; @@ -160,14 +160,14 @@ element_t* element_find(element_t* elem, element_id_t id) return NULL; } -void element_set_private(element_t* elem, void* private) +void element_set_private(element_t* elem, void* data) { if (elem == NULL) { return; } - elem->private = private; + elem->data = data; } void* element_get_private(element_t* elem) @@ -177,7 +177,7 @@ void* element_get_private(element_t* elem) return NULL; } - return elem->private; + return elem->data; } element_id_t element_get_id(element_t* elem) diff --git a/src/libpatchwork/internal.h b/src/libpatchwork/internal.h index d94662fe8..0326f0cf3 100644 --- a/src/libpatchwork/internal.h +++ b/src/libpatchwork/internal.h @@ -27,7 +27,7 @@ typedef struct element element_id_t id; procedure_t proc; window_t* win; - void* private; + void* data; rect_t rect; element_flags_t flags; char* text; @@ -38,7 +38,7 @@ typedef struct element } element_t; element_t* element_new_root(window_t* win, element_id_t id, const rect_t* rect, const char* text, element_flags_t flags, - procedure_t procedure, void* private); + procedure_t procedure, void* data); typedef struct window { diff --git a/src/libpatchwork/window.c b/src/libpatchwork/window.c index 6bbac788a..8f72b7e21 100644 --- a/src/libpatchwork/window.c +++ b/src/libpatchwork/window.c @@ -311,7 +311,7 @@ static uint64_t window_deco_procedure(window_t* win, element_t* elem, const even } window_t* window_new(display_t* disp, const char* name, const rect_t* rect, surface_type_t type, window_flags_t flags, - procedure_t procedure, void* private) + procedure_t procedure, void* data) { if (disp == NULL || name == NULL || rect == NULL || procedure == NULL || strnlen_s(name, MAX_NAME + 1) >= MAX_NAME) { @@ -402,7 +402,7 @@ window_t* window_new(display_t* disp, const char* name, const rect_t* rect, surf RECT_WIDTH(&win->rect) - theme->frameSize, RECT_HEIGHT(&win->rect) - theme->frameSize); win->clientElement = - element_new(win->root, WINDOW_CLIENT_ELEM_ID, &clientRect, "client", ELEMENT_NONE, procedure, private); + element_new(win->root, WINDOW_CLIENT_ELEM_ID, &clientRect, "client", ELEMENT_NONE, procedure, data); if (win->clientElement == NULL) { window_free(win); @@ -412,7 +412,7 @@ window_t* window_new(display_t* disp, const char* name, const rect_t* rect, surf else { win->clientElement = - element_new_root(win, WINDOW_CLIENT_ELEM_ID, &rootRect, "client", ELEMENT_NONE, procedure, private); + element_new_root(win, WINDOW_CLIENT_ELEM_ID, &rootRect, "client", ELEMENT_NONE, procedure, data); if (win->clientElement == NULL) { window_free(win); diff --git a/src/libstd/common/print.h b/src/libstd/common/print.h index 93f2e062c..c0422a5ac 100644 --- a/src/libstd/common/print.h +++ b/src/libstd/common/print.h @@ -51,7 +51,7 @@ typedef struct size_t n; const char* p; va_list arg; - void* private; + void* data; } _print_ctx_t; typedef enum { @@ -614,7 +614,7 @@ static inline int _print_format(_print_ctx_t* ctx) return ret; } -static inline int _print(const char* _RESTRICT format, size_t n, va_list arg, void* private) +static inline int _print(const char* _RESTRICT format, size_t n, va_list arg, void* data) { assert(format != NULL); @@ -622,7 +622,7 @@ static inline int _print(const char* _RESTRICT format, size_t n, va_list arg, vo .written = 0, .n = n, .p = format, - .private = private, + .data = data, }; va_copy(ctx.arg, arg); diff --git a/src/libstd/common/scan.h b/src/libstd/common/scan.h index fc3a66928..daf5636cc 100644 --- a/src/libstd/common/scan.h +++ b/src/libstd/common/scan.h @@ -45,7 +45,7 @@ typedef struct int parsedItems; const char* p; va_list arg; - void* private; + void* data; uint64_t count; char prev; } _scan_ctx_t; @@ -663,14 +663,14 @@ static inline int _scan_format(_scan_ctx_t* ctx) return ret; } -static inline int _scan(const char* _RESTRICT format, va_list arg, void* private) +static inline int _scan(const char* _RESTRICT format, va_list arg, void* data) { assert(format != NULL); _scan_ctx_t ctx = { .parsedItems = 0, .p = format, - .private = private, + .data = data, .count = 0, .prev = EOF, }; diff --git a/src/libstd/functions/bitmap/bitmap_clear.c b/src/libstd/functions/bitmap/bitmap_clear.c deleted file mode 100644 index 893211d5f..000000000 --- a/src/libstd/functions/bitmap/bitmap_clear.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -void bitmap_clear(bitmap_t* map, uint64_t index) -{ - if (index >= map->length) - { - return; - } - - uint64_t qwordIdx = index / 64; - uint64_t bitInQword = index % 64; - map->buffer[qwordIdx] &= ~(1ULL << bitInQword); - map->firstZeroIdx = MIN(map->firstZeroIdx, index); -} \ No newline at end of file diff --git a/src/libstd/functions/bitmap/bitmap_clear_range.c b/src/libstd/functions/bitmap/bitmap_clear_range.c deleted file mode 100644 index 041f5fe8c..000000000 --- a/src/libstd/functions/bitmap/bitmap_clear_range.c +++ /dev/null @@ -1,35 +0,0 @@ -#include - -void bitmap_clear_range(bitmap_t* map, uint64_t low, uint64_t high) -{ - if (low >= high || high > map->length) - { - return; - } - - if (low < map->firstZeroIdx) - { - map->firstZeroIdx = low; - } - - uint64_t firstQwordIdx = low / 64; - uint64_t firstBitInQword = low % 64; - uint64_t lastQwordIdx = (high - 1) / 64; - uint64_t lastBitInQword = (high - 1) % 64; - - if (firstQwordIdx == lastQwordIdx) - { - uint64_t mask = (~0ULL << firstBitInQword) & (~0ULL >> (63 - lastBitInQword)); - map->buffer[firstQwordIdx] &= ~mask; - return; - } - - map->buffer[firstQwordIdx] &= ~(~0ULL << firstBitInQword); - - for (uint64_t i = firstQwordIdx + 1; i < lastQwordIdx; i++) - { - map->buffer[i] = 0ULL; - } - - map->buffer[lastQwordIdx] &= ~(~0ULL >> (63 - lastBitInQword)); -} \ No newline at end of file diff --git a/src/libstd/functions/bitmap/bitmap_find_clear_region_and_set.c b/src/libstd/functions/bitmap/bitmap_find_clear_region_and_set.c deleted file mode 100644 index db668d3cd..000000000 --- a/src/libstd/functions/bitmap/bitmap_find_clear_region_and_set.c +++ /dev/null @@ -1,31 +0,0 @@ -#include - -uint64_t bitmap_find_clear_region_and_set(bitmap_t* map, uint64_t minIdx, uintptr_t maxIdx, uint64_t length, - uint64_t alignment) -{ - if (length == 0 || minIdx >= maxIdx || maxIdx > map->length) - { - return map->length; - } - - if (alignment == 0) - { - alignment = 1; - } - - uint64_t idx = MAX(minIdx, map->firstZeroIdx); - idx = ROUND_UP(idx, alignment); - - while (idx <= maxIdx - length) - { - uint64_t firstSet = bitmap_find_first_set(map, idx, idx + length); - if (firstSet >= idx + length) - { - bitmap_set_range(map, idx, idx + length); - return idx; - } - idx = ROUND_UP(firstSet + 1, alignment); - } - - return map->length; -} \ No newline at end of file diff --git a/src/libstd/functions/bitmap/bitmap_find_first_clear.c b/src/libstd/functions/bitmap/bitmap_find_first_clear.c deleted file mode 100644 index 79c2d1075..000000000 --- a/src/libstd/functions/bitmap/bitmap_find_first_clear.c +++ /dev/null @@ -1,35 +0,0 @@ -#include - -uint64_t bitmap_find_first_clear(bitmap_t* map, uint64_t startIdx, uint64_t endIdx) -{ - if (map->firstZeroIdx >= map->length) - { - return map->length; - } - - startIdx = MAX(startIdx, map->firstZeroIdx); - uint64_t qwordIdx = startIdx / 64; - uint64_t bitIdx = startIdx % 64; - uint64_t endQwordIdx = BITMAP_BITS_TO_QWORDS(MIN(endIdx, map->length)); - - if (bitIdx != 0) - { - uint64_t qword = map->buffer[qwordIdx]; - uint64_t maskedQword = qword | ((1ULL << bitIdx) - 1); - if (maskedQword != ~0ULL) - { - return qwordIdx * 64 + __builtin_ctzll(~maskedQword); - } - qwordIdx++; - } - - for (uint64_t i = qwordIdx; i < endQwordIdx; ++i) - { - if (map->buffer[i] != ~0ULL) - { - return i * 64 + __builtin_ctzll(~map->buffer[i]); - } - } - - return map->length; -} \ No newline at end of file diff --git a/src/libstd/functions/bitmap/bitmap_find_first_set.c b/src/libstd/functions/bitmap/bitmap_find_first_set.c deleted file mode 100644 index 1e2d46699..000000000 --- a/src/libstd/functions/bitmap/bitmap_find_first_set.c +++ /dev/null @@ -1,32 +0,0 @@ -#include - -uint64_t bitmap_find_first_set(bitmap_t* map, uint64_t startIdx, uint64_t endIdx) -{ - if (startIdx >= map->length) - { - return map->length; - } - - uint64_t startQwordIdx = startIdx / 64; - uint64_t startBitIdx = startIdx % 64; - uint64_t endQwordIdx = BITMAP_BITS_TO_QWORDS(MIN(endIdx, map->length)); - - while (startQwordIdx < endQwordIdx) - { - uint64_t qword = map->buffer[startQwordIdx]; - if (startBitIdx != 0) - { - qword &= ~((1ULL << startBitIdx) - 1); - } - - if (qword != 0) - { - return startQwordIdx * 64 + __builtin_ctzll(qword); - } - - startQwordIdx++; - startBitIdx = 0; - } - - return map->length; -} \ No newline at end of file diff --git a/src/libstd/functions/bitmap/bitmap_init.c b/src/libstd/functions/bitmap/bitmap_init.c deleted file mode 100644 index 0e91e2606..000000000 --- a/src/libstd/functions/bitmap/bitmap_init.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -void bitmap_init(bitmap_t* map, void* buffer, uint64_t length) -{ - map->firstZeroIdx = 0; - map->length = length; - map->buffer = (uint64_t*)buffer; -} \ No newline at end of file diff --git a/src/libstd/functions/bitmap/bitmap_is_empty.c b/src/libstd/functions/bitmap/bitmap_is_empty.c deleted file mode 100644 index 03ec38520..000000000 --- a/src/libstd/functions/bitmap/bitmap_is_empty.c +++ /dev/null @@ -1,25 +0,0 @@ -#include - -bool bitmap_is_empty(bitmap_t* map) -{ - uint64_t fullQwords = map->length / 64; - for (uint64_t i = 0; i < fullQwords; i++) - { - if (map->buffer[i] != 0) - { - return false; - } - } - - uint64_t remainingBits = map->length % 64; - if (remainingBits != 0) - { - uint64_t mask = (1ULL << remainingBits) - 1; - if ((map->buffer[fullQwords] & mask) != 0) - { - return false; - } - } - - return true; -} \ No newline at end of file diff --git a/src/libstd/functions/bitmap/bitmap_is_set.c b/src/libstd/functions/bitmap/bitmap_is_set.c deleted file mode 100644 index 1b0be3306..000000000 --- a/src/libstd/functions/bitmap/bitmap_is_set.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -bool bitmap_is_set(bitmap_t* map, uint64_t idx) -{ - if (idx >= map->length) - { - return false; - } - - uint64_t qwordIdx = idx / 64; - uint64_t bitInQword = idx % 64; - return (map->buffer[qwordIdx] & (1ULL << bitInQword)); -} \ No newline at end of file diff --git a/src/libstd/functions/bitmap/bitmap_set.c b/src/libstd/functions/bitmap/bitmap_set.c deleted file mode 100644 index 38557ef7f..000000000 --- a/src/libstd/functions/bitmap/bitmap_set.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -void bitmap_set(bitmap_t* map, uint64_t index) -{ - if (index >= map->length) - { - return; - } - - uint64_t qwordIdx = index / 64; - uint64_t bitInQword = index % 64; - map->buffer[qwordIdx] |= (1ULL << bitInQword); -} \ No newline at end of file diff --git a/src/libstd/functions/bitmap/bitmap_set_range.c b/src/libstd/functions/bitmap/bitmap_set_range.c deleted file mode 100644 index 692938bc4..000000000 --- a/src/libstd/functions/bitmap/bitmap_set_range.c +++ /dev/null @@ -1,30 +0,0 @@ -#include - -void bitmap_set_range(bitmap_t* map, uint64_t low, uint64_t high) -{ - if (low >= high || high > map->length) - { - return; - } - - uint64_t firstQwordIdx = low / 64; - uint64_t firstBitInQword = low % 64; - uint64_t lastQwordIdx = (high - 1) / 64; - uint64_t lastBitInQword = (high - 1) % 64; - - if (firstQwordIdx == lastQwordIdx) - { - uint64_t mask = (~0ULL << firstBitInQword) & (~0ULL >> (63 - lastBitInQword)); - map->buffer[firstQwordIdx] |= mask; - return; - } - - map->buffer[firstQwordIdx] |= (~0ULL << firstBitInQword); - - for (uint64_t i = firstQwordIdx + 1; i < lastQwordIdx; i++) - { - map->buffer[i] = ~0ULL; - } - - map->buffer[lastQwordIdx] |= (~0ULL >> (63 - lastBitInQword)); -} \ No newline at end of file diff --git a/src/libstd/functions/elf/elf64_relocate.c b/src/libstd/functions/elf/elf64_relocate.c index 0a58eb9d2..04bc2fe70 100644 --- a/src/libstd/functions/elf/elf64_relocate.c +++ b/src/libstd/functions/elf/elf64_relocate.c @@ -1,7 +1,7 @@ #include "common/elf.h" uint64_t elf64_relocate(const Elf64_File* elf, Elf64_Addr base, Elf64_Off offset, - void* (*resolve_symbol)(const char* name, void* private), void* private) + void* (*resolve_symbol)(const char* name, void* data), void* data) { for (uint64_t i = 0; i < elf->header->e_shnum; i++) { @@ -49,7 +49,7 @@ uint64_t elf64_relocate(const Elf64_File* elf, Elf64_Addr base, Elf64_Off offset break; } - *patchAddr = (uint64_t)resolve_symbol(symName, private); + *patchAddr = (uint64_t)resolve_symbol(symName, data); if (*patchAddr == 0) { return ERR; diff --git a/src/libstd/functions/stdio/vsnprintf.c b/src/libstd/functions/stdio/vsnprintf.c index 4b98ccca0..d740f4095 100644 --- a/src/libstd/functions/stdio/vsnprintf.c +++ b/src/libstd/functions/stdio/vsnprintf.c @@ -2,27 +2,27 @@ #define _PRINT_WRITE(ctx, buffer, count) \ ({ \ - char* str = (char*)(ctx)->private; \ + char* str = (char*)(ctx)->data; \ size_t i; \ for (i = 0; i < (size_t)(count); i++) \ { \ str[i] = (buffer)[i]; \ } \ str += i; \ - (ctx)->private = str; \ + (ctx)->data = str; \ (int)i; \ }) #define _PRINT_FILL(ctx, c, count) \ ({ \ - char* str = (char*)(ctx)->private; \ + char* str = (char*)(ctx)->data; \ size_t i; \ for (i = 0; i < (size_t)(count); i++) \ { \ str[i] = (c); \ } \ str += i; \ - (ctx)->private = str; \ + (ctx)->data = str; \ (int)i; \ }) diff --git a/src/libstd/functions/stdio/vsscanf.c b/src/libstd/functions/stdio/vsscanf.c index e5a6f0dda..af4de87aa 100644 --- a/src/libstd/functions/stdio/vsscanf.c +++ b/src/libstd/functions/stdio/vsscanf.c @@ -4,7 +4,7 @@ #define _SCAN_GET(ctx) \ ({ \ - const char** str = (const char**)(ctx)->private; \ + const char** str = (const char**)(ctx)->data; \ char c = **str; \ if (c != '\0') \ { \ @@ -15,7 +15,7 @@ #define _SCAN_UNGET(ctx, c) \ ({ \ - const char** str = (const char**)(ctx)->private; \ + const char** str = (const char**)(ctx)->data; \ if ((c) != EOF) \ { \ (*str)--; \ diff --git a/src/libstd/user/functions/io/vscan.c b/src/libstd/user/functions/io/vscan.c index 548619cfa..7f127c137 100644 --- a/src/libstd/user/functions/io/vscan.c +++ b/src/libstd/user/functions/io/vscan.c @@ -5,7 +5,7 @@ #define _SCAN_GET(ctx) \ ({ \ - fd_t fd = (fd_t)(ctx)->private; \ + fd_t fd = (fd_t)(ctx)->data; \ int res = EOF; \ char c; \ if (read(fd, &c, 1) == 1) \ @@ -17,7 +17,7 @@ #define _SCAN_UNGET(ctx, c) \ ({ \ - fd_t fd = (fd_t)(ctx)->private; \ + fd_t fd = (fd_t)(ctx)->data; \ if ((c) != EOF) \ { \ seek(fd, -1, SEEK_CUR); \ diff --git a/src/libstd/user/functions/stdio/vfprintf.c b/src/libstd/user/functions/stdio/vfprintf.c index 3741da56a..c477e8358 100644 --- a/src/libstd/user/functions/stdio/vfprintf.c +++ b/src/libstd/user/functions/stdio/vfprintf.c @@ -5,7 +5,7 @@ #define _PRINT_WRITE(ctx, buffer, count) \ ({ \ - FILE* file = (FILE*)(ctx)->private; \ + FILE* file = (FILE*)(ctx)->data; \ int ret = 0; \ if (fwrite(buffer, 1, count, file) != (size_t)(count)) \ { \ @@ -16,7 +16,7 @@ #define _PRINT_FILL(ctx, c, count) \ ({ \ - FILE* file = (FILE*)(ctx)->private; \ + FILE* file = (FILE*)(ctx)->data; \ int ret = 0; \ for (size_t i = 0; i < (size_t)(count); i++) \ { \ diff --git a/src/libstd/user/functions/stdio/vfscanf.c b/src/libstd/user/functions/stdio/vfscanf.c index 431e09797..bdcac6a4a 100644 --- a/src/libstd/user/functions/stdio/vfscanf.c +++ b/src/libstd/user/functions/stdio/vfscanf.c @@ -6,13 +6,13 @@ #define _SCAN_GET(ctx) \ ({ \ - FILE* file = (FILE*)(ctx)->private; \ + FILE* file = (FILE*)(ctx)->data; \ fgetc(file); \ }) #define _SCAN_UNGET(ctx, c) \ ({ \ - FILE* file = (FILE*)(ctx)->private; \ + FILE* file = (FILE*)(ctx)->data; \ if ((c) != EOF) \ { \ ungetc(c, file); \ diff --git a/src/modules/acpi/tables.c b/src/modules/acpi/tables.c index 8cc77b22e..2f8d55422 100644 --- a/src/modules/acpi/tables.c +++ b/src/modules/acpi/tables.c @@ -29,7 +29,7 @@ static uint64_t acpi_table_read(file_t* file, void* buffer, size_t count, size_t return ERR; } - sdt_header_t* table = file->inode->private; + sdt_header_t* table = file->inode->data; if (table == NULL) { errno = EINVAL; diff --git a/src/modules/drivers/apic/ioapic.c b/src/modules/drivers/apic/ioapic.c index cbbc2f75f..6df70f682 100644 --- a/src/modules/drivers/apic/ioapic.c +++ b/src/modules/drivers/apic/ioapic.c @@ -47,7 +47,7 @@ static uint64_t ioapic_enable(irq_t* irq) { CLI_SCOPE(); - ioapic_t* ioapic = irq->domain->private; + ioapic_t* ioapic = irq->domain->data; ioapic_redirect_entry_t redirect = { .vector = irq->virt, @@ -67,7 +67,7 @@ static uint64_t ioapic_enable(irq_t* irq) static void ioapic_disable(irq_t* irq) { - ioapic_t* ioapic = irq->domain->private; + ioapic_t* ioapic = irq->domain->data; ioapic_redirect_entry_t redirect = {.mask = 1}; diff --git a/src/modules/drivers/ps2/ps2.h b/src/modules/drivers/ps2/ps2.h index ecf1b48ff..8ba201ce4 100644 --- a/src/modules/drivers/ps2/ps2.h +++ b/src/modules/drivers/ps2/ps2.h @@ -206,7 +206,7 @@ typedef struct irq_virt_t irq; ///< IRQ assigned to the device by ACPI. bool attached; ///< The device has been attached from ACPI. bool initialized; ///< The device has been initialized. - void* private; ///< Driver-specific private data. + void* data; ///< Driver-specific private data. } ps2_device_info_t; /** diff --git a/src/modules/drivers/ps2/ps2_kbd.c b/src/modules/drivers/ps2/ps2_kbd.c index 029ec6516..a71526210 100644 --- a/src/modules/drivers/ps2/ps2_kbd.c +++ b/src/modules/drivers/ps2/ps2_kbd.c @@ -8,7 +8,7 @@ static void ps2_kbd_irq(irq_func_data_t* data) { - ps2_kbd_t* kbd = data->private; + ps2_kbd_t* kbd = data->data; uint64_t response = ps2_read_no_wait(); if (response == ERR) @@ -71,13 +71,13 @@ uint64_t ps2_kbd_init(ps2_device_info_t* info) return ERR; } - info->private = kbd; + info->data = kbd; return 0; } uint64_t ps2_kbd_irq_register(ps2_device_info_t* info) { - ps2_kbd_t* kbd = info->private; + ps2_kbd_t* kbd = info->data; if (kbd == NULL) { LOG_ERR("PS/2 keyboard data is NULL during IRQ registration\n"); @@ -96,16 +96,16 @@ uint64_t ps2_kbd_irq_register(ps2_device_info_t* info) void ps2_kbd_deinit(ps2_device_info_t* info) { - if (info->private == NULL) + if (info->data == NULL) { return; } - ps2_kbd_t* kbd = info->private; + ps2_kbd_t* kbd = info->data; irq_handler_unregister(ps2_kbd_irq, info->irq); kbd_free(kbd->kbd); free(kbd); - info->private = NULL; + info->data = NULL; } diff --git a/src/modules/drivers/ps2/ps2_mouse.c b/src/modules/drivers/ps2/ps2_mouse.c index a092dd64a..59cccc76a 100644 --- a/src/modules/drivers/ps2/ps2_mouse.c +++ b/src/modules/drivers/ps2/ps2_mouse.c @@ -58,7 +58,7 @@ static void ps2_mouse_handle_packet(mouse_t* mouse, ps2_mouse_t* ps2) static void ps2_mouse_irq(irq_func_data_t* data) { - ps2_mouse_t* mouse = data->private; + ps2_mouse_t* mouse = data->data; uint64_t byte = ps2_read_no_wait(); if (byte == ERR) { @@ -134,13 +134,13 @@ uint64_t ps2_mouse_init(ps2_device_info_t* info) return ERR; } - info->private = mouse; + info->data = mouse; return 0; } uint64_t ps2_mouse_irq_register(ps2_device_info_t* info) { - ps2_mouse_t* mouse = info->private; + ps2_mouse_t* mouse = info->data; if (mouse == NULL) { LOG_ERR("PS/2 mouse data is NULL during IRQ registration\n"); @@ -159,16 +159,16 @@ uint64_t ps2_mouse_irq_register(ps2_device_info_t* info) void ps2_mouse_deinit(ps2_device_info_t* info) { - if (info->private == NULL) + if (info->data == NULL) { return; } - ps2_mouse_t* mouse = info->private; + ps2_mouse_t* mouse = info->data; irq_handler_unregister(ps2_mouse_irq, info->irq); mouse_free(mouse->mouse); free(mouse); - info->private = NULL; + info->data = NULL; } diff --git a/src/modules/fs/9p/9p.c b/src/modules/fs/9p/9p.c index 5fa12b60a..bce207130 100644 --- a/src/modules/fs/9p/9p.c +++ b/src/modules/fs/9p/9p.c @@ -33,7 +33,7 @@ typedef struct static void ninep_super_cleanup(superblock_t* sb) { - ninep_t* ninep = sb->private; + ninep_t* ninep = sb->data; if (ninep == NULL) { return; @@ -42,16 +42,16 @@ static void ninep_super_cleanup(superblock_t* sb) UNREF(ninep->in); UNREF(ninep->out); free(ninep); - sb->private = NULL; + sb->data = NULL; } static superblock_ops_t superOps = { .cleanup = ninep_super_cleanup, }; -static dentry_t* ninep_mount(filesystem_t* fs, const char* options, void* private) +static dentry_t* ninep_mount(filesystem_t* fs, const char* options, void* data) { - UNUSED(private); + UNUSED(data); if (options == NULL) { @@ -128,7 +128,7 @@ static dentry_t* ninep_mount(filesystem_t* fs, const char* options, void* privat return NULL; } - superblock->private = ninep; + superblock->data = ninep; inode_t* inode = inode_new(superblock, 0, INODE_DIR, NULL, NULL); if (inode == NULL) diff --git a/src/modules/ipc/pipe/pipe.c b/src/modules/ipc/pipe/pipe.c index f87d1f655..b8a635d73 100644 --- a/src/modules/ipc/pipe/pipe.c +++ b/src/modules/ipc/pipe/pipe.c @@ -73,7 +73,7 @@ static uint64_t pipe_open(file_t* file) data->readEnd = file; data->writeEnd = file; - file->private = data; + file->data = data; return 0; } @@ -99,14 +99,14 @@ static uint64_t pipe_open2(file_t* files[2]) data->readEnd = files[PIPE_READ]; data->writeEnd = files[PIPE_WRITE]; - files[0]->private = data; - files[1]->private = data; + files[0]->data = data; + files[1]->data = data; return 0; } static void pipe_close(file_t* file) { - pipe_t* data = file->private; + pipe_t* data = file->data; lock_acquire(&data->lock); if (data->readEnd == file) { @@ -139,7 +139,7 @@ static uint64_t pipe_read(file_t* file, void* buffer, size_t count, size_t* offs return 0; } - pipe_t* data = file->private; + pipe_t* data = file->data; if (data->readEnd != file) { errno = ENOSYS; @@ -178,7 +178,7 @@ static uint64_t pipe_write(file_t* file, const void* buffer, size_t count, size_ { UNUSED(offset); - pipe_t* data = file->private; + pipe_t* data = file->data; if (data->writeEnd != file) { errno = ENOSYS; @@ -222,7 +222,7 @@ static uint64_t pipe_write(file_t* file, const void* buffer, size_t count, size_ static wait_queue_t* pipe_poll(file_t* file, poll_events_t* revents) { - pipe_t* data = file->private; + pipe_t* data = file->data; LOCK_SCOPE(&data->lock); if (fifo_bytes_readable(&data->ring) != 0 || data->isWriteClosed) diff --git a/src/modules/ipc/shmem/shmem.c b/src/modules/ipc/shmem/shmem.c index e65e37692..6dc4262ed 100644 --- a/src/modules/ipc/shmem/shmem.c +++ b/src/modules/ipc/shmem/shmem.c @@ -86,9 +86,9 @@ static shmem_object_t* shmem_object_new(void) return shmem; } -static void shmem_vmm_callback(void* private) +static void shmem_vmm_callback( void* data) { - shmem_object_t* shmem = private; + shmem_object_t* shmem = data; if (shmem == NULL) { return; @@ -150,13 +150,13 @@ static uint64_t shmem_open(file_t* file) return ERR; } - file->private = shmem; + file->data = shmem; return 0; } static void shmem_close(file_t* file) { - shmem_object_t* shmem = file->private; + shmem_object_t* shmem = file->data; if (shmem == NULL) { return; @@ -167,7 +167,7 @@ static void shmem_close(file_t* file) static void* shmem_mmap(file_t* file, void* address, size_t length, size_t* offset, pml_flags_t flags) { - shmem_object_t* shmem = file->private; + shmem_object_t* shmem = file->data; if (shmem == NULL) { errno = EINVAL; diff --git a/src/modules/net/local/local.c b/src/modules/net/local/local.c index 409e4b77d..b8e696148 100644 --- a/src/modules/net/local/local.c +++ b/src/modules/net/local/local.c @@ -51,13 +51,13 @@ static uint64_t local_socket_init(socket_t* sock) { return ERR; } - sock->private = data; + sock->data = data; return 0; } static void local_socket_deinit(socket_t* sock) { - local_socket_t* data = sock->private; + local_socket_t* data = sock->data; if (data == NULL) { return; @@ -88,12 +88,12 @@ static void local_socket_deinit(socket_t* sock) } free(data); - sock->private = NULL; + sock->data = NULL; } static uint64_t local_socket_bind(socket_t* sock) { - local_socket_t* data = sock->private; + local_socket_t* data = sock->data; if (data == NULL) { errno = EINVAL; @@ -118,7 +118,7 @@ static uint64_t local_socket_bind(socket_t* sock) static uint64_t local_socket_listen(socket_t* sock, uint32_t backlog) { - local_socket_t* data = sock->private; + local_socket_t* data = sock->data; if (data == NULL) { errno = EINVAL; @@ -144,7 +144,7 @@ static uint64_t local_socket_listen(socket_t* sock, uint32_t backlog) static uint64_t local_socket_connect(socket_t* sock) { - local_socket_t* data = sock->private; + local_socket_t* data = sock->data; if (data == NULL) { errno = EINVAL; @@ -198,7 +198,7 @@ static uint64_t local_socket_connect(socket_t* sock) static uint64_t local_socket_accept(socket_t* sock, socket_t* newSock, mode_t mode) { - local_socket_t* data = sock->private; + local_socket_t* data = sock->data; if (data == NULL) { errno = EINVAL; @@ -249,7 +249,7 @@ static uint64_t local_socket_accept(socket_t* sock, socket_t* newSock, mode_t mo assert(conn != NULL); - local_socket_t* newData = newSock->private; + local_socket_t* newData = newSock->data; if (newData == NULL) { errno = EINVAL; @@ -265,7 +265,7 @@ static size_t local_socket_send(socket_t* sock, const void* buffer, size_t count { UNUSED(offset); - local_socket_t* data = sock->private; + local_socket_t* data = sock->data; if (data == NULL) { errno = EINVAL; @@ -333,7 +333,7 @@ static size_t local_socket_recv(socket_t* sock, void* buffer, size_t count, size { UNUSED(offset); - local_socket_t* data = sock->private; + local_socket_t* data = sock->data; if (data == NULL) { errno = EINVAL; @@ -408,7 +408,7 @@ static size_t local_socket_recv(socket_t* sock, void* buffer, size_t count, size static wait_queue_t* local_socket_poll(socket_t* sock, poll_events_t* revents) { - local_socket_t* data = sock->private; + local_socket_t* data = sock->data; if (data == NULL) { errno = EINVAL;