diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-16 19:56:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-16 19:56:21 +0200 |
| commit | 1a32b9307357ac0fc9095e853b2b6d94f9fe62bb (patch) | |
| tree | f41f723659c8926e38182fbe062746d821ab487e /dev/boot/src/BootSupport.cc | |
| parent | eb9df5eea339812513c25a8d3b2eeb03c633e7ac (diff) | |
| parent | b301047903b79560dce69085fc271a653a1eb4b6 (diff) | |
Merge pull request #55 from nekernel-org/dev
v0.0.4
Diffstat (limited to 'dev/boot/src/BootSupport.cc')
| -rw-r--r-- | dev/boot/src/BootSupport.cc | 66 |
1 files changed, 63 insertions, 3 deletions
diff --git a/dev/boot/src/BootSupport.cc b/dev/boot/src/BootSupport.cc index ce824e0f..4bf3e68a 100644 --- a/dev/boot/src/BootSupport.cc +++ b/dev/boot/src/BootSupport.cc @@ -18,6 +18,69 @@ /// @param dst destination pointer. /// @param byte value to fill in. /// @param len length of of src. +EXTERN_C VoidPtr memnset(void* dst, int byte, long long unsigned int len, + long long unsigned int dst_size) { + if (!dst || len > dst_size) { + // For now, we return nullptr or an error status. + return nullptr; + } + unsigned char* p = (unsigned char*) dst; + unsigned char val = (unsigned char) byte; + for (size_t i = 0UL; i < len; ++i) { + p[i] = val; + } + return dst; +} + +/// @brief memcpy definition in C++. +/// @param dst destination pointer. +/// @param src source pointer. +/// @param len length of of src. +EXTERN_C VoidPtr memncpy(void* dst, const void* src, long long unsigned int len, + long long unsigned int dst_size) { + if (!dst || !src || len > dst_size) { + // Similar to memset, this is a critical failure. + return nullptr; + } + unsigned char* d = (unsigned char*) dst; + const unsigned char* s = (const unsigned char*) src; + for (size_t i = 0UL; i < len; ++i) { + d[i] = s[i]; + } + return dst; +} + +/// @brief strlen definition in C++. +EXTERN_C size_t strnlen(const char* whatToCheck, size_t max_len) { + size_t len = 0; + while (len < max_len && whatToCheck[len] != '\0') { + ++len; + } + return len; +} + +/// @brief strcmp definition in C++. +EXTERN_C int strncmp(const char* whatToCheck, const char* whatToCheckRight, size_t max_len) { + size_t i = 0; + while (i < max_len && whatToCheck[i] == whatToCheckRight[i]) { + if (whatToCheck[i] == '\0') return 0; + ++i; + } + if (i == max_len) { + return 0; + } + return (unsigned char) whatToCheck[i] - (unsigned char) whatToCheckRight[i]; +} + +/// @brief something specific to the Microsoft's ABI, When the stack grows too big. +EXTERN_C void ___chkstk_ms(void) {} + +/// @note GCC expects them to be here. + +/// @brief memset definition in C++. +/// @param dst destination pointer. +/// @param byte value to fill in. +/// @param len length of of src. EXTERN_C VoidPtr memset(void* dst, int byte, long long unsigned int len) { for (size_t i = 0UL; i < len; ++i) { ((int*) dst)[i] = byte; @@ -62,7 +125,4 @@ EXTERN_C int strcmp(const char* whatToCheck, const char* whatToCheckRight) { return len; } -/// @brief something specific to the Microsoft's ABI, When the stack grows too big. -EXTERN_C void ___chkstk_ms(void) {} - #endif |
