libc.obj: update exit #340
@@ -47,11 +47,13 @@ vsscanf
|
|||||||
ungetc
|
ungetc
|
||||||
;____STDLIB____
|
;____STDLIB____
|
||||||
abs
|
abs
|
||||||
|
abort
|
||||||
atoi
|
atoi
|
||||||
atol
|
atol
|
||||||
atoll
|
atoll
|
||||||
atof
|
atof
|
||||||
calloc
|
calloc
|
||||||
|
_exit
|
||||||
exit
|
exit
|
||||||
free
|
free
|
||||||
itoa
|
itoa
|
||||||
|
|||||||
4
programs/develop/ktcc/trunk/libc.obj/.gitignore
vendored
Normal file
4
programs/develop/ktcc/trunk/libc.obj/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
.tup
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.kex
|
||||||
@@ -48,7 +48,13 @@ DLLAPI void free(void* ptr);
|
|||||||
|
|
||||||
DLLAPI long int strtol(const char* str, char** endptr, int base);
|
DLLAPI long int strtol(const char* str, char** endptr, int base);
|
||||||
|
|
||||||
|
DLLAPI void _exit(int status);
|
||||||
|
#ifndef _Exit
|
||||||
|
#define _Exit(status) _exit(status);
|
||||||
|
#endif
|
||||||
|
|
||||||
DLLAPI void exit(int status);
|
DLLAPI void exit(int status);
|
||||||
|
DLLAPI void abort();
|
||||||
|
|
||||||
DLLAPI void srand(unsigned s);
|
DLLAPI void srand(unsigned s);
|
||||||
DLLAPI int rand(void);
|
DLLAPI int rand(void);
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ BIN = \
|
|||||||
libc_test.kex \
|
libc_test.kex \
|
||||||
pipe.kex \
|
pipe.kex \
|
||||||
defgen.kex \
|
defgen.kex \
|
||||||
futex.kex
|
futex.kex \
|
||||||
|
atexit_test.kex
|
||||||
|
|
||||||
all: $(BIN)
|
all: $(BIN)
|
||||||
|
|
||||||
|
|||||||
18
programs/develop/ktcc/trunk/libc.obj/samples/atexit_test.c
Normal file
18
programs/develop/ktcc/trunk/libc.obj/samples/atexit_test.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void f()
|
||||||
|
{
|
||||||
|
static int c = 1;
|
||||||
|
printf("exit #%d\n", c);
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
atexit(&f);
|
||||||
|
atexit(&f);
|
||||||
|
atexit(&f);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -23,5 +23,6 @@ cp clayer/logo.png /tmp0/1/tcc_samples/logo.png
|
|||||||
../tcc defgen.c -o /tmp0/1/tcc_samples/defgen
|
../tcc defgen.c -o /tmp0/1/tcc_samples/defgen
|
||||||
../tcc pipe.c -o /tmp0/1/tcc_samples/pipe
|
../tcc pipe.c -o /tmp0/1/tcc_samples/pipe
|
||||||
../tcc futex.c -o /tmp0/1/tcc_samples/futex
|
../tcc futex.c -o /tmp0/1/tcc_samples/futex
|
||||||
|
../tcc atexit_test.c -o /tmp0/1/tcc_samples/atexit_test
|
||||||
"/sys/File managers/Eolite" /tmp0/1/tcc_samples
|
"/sys/File managers/Eolite" /tmp0/1/tcc_samples
|
||||||
exit
|
exit
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public start
|
|||||||
public start as '_start'
|
public start as '_start'
|
||||||
|
|
||||||
extrn main
|
extrn main
|
||||||
|
extrn exit
|
||||||
|
|
||||||
include '../../../../../../proc32.inc'
|
include '../../../../../../proc32.inc'
|
||||||
include '../../../../../../macros.inc'
|
include '../../../../../../macros.inc'
|
||||||
@@ -38,36 +39,36 @@ start:
|
|||||||
call push_param
|
call push_param
|
||||||
; retrieving parameters
|
; retrieving parameters
|
||||||
mov esi, params
|
mov esi, params
|
||||||
xor edx, edx ; dl - èä¸ò ïàðàìåòð(1) èëè ðàçäåëèòåëè(0)
|
xor edx, edx ; dl - is it a parameter (1) or delimiters (0)
|
||||||
; dh - ñèìâîë ñ êîòîðîãî íà÷àëñÿ ïàðàìåòð (1 êàâû÷êè, 0 îñòàëüíîå)
|
; dh - character with which the parameter started (1 quotes, 0 everything else)
|
||||||
mov ecx, 1 ; cl = 1
|
mov ecx, 1 ; cl = 1
|
||||||
; ch = 0 ïðîñòî íîëü
|
; ch = 0 just zero
|
||||||
.parse:
|
.parse:
|
||||||
lodsb
|
lodsb
|
||||||
test al, al
|
test al, al
|
||||||
jz .run
|
jz .run
|
||||||
test dl, dl
|
test dl, dl
|
||||||
jnz .findendparam
|
jnz .findendparam
|
||||||
;{åñëè áûë ðàçäåëèòåëü
|
;{if it was a delimiter
|
||||||
cmp al, ' '
|
cmp al, ' '
|
||||||
jz .parse ;çàãðóæåí ïðîáåë, ãðóçèì ñëåäóþùèé ñèìâîë
|
jz .parse ; space loaded, load next character
|
||||||
mov dl, cl ;íà÷èíàåòñÿ ïàðàìåòð
|
mov dl, cl ; parameter starts
|
||||||
cmp al, '"'
|
cmp al, '"'
|
||||||
jz @f ;çàãðóæåíû êàâû÷êè
|
jz @f ; quotes loaded
|
||||||
mov dh, ch ;ïàðàìåòð áåç êàâû÷åê
|
mov dh, ch ; parameter without quotes
|
||||||
|
mxlgv
commented
Please fix indent Please fix indent
|
|||||||
dec esi
|
dec esi
|
||||||
call push_param
|
call push_param
|
||||||
inc esi
|
inc esi
|
||||||
jmp .parse
|
jmp .parse
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
mov dh, cl ;ïàðàìåòð â êàâû÷åêàõ
|
mov dh, cl ; parameter in quotes
|
||||||
call push_param ;åñëè íå ïðîáåë çíà÷èò íà÷èíàåòñÿ êàêîé òî ïàðàìåòð
|
call push_param ; if not a space, then some parameter starts
|
||||||
jmp .parse ;åñëè áûë ðàçäåëèòåëü}
|
jmp .parse ; if it was a delimiter}
|
||||||
|
|
||||||
.findendparam:
|
.findendparam:
|
||||||
test dh, dh
|
test dh, dh
|
||||||
jz @f ; áåç êàâû÷åê
|
jz @f ; without quotes
|
||||||
cmp al, '"'
|
cmp al, '"'
|
||||||
jz .clear
|
jz .clear
|
||||||
jmp .parse
|
jmp .parse
|
||||||
@@ -86,10 +87,9 @@ start:
|
|||||||
push [argc]
|
push [argc]
|
||||||
call main
|
call main
|
||||||
.exit:
|
.exit:
|
||||||
xor eax,eax
|
push eax
|
||||||
dec eax
|
call dword [exit]
|
||||||
int 0x40
|
dd -1
|
||||||
dd -1
|
|
||||||
.crash:
|
.crash:
|
||||||
jmp .exit
|
jmp .exit
|
||||||
;============================
|
;============================
|
||||||
|
|||||||
@@ -82,6 +82,7 @@
|
|||||||
#include "string/strstr.c"
|
#include "string/strstr.c"
|
||||||
#include "string/strtok.c"
|
#include "string/strtok.c"
|
||||||
#include "string/strxfrm.c"
|
#include "string/strxfrm.c"
|
||||||
|
|
||||||
#include "stdlib/abs.c"
|
#include "stdlib/abs.c"
|
||||||
#include "stdlib/assert.c"
|
#include "stdlib/assert.c"
|
||||||
#include "stdlib/atof.c"
|
#include "stdlib/atof.c"
|
||||||
@@ -89,7 +90,9 @@
|
|||||||
#include "stdlib/atol.c"
|
#include "stdlib/atol.c"
|
||||||
#include "stdlib/atoll.c"
|
#include "stdlib/atoll.c"
|
||||||
#include "stdlib/calloc.c"
|
#include "stdlib/calloc.c"
|
||||||
|
#include "stdlib/atexit.c"
|
||||||
#include "stdlib/exit.c"
|
#include "stdlib/exit.c"
|
||||||
|
#include "stdlib/_exit.c"
|
||||||
#include "stdlib/free.c"
|
#include "stdlib/free.c"
|
||||||
#include "stdlib/itoa.c"
|
#include "stdlib/itoa.c"
|
||||||
#include "stdlib/labs.c"
|
#include "stdlib/labs.c"
|
||||||
@@ -100,6 +103,7 @@
|
|||||||
#include "stdlib/realloc.c"
|
#include "stdlib/realloc.c"
|
||||||
#include "stdlib/strtod.c"
|
#include "stdlib/strtod.c"
|
||||||
#include "stdlib/strtol.c"
|
#include "stdlib/strtol.c"
|
||||||
|
#include "stdlib/abort.c"
|
||||||
|
|
||||||
#include "math/acosh.c"
|
#include "math/acosh.c"
|
||||||
#include "math/asinh.c"
|
#include "math/asinh.c"
|
||||||
@@ -170,7 +174,9 @@ ksys_dll_t EXPORTS[] = {
|
|||||||
{ "atoll", &atoll },
|
{ "atoll", &atoll },
|
||||||
{ "atof", &atof },
|
{ "atof", &atof },
|
||||||
{ "calloc", &calloc },
|
{ "calloc", &calloc },
|
||||||
|
{ "_exit", &_exit },
|
||||||
{ "exit", &exit },
|
{ "exit", &exit },
|
||||||
|
{ "abort", &abort },
|
||||||
{ "free", &free },
|
{ "free", &free },
|
||||||
{ "itoa", &itoa },
|
{ "itoa", &itoa },
|
||||||
{ "labs", &labs },
|
{ "labs", &labs },
|
||||||
|
|||||||
26
programs/develop/ktcc/trunk/libc.obj/source/stdlib/_exit.c
Normal file
26
programs/develop/ktcc/trunk/libc.obj/source/stdlib/_exit.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include <conio.h>
|
||||||
|
mxlgv
commented
Please add copyright: Please add copyright:
```c
/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2026 KolibriOS team
*/
```
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/ksys.h>
|
||||||
|
|
||||||
|
void _exit(int status)
|
||||||
|
{
|
||||||
|
__libc_exit(status, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __libc_exit(int status, void (*before_exit)(int status))
|
||||||
|
{
|
||||||
|
// return error and this is not abort
|
||||||
|
if (status && status != 128) {
|
||||||
|
fprintf(stderr, "\nexit code: %d\n", status);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (before_exit) {
|
||||||
|
before_exit(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (__con_is_load) {
|
||||||
|
con_exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ksys_exit();
|
||||||
|
}
|
||||||
17
programs/develop/ktcc/trunk/libc.obj/source/stdlib/abort.c
Normal file
17
programs/develop/ktcc/trunk/libc.obj/source/stdlib/abort.c
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
mxlgv
commented
Please add copyright: Please add copyright:
```c
/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2026 KolibriOS team
*/
```
|
|||||||
|
* SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
* Copyright (C) 2026 KolibriOS team
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/ksys.h>
|
||||||
|
|
||||||
|
void abort()
|
||||||
|
{
|
||||||
|
ksys_thread_t t;
|
||||||
|
_ksys_thread_info(&t, -1);
|
||||||
|
fprintf(stderr, "\nAbort in %d\n", t.pid);
|
||||||
|
|
||||||
|
_exit(128);
|
||||||
|
}
|
||||||
40
programs/develop/ktcc/trunk/libc.obj/source/stdlib/atexit.c
Normal file
40
programs/develop/ktcc/trunk/libc.obj/source/stdlib/atexit.c
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
mxlgv
commented
Please add copyright: Please add copyright:
```c
/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2026 KolibriOS team
*/
```
|
|||||||
|
* SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
* Copyright (C) 2026 KolibriOS team
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
struct atexit_n {
|
||||||
|
struct atexit_n* last;
|
||||||
|
void (*func)(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct atexit_n* __last_n = NULL;
|
||||||
|
|
||||||
|
int atexit(void (*func)(void))
|
||||||
|
{
|
||||||
|
struct atexit_n* n = malloc(sizeof(struct atexit_n));
|
||||||
|
|
||||||
|
if (n == NULL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
n->last = __last_n;
|
||||||
|
n->func = func;
|
||||||
|
|
||||||
|
__last_n = n;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void __run_atexit()
|
||||||
|
{
|
||||||
|
struct atexit_n* n = __last_n;
|
||||||
|
while (n != NULL) {
|
||||||
|
n->func();
|
||||||
|
struct atexit_n* to_free = n;
|
||||||
|
n = n->last;
|
||||||
|
free(to_free);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,32 @@
|
|||||||
/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */
|
/*
|
||||||
|
mxlgv
commented
Please udate copyright: Please udate copyright:
```c
/*
* SPDX-License-Identifier: GPL-2.0-only
* Copyright (C) 2021 Logaev Maxim
* Copyright (C) 2026 KolibriOS team
*/
```
|
|||||||
|
* SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
* Copyright (C) 2021 Logaev Maxim
|
||||||
|
* Copyright (C) 2026 KolibriOS team
|
||||||
|
*/
|
||||||
|
|
||||||
#include <conio.h>
|
#include <stdlib.h>
|
||||||
|
mxlgv
commented
TCC does not optimize the codegen. Comment out and write TODO.
TCC does not optimize the codegen. Comment out and write TODO.
|
|||||||
#include <sys/ksys.h>
|
#include <sys/ksys.h>
|
||||||
|
#include "_exit.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO
|
||||||
|
static void __close_all()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __free_all_mem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
void __normal_exit(int status)
|
||||||
|
{
|
||||||
|
__run_atexit();
|
||||||
|
__close_all();
|
||||||
|
__free_all_mem();
|
||||||
|
}
|
||||||
|
|
||||||
void exit(int status)
|
void exit(int status)
|
||||||
{
|
{
|
||||||
if (__con_is_load) {
|
__libc_exit(status, &__normal_exit);
|
||||||
con_exit(status);
|
|
||||||
}
|
|
||||||
_ksys_exit();
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user
Please add copyright: