diff --git a/README b/README index 7b37e03..1e56510 100644 --- a/README +++ b/README @@ -55,7 +55,7 @@ BUILD $ KOLIBRI=/path/to/kolibrios make -/path/to/kolibrios is where you checked out `svn co svn://kolibrios.org`. +/path/to/kolibrios is where you checked out 'svn co svn://kolibrios.org'. Architecture @@ -75,8 +75,29 @@ sudo cp --parents /sys/firmware/acpi/tables/?SDT* /sys/bus/pci/devices/*/config Troubleshooting --------------- -# sysctl -w kernel.yama.ptrace_scope=0 -# sysctl -w vm.mmap_min_addr=0 +# lfbviewx + +Allow reading process_vm_readv syscall. + + # sysctl -w kernel.yama.ptrace_scope=0 + +# umka_os + +Managing tap devices. + + # ip tuntap add dev tap0 mode tap + # ip link set tap0 address 00:11:00:00:00:00 + # ip addr add 10.50.0.1/24 dev tap0 + # ip link set up dev tap0 + # ip tuntap del dev tap0 mode tap + +To create tap devices. + + # setcap cap_net_admin+ep ../umka_os + +Not yet used, but may be one day. + + # sysctl -w vm.mmap_min_addr=0 Links & Acknowledgements diff --git a/linux/thread.c b/linux/thread.c index 58df339..ea7d59d 100644 --- a/linux/thread.c +++ b/linux/thread.c @@ -11,12 +11,6 @@ void reset_procmask(void) { sigprocmask(SIG_UNBLOCK, &mask, NULL); } -void set_procmask(void) { - sigemptyset (&mask); - sigaddset (&mask, SIGPROF); - sigprocmask(SIG_BLOCK, &mask, NULL); -} - int get_fake_if(ucontext_t *ctx) { // we fake IF with id flag return !(ctx->uc_mcontext.__gregs[REG_EFL] & (1 << 21)); diff --git a/shell.c b/shell.c index a809f92..7589f3f 100644 --- a/shell.c +++ b/shell.c @@ -1354,7 +1354,7 @@ void shell_pci_get_path(int argc, char **argv) { void shell_stack_init(int argc, char **argv) { (void)argc; (void)argv; - kos_stack_init(); + umka_stack_init(); } void shell_net_add_device(int argc, char **argv) { diff --git a/umka.asm b/umka.asm index 225040a..15731e2 100644 --- a/umka.asm +++ b/umka.asm @@ -28,7 +28,7 @@ public coverage_end public sha3_256_oneshot as 'hash_oneshot' public kos_time_to_epoch -public kos_init +public umka_init public CURRENT_TASK as 'kos_current_task' public current_slot as 'kos_current_slot' @@ -52,7 +52,7 @@ public acpi_ssdt_size as 'kos_acpi_ssdt_size' public acpi_ctx public acpi_usage as 'kos_acpi_usage' -public stack_init +public stack_init as 'kos_stack_init' public net_add_device public draw_data @@ -60,12 +60,12 @@ public img_background public mem_BACKGROUND public sys_background public REDRAW_BACKGROUND -public scheduler_add_thread -public new_sys_threads -public osloop +public new_sys_threads as 'kos_new_sys_threads' +public osloop as 'kos_osloop' public set_mouse_data as 'kos_set_mouse_data' public scheduler_current as 'kos_scheduler_current' public eth_input as 'kos_eth_input' +public net_buff_alloc as 'kos_net_buff_alloc' macro cli { pushfd @@ -288,7 +288,7 @@ proc kos_time_to_epoch c uses ebx esi edi ebp, _time ret endp -proc kos_init c uses ebx esi edi ebp +proc umka_init c uses ebx esi edi ebp mov edi, endofcode mov ecx, uglobals_size xor eax, eax @@ -539,36 +539,20 @@ proc delay_ms ret endp -;public inject_packet as 'kos_inject_packet' -public umka_inject_packet -proc umka_inject_packet c uses ebx esi edi, _data, _size, _dev - mov ebx, [_dev] - mov ecx, [_size] - push ecx - add ecx, NET_BUFF.data - stdcall net_buff_alloc, ecx ; Allocate a buffer to put packet into - pop ecx - test eax, eax ; Test if we allocated succesfully - jz .abort - mov [eax + NET_BUFF.length], ecx - mov [eax + NET_BUFF.device], ebx - mov [eax + NET_BUFF.offset], NET_BUFF.data +public umka_cli +proc umka_cli + cli ; macro + ret +endp - lea edi, [eax + NET_BUFF.data] ; Where we will copy too - mov esi, [_data] ; The buffer we will copy from - rep movsb - - push .abort - push eax ; buffer ptr for Eth_input - - jmp eth_input ; Send it to kernel -.abort: +public umka_sti +proc umka_sti + sti ; macro ret endp extrn reset_procmask extrn get_fake_if -extrn restart_timer public irq0 proc irq0 c, _signo, _info, _context DEBUGF 2, "### irq0\n" diff --git a/umka.h b/umka.h index dd4e698..a120f6d 100644 --- a/umka.h +++ b/umka.h @@ -346,10 +346,10 @@ typedef struct { uint16_t ttl; } arp_entry_t; -void osloop(void); +void kos_osloop(void); void irq0(int signo, siginfo_t *info, void *context); -void kos_init(void); +void umka_init(void); void i40(void); uint32_t kos_time_to_epoch(uint32_t *time); @@ -380,12 +380,12 @@ static inline void umka_mouse_move(int lbheld, int mbheld, int rbheld, kos_set_mouse_data(btn_state, xmoving, ymoving, vscroll, hscroll); } -void umka_inject_packet(void *data, size_t size, net_device_t *dev); +net_buff_t *kos_net_buff_alloc(size_t size) __attribute__((__stdcall__)); static inline void umka_new_sys_threads(uint32_t flags, void (*entry)(), void *stack) { __asm__ __inline__ __volatile__ ( "pushad;" - "call new_sys_threads;" + "call kos_new_sys_threads;" "popad" : : "b"(flags), @@ -426,10 +426,10 @@ typedef struct { uint32_t ebx; } f76ret_t; -static inline void kos_stack_init() { +static inline void umka_stack_init() { __asm__ __inline__ __volatile__ ( "pushad;" - "call stack_init;" + "call kos_stack_init;" "popad" : : @@ -447,6 +447,9 @@ static inline int32_t kos_net_add_device(net_device_t *dev) { return dev_num; } +void umka_cli(void); +void umka_sti(void); + extern uint8_t coverage_begin[]; extern uint8_t coverage_end[]; diff --git a/umka_fuse.c b/umka_fuse.c index 4091ecb..47e82bd 100644 --- a/umka_fuse.c +++ b/umka_fuse.c @@ -51,8 +51,8 @@ static void bdfe_to_stat(bdfe_t *kf, struct stat *st) { st->st_ctime = kos_time_to_epoch(&(kf->ctime)); } -static void *umka_init(struct fuse_conn_info *conn, - struct fuse_config *cfg) { +static void *umka_fuse_init(struct fuse_conn_info *conn, + struct fuse_config *cfg) { (void) conn; cfg->kernel_cache = 1; return NULL; @@ -131,7 +131,7 @@ static int umka_read(const char *path, char *buf, size_t size, off_t offset, } static struct fuse_operations umka_oper = { - .init = umka_init, + .init = umka_fuse_init, .getattr = umka_getattr, .readdir = umka_readdir, .open = umka_open, @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) { printf("usage: umka_fuse dir img\n"); exit(1); } - kos_init(); + umka_init(); void *userdata = vdisk_init(argv[2], 1, 0u); void *vdisk = disk_add(&vdisk_functions, "hd0", userdata, 0); disk_media_changed(vdisk, 1); diff --git a/umka_os.c b/umka_os.c index d5135e1..3b1225a 100644 --- a/umka_os.c +++ b/umka_os.c @@ -13,12 +13,7 @@ #define MONITOR_THREAD_STACK_SIZE 0x100000 void monitor() { - __asm__ __inline__ __volatile__ ( - "pushfd;" - "btr dword ptr[esp], 21;" - "popfd" - : : : "memory"); - + umka_sti(); fprintf(stderr, "Start monitor thread\n"); // mkfifo("/tmp/umka.fifo.2u", 0644); // mkfifo("/tmp/umka.fifo.4u", 0644); @@ -39,12 +34,7 @@ struct itimerval timeout = {.it_value = {.tv_sec = 0, .tv_usec = 10000}, .it_interval = {.tv_sec = 0, .tv_usec = 10000}}; int main() { - __asm__ __inline__ __volatile__ ( - "pushfd;" - "btr dword ptr[esp], 21;" - "popfd" - : : : "memory"); - + umka_sti(); umka_tool = UMKA_OS; struct sigaction sa; @@ -57,7 +47,6 @@ int main() { return 1; } - /* void *app_base = mmap((void*)0x000000, 16*0x100000, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (app_base == MAP_FAILED) { @@ -67,8 +56,8 @@ int main() { */ printf("pid=%d, kos_lfb_base=%p\n", getpid(), (void*)kos_lfb_base); - kos_init(); - kos_stack_init(); + umka_init(); + umka_stack_init(); uint8_t *monitor_stack = malloc(MONITOR_THREAD_STACK_SIZE); umka_new_sys_threads(0, monitor, monitor_stack + MONITOR_THREAD_STACK_SIZE); @@ -80,7 +69,7 @@ int main() { setitimer(ITIMER_PROF, &timeout, NULL); - osloop(); // doesn't return + kos_osloop(); // doesn't return return 0; } diff --git a/umka_ping.c b/umka_ping.c index 81c1bf1..caa96fe 100644 --- a/umka_ping.c +++ b/umka_ping.c @@ -83,12 +83,7 @@ int tapfd; _Atomic int go_ping = 0; int umka_thread_ping(void) { - __asm__ __inline__ __volatile__ ( - "pushfd;" - "btr dword ptr[esp], 21;" - "popfd" - : : : "memory"); - + umka_sti(); while (!go_ping) { /* wait until initialized */ } fprintf(stderr, "[ping] tapfd is %i\n", tapfd); @@ -135,26 +130,19 @@ int umka_thread_ping(void) { return 0; } -uint8_t buffer[2*1024]; -int plen = 0; - void umka_thread_net_drv(void) { - __asm__ __inline__ __volatile__ ( - "pushfd;" - "btr dword ptr[esp], 21;" - "popfd" - : : : "memory"); - + umka_sti(); fprintf(stderr, "[net_drv] starting\n"); + uint8_t buffer[2048]; + int plen = 0; char tapdev[IFNAMSIZ] = "tap0"; tapfd = tap_alloc(tapdev); net_device_t *vnet = vnet_init(tapfd); kos_net_add_device(vnet); - umka_sys_net_dev_reset(1); char devname[64]; for (size_t i = 0; i < umka_sys_net_get_dev_count(); i++) { -// umka_sys_net_dev_reset(i); + umka_sys_net_dev_reset(i); umka_sys_net_get_dev_name(i, devname); uint32_t devtype = umka_sys_net_get_dev_type(i); printf("[net_drv] device %i: %s %u\n", i, devname, devtype); @@ -197,7 +185,7 @@ void umka_thread_net_drv(void) { fprintf(stderr, " %2.2x", buffer[i]); } fprintf(stderr, "\n"); - umka_inject_packet(buffer, plen, vnet); + vnet_receive_frame(vnet, buffer, plen); } else if(plen == -1 && (errno == EAGAIN || errno == EINTR)) { continue; } else { diff --git a/umka_shell.c b/umka_shell.c index 391b52e..2a72ac9 100644 --- a/umka_shell.c +++ b/umka_shell.c @@ -77,7 +77,7 @@ int main(int argc, char **argv) { trace_begin(); COVERAGE_ON(); - kos_init(); + umka_init(); COVERAGE_OFF(); run_test(fin, fout, 1); diff --git a/vnet.c b/vnet.c index 1d8e967..7089aed 100644 --- a/vnet.c +++ b/vnet.c @@ -83,3 +83,25 @@ int vnet_transmit(net_buff_t *buf) { return 0; } +void vnet_receive_frame(net_device_t *dev, void *data, size_t size) { + net_buff_t *buf = kos_net_buff_alloc(size + offsetof(net_buff_t, data)); + if (!buf) { + fprintf(stderr, "[vnet] Can't allocate network buffer!\n"); + return; + } + buf->length = size; + buf->device = dev; + buf->offset = offsetof(net_buff_t, data); + memcpy(buf->data, data, size); + __asm__ __inline__ __volatile__ ( + "pushad;" + "lea ecx, 1f;" + "push ecx;" + "push eax;" + "jmp kos_eth_input;" + "1:" + "popad" + : + : "a"(buf) + : "memory", "ecx"); +} diff --git a/vnet.h b/vnet.h index ff51eff..43664ab 100644 --- a/vnet.h +++ b/vnet.h @@ -16,4 +16,6 @@ void vnet_reset(void); __attribute__((__stdcall__)) int vnet_transmit(net_buff_t *buf); +void vnet_receive_frame(net_device_t *dev, void *data, size_t size); + #endif // VNET_H_INCLUDED