Compare commits
2 Commits
55d9b1fcd5
...
ab8856cf4b
| Author | SHA1 | Date | |
|---|---|---|---|
| ab8856cf4b | |||
| bf99bedfc5 |
44
ce/interp.c
44
ce/interp.c
@@ -11,6 +11,7 @@
|
|||||||
#include <kb.h>
|
#include <kb.h>
|
||||||
#include <liballoc.h>
|
#include <liballoc.h>
|
||||||
#include <path.h>
|
#include <path.h>
|
||||||
|
#include <printf.h>
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <str_status.h>
|
#include <str_status.h>
|
||||||
@@ -24,6 +25,26 @@ bool interp_is_running (void) { return run; }
|
|||||||
|
|
||||||
void interp_shutdown (void) { run = false; }
|
void interp_shutdown (void) { run = false; }
|
||||||
|
|
||||||
|
static void human_size (double size, double* out, char** str) {
|
||||||
|
if (size >= 1024.0f && size < 1024.0f * 1024.0f) {
|
||||||
|
*out = (double)size / 1024.0f;
|
||||||
|
*str = "KiB";
|
||||||
|
} else if (size >= 1024.0f * 1024.0f && size < 1024.0f * 1024.0f * 1024.0f) {
|
||||||
|
*out = (double)size / (1024.0f * 1024.0f);
|
||||||
|
*str = "MiB";
|
||||||
|
} else if (size >= 1024.0f * 1024.0f * 1024.0f && size < 1024.0f * 1024.0f * 1024.0f * 1024.0f) {
|
||||||
|
*out = (double)size / (1024.0f * 1024.0f * 1024.0f);
|
||||||
|
*str = "GiB";
|
||||||
|
} else if (size >= 1024.0f * 1024.0f * 1024.0f * 1024.0f &&
|
||||||
|
size < 1024.0f * 1024.0f * 1024.0f * 1024.0f * 1024.0f) {
|
||||||
|
*out = (double)size / (1024.0f * 1024.0f * 1024.0f * 1024.0f);
|
||||||
|
*str = "TiB";
|
||||||
|
} else {
|
||||||
|
*out = 0.0f;
|
||||||
|
*str = "???";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void echo (struct context* context, char** strings, size_t strings_count) {
|
static void echo (struct context* context, char** strings, size_t strings_count) {
|
||||||
for (size_t i = 0; i < strings_count; i++)
|
for (size_t i = 0; i < strings_count; i++)
|
||||||
cprintf (context, "%s ", strings[i]);
|
cprintf (context, "%s ", strings[i]);
|
||||||
@@ -192,8 +213,16 @@ static void ls (struct context* context, const char* path_string) {
|
|||||||
read_dir_entry (path, &entry, entry_num);
|
read_dir_entry (path, &entry, entry_num);
|
||||||
describe (entry.path, &desc);
|
describe (entry.path, &desc);
|
||||||
|
|
||||||
cprintf (context, "%c %-40s %-40zu\n", (desc.type == FS_DIR ? 'D' : 'F'), entry.path,
|
char* hs_string;
|
||||||
desc.size);
|
double hs;
|
||||||
|
human_size ((double)desc.size, &hs, &hs_string);
|
||||||
|
|
||||||
|
char size_buf[64];
|
||||||
|
snprintf (size_buf, sizeof (size_buf), "%.2f %s", hs, hs_string);
|
||||||
|
|
||||||
|
char type = (desc.type == FS_DIR ? 'D' : 'F');
|
||||||
|
|
||||||
|
cprintf (context, "%c %-40s %-40s\n", type, entry.path, size_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
volume_close ();
|
volume_close ();
|
||||||
@@ -260,8 +289,8 @@ static void help (struct context* context) {
|
|||||||
cprintf (context, "quit\n");
|
cprintf (context, "quit\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_cancel_proc (void) {
|
static void cmd_cancel_proc (void* arg) {
|
||||||
int pid = *(int*)argument_ptr ();
|
int pid = *(int*)arg;
|
||||||
|
|
||||||
char ch = 0;
|
char ch = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -272,8 +301,6 @@ static void cmd_cancel_proc (void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kill (pid);
|
kill (pid);
|
||||||
|
|
||||||
quit ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
|
static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
|
||||||
@@ -313,11 +340,12 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cancel_pid = process_spawn (&cmd_cancel_proc, &pid);
|
struct process_data* cancel_pdata = process_spawn (&cmd_cancel_proc, &pid);
|
||||||
|
|
||||||
wait_for_pid (pid);
|
wait_for_pid (pid);
|
||||||
|
|
||||||
kill (cancel_pid);
|
if (kill (cancel_pdata->pid) < 0)
|
||||||
|
free (cancel_pdata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ cflags += -nostdinc \
|
|||||||
-Wextra
|
-Wextra
|
||||||
|
|
||||||
ifeq ($(buildtype),debug)
|
ifeq ($(buildtype),debug)
|
||||||
cflags += -O0 -g
|
cflags += -O0 -g3
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(buildtype),release)
|
ifeq ($(buildtype),release)
|
||||||
|
|||||||
@@ -10,7 +10,9 @@
|
|||||||
|
|
||||||
static int ce_pgid;
|
static int ce_pgid;
|
||||||
|
|
||||||
void receiver (void) {
|
void receiver (void* arg) {
|
||||||
|
(void)arg;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char recv[RECV_MAX];
|
char recv[RECV_MAX];
|
||||||
memset (recv, 0, sizeof (recv));
|
memset (recv, 0, sizeof (recv));
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ cflags += -DPRINTF_INCLUDE_CONFIG_H=1 \
|
|||||||
-DXXH_NAMESPACE=LZ4_
|
-DXXH_NAMESPACE=LZ4_
|
||||||
|
|
||||||
ifeq ($(buildtype),debug)
|
ifeq ($(buildtype),debug)
|
||||||
cflags += -O0 -g
|
cflags += -O0 -g3
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(buildtype),release)
|
ifeq ($(buildtype),release)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#define _KERNEL_LIBK_PRINTF_CONFIG_H
|
#define _KERNEL_LIBK_PRINTF_CONFIG_H
|
||||||
|
|
||||||
#define PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_HARD 1
|
#define PRINTF_ALIAS_STANDARD_FUNCTION_NAMES_HARD 1
|
||||||
#define PRINTF_SUPPORT_DECIMAL_SPECIFIERS 0
|
#define PRINTF_SUPPORT_DECIMAL_SPECIFIERS 1
|
||||||
#define PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS 0
|
#define PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS 1
|
||||||
|
|
||||||
#endif // _KERNEL_LIBK_PRINTF_CONFIG_H
|
#endif // _KERNEL_LIBK_PRINTF_CONFIG_H
|
||||||
|
|||||||
1
libprocess/amd64/.gitignore
vendored
Normal file
1
libprocess/amd64/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.o
|
||||||
7
libprocess/amd64/clone_tramp.S
Normal file
7
libprocess/amd64/clone_tramp.S
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
.global _clone_tramp
|
||||||
|
_clone_tramp:
|
||||||
|
xorq %rbp, %rbp
|
||||||
|
movq %rsp, %rbp
|
||||||
|
andq $-16, %rsp
|
||||||
|
|
||||||
|
callq _clone_tramp1
|
||||||
12
libprocess/amd64/clone_tramp1.c
Normal file
12
libprocess/amd64/clone_tramp1.c
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include <liballoc.h>
|
||||||
|
#include <process.h>
|
||||||
|
#include <system.h>
|
||||||
|
|
||||||
|
void _clone_tramp1 (void) {
|
||||||
|
struct process_data* pdata = argument_ptr ();
|
||||||
|
|
||||||
|
pdata->fn (pdata->arg_ptr);
|
||||||
|
|
||||||
|
free (pdata);
|
||||||
|
quit ();
|
||||||
|
}
|
||||||
6
libprocess/amd64/src.mk
Normal file
6
libprocess/amd64/src.mk
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
c += amd64/clone_tramp1.c
|
||||||
|
|
||||||
|
S += amd64/clone_tramp.S
|
||||||
|
|
||||||
|
o += amd64/clone_tramp.o \
|
||||||
|
amd64/clone_tramp1.o
|
||||||
@@ -7,11 +7,32 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <system.h>
|
#include <system.h>
|
||||||
|
|
||||||
int process_spawn (process_func_t func, void* argument_ptr) {
|
void _clone_tramp (void);
|
||||||
|
|
||||||
|
struct process_data* process_spawn (process_func_t func, void* argument_ptr) {
|
||||||
void* stack = malloc (STACK_SIZE);
|
void* stack = malloc (STACK_SIZE);
|
||||||
if (stack == NULL)
|
if (stack == NULL)
|
||||||
return -ST_OOM_ERROR;
|
return NULL;
|
||||||
|
|
||||||
|
struct process_data* pdata = malloc (sizeof (*pdata));
|
||||||
|
|
||||||
|
if (pdata == NULL) {
|
||||||
|
free (stack);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pdata->arg_ptr = argument_ptr;
|
||||||
|
pdata->fn = func;
|
||||||
|
|
||||||
uintptr_t top = (uintptr_t)stack + STACK_SIZE;
|
uintptr_t top = (uintptr_t)stack + STACK_SIZE;
|
||||||
return clone (top, func, argument_ptr);
|
int pid = clone (top, &_clone_tramp, (void*)pdata);
|
||||||
|
|
||||||
|
if (pid < 0) {
|
||||||
|
free (stack);
|
||||||
|
free (pdata);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pdata->pid = pid;
|
||||||
|
return pdata;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,15 @@
|
|||||||
#define STACK_SIZE (256 * PAGE_SIZE)
|
#define STACK_SIZE (256 * PAGE_SIZE)
|
||||||
|
|
||||||
/* Process entry function */
|
/* Process entry function */
|
||||||
typedef void (*process_func_t) (void);
|
typedef void (*process_func_t) (void*);
|
||||||
|
|
||||||
|
struct process_data {
|
||||||
|
void* arg_ptr;
|
||||||
|
process_func_t fn;
|
||||||
|
int pid;
|
||||||
|
};
|
||||||
|
|
||||||
/* Spawn a new process within the same procgroup with argument */
|
/* Spawn a new process within the same procgroup with argument */
|
||||||
int process_spawn (process_func_t func, void* argument_ptr);
|
struct process_data* process_spawn (process_func_t func, void* argument_ptr);
|
||||||
|
|
||||||
#endif // _LIBPROCESS_PROCESS_PROCESS_H
|
#endif // _LIBPROCESS_PROCESS_PROCESS_H
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
include $(platform)/src.mk
|
||||||
|
|
||||||
c += process.c
|
c += process.c
|
||||||
|
|
||||||
o += process.o
|
o += process.o
|
||||||
|
|||||||
@@ -3,6 +3,5 @@ _start:
|
|||||||
xorq %rbp, %rbp
|
xorq %rbp, %rbp
|
||||||
movq %rsp, %rbp
|
movq %rsp, %rbp
|
||||||
andq $-16, %rsp
|
andq $-16, %rsp
|
||||||
subq $8, %rsp
|
|
||||||
|
|
||||||
callq __premain
|
callq __premain
|
||||||
|
|||||||
Reference in New Issue
Block a user