forked from KolibriOS/kolibrios
Compare commits
6 Commits
add-SHELL-
...
libc.ob--u
| Author | SHA1 | Date | |
|---|---|---|---|
| aa619aa602 | |||
| 275401c06a | |||
| f675fd31b7 | |||
| ba8747e2ab | |||
| 0319a2d7cb | |||
|
|
668fd4deeb |
@@ -47,11 +47,13 @@ vsscanf
|
||||
ungetc
|
||||
;____STDLIB____
|
||||
abs
|
||||
abort
|
||||
atoi
|
||||
atol
|
||||
atoll
|
||||
atof
|
||||
calloc
|
||||
_exit
|
||||
exit
|
||||
free
|
||||
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 void _exit(int status);
|
||||
#ifndef _Exit
|
||||
#define _Exit(status) _exit(status);
|
||||
#endif
|
||||
|
||||
DLLAPI void exit(int status);
|
||||
DLLAPI void abort();
|
||||
|
||||
DLLAPI void srand(unsigned s);
|
||||
DLLAPI int rand(void);
|
||||
|
||||
@@ -27,7 +27,8 @@ BIN = \
|
||||
libc_test.kex \
|
||||
pipe.kex \
|
||||
defgen.kex \
|
||||
futex.kex
|
||||
futex.kex \
|
||||
atexit_test.kex
|
||||
|
||||
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 pipe.c -o /tmp0/1/tcc_samples/pipe
|
||||
../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
|
||||
exit
|
||||
|
||||
@@ -14,6 +14,7 @@ public start
|
||||
public start as '_start'
|
||||
|
||||
extrn main
|
||||
extrn exit
|
||||
|
||||
include '../../../../../../proc32.inc'
|
||||
include '../../../../../../macros.inc'
|
||||
@@ -38,36 +39,36 @@ start:
|
||||
call push_param
|
||||
; retrieving parameters
|
||||
mov esi, params
|
||||
xor edx, edx ; dl - èä¸ò ïàðàìåòð(1) èëè ðàçäåëèòåëè(0)
|
||||
; dh - ñèìâîë ñ êîòîðîãî íà÷àëñÿ ïàðàìåòð (1 êàâû÷êè, 0 îñòàëüíîå)
|
||||
xor edx, edx ; dl - is it a parameter (1) or delimiters (0)
|
||||
; dh - character with which the parameter started (1 quotes, 0 everything else)
|
||||
mov ecx, 1 ; cl = 1
|
||||
; ch = 0 ïðîñòî íîëü
|
||||
; ch = 0 just zero
|
||||
.parse:
|
||||
lodsb
|
||||
test al, al
|
||||
jz .run
|
||||
test dl, dl
|
||||
jnz .findendparam
|
||||
;{åñëè áûë ðàçäåëèòåëü
|
||||
;{if it was a delimiter
|
||||
cmp al, ' '
|
||||
jz .parse ;çàãðóæåí ïðîáåë, ãðóçèì ñëåäóþùèé ñèìâîë
|
||||
mov dl, cl ;íà÷èíàåòñÿ ïàðàìåòð
|
||||
jz .parse ; space loaded, load next character
|
||||
mov dl, cl ; parameter starts
|
||||
cmp al, '"'
|
||||
jz @f ;çàãðóæåíû êàâû÷êè
|
||||
mov dh, ch ;ïàðàìåòð áåç êàâû÷åê
|
||||
jz @f ; quotes loaded
|
||||
mov dh, ch ; parameter without quotes
|
||||
dec esi
|
||||
call push_param
|
||||
inc esi
|
||||
jmp .parse
|
||||
|
||||
@@:
|
||||
mov dh, cl ;ïàðàìåòð â êàâû÷åêàõ
|
||||
call push_param ;åñëè íå ïðîáåë çíà÷èò íà÷èíàåòñÿ êàêîé òî ïàðàìåòð
|
||||
jmp .parse ;åñëè áûë ðàçäåëèòåëü}
|
||||
mov dh, cl ; parameter in quotes
|
||||
call push_param ; if not a space, then some parameter starts
|
||||
jmp .parse ; if it was a delimiter}
|
||||
|
||||
.findendparam:
|
||||
test dh, dh
|
||||
jz @f ; áåç êàâû÷åê
|
||||
jz @f ; without quotes
|
||||
cmp al, '"'
|
||||
jz .clear
|
||||
jmp .parse
|
||||
@@ -86,10 +87,9 @@ start:
|
||||
push [argc]
|
||||
call main
|
||||
.exit:
|
||||
xor eax,eax
|
||||
dec eax
|
||||
int 0x40
|
||||
dd -1
|
||||
push eax
|
||||
call dword [exit]
|
||||
dd -1
|
||||
.crash:
|
||||
jmp .exit
|
||||
;============================
|
||||
|
||||
@@ -82,6 +82,7 @@
|
||||
#include "string/strstr.c"
|
||||
#include "string/strtok.c"
|
||||
#include "string/strxfrm.c"
|
||||
|
||||
#include "stdlib/abs.c"
|
||||
#include "stdlib/assert.c"
|
||||
#include "stdlib/atof.c"
|
||||
@@ -89,7 +90,9 @@
|
||||
#include "stdlib/atol.c"
|
||||
#include "stdlib/atoll.c"
|
||||
#include "stdlib/calloc.c"
|
||||
#include "stdlib/atexit.c"
|
||||
#include "stdlib/exit.c"
|
||||
#include "stdlib/_exit.c"
|
||||
#include "stdlib/free.c"
|
||||
#include "stdlib/itoa.c"
|
||||
#include "stdlib/labs.c"
|
||||
@@ -100,6 +103,7 @@
|
||||
#include "stdlib/realloc.c"
|
||||
#include "stdlib/strtod.c"
|
||||
#include "stdlib/strtol.c"
|
||||
#include "stdlib/abort.c"
|
||||
|
||||
#include "math/acosh.c"
|
||||
#include "math/asinh.c"
|
||||
@@ -170,7 +174,9 @@ ksys_dll_t EXPORTS[] = {
|
||||
{ "atoll", &atoll },
|
||||
{ "atof", &atof },
|
||||
{ "calloc", &calloc },
|
||||
{ "_exit", &_exit },
|
||||
{ "exit", &exit },
|
||||
{ "abort", &abort },
|
||||
{ "free", &free },
|
||||
{ "itoa", &itoa },
|
||||
{ "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>
|
||||
#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 @@
|
||||
/*
|
||||
* 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 @@
|
||||
/*
|
||||
* 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 */
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
* Copyright (C) 2021 Logaev Maxim
|
||||
* Copyright (C) 2026 KolibriOS team
|
||||
*/
|
||||
|
||||
#include <conio.h>
|
||||
#include <stdlib.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)
|
||||
{
|
||||
if (__con_is_load) {
|
||||
con_exit(status);
|
||||
}
|
||||
_ksys_exit();
|
||||
__libc_exit(status, &__normal_exit);
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ start:
|
||||
mov [sockaddr1.port], ax
|
||||
|
||||
xchg al, ah
|
||||
invoke con_printf, str1, eax
|
||||
invoke con_printf, str1, ini_buf, eax
|
||||
add esp, 8
|
||||
|
||||
; open listening socket
|
||||
@@ -341,7 +341,7 @@ thread_exit:
|
||||
; initialized data
|
||||
|
||||
title db 'FTP daemon', 0
|
||||
str1 db 'Starting FTP daemon on port %u.', 0
|
||||
str1 db 'Starting FTP daemon on %s:%u', 0
|
||||
str2 db '.', 0
|
||||
str2b db ' OK!',10,0
|
||||
str3 db 'Listen error',10,0
|
||||
|
||||
Reference in New Issue
Block a user