Compare commits

..

49 Commits

Author SHA1 Message Date
170fa3e1b0 libc.obj: add authorship && other 2026-03-06 00:08:10 +05:00
81ea535fed Merge branch 'main' into libc.obj--add-allocator 2026-02-22 10:11:16 +00:00
badae1fbf2 libc.obj: add EXIT_SUCCESS/FAILURE to stdlib.h 2026-02-22 14:47:21 +05:00
01cae0a587 libc.obj: malloc_test: use fprintf(stderr, ...
KolibriOS/kolibrios#311 (comment)
2026-02-22 14:37:41 +05:00
5525fd2a86 translate comments
I didn't notice that forgot
2026-02-22 09:11:57 +00:00
23c75c33b1 lib.obj: kek fix
heh kek
2026-02-22 07:57:59 +00:00
70b90f1d3a libc.obj: Add allocator
just add allocator instead of `_ksys_alloc`, `_ksys_free` and `_ksys_realloc`.
2026-02-22 12:42:48 +05:00
cb1d69ff72 oberon07: Option -nochk a by default
This option disables runtime checks to reduce binary file size.

Signed-off-by: Max Logaev <maxlogaev@proton.me>
2026-02-21 19:22:11 +00:00
b09d09d66b ci/cd: Added checkout of submodules
Signed-off-by: Max Logaev <maxlogaev@proton.me>
2026-02-21 19:22:11 +00:00
3c0f65ed27 cedit: Added to build system
Fixed installation of oberon07 compiler in ISO image

Signed-off-by: Max Logaev <maxlogaev@proton.me>
2026-02-21 19:22:11 +00:00
03efcd7532 oberon07: Added as a git submodule
Signed-off-by: Max Logaev <maxlogaev@proton.me>
2026-02-21 19:22:11 +00:00
7fc1361c4c oberon07: Source code removed
Signed-off-by: Max Logaev <maxlogaev@proton.me>
2026-02-21 19:22:11 +00:00
Igor Shutrov
c8c46d4f60 ftpd: add ip to first message 2026-02-17 22:08:04 +05:00
2ff587a69f libc.obj: Fixed build skip with TCC build enabled
Signed-off-by: Max Logaev <maxlogaev@proton.me>
2026-01-28 17:22:54 +03:00
Igor Shutrov
512dc28549 Cedit: Improve search panel (#313)
Улучшения для Cedit в Панели поиска:
- Добавлен поиск следующего фрагмента текста по нажатию Enter
- Добавлен обратный переход по полям ввода в Панели поиска по Shift-Tab

Co-authored-by: Igor Shutrov <igor@shutrov.ru>
Reviewed-on: KolibriOS/kolibrios#313
Reviewed-by: Burer <burer@noreply.localhost>
Co-authored-by: Igor Shutrov <kolibridev@inbox.ru>
Co-committed-by: Igor Shutrov <kolibridev@inbox.ru>
2026-01-18 16:28:46 +00:00
e8f322ece8 mtdbg: Backtrace implemented (#315)
Added support for backtrace/stacktrace output.
This is useful for high-level languages ​​like C and Oberon07.
If a debug file is provided, searches for the nearest debug symbol.

Reviewed-on: KolibriOS/kolibrios#315
Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com>
Reviewed-by: Burer <burer@noreply.localhost>
2026-01-18 13:08:02 +00:00
6583d79dcf mtdbg: Fixed magic cmd flags
Signed-off-by: Max Logaev <maxlogaev@proton.me>
2026-01-11 13:35:58 +00:00
98028bf4bf libc.obj: Added missing strpbrk() to EXPORTS (#310)
Reviewed-on: KolibriOS/kolibrios#310
Reviewed-by: Max Logaev <maxlogaev@proton.me>
Co-authored-by: Егор <velikiydolbayeb@gmail.com>
Co-committed-by: Егор <velikiydolbayeb@gmail.com>
2026-01-10 23:27:51 +00:00
igorsh
4f79d17ac1 ftpd: Add XPWD and XCWD commands (#309)
Добавлены команды XPWD и XCWD, дублирующие PWD и CWD

Co-authored-by: Igor Shutrov <igor@shutrov.ru>
Co-authored-by: Burer <burer@kolibrios.org>
Reviewed-on: KolibriOS/kolibrios#309
Reviewed-by: Burer <burer@noreply.localhost>
Co-authored-by: igorsh <kolibridev@inbox.ru>
Co-committed-by: igorsh <kolibridev@inbox.ru>
2026-01-08 17:03:23 +00:00
Igor Shutrov
c0d2dd2698 ftpd: Fix typo 2026-01-07 19:41:28 +00:00
Igor Shutrov
f9c519f353 ftpd: Fix typo 2026-01-07 19:41:28 +00:00
Igor Shutrov
6471e7889b ftpd: Fix RETR for small and empty files 2026-01-06 18:20:39 +00:00
cf51adfbbb Info3ds: added resizing of the window with the figure (#241)
info3ds: added resizing of the window with the figure
and the list of vertices in the properties window,

info3ds, info3ds_u: files with menu icons are embedded into the program

Reviewed-on: KolibriOS/kolibrios#241
Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com>
Reviewed-by: Burer <burer@noreply.localhost>
Co-authored-by: IgorA <aie85playm@gmail.com>
Co-committed-by: IgorA <aie85playm@gmail.com>
2025-12-31 07:34:00 +00:00
ba472f07df apps/floppybird: rewrite to c (#284)
What was done:
- [x] Rewritten to C
- [x] Refactored some code
- [x] Fixed window resizing (#182)
- [x] Adaptation for different skin height
- [x] Fixed some tubes leftovers drawing
- [x] Changed tubes generation a little bit
- [x] Changed interface a little bit
- [x] Added Escape key for exit to main menu
- [x] Removed buttons from main menu (hotkeys left) :(

What needs to be done:
- [ ] ~~Fix rolled-up bug?~~
- [ ] ~~Fit it into 2048 bytes?~~
- [ ] ~~Add pause?~~
- [ ] ~~Use buffer for drawing without flickering?~~

P.S. There is no way game with all this changes will fit in 2560 bytes, as previous version, so I decided to skip them.

Reviewed-on: KolibriOS/kolibrios#284
Reviewed-by: Ivan B <dunkaist@noreply.localhost>
Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com>
Co-authored-by: Burer <burer@kolibrios.org>
Co-committed-by: Burer <burer@kolibrios.org>
2025-12-29 06:34:23 +00:00
Igor Shutrov
f081890d8c Remove redundant space before 220 code 2025-12-29 06:32:40 +00:00
manh-td
37fdb91612 Use 64 bit for times in mpeg4_encode_gop_header() 2025-12-20 11:01:45 +00:00
manh-td
bdb5e7570d Fix DoS due to lack of eof check 2025-12-20 11:00:16 +00:00
manh-td
2c1133cbab Fixes out of array access 2025-12-20 10:59:41 +00:00
manh-td
b9136bc2fc Add missing check for av_malloc 2025-12-20 10:37:35 +00:00
6e73b90916 Correcting typos in C_Layer libini (#289)
Change `int_get_color` to `int_get_shortcut` to `ini_get_color` and `ini_get_shortcut` to fix library initialization.

Reviewed-on: KolibriOS/kolibrios#289
Reviewed-by: Gleb Zaharov <risdeveau@codrs.ru>
Reviewed-by: Burer <burer@noreply.localhost>
Co-authored-by: Егор <egor00f@noreply.localhost>
Co-committed-by: Егор <egor00f@noreply.localhost>
2025-12-14 10:02:43 +00:00
47ae7a5e33 [apps/cmm] add new proxy for https sources (#277)
Deployed new https proxy for WebView and Downloader.
Made it configurable through /sys/settings/app.ini.

Reviewed-on: KolibriOS/kolibrios#277
Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com>
Co-authored-by: Burer <burer@kolibrios.org>
Co-committed-by: Burer <burer@kolibrios.org>
2025-10-17 11:04:08 +02:00
dd5eb366d5 programs: Add Uxn emulator (#272)
To build this, a zig compiler (tested: 0.14.1) is needed, run `zig build --release=fast`.
It will download https://github.com/chmod222/zuxn when building.

Co-authored-by: 宋文武 <iyzsong@member.fsf.org>
Reviewed-on: KolibriOS/kolibrios#272
Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com>
Reviewed-by: Burer <burer@kolibrios.org>
Co-authored-by: iyzsong <iyzsong@envs.net>
Co-committed-by: iyzsong <iyzsong@envs.net>
2025-10-13 11:52:24 +02:00
90b1db6408 Webview: Fix many typos with the English translation (#282)
- Fixes a few spelling mistakes and rewords things to sound more natural.
- Reworded to sound more natural in English.
- Fixes many typos on the English homepage of WebView.

Reviewed-on: KolibriOS/kolibrios#282
Reviewed-by: Gleb Zaharov <risdeveau@codrs.ru>
Reviewed-by: Burer <burer@noreply.localhost>
Co-authored-by: Talkashie <talkashie97@gmail.com>
Co-committed-by: Talkashie <talkashie97@gmail.com>
2025-10-08 00:12:15 +02:00
48b91b072d general: Fix brand name to КолибриОС (#280)
- Ensure consistent brand name`КолибриОС`; update Docs and source code. Fixes #6.
- Minimal whitespace clean-up; remove some trailing space from end of lines.

Reviewed-on: KolibriOS/kolibrios#280
Reviewed-by: Burer <burer@noreply.localhost>
Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com>
Co-authored-by: Andrew <dent.ace@gmail.com>
Co-committed-by: Andrew <dent.ace@gmail.com>
2025-09-25 16:39:01 +02:00
1e6587b8e9 Libraries: fixed a bug in lib_init functions (#274)
added verification of the second initialization attempt

Reviewed-on: KolibriOS/kolibrios#274
2025-08-02 18:00:18 +02:00
7e26a74ea3 CtrlDemo: code cleaning, library import optimization (#242)
CtrlDemo, EditboxEx, TooltipDemo:
- code cleaning, library import optimization

Reviewed-on: KolibriOS/kolibrios#242
Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com>
Reviewed-by: Ivan B <dunkaist@noreply.localhost>
Co-authored-by: IgorA <aie85playm@gmail.com>
Co-committed-by: IgorA <aie85playm@gmail.com>
2025-07-14 08:49:18 +02:00
dbea5b03fa Libraries (box_lib, buf2d, libimg, tinygl): optimize function import (#231)
Libraries (box_lib, buf2d, libimg, tinygl): optimize function import

Programs updated:
- gears, test3, test_glu1, test_glu2,
- test_array1, textures0, textures1, textures2,
- ctrldemo, editbox_ex, crypt_files, img_transform,
- scrshoot, t_edit, cnc_control, cnc_editor

Reviewed-on: KolibriOS/kolibrios#231
Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com>
Reviewed-by: Ivan B <dunkaist@noreply.localhost>
Co-authored-by: IgorA <aie85playm@gmail.com>
Co-committed-by: IgorA <aie85playm@gmail.com>
2025-07-14 08:20:32 +02:00
ba7bbb8a77 drivers/usb: add usbother driver and usbdrv.dat config (#253)
This driver loading usb drivers for class and for vendor and product id device.

Co-authored-by: Burer <burer@kolibrios.org>
Reviewed-on: KolibriOS/kolibrios#253
Reviewed-by: Ivan B <dunkaist@noreply.localhost>
Reviewed-by: Burer <burer@noreply.localhost>
2025-07-12 03:31:44 +02:00
f8009ca01e Kernel: Fixed bug in iso9660
Fixed a bug of outputting erroneous file names in iso9660 (not juliet)
2025-06-23 12:54:22 +02:00
7780874199 Kernel: Fixed magic numbers and constants in iso9660 2025-06-23 12:54:22 +02:00
273b2d268b FASM: Remove SVN tagged versions (#268)
- Delete SVN tagged versions `1.68` and `1.71`. We do not need to retain historic FASM versions in KolibriOS source code.

(Work towards #75, point 1)

Reviewed-on: KolibriOS/kolibrios#268
Reviewed-by: Burer <burer@noreply.localhost>
Co-authored-by: Andrew <dent.ace@gmail.com>
Co-committed-by: Andrew <dent.ace@gmail.com>
2025-06-23 09:08:41 +02:00
6d84369dac programs: Optimize GIFs (Pt 2) (#238)
Lossless optimization of GIF image files.
Processed with `gifsicle -O3`(extreme) or `gifsicle --no-loopcount --no-comments` (when only minimal adjustment is permitted).
LZW stream optimized with `flexigif -p -f -a=1`. Methods selected to ensure optimal compression with final KPACK step, since better LZW may reduce LZMA used in bundling programs; evaluated with: `xz --format=lzma --check=none --lzma1=mode=normal,dict=64KiB,nice=273,lc=3,lp=0,pb=2 -k -c in.gif > out.lzma`
QA with [GIF Inspector](https://movableink.github.io/gif-inspector/) and via code review.

📦 Program graphics (compiled or included with software):
- Slimmed `demos/free3d04 `, saved 1489 bytes, ~4%.
- Slimmed `media/midamp/` 3 files, saving 131 bytes, average ~4%.
- Slimmed `testing/cpuid/trunk/cyrix.gif`, saved 25 bytes, ~3%.

📖 Documentation only artwork (distributed outside a program):
- Slimmed `Beat/Beat.gif`, saved 29 bytes, ~0.5%.

🥀 Old vestigial images, no longer used (pending deletion):
- Slimmed `demos/3detx60b/` 2 files, saving 762 bytes, average ~5%.

Reviewed-on: KolibriOS/kolibrios#238
Reviewed-by: Burer <burer@noreply.localhost>
Reviewed-by: Ivan B <dunkaist@noreply.localhost>
Co-authored-by: Andrew <dent.ace@gmail.com>
Co-committed-by: Andrew <dent.ace@gmail.com>
2025-06-18 07:04:52 +02:00
75d622c203 programs/games: Optimize GIFs (#235)
Lossless optimization of GIF image files.
Processed with `gifsicle -O3`(extreme) or `gifsicle --no-loopcount` (when only minimal adjustment is permitted).
LZW stream optimized with `flexigif -p -f -a=1`. Methods selected to ensure optimal compression with final KPACK step, since better LZW may reduce LZMA used in bundling programs, using: `xz --format=lzma --check=none --lzma1=mode=normal,dict=64KiB,nice=273,lc=3,lp=0,pb=2 -k -c in.gif > out.lzma`
QA with [GIF Inspector](https://movableink.github.io/gif-inspector/) and via code review.

📦 Program graphics (compiled or included with software):
- Slimmed `almaz/aniall.gif`, saving 380 bytes, ~9%.
- Slimmed `invaders/` 21 files, saving 1232 bytes, average ~3%.
- Slimmed `megamaze/orientg2.gif`, saving 986 bytes, ~31%.
- Slimmed `phenix/objects.gif`, saving 24 bytes, ~2%.

🥀 Old vestigial images, no longer used:
- Deleted `almaz/explode1.gif`, 4865 bytes.

Reviewed-on: KolibriOS/kolibrios#235
Reviewed-by: Burer <burer@noreply.localhost>
Reviewed-by: Ivan B <dunkaist@noreply.localhost>
Co-authored-by: Andrew <dent.ace@gmail.com>
Co-committed-by: Andrew <dent.ace@gmail.com>
2025-06-17 23:54:40 +02:00
d84f4d875d Return four space indents in kermel Makefile 2025-06-13 18:19:10 +02:00
3f1534fb3d Updated kernel Makefile
TBH it worked even without this but okay.
2025-06-13 18:04:59 +02:00
cfacd6c89e Fixed kernel's Makefile by removing bootbios target 2025-06-13 12:32:32 +02:00
206f9b49fa kernel: Remove SVN tags (#247)
- Delete directories (and files) for SVN tags, as these are captured by Git tags: https://git.kolibrios.org/KolibriOS/kolibrios/tags.

(Work towards #75, point 1)

Reviewed-on: KolibriOS/kolibrios#247
Reviewed-by: Burer <burer@noreply.localhost>
Reviewed-by: Ivan B <dunkaist@noreply.localhost>
Co-authored-by: Andrew <dent.ace@gmail.com>
Co-committed-by: Andrew <dent.ace@gmail.com>
2025-06-12 20:00:14 +02:00
e7318d2202 Fix ftpc crash 2025-06-12 19:31:16 +02:00
eca64295b8 Implement serial reconf 2025-05-22 21:26:05 +05:00
15 changed files with 707 additions and 97 deletions

View File

@@ -0,0 +1,4 @@
.tup
*.o
*.obj
*.kex

View File

@@ -8,6 +8,9 @@
#define NULL ((void*)0)
#endif
#define EXIT_SUCCESS 0 // Successful execution of a program
#define EXIT_FAILURE 1 // Unsuccessful execution of a program
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

View File

@@ -32,7 +32,6 @@ DLLAPI char* strrchr(const char* s, int c);
DLLAPI size_t strspn(const char* s1, const char* s2);
DLLAPI char* strstr(const char* s1, const char* s2);
DLLAPI char* strtok(char* s1, const char* s2);
DLLAPI char* strtok_r(char* s1, const char* s2, char** saveptr);
DLLAPI char* strerror(int errnum);
DLLAPI size_t strlen(const char* s);
DLLAPI char* strrev(char* str);

View File

@@ -27,7 +27,8 @@ BIN = \
libc_test.kex \
pipe.kex \
defgen.kex \
futex.kex
futex.kex \
malloc_test.kex
all: $(BIN)

View File

@@ -23,5 +23,6 @@ cp clayer/logo.png /tmp0/1/tcc_samples/logo.png
../tcc defgen.c -o /tmp0/1/tcc_samples/defgen
../tcc pipe.c -o /tmp0/1/tcc_samples/pipe
../tcc futex.c -o /tmp0/1/tcc_samples/futex
../tcc malloc_test.c -o /tmp0/1/tcc_samples/malloc_test
"/sys/File managers/Eolite" /tmp0/1/tcc_samples
exit

View File

@@ -0,0 +1,292 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "../source/stdlib/_mem.h"
#define RUN_TEST(func) \
printf("---\tRUN TEST: %s\t---\n", #func); \
if (func()) { \
printf("[SUCCESS]\tTest %s is ok.\n\n", #func); \
} else { \
fprintf(stderr, "[FAIL]\tTest %s failed.\n\n", #func); \
exit(EXIT_FAILURE); \
}
// c between a and b
#define IN_RANGE(a, b, c, len) ((a > c && c > b) || ((a > c + len && c + len > b)))
bool test_malloc_basic_allocation()
{
void* ptr = malloc(sizeof(int));
if (ptr)
free(ptr);
return ptr;
}
bool test_malloc_zero_bytes()
{
return malloc(0) == NULL;
}
bool test_malloc_multiple_allocations()
{
void* ptr[512];
for (int i = 1; i < sizeof(ptr) / sizeof(*ptr); i++) {
ptr[i] = malloc(i);
if (ptr[i] == NULL) {
return false;
}
}
for (int i = 1; i < sizeof(ptr) / sizeof(*ptr); i++) {
for (int j = 1; j < sizeof(ptr) / sizeof(*ptr); j++) {
if (i != j) {
if (ptr[i] == ptr[j]) {
fprintf(stderr, "ptrs[%d] == ptrs[%d].\n", i, j);
return false;
} else if (IN_RANGE(
(char*)GET_MEM_NODE_HEADER(ptr[i]) + GET_MEM_NODE_HEADER(ptr[i])->size,
(char*)GET_MEM_NODE_HEADER(ptr[i]),
(char*)GET_MEM_NODE_HEADER(ptr[j]),
GET_MEM_NODE_HEADER(ptr[j])->size)) {
fprintf(stderr, "node %p in node %p", GET_MEM_NODE_HEADER(ptr[i]), GET_MEM_NODE_HEADER(ptr[j]));
// additional info, may help with debug
fprintf(stderr, "node %p\n size:%p\n free:%p\n next: %p\n last: %p\n", GET_MEM_NODE_HEADER(ptr[i]), GET_MEM_NODE_HEADER(ptr[i])->size, GET_MEM_NODE_HEADER(ptr[i])->free, GET_MEM_NODE_HEADER(ptr[i])->next, GET_MEM_NODE_HEADER(ptr[i])->last);
fprintf(stderr, "node %p\n size:%p\n free:%p\n next: %p\n last: %p\n", GET_MEM_NODE_HEADER(ptr[j]), GET_MEM_NODE_HEADER(ptr[j])->size, GET_MEM_NODE_HEADER(ptr[j])->free, GET_MEM_NODE_HEADER(ptr[j])->next, GET_MEM_NODE_HEADER(ptr[j])->last);
exit(EXIT_FAILURE);
}
}
}
}
for (int i = 1; i < sizeof(ptr) / sizeof(*ptr); i++) {
free(ptr[i]);
}
return true;
}
bool test_malloc_data_integrity()
{
const char* As = "AAA";
const char* Cs = "CCC";
char* A = (char*)malloc(10);
char* B = (char*)malloc(10);
char* C = (char*)malloc(10);
if (!A || !B || !C) {
printf("can't alloc\n");
free(A);
free(B);
free(C);
return false;
}
strcpy(A, As);
strcpy(C, Cs);
free(B);
if (strcmp(A, As) != 0) {
printf("A data is broken after free(B). A = '%s'\n", A);
free(A);
free(C);
return false;
}
if (strcmp(C, Cs) != 0) {
printf("C data is broken after free(B). C = '%s'\n", C);
free(A);
free(C);
return false;
}
free(A);
free(C);
return true;
}
bool test_malloc_large_allocation()
{
void* ptr = malloc(1024 * 1024 * 16); // alloc 16mb
if (ptr)
free(ptr);
return ptr;
}
bool test_malloc_allocation_and_free()
{
free(malloc(sizeof(int)));
return true;
}
void fill_buffer(void* ptr, size_t size, unsigned char pattern)
{
if (ptr) {
memset(ptr, pattern, size);
}
}
bool check_buffer(void* ptr, size_t size, unsigned char pattern)
{
if (!ptr) {
return false;
}
unsigned char* byte_ptr = (unsigned char*)ptr;
for (size_t i = 0; i < size; ++i) {
if (byte_ptr[i] != pattern) {
fprintf(stderr, "Error: Byte %u does not match pattern. Expected %02X, got %02X\n",
i, pattern, byte_ptr[i]);
return false;
}
}
return true;
}
bool test_realloc_basic_grow()
{
size_t old_size = 10;
size_t new_size = 20;
int* ptr = (int*)malloc(old_size * sizeof(int));
if (ptr == NULL) {
return false;
}
fill_buffer(ptr, old_size * sizeof(int), 0xAA);
int* new_ptr = (int*)realloc(ptr, new_size * sizeof(int));
if (new_ptr == NULL) {
free(ptr);
return false;
}
if (!check_buffer(new_ptr, old_size * sizeof(int), 0xAA)) {
free(new_ptr);
return false;
}
fill_buffer(new_ptr + old_size, (new_size - old_size) * sizeof(int), 0xBB);
if (!check_buffer(new_ptr + old_size, (new_size - old_size) * sizeof(int), 0xBB)) {
free(new_ptr);
return false;
}
free(new_ptr);
return true;
}
bool test_realloc_basic_shrink()
{
size_t old_size = 20;
size_t new_size = 10;
int* ptr = (int*)malloc(old_size * sizeof(int));
if (ptr == NULL) {
return false;
}
fill_buffer(ptr, old_size * sizeof(int), 0xCC);
int* new_ptr = (int*)realloc(ptr, new_size * sizeof(int));
if (new_ptr == NULL) {
free(ptr);
return false;
}
if (!check_buffer(new_ptr, new_size * sizeof(int), 0xCC)) {
free(new_ptr);
return false;
}
free(new_ptr);
return true;
}
bool test_realloc_same_size()
{
size_t size = 15;
int* ptr = (int*)malloc(size * sizeof(int));
if (ptr == NULL) {
return false;
}
fill_buffer(ptr, size * sizeof(int), 0xDD);
int* new_ptr = (int*)realloc(ptr, size * sizeof(int));
if (new_ptr == NULL) {
free(ptr);
return false;
}
if (!check_buffer(new_ptr, size * sizeof(int), 0xDD)) {
free(new_ptr);
return false;
}
free(new_ptr);
return true;
}
bool test_realloc_null_ptr()
{
size_t size = 25;
void* ptr = realloc(NULL, size);
if (ptr == NULL) {
return false;
}
fill_buffer(ptr, size, 0xEE);
if (!check_buffer(ptr, size, 0xEE)) {
free(ptr);
return false;
}
free(ptr);
return true;
}
bool test_realloc_to_zero_size()
{
size_t old_size = 30;
void* ptr = malloc(old_size);
if (ptr == NULL) {
return false;
}
fill_buffer(ptr, old_size, 0xFF);
void* new_ptr = realloc(ptr, 0);
if (new_ptr == NULL) {
printf("realloc(ptr, 0) return NULL.\n");
free(ptr);
} else {
printf("realloc(ptr, 0) return: %p.\n", new_ptr);
free(new_ptr);
}
return true;
}
int main()
{
RUN_TEST(test_malloc_basic_allocation);
RUN_TEST(test_malloc_zero_bytes);
RUN_TEST(test_malloc_multiple_allocations);
RUN_TEST(test_malloc_data_integrity);
RUN_TEST(test_malloc_large_allocation);
RUN_TEST(test_malloc_basic_allocation);
RUN_TEST(test_malloc_allocation_and_free);
RUN_TEST(test_realloc_basic_grow);
RUN_TEST(test_realloc_basic_shrink);
RUN_TEST(test_realloc_same_size);
RUN_TEST(test_realloc_null_ptr);
RUN_TEST(test_realloc_to_zero_size);
return 0;
}

View File

@@ -19,9 +19,6 @@ FILE* out = stdout;
FILE* out = stderr;
#endif
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#define fprintf fprintf
void show_help()

View File

@@ -203,7 +203,6 @@ ksys_dll_t EXPORTS[] = {
{ "strspn", &strspn },
{ "strstr", &strstr },
{ "strtok", &strtok },
{ "strtok_r", &strtok_r },
{ "strxfrm", &strxfrm },
{ "strpbrk", &strpbrk },
{ "__errno", &__errno },

View File

@@ -0,0 +1,87 @@
/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2026 KolibriOS team
* Author: Yarin Egor<y.yarin@inbox.ru>
*/
#ifndef _LIBC_STDLIB__MEM_
#define _LIBC_STDLIB__MEM_
#include <stddef.h>
struct mem_node {
size_t free; // Amount of free space in this node. When equal to size, the entire node is free.
size_t size; // Total size of this memory node.
struct mem_node* last; // Pointer to the previous memory node in the linked list.
struct mem_node* next; // Pointer to the next memory node in the linked list.
};
struct mem_block {
size_t size; // Size of the allocated memory block.
size_t a; // align to 8bytes
};
// Size of the blocks allocated by `_ksys_alloc`
#define ALLOC_BLOCK_SIZE 4096
// Macro to get a pointer to the user data area from a mem_node pointer.
// This is done by adding the size of the mem_node structure to the mem_node pointer.
#define GET_MEM_NODE_PTR(node) (char*)((char*)(node) + sizeof(struct mem_node))
// Macro to check if a memory node is completely free.
#define MEM_NODE_IS_FREE(node) (node->free == node->size)
// Macro to get the amount of used memory in a memory node.
#define GET_MEM_NODE_USED_MEM(node) (node->size - node->free)
// Macro to get a pointer to the mem_node structure from a user data pointer.
// This is done by subtracting the size of the mem_node structure from the user data pointer.
#define GET_MEM_NODE_HEADER(ptr) ((struct mem_node*)(((char*)ptr) - sizeof(struct mem_node)))
// Macro to check if two adjacent memory nodes are in the same block.
// Checks if the end of the left node's allocated space is the start of the right node.
#define MEM_NODES_ARE_IN_ONE_BLOCK(left, right) (GET_MEM_NODE_PTR(left) + ((struct mem_node*)left)->size == (char*)right)
// Macro to merge two adjacent memory nodes.
#define CHECK_SIDE_IN_OTHER_BLOCK(node, side) (side == NULL || ((side != NULL) && !MEM_NODES_ARE_IN_ONE_BLOCK(node, side)))
// align a value to a specified alignment.
// Ensures that the allocated memory is aligned to a certain boundary
inline size_t __mem_align(size_t value, size_t align)
{
return ((value + align - 1) & ~(align - 1));
}
#define __mem_default_align(value) __mem_align(value, 8)
inline struct mem_node* __mem_MERGE_MEM_NODES(struct mem_node* base, struct mem_node* addition)
{
// addition is free && nodes base and addition both in one block, else merge is impossible
if (MEM_NODE_IS_FREE(addition) && MEM_NODES_ARE_IN_ONE_BLOCK(base, addition)) {
// just change size
const size_t s = addition->size + sizeof(struct mem_node);
base->size += s;
base->free += s;
// and delete addition from list
if (addition->next != NULL) {
addition->next->last = base;
base->next = addition->next;
} else {
base->next = NULL;
}
return base;
}
return NULL;
}
// Static pointer to the first memory node in the linked list.
// This acts as the head of the memory pool.
static struct mem_node* __mem_node = NULL;
static struct mem_node* __last_biggest_mem_node = NULL;
#endif // _LIBC_STDLIB_MEM_

View File

@@ -1,14 +1,10 @@
#include <errno.h>
#include <stdlib.h>
#include <sys/ksys.h>
void* calloc(size_t num, size_t size)
{
void* ptr = _ksys_alloc(num * size);
if (!ptr) {
__errno = ENOMEM;
return NULL;
void* ptr = malloc(num * size);
if (ptr) {
memset(ptr, 0, num * size);
}
memset(ptr, 0, num * size);
return ptr;
}

View File

@@ -1,7 +1,103 @@
/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2026 KolibriOS team
* Author: Yarin Egor<y.yarin@inbox.ru>
*/
#include <stdlib.h>
#include <stdbool.h>
#include <sys/ksys.h>
#include "_mem.h"
void free(void* ptr)
{
_ksys_free(ptr);
}
// Handle NULL pointer.
if (ptr == NULL)
return;
// Get a pointer to the mem_node header from the user data pointer.
struct mem_node* node = GET_MEM_NODE_HEADER(ptr);
// Mark the memory node as free.
node->free = node->size;
if (__last_biggest_mem_node == node) {
if (node->last) {
__last_biggest_mem_node = node->last; // anyway node will be merged with next
// and last and last will have size = last + node + next(if its free too)
}
}
// Merge with the next node if possible.
if (node->next != NULL)
__mem_MERGE_MEM_NODES(node, node->next);
// Merge with the previous node if possible.
if (node->last != NULL)
node = __mem_MERGE_MEM_NODES(node->last, node);
if (node) {
// If the current node is not adjacent to either the next or previous node,
// it might be a separate block that can be freed.
if (MEM_NODE_IS_FREE(node) // check it because node maybe was merged with last
&& (node->last == NULL || !MEM_NODES_ARE_IN_ONE_BLOCK(node, node->next))
&& (node->next == NULL || !MEM_NODES_ARE_IN_ONE_BLOCK(node->last, node))) {
// Get a pointer to the mem_block header from the mem_node header.
struct mem_block* block = (struct mem_block*)(((char*)node) - sizeof(struct mem_block));
// Check if the block size matches the node size.
if (block->size == node->size + sizeof(struct mem_block) + sizeof(struct mem_node)) {
// Update the linked list pointers to remove the current node.
if (node->last != NULL)
node->last->next = node->next;
if (node->next != NULL)
node->next->last = node->last;
// Update the head of the linked list if necessary.
if (__mem_node == node) {
if (node->last != NULL) {
__mem_node = node->last;
} else if (node->next != NULL) {
__mem_node = node->next;
} else {
__mem_node = NULL;
}
}
struct mem_node* a = node->next;
struct mem_node* b = node->last;
if (!a && !b) {
__last_biggest_mem_node = NULL;
} else if (a && !b) {
__last_biggest_mem_node = a;
} else if (!a && b) {
__last_biggest_mem_node = b;
} else if (a && b) {
__last_biggest_mem_node = (a->free > b->free) ? a : b;
}
if (__last_biggest_mem_node == node) {
if (node->next && !(node->last)) {
__last_biggest_mem_node = node->next;
} else if (node->last && !(node->next)) {
__last_biggest_mem_node = node->last;
} else if (node->next && node->last) {
if (node->last->free > node->next->free) {
__last_biggest_mem_node = node->last;
} else {
__last_biggest_mem_node = node->next;
}
}
}
// Free the memory block using the ksys_free function.
_ksys_free(block);
}
}
}
}

View File

@@ -1,7 +1,134 @@
/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2026 KolibriOS team
* Author: Yarin Egor<y.yarin@inbox.ru>
*/
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/ksys.h>
#include <stdbool.h>
#include "_mem.h"
static struct mem_node* __new_mem_node_from_exist(struct mem_node* current_node, size_t size, bool* from_empty_node)
{
struct mem_node* new_node = NULL;
// Check if the current node has enough free space for the requested size.
if (size + sizeof(struct mem_node) <= current_node->free) {
*from_empty_node = MEM_NODE_IS_FREE(current_node);
if (*from_empty_node) {
new_node = current_node;
} else {
// Calculate the used memory in current node
const size_t s = GET_MEM_NODE_USED_MEM(current_node);
// Create a new memory node after the current node's used space.
new_node = (struct mem_node*)(GET_MEM_NODE_PTR(current_node) + s);
// Update current node's size
current_node->size = s;
// Set the size of the new node.
// for new node give all free space in current node
new_node->size = current_node->free - sizeof(struct mem_node);
// Mark current node as used.
current_node->free = 0;
}
}
return new_node;
}
void* malloc(size_t size)
{
return _ksys_alloc(size);
}
char b[32];
// Handle zero-size allocation.
if (size == 0) {
return NULL;
}
// Align the size to 8 bytes.
size = __mem_default_align(size);
struct mem_node* current_node = __mem_node;
struct mem_node* new_node = NULL; // Pointer to the new node that will be created.
bool from_empty_node = false;
if (__last_biggest_mem_node != NULL)
new_node = __new_mem_node_from_exist(__last_biggest_mem_node, size, &from_empty_node); // try find free space in last created node
// if cant find in __last_biggest_mem_node
if (new_node == NULL) {
// Iterate through the linked list of memory nodes.
while (current_node != NULL) {
new_node = __new_mem_node_from_exist(current_node, size, &from_empty_node);
if (new_node)
break; // Found a suitable node, exit the loop.
current_node = current_node->next; // Move to the next node in the list.
}
}
// If no suitable node was found in the existing list:
if (new_node == NULL) {
// Calculate the size of the new block, including the mem_block header, mem_node header and alignment.
const size_t s = __mem_align(size + sizeof(struct mem_block) + sizeof(struct mem_node), ALLOC_BLOCK_SIZE);
// Allocate a new block of memory using the ksys_alloc function (presumably a kernel-level allocation function).
struct mem_block* block = (struct mem_block*)_ksys_alloc(s);
// Check if the allocation was successful.
if (block == NULL) {
__errno = ENOMEM; // Set the error number to indicate memory allocation failure.
return NULL; // Return NULL to indicate allocation failure.
}
block->size = s;
// Create a new memory node after the mem_block header.
new_node = (struct mem_node*)(((char*)block) + sizeof(struct mem_block));
// Set the size of the new node.
new_node->size = s - sizeof(struct mem_block) - sizeof(struct mem_node);
}
// Set the free space in the new node.
new_node->free = new_node->size - size;
if (!from_empty_node) {
// Set the last pointer of the new node to the current node.
new_node->last = current_node;
// Link the new node into the linked list.
if (current_node != NULL) {
// Set the next pointer of the current node to the new node.
new_node->next = current_node->next;
// Update the last pointer of the next node, if it exists.
if (current_node->next != NULL) {
current_node->next->last = new_node;
}
current_node->next = new_node;
} else {
// If the current node is NULL, the new node is the first node in the list.
new_node->next = NULL;
}
}
// If the linked list was empty, set the head to the new node.
if (__mem_node == NULL) {
__mem_node = new_node;
}
if (__last_biggest_mem_node == NULL || new_node->free > __last_biggest_mem_node->free) {
__last_biggest_mem_node = new_node;
}
// Return a pointer to the user data area of the new node.
return GET_MEM_NODE_PTR(new_node);
}
#undef __mem_align

View File

@@ -1,7 +1,82 @@
/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2026 KolibriOS team
* Author: Yarin Egor<y.yarin@inbox.ru>
*/
#include <stdlib.h>
#include <string.h>
#include <sys/ksys.h>
#include "_mem.h"
// realloc mem. using if other ways not working
static void* fail_realloc(void* ptr, size_t newsize)
{
// Allocate a new block of memory with the new size.
void* new_ptr = malloc(newsize);
// If both the old pointer and the new pointer are not NULL:
if (ptr != NULL && new_ptr != NULL) {
// Copy the data from the old block to the new block.
memcpy(new_ptr, ptr, min(newsize, GET_MEM_NODE_USED_MEM(GET_MEM_NODE_HEADER(ptr))));
}
if (ptr) {
free(ptr); // Free the old block.
}
return new_ptr;
}
void* realloc(void* ptr, size_t newsize)
{
return _ksys_realloc(ptr, newsize);
}
void* new_ptr = NULL;
struct mem_node* node = NULL;
if (ptr && newsize) {
// Get a pointer to the mem_node header from the user data pointer.
node = GET_MEM_NODE_HEADER(ptr);
newsize = __mem_default_align(newsize);
if (node->size >= newsize) { // current node have enough mem
// it work always if newsize is smaller
// Update the free space in the current node.
node->free = node->size - newsize;
// Return the original pointer.
new_ptr = ptr;
} else if (node->last && MEM_NODE_IS_FREE(node->last) && node->size + node->last->size >= newsize) {
// So what happens here is that the node merges with the last node if their volume is sufficient.
// And a reallock is called in the hopes that the first condition will be met.
// if merge failed realloc anyway return pointer, but it will got from `fail_realloc`
struct mem_node* l = node->last;
l = __mem_MERGE_MEM_NODES(l, node);
if (l) {
memmove(GET_MEM_NODE_PTR(l), ptr, GET_MEM_NODE_USED_MEM(node));
new_ptr = realloc(GET_MEM_NODE_PTR(l), newsize);
}
}
}
if (new_ptr == NULL) {
// Allocate a new block of memory with the new size.
new_ptr = malloc(newsize);
// If both the old pointer and the new pointer are not NULL:
if (ptr != NULL && new_ptr != NULL) {
// Copy the data from the old block to the new block.
memcpy(new_ptr, ptr, min(newsize, GET_MEM_NODE_USED_MEM(GET_MEM_NODE_HEADER(ptr))));
}
if (ptr) {
free(ptr); // Free the old block.
}
}
// Return the new pointer.
return new_ptr;
}

View File

@@ -1,12 +1,14 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
char* strtok_r(char* s, const char* delim, char** last)
char* strtok(char* s, const char* delim)
{
char *spanp, *tok;
const char* spanp;
int c, sc;
char* tok;
static char* last;
if (s == NULL && (s = *last) == NULL)
if (s == NULL && (s = last) == NULL)
return (NULL);
/*
@@ -14,13 +16,13 @@ char* strtok_r(char* s, const char* delim, char** last)
*/
cont:
c = *s++;
for (spanp = (char*)delim; (sc = *spanp++) != 0;) {
for (spanp = delim; (sc = *spanp++) != 0;) {
if (c == sc)
goto cont;
}
if (c == 0) { /* no non-delimiter characters */
*last = NULL;
last = NULL;
return (NULL);
}
tok = s - 1;
@@ -31,24 +33,17 @@ cont:
*/
for (;;) {
c = *s++;
spanp = (char*)delim;
spanp = delim;
do {
if ((sc = *spanp++) == c) {
if (c == 0)
s = NULL;
else
s[-1] = '\0';
*last = s;
s[-1] = 0;
last = s;
return (tok);
}
} while (sc != 0);
}
/* NOTREACHED */
}
char *strtok(char *s, const char *delim)
{
static char *last;
return (strtok_r(s, delim, &last));
}

View File

@@ -86,7 +86,7 @@ commands: ; all commands must be in uppercase
dd 'CWD', login_first, login_first, login_first, cmdCWD
dd 'XCWD', login_first, login_first, login_first, cmdCWD
dd 'DELE', login_first, login_first, login_first, cmdDELE
dd 'HELP', login_first, login_first, login_first, cmdHELP
; dd 'HELP', login_first, login_first, login_first, cmd_HELP
dd 'LIST', login_first, login_first, login_first, cmdLIST
; dd 'MDTM', login_first, login_first, login_first, cmd_MDTM
; dd 'MKD', login_first, login_first, login_first, cmd_MKD
@@ -1247,68 +1247,6 @@ cmdTYPE:
sendFTP "200 Command ok"
ret
;------------------------------------------------
; "HELP"
;
; Provide help information.
;
;------------------------------------------------
align 4
cmdHELP:
lea edi, [ebp + thread_data.buffer]
mov eax, '214 '
stosd
mov eax, 'Help'
stosd
mov ax, ': '
stosw
mov esi, commands ; pointer to commands table
.next_command:
cmp byte [esi], 0 ; end of table?
je .list_done
; Copy command name (4 bytes), skip null bytes
mov ecx, 4
.copy_name:
mov al, [esi]
test al, al
jz .skip_null
stosb
.skip_null:
inc esi
loop .copy_name
; Add space after command name
mov al, ' '
stosb
; Skip the four address pointers (16 bytes)
add esi, 16
jmp .next_command
.list_done:
; Remove trailing space (if any)
dec edi
; Add CRLF
mov ax, 0x0a0d ; \r\n
stosw
xor al, al ; null terminator
stosb
; Calculate length
lea edx, [ebp + thread_data.buffer]
sub edi, edx
; Send response
mcall send, [ebp + thread_data.socketnum], edx, edi
; Also log to console
invoke con_write_asciiz, edx
ret
;------------------------------------------------
; "USER"
;