diff --git a/contrib/kolibri-libc/samples/shell_io.c b/contrib/kolibri-libc/samples/shell_io.c index 6e9c428903..9f50737517 100644 --- a/contrib/kolibri-libc/samples/shell_io.c +++ b/contrib/kolibri-libc/samples/shell_io.c @@ -4,6 +4,7 @@ int main(int argc, char**argv) { + debug_printf("%u\n", shell_get_pid()); char string[256]; shell_cls(); shell_printf("Number of arguments %d\n",argc); diff --git a/contrib/kolibri-libc/source/include/shell_api.h b/contrib/kolibri-libc/source/include/shell_api.h index 8bb00c34e8..60fd6552a7 100644 --- a/contrib/kolibri-libc/source/include/shell_api.h +++ b/contrib/kolibri-libc/source/include/shell_api.h @@ -10,5 +10,6 @@ extern char _FUNC(shell_getc)(); extern void _FUNC(shell_gets)(char *str); extern void _FUNC(shell_cls)(); extern void _FUNC(shell_exit)(); - +extern unsigned _FUNC(shell_get_pid)(); +extern int _FUNC(shell_ping)(); #endif \ No newline at end of file diff --git a/contrib/kolibri-libc/source/include/stdio.h b/contrib/kolibri-libc/source/include/stdio.h index 84df4863f3..7593a722c4 100644 --- a/contrib/kolibri-libc/source/include/stdio.h +++ b/contrib/kolibri-libc/source/include/stdio.h @@ -98,6 +98,7 @@ extern size_t _FUNC(fread)(void *restrict, size_t size, size_t count, FILE *rest extern int _FUNC(fscanf)(FILE *restrict, const char *restrict, ...); extern size_t _FUNC(fwrite)(const void *restrict, size_t size, size_t count, FILE *restrict); extern int _FUNC(getc)(FILE *); +#define getc _FUNC(fgetc) extern int _FUNC(getchar)(void); extern int _FUNC(printf)(const char *restrict, ...); extern int _FUNC(putc)(int, FILE *); diff --git a/contrib/kolibri-libc/source/include/stdlib.h b/contrib/kolibri-libc/source/include/stdlib.h index d59a1d0f9a..27520b1947 100644 --- a/contrib/kolibri-libc/source/include/stdlib.h +++ b/contrib/kolibri-libc/source/include/stdlib.h @@ -28,7 +28,7 @@ extern div_t _FUNC(div)(int, int); extern ldiv_t _FUNC(ldiv)(long, long); extern lldiv_t _FUNC(lldiv)(long long, long long); -extern void _FUNC(*malloc)(size_t size); +extern void* _FUNC(malloc)(size_t size); extern void* _FUNC(calloc)(size_t num, size_t size); extern void* _FUNC(realloc)(void *ptr, size_t newsize); extern void _FUNC(free)(void *ptr); diff --git a/contrib/kolibri-libc/source/shell_api/shell.h b/contrib/kolibri-libc/source/shell_api/shell.h index d613670714..c05f580175 100644 --- a/contrib/kolibri-libc/source/shell_api/shell.h +++ b/contrib/kolibri-libc/source/shell_api/shell.h @@ -1,20 +1,22 @@ #include -#define SHELL_OK 0 -#define SHELL_EXIT 1 -#define SHELL_PUTC 2 -#define SHELL_PUTS 3 -#define SHELL_GETC 4 -#define SHELL_GETS 5 -#define SHELL_CLS 6 +#define SHELL_OK 0 +#define SHELL_EXIT 1 +#define SHELL_PUTC 2 +#define SHELL_PUTS 3 +#define SHELL_GETC 4 +#define SHELL_GETS 5 +#define SHELL_CLS 6 +#define SHELL_PID 7 +#define SHELL_PING 8 #define SHELL_SHM_MAX 1024*16 extern char __shell_shm_name[32]; extern char *__shell_shm; extern int __shell_is_init; -extern int __shell_init(); +extern void __shell_init(); #define SHELL_WAIT() while (*__shell_shm) _ksys_delay(5) diff --git a/contrib/kolibri-libc/source/shell_api/shell_get_pid.c b/contrib/kolibri-libc/source/shell_api/shell_get_pid.c new file mode 100644 index 0000000000..9b53e25eff --- /dev/null +++ b/contrib/kolibri-libc/source/shell_api/shell_get_pid.c @@ -0,0 +1,12 @@ +#include "shell.h" +#include + +unsigned shell_get_pid() +{ + unsigned pid; + __shell_init(); + *__shell_shm = SHELL_PID; + SHELL_WAIT(); + memcpy(&pid, __shell_shm+1, sizeof(unsigned)); + return pid; +} \ No newline at end of file diff --git a/contrib/kolibri-libc/source/shell_api/shell_init.c b/contrib/kolibri-libc/source/shell_api/shell_init.c index 4075dd47ec..39dfe17afb 100644 --- a/contrib/kolibri-libc/source/shell_api/shell_init.c +++ b/contrib/kolibri-libc/source/shell_api/shell_init.c @@ -2,6 +2,7 @@ #include #include #include "shell.h" +#include char __shell_shm_name[32]; char*__shell_shm=NULL; @@ -25,14 +26,17 @@ int __shell_shm_init() return _ksys_shm_open(__shell_shm_name, KSYS_SHM_OPEN_ALWAYS | KSYS_SHM_WRITE, SHELL_SHM_MAX, &__shell_shm); } -int __shell_init() +void __shell_init() { - if(__shell_is_init){ - return 0; + if(!__shell_is_init){ + if(__shell_shm_init()){ + debug_printf("SHELL problems detected!\n"); + _ksys_exit(); + } + + if(!shell_ping()){ + debug_printf("No SHELL found!\n"); + _ksys_exit(); + } } - if(__shell_shm_init()){ - debug_printf("Shell problems detected!\n"); - return -1; - } - return 0; } \ No newline at end of file diff --git a/contrib/kolibri-libc/source/shell_api/shell_ping.c b/contrib/kolibri-libc/source/shell_api/shell_ping.c new file mode 100644 index 0000000000..5200b63fa7 --- /dev/null +++ b/contrib/kolibri-libc/source/shell_api/shell_ping.c @@ -0,0 +1,14 @@ +#include "shell.h" +#include +#include + +int shell_ping() +{ + __shell_init(); + *__shell_shm = SHELL_PING; + _ksys_delay(10); + if(*__shell_shm==SHELL_OK){ + return 1; + } + return 0; +} \ No newline at end of file