diff --git a/.gitignore b/.gitignore index 6b8a9b5..36578e6 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ umka_shell umka_fuse umka_os +umka_monitor umka_ping umka_gen_devices_dat tools/mkdirrange diff --git a/README b/README index 06cd3c1..5425016 100644 --- a/README +++ b/README @@ -57,8 +57,6 @@ mkdirrange - make directories with names in range mkfilepattern - make a file with contents of specific pattern -lfbviewx - framebuffer viewer for X - BUILD ----- @@ -105,7 +103,7 @@ Testing Troubleshooting --------------- -# lfbviewx +# umka_monitor Allow reading process_vm_readv syscall. diff --git a/tools/lfbview.c b/tools/lfbview.c deleted file mode 100644 index 645c88b..0000000 --- a/tools/lfbview.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - SPDX-License-Identifier: GPL-2.0-or-later - - UMKa - User-Mode KolibriOS developer tools - lfbview - KolibriOS framebuffer viewer via SDL2 - - Copyright (C) 2023 Ivan Baravy -*/ - -#include -#include -#include -#include -#include -#include - -int -main(int argc, char *argv[]) { - const char *usage = "usage: lfbview
"; - if (argc != 5) { - puts(usage); - exit(1); - } - int depth = 32; - int umka_pid = strtol(argv[1], NULL, 0); - uintptr_t umka_lfb_addr = strtol(argv[2], NULL, 0); - size_t lfb_width = strtoul(argv[3], NULL, 0); - size_t lfb_height = strtoul(argv[4], NULL, 0); - - if(SDL_Init(SDL_INIT_VIDEO) < 0) - { - fprintf(stderr, "Failed to initialize the SDL2 library\n"); - return -1; - } - - SDL_Window *window = SDL_CreateWindow("LFB Viewer SDL2", - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - 400, 300, - 0); - - if(!window) - { - fprintf(stderr, "Failed to create window\n"); - return -1; - } - - SDL_Surface *window_surface = SDL_GetWindowSurface(window); - - if(!window_surface) - { - fprintf(stderr, "Failed to get the surface from the window\n"); - return -1; - } - - uint32_t *lfb = (uint32_t*)malloc(lfb_width*lfb_height*sizeof(uint32_t)); - - struct iovec remote = {.iov_base = (void*)umka_lfb_addr, - .iov_len = lfb_width*lfb_height*4}; - struct iovec local = {.iov_base = lfb, - .iov_len = lfb_width*lfb_height*4}; - - - uint32_t *p = window_surface->pixels; - while (1) { - process_vm_readv(umka_pid, &local, 1, &remote, 1, 0); - memcpy(window_surface->pixels, lfb, 400*300*4); - SDL_LockSurface(window_surface); - for (size_t y = 0; y < window_surface->h; y++) { - for (size_t x = 0; x < window_surface->w; x++) { - p[y*window_surface->pitch/4+x] = lfb[y*400+x]; - } - } - SDL_UnlockSurface(window_surface); - SDL_UpdateWindowSurface(window); - sleep(1); - } - - return 0; -} diff --git a/tools/lfbviewx.c b/tools/lfbviewx.c deleted file mode 100644 index b4d2dcd..0000000 --- a/tools/lfbviewx.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - SPDX-License-Identifier: GPL-2.0-or-later - - UMKa - User-Mode KolibriOS developer tools - lfbviewx - framebuffer viewer for X - - Copyright (C) 2020 Ivan Baravy -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char *argv[]) { - if (argc != 5) { - printf("usage: lfbviewx
\n"); - exit(1); - } - int depth = 32; - int umka_pid = strtol(argv[1], NULL, 0); - uintptr_t umka_lfb_addr = strtol(argv[2], NULL, 0); - size_t lfb_width = strtoul(argv[3], NULL, 0); - size_t lfb_height = strtoul(argv[4], NULL, 0); - - Display *display = XOpenDisplay(NULL); - int screen_num = XDefaultScreen(display); - Window root = XDefaultRootWindow(display); - - XVisualInfo vis_info; - if(!XMatchVisualInfo(display, screen_num, depth, TrueColor, &vis_info)) { - fprintf(stderr, "ERR: %d-bit depth is not supported\n", depth); - exit(1); - } - - Visual *visual = vis_info.visual; - XSetWindowAttributes win_attr = { - .colormap = XCreateColormap(display, root, visual, AllocNone), - .background_pixel = 0, - .border_pixel = 0}; - unsigned long win_mask = CWBackPixel | CWColormap | CWBorderPixel; - Window window = XCreateWindow(display, root, 0, 0, lfb_width, lfb_height, 0, depth, InputOutput, visual, win_mask, &win_attr); - GC gc = XCreateGC(display, window, 0, 0); - - uint32_t *lfb = (uint32_t*)malloc(lfb_width*lfb_height*sizeof(uint32_t)); - XImage *image = XCreateImage(display, visual, depth, ZPixmap, 0, (char*)lfb, lfb_width, lfb_height, 32, 0); - - XSelectInput(display, window, ExposureMask | KeyPressMask); - XStoreName(display, window, "KolibriOS LFB Viewer for X"); - XMapWindow(display, window); - - - struct iovec remote = {.iov_base = (void*)umka_lfb_addr, - .iov_len = lfb_width*lfb_height*4}; - struct iovec local = {.iov_base = lfb, - .iov_len = lfb_width*lfb_height*4}; -/* - XEvent event; - while (true) { - XNextEvent(display, &event); - if (event.type == Expose) { - process_vm_readv(umka_pid, &local, 1, &remote, 1, 0); - XPutImage(display, window, gc, image, 0, 0, 0, 0, lfb_width, lfb_height); - } else if (event.type == KeyPress) { - int keysym = XkbKeycodeToKeysym(display, event. xkey.keycode, 0, 0); - - if (keysym == XK_Escape) break; - switch (keysym) { - case XK_Left: {break;} - } - } - } -*/ - XEvent event; - while (true) { - while (XCheckMaskEvent(display, (long)-1, &event)) { /* skip */ } - process_vm_readv(umka_pid, &local, 1, &remote, 1, 0); - XPutImage(display, window, gc, image, 0, 0, 0, 0, lfb_width, lfb_height); - sleep(1); - } - - XCloseDisplay(display); - return 0; -} diff --git a/tools/makefile b/tools/makefile index b0bcf50..e6abf84 100644 --- a/tools/makefile +++ b/tools/makefile @@ -7,8 +7,8 @@ CFLAGS=$(WARNINGS) $(NOWARNINGS) -std=c11 -O2 \ -DNDEBUG -D_POSIX_C_SOURCE=200809L -fno-pie LDFLAGS=-no-pie -all: mkdirrange mkfilepattern lfbviewx randdir covpreproc mkdoubledirs \ - gensamehash mksamehash lfbview +all: mkdirrange mkfilepattern randdir covpreproc mkdoubledirs gensamehash \ + mksamehash gensamehash: gensamehash.c $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ @@ -25,11 +25,6 @@ mkdirrange: mkdirrange.c mkfilepattern: mkfilepattern.c $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ -lfbviewx: lfbviewx.c - $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ -lX11 -lXext -D_GNU_SOURCE - -lfbview: lfbview.c - $(CC) `sdl2-config --cflags --libs` -o $@ $< -D_GNU_SOURCE randdir: randdir.c $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ @@ -39,5 +34,5 @@ covpreproc: covpreproc.c .PHONY: all clean clean: - rm -f *.o mkdirrange mkfilepattern lfbviewx randdir covpreproc \ - mkdoubledirs gensamehash mksamehash lfbview + rm -f *.o mkdirrange mkfilepattern randdir covpreproc mkdoubledirs \ + gensamehash mksamehash diff --git a/umka_monitor.c b/umka_monitor.c new file mode 100644 index 0000000..6c8c720 --- /dev/null +++ b/umka_monitor.c @@ -0,0 +1,156 @@ +/* + SPDX-License-Identifier: GPL-2.0-or-later + + UMKa - User-Mode KolibriOS developer tools + umka_monitor - a program to monitor and control umka_os + + Copyright (C) 2023 Ivan Baravy +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "umka_os.h" +#include "bestline.h" +#include "optparse.h" + +struct shared_info sinfo; + +int +sdlthr(void *arg) { + (void)arg; + if(SDL_Init(SDL_INIT_VIDEO) < 0) + { + fprintf(stderr, "Failed to initialize the SDL2 library\n"); + return -1; + } + + SDL_Window *window = SDL_CreateWindow("LFB Viewer SDL2", + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + sinfo.lfb_width, sinfo.lfb_height, + 0); + + if(!window) + { + fprintf(stderr, "Failed to create window\n"); + return -1; + } + + SDL_Surface *window_surface = SDL_GetWindowSurface(window); + + if(!window_surface) + { + fprintf(stderr, "Failed to get the surface from the window\n"); + return -1; + } + + uint32_t *lfb = (uint32_t*)malloc(sinfo.lfb_width*sinfo.lfb_height*sizeof(uint32_t)); + + struct iovec remote = {.iov_base = (void*)(uintptr_t)sinfo.lfb_base, + .iov_len = sinfo.lfb_width*sinfo.lfb_height*4}; + struct iovec local = {.iov_base = lfb, + .iov_len = sinfo.lfb_width*sinfo.lfb_height*4}; + + + uint32_t *p = window_surface->pixels; + while (1) { + process_vm_readv(sinfo.pid, &local, 1, &remote, 1, 0); + memcpy(window_surface->pixels, lfb, 400*300*4); + SDL_LockSurface(window_surface); + for (ssize_t y = 0; y < window_surface->h; y++) { + for (ssize_t x = 0; x < window_surface->w; x++) { + p[y*window_surface->pitch/4+x] = lfb[y*400+x]; + } + } + SDL_UnlockSurface(window_surface); + SDL_UpdateWindowSurface(window); + sleep(1); + } + + + return 0; +} + +int +main(int argc, char *argv[]) { + (void)argc; + const char *usage = "umka_monitor [-i ] [-o ] [-s ]\n"; + const char *shname = "/umka"; + int shfd = 0; + const char *infile = NULL, *outfile = NULL; + + struct optparse options; + int opt; + optparse_init(&options, argv); + + while ((opt = optparse(&options, "i:o:s:")) != -1) { + switch (opt) { + case 'i': + infile = options.optarg; + break; + case 'o': + outfile = options.optarg; + break; + case 's': + shname = options.optarg; + break; + default: + fprintf(stderr, "bad option: %c\n", opt); + fputs(usage, stderr); + exit(1); + } + } + + if (infile && !freopen(infile, "r", stdin)) { + fprintf(stderr, "[!] can't open file for reading: %s\n", infile); + exit(1); + } + if (outfile && !freopen(outfile, "w", stdout)) { + fprintf(stderr, "[!] can't open file for writing: %s\n", outfile); + exit(1); + } + + if (shname) { + shfd = shm_open(shname, O_RDONLY, S_IRUSR | S_IWUSR); + if (!shfd) { + perror("[!] can't open shared memory"); + exit(1); + } + } + ssize_t nread = read(shfd, &sinfo, sizeof(sinfo)); + if (nread != sizeof(sinfo)) { + perror("can't read from shared memory"); + exit(1); + } + printf("read umka_os configuration:\n" + " pid: %d\n" + " lfb_base: %p\n" + " lfb_bpp: %u" + " lfb_width: %u" + " lfb_height: %u" + " cmd: %p\n", + (pid_t)sinfo.pid, (void*)(uintptr_t)sinfo.lfb_base, sinfo.lfb_bpp, + sinfo.lfb_width, sinfo.lfb_height, (void*)(uintptr_t)sinfo.cmd_buf); + shm_unlink(shname); + + union sigval sval = (union sigval){.sival_int = 14}; + + thrd_t st; + thrd_create(&st, sdlthr, NULL); + + while (1) { + getchar(); + sigqueue(sinfo.pid, SIGUSR2, sval); + } + + return 0; +} diff --git a/umka_os.h b/umka_os.h new file mode 100644 index 0000000..39373af --- /dev/null +++ b/umka_os.h @@ -0,0 +1,24 @@ +/* + SPDX-License-Identifier: GPL-2.0-or-later + + UMKa - User-Mode KolibriOS developer tools + umka_os - kind of KolibriOS anykernel + + Copyright (C) 2023 Ivan Baravy +*/ + +struct shared_info { + uint64_t pid; + uint32_t lfb_base; + uint32_t lfb_bpp; + uint32_t lfb_width; + uint32_t lfb_height; + uint32_t cmd_buf; + uint32_t pad; +}; + +#define CMD_BUF_LEN 0x10000 + +uint8_t cmd_buf[CMD_BUF_LEN]; + +