libc.obj: update exit #340

Merged
Burer merged 8 commits from Egor00f/kolibrios:libc.ob--update-exit into main 2026-05-19 10:30:48 +00:00
Collaborator

New functions:

  • implement _exit/_Exit.
  • implement atexit.
  • implement abort.
    abort write Aborted pid: %d to debug board

Changes:

call exit after main.

Just calling exit

exit write exit code

If exit code isn't 0 exit will write exit code to debug board.

use con_exit(0)

use

con_exit(0)

instead of

con_exit(status);

from console.obj readme.
I think the console window shouldn't be so dependent on the exit code. It's must only always close or always stay on screen

exit writing exit code to debug board

Since the exit code is not used anywhere right now, I think it's better to just show it on the debug board.

for auto rebuild crt0.o need #339

from #311

## New functions: + implement `_exit`/`_Exit`. + implement `atexit`. + implement `abort`. `abort` write `Aborted pid: %d` to debug board ## Changes: ### call `exit` after main. Just calling `exit` ### `exit` write exit code If exit code isn't 0 `exit` will write exit code to debug board. ### use `con_exit(0)` use ```c con_exit(0) ``` instead of ```c con_exit(status); ``` [from console.obj readme](https://git.kolibrios.org/KolibriOS/kolibrios/src/commit/310999dcc4c7e40b971974e0f96c48e1e39815ef/programs/develop/libraries/console_coff/console_en.txt#L15). I think the console window shouldn't be so dependent on the exit code. It's must only always close or always stay on screen ### `exit` writing exit code to debug board Since the exit code is not used anywhere right now, I think it's better to just show it on the debug board. for auto rebuild `crt0.o` need #339 from #311
Egor00f requested review from mxlgv 2026-02-22 09:03:38 +00:00
mxlgv requested changes 2026-02-23 22:51:23 +00:00
@@ -0,0 +1,18 @@
#include <stdlib.h>
Owner

Please add copyright:

/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2026 KolibriOS team
*/
Please add copyright: ```c /* * SPDX-License-Identifier: GPL-2.0-only * Copyright (C) 2026 KolibriOS team */ ```
Egor00f marked this conversation as resolved
@@ -56,2 +57,2 @@
jz @f ;чруЁєцхэ√ ърт√ўъш
mov dh, ch ;ярЁрьхЄЁ схч ърт√ўхъ
jz @f ; quotes loaded
mov dh, ch ; parameter without quotes
Owner

Please fix indent

Please fix indent
mxlgv marked this conversation as resolved
@@ -0,0 +1,29 @@
#include <conio.h>
Owner

Please add copyright:

/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2026 KolibriOS team
*/
Please add copyright: ```c /* * SPDX-License-Identifier: GPL-2.0-only * Copyright (C) 2026 KolibriOS team */ ```
Egor00f marked this conversation as resolved
@@ -0,0 +1,69 @@
#ifndef __STDLIB_EXIT_H__
Owner

It's actually super redundant. I assume that this serves some purpose, but in native code it is unnecessary.

It's actually super redundant. I assume that this serves some purpose, but in native code it is unnecessary.
Author
Collaborator

I add it for system(). now i thnink will be better add it later.

I add it for `system()`. now i thnink will be better add it later.
Owner

I suspect this is redundant. I saw the code for system() in the recent PR. You don't have to wait there for the shell to close; you can call shell exit and it will close immediately.

In fact, in KolibriOS there are no exit codes, what you are trying to do looks like a dirty hack.

I suspect this is redundant. I saw the code for `system()` in the recent PR. You don't have to wait there for the shell to close; you can call `shell exit` and it will close immediately. In fact, in KolibriOS there are no exit codes, what you are trying to do looks like a dirty hack.
Author
Collaborator

Okay, I'll just delete this. I'll think about it later.

Okay, I'll just delete this. I'll think about it later.
Egor00f marked this conversation as resolved
@@ -0,0 +1,12 @@
#include <stdio.h>
Owner

Please add copyright:

/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2026 KolibriOS team
*/
Please add copyright: ```c /* * SPDX-License-Identifier: GPL-2.0-only * Copyright (C) 2026 KolibriOS team */ ```
mxlgv marked this conversation as resolved
@@ -0,0 +1,35 @@
#include <stdlib.h>
Owner

Please add copyright:

/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2026 KolibriOS team
*/
Please add copyright: ```c /* * SPDX-License-Identifier: GPL-2.0-only * Copyright (C) 2026 KolibriOS team */ ```
mxlgv marked this conversation as resolved
@@ -1,12 +1,25 @@
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
Owner

Please udate copyright:

/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2021 Logaev Maxim
* Copyright (C) 2026 KolibriOS team
*/
Please udate copyright: ```c /* * SPDX-License-Identifier: GPL-2.0-only * Copyright (C) 2021 Logaev Maxim * Copyright (C) 2026 KolibriOS team */ ```
Egor00f marked this conversation as resolved
@@ -4,1 +4,4 @@
#include <sys/ksys.h>
#include "_exit.h"
static void __close_all()
Owner

TCC does not optimize the codegen. Comment out and write TODO.

TCC does not optimize the codegen. Comment out and write TODO.
mxlgv marked this conversation as resolved
mxlgv added a new dependency 2026-02-24 00:02:05 +00:00
Author
Collaborator

Hmm... maybe it would be better to declare _exit with #define? No sdl and some other libraries require it as function

Hmm... maybe it would be better to declare `_exit` with `#define`? No sdl and some other libraries require it as function
Egor00f requested review from mxlgv 2026-03-07 18:52:27 +00:00
mxlgv added the CCategory/Libraries
Kind
Enhancement
Priority
Low
labels 2026-03-11 11:52:57 +00:00
mxlgv added the
PR
Dependent
label 2026-03-11 12:01:08 +00:00
Egor00f added a new dependency 2026-03-14 18:24:34 +00:00
Egor00f marked the pull request as work in progress 2026-04-12 10:09:00 +00:00
Egor00f marked the pull request as ready for review 2026-04-18 09:11:57 +00:00
Egor00f force-pushed libc.ob--update-exit from 91763282f5 to 384781f570 2026-04-26 12:05:44 +00:00 Compare
Egor00f force-pushed libc.ob--update-exit from 384781f570 to 7af77fe7f4 2026-04-28 18:27:15 +00:00 Compare
Egor00f force-pushed libc.ob--update-exit from d786ae0acb to 637b030f4b 2026-05-17 06:53:32 +00:00 Compare
Egor00f force-pushed libc.ob--update-exit from 637b030f4b to b049f7a28b 2026-05-17 06:54:31 +00:00 Compare
Egor00f force-pushed libc.ob--update-exit from b049f7a28b to fd0f932959 2026-05-17 07:00:35 +00:00 Compare
Burer requested changes 2026-05-17 15:19:11 +00:00
Dismissed
Burer left a comment
Owner

Current problems:

  • Duplicate #include "stdlib/_exit.c" in libc.c.
    Included twice in one amalgamated TU => duplicate definitions of __libc_exit/_exit => won't compile.
    Remove the second include.

  • crt0.asm include path ../×5 → ../×6.
    File stays in .../source/crt/; ../×5 = programs/proc32.inc (exists), ../×6 = repo root (no such file).
    Breaks crt0 assembly. Keep 5 levels.

  • atexit missing from libc.def.
    Added to stdlib.h and EXPORTS[] but not libc.def (unlike abort/_exit) => export incomplete, atexit_test.c won't link.
    Add it.

  • Trailing-whitespace churn in crt0.asm.
    Mostly resolved (the push_param/.dont_add/section '.bss'/path rb buf_len churn was dropped).
    One stray trailing space remains on an unrelated line: cmp word ptr eax, 32fh ; '/#3' UTF8 .
    Drop it and this is fully closed.

  • #define _Exit(status) _exit(status); - trailing ; breaks if/else; drop it.

  • void abort(); - now void abort(void); in stdlib.h and abort.c.

  • Unused WRITE_EXIT_CODE/READ_EXIT_CODE in _exit.h - _exit.h removed entirely; _exit.c rewritten clean.

  • _exit.c - new _exit.c ends with a newline.

  • exit() prints fprintf(stderr, "Exit code: %d") on nonzero status.
    Non-standard: C exit() produces no output. Programs that legitimately exit nonzero (tools returning a status) will now spam stderr. Same class as abort()'s "Aborted pid:" message.
    Not a bug, but a deliberate, undocumented behavior change - decide to keep it (and document) or drop it.

  • con_exit(status)con_exit(0) (behavior change, undocumented).
    con_exit's argument is a console-close flag, not an exit code; passing status was likely unintentional, so con_exit(0) is probably more correct. But it changes console-close behavior for nonzero-exit programs and is not mentioned in the PR.
    Confirm intent / note it.

  • abort_test.c: int main() with no return - now ends with return 0;.

Current problems: - [x] **Duplicate `#include "stdlib/_exit.c"` in `libc.c`.** Included twice in one amalgamated TU => duplicate definitions of `__libc_exit`/`_exit` => won't compile. Remove the second include. - [x] **`crt0.asm` include path `../`×5 → `../`×6.** File stays in `.../source/crt/`; `../`×5 = `programs/proc32.inc` (exists), `../`×6 = repo root (no such file). Breaks `crt0` assembly. Keep 5 levels. - [x] **`atexit` missing from `libc.def`.** Added to `stdlib.h` and `EXPORTS[]` but not `libc.def` (unlike `abort`/`_exit`) => export incomplete, `atexit_test.c` won't link. Add it. - [x] **Trailing-whitespace churn in `crt0.asm`.** Mostly resolved (the `push_param`/`.dont_add`/`section '.bss'`/`path rb buf_len` churn was dropped). One stray trailing space remains on an unrelated line: `cmp word ptr eax, 32fh ; '/#3' UTF8 `. Drop it and this is fully closed. - [x] **`#define _Exit(status) _exit(status);`** - trailing `;` breaks `if/else`; drop it. - [x] **`void abort();`** - now `void abort(void);` in `stdlib.h` and `abort.c`. - [x] **Unused `WRITE_EXIT_CODE`/`READ_EXIT_CODE` in `_exit.h`** - `_exit.h` removed entirely; `_exit.c` rewritten clean. - [x] **`_exit.c`** - new `_exit.c` ends with a newline. - [x] **`exit()` prints `fprintf(stderr, "Exit code: %d")` on nonzero status.** Non-standard: C `exit()` produces no output. Programs that legitimately exit nonzero (tools returning a status) will now spam stderr. Same class as `abort()`'s "Aborted pid:" message. Not a bug, but a deliberate, undocumented behavior change - decide to keep it (and document) or drop it. - [x] **`con_exit(status)` → `con_exit(0)` (behavior change, undocumented).** `con_exit`'s argument is a console-close flag, not an exit code; passing `status` was likely unintentional, so `con_exit(0)` is probably more correct. But it changes console-close behavior for nonzero-exit programs and is not mentioned in the PR. Confirm intent / note it. - [x] **`abort_test.c`: `int main()` with no `return`** - now ends with `return 0;`.
Egor00f force-pushed libc.ob--update-exit from fd0f932959 to 3486d12d3d 2026-05-18 16:54:37 +00:00 Compare
Egor00f added 1 commit 2026-05-18 18:12:43 +00:00
Egor00f force-pushed libc.ob--update-exit from 3486d12d3d to 425aaee697 2026-05-18 18:12:43 +00:00 Compare
Egor00f requested review from Burer 2026-05-18 18:12:51 +00:00
Egor00f force-pushed libc.ob--update-exit from 425aaee697 to 20d4ddc89a 2026-05-18 18:49:59 +00:00 Compare
Egor00f added 6 commits 2026-05-18 19:20:11 +00:00
and add it to build of all samples
and add it to build of all samples
extra spaces removed
Build system / Check kernel codestyle (pull_request) Successful in 27s
Build system / Build (pull_request) Successful in 9m34s
b77b8ff69f
Egor00f force-pushed libc.ob--update-exit from 19ed6fd049 to b77b8ff69f 2026-05-18 19:20:11 +00:00 Compare
Doczom approved these changes 2026-05-19 06:50:26 +00:00
Burer added 1 commit 2026-05-19 10:17:00 +00:00
crt0.asm, atexit.h: final whitespace fixes
Build system / Check kernel codestyle (pull_request) Successful in 29s
Build system / Build (pull_request) Successful in 9m43s
20ba89ca43
Burer approved these changes 2026-05-19 10:27:53 +00:00
Burer merged commit d486c6b33a into main 2026-05-19 10:30:48 +00:00
Burer deleted branch libc.ob--update-exit 2026-05-19 10:30:48 +00:00
Sign in to join this conversation.
No Reviewers
4 Participants
Notifications
Due Date
No due date set.
Blocks Depends on
Reference: KolibriOS/kolibrios#340