static int pdt_close_out(void *handle) { Sclose_function cf = free_console(NULL, handle); if ( cf ) return (*cf)(handle); return -1; }
/* a process has been killed (i.e. its last thread died) */ static void process_killed(struct w32process *process) { struct list_head *ptr; ktrace("process %p\n", process); if (!process->is_system) close_process_desktop(process); /* close the console attached to this process, if any */ free_console(process); while ((ptr = list_head(&process->dlls))) { struct process_dll *dll = LIST_ENTRY(ptr, struct process_dll, entry); if (dll->file) release_object(dll->file); free(dll->filename); list_remove(&dll->entry); free(dll); } destroy_process_classes(process); remove_process_locks(process); set_process_startup_state(process, STARTUP_ABORTED); }
void main() { char s[200],cdir[200]="/",tmp[200]; int a,b,ID=alloc_console(); FILE *fp; meminit(); fileinit(); printf("ChaOS shell ID=%x\n",ID); do { printf(">"); gets(s); if (!strcmp(s,"exit")) break; if (s[0]=='t'&&s[1]=='y'&&s[2]=='p'&&s[3]=='e'&&s[4]==' '){ fp=fopen(s+5,"rb"); while((a=fread(tmp,1,199,fp))) for (b=0;b<a;b++) putch(tmp[b]); fclose(fp); continue; } if (!strcmp(s,"dir")){ showdir(cdir);continue; } if (!strcmp(s,"cls")){ clrscr(); continue; } if (s[0]=='c'&&s[1]=='d'&&s[2]==' '){ if (s[3]=='.'&&s[4]=='.'&&s[5]==0){ if (strlen(cdir)<=1) continue; b=strlen(cdir);b--; cdir[b]=0; for(b--;b>=0;b--) if (cdir[b]=='/'){ cdir[b+1]=0;break;} continue; } if (s[3]=='/') strcpy(tmp,s+3); else { strcpy(tmp,cdir);strcat(tmp,s+3);} if (tmp[strlen(tmp)-1]!='/') strcat(tmp,"/"); if (strlen(tmp)>1){ tmp[strlen(tmp)-1]=0; if (findfirst(tmp,&sr,_FF_NORMAL)==0){ strcpy(cdir,tmp);strcat(cdir,"/"); } else printf("not found: %s\n",tmp); } else strcpy(cdir,tmp); continue; } if (!strcmp(s,"mem")){ printf("free = %i\n",get_free_mem()<<12); continue; } // Execute if (s[0]==0) continue; if (s[0]!='/'){ strcpy(tmp,cdir);strcat(tmp,s);strcpy(s,tmp); } if ((a=system(s))!=0) printf("not found: %s (%x)\n",s,a); } while(1); free_console(ID); }
static void fb_wait(GP_Backend *self) { struct fb_priv *fb = GP_BACKEND_PRIV(self); struct pollfd fd = {.fd = fb->con_fd, .events = POLLIN, .revents = 0}; if (poll(&fd, 1, -1) > 0) fb_poll(self); else GP_WARN("poll(): %s", strerror(errno)); } static void fb_exit(GP_Backend *self) { struct fb_priv *fb = GP_BACKEND_PRIV(self); if (fb->flags & GP_FB_SHADOW) free(fb->context.pixels); /* unmap framebuffer */ munmap(fb->fb_mem, fb->bsize); close(fb->fb_fd); if (fb->flags & GP_FB_INPUT_KBD) exit_kbd(fb); free_console(fb); free(self); } static void fb_flip_shadow(GP_Backend *self) { struct fb_priv *fb = GP_BACKEND_PRIV(self); GP_DEBUG(2, "Flipping buffer"); memcpy(fb->fb_mem, fb->context.pixels, fb->bsize); } static void fb_update_rect_shadow(GP_Backend *self, GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1) { struct fb_priv *fb = GP_BACKEND_PRIV(self); GP_DEBUG(2, "Flipping buffer"); size_t size = ((x1 - x0) * fb->context.bpp) / 8; for (;y0 <= y1; y0++) { void *src = GP_PIXEL_ADDR(&fb->context, x0, y0); void *dst = (char*)fb->fb_mem + y0 * fb->context.bytes_per_row + (x0 * fb->context.bpp)/8; memcpy(dst, src, size); } } GP_Backend *GP_BackendLinuxFBInit(const char *path, int flags) { GP_Backend *backend; struct fb_priv *fb; struct fb_fix_screeninfo fscri; struct fb_var_screeninfo vscri; int fd; backend = malloc(sizeof(GP_Backend) + sizeof(struct fb_priv) + strlen(path) + 1); if (backend == NULL) return NULL; fb = GP_BACKEND_PRIV(backend); if (allocate_console(fb, flags)) goto err0; if (flags & GP_FB_INPUT_KBD) { if (init_kbd(fb)) goto err1; } /* open and mmap framebuffer */ GP_DEBUG(1, "Opening framebuffer '%s'", path); fd = open(path, O_RDWR); if (fd < 0) { GP_DEBUG(1, "Opening framebuffer failed: %s", strerror(errno)); goto err2; } if (ioctl(fd, FBIOGET_FSCREENINFO, &fscri) < 0) { GP_DEBUG(1, "Failed to ioctl FBIOGET_FSCREENINFO: %s", strerror(errno)); goto err3; } if (ioctl(fd, FBIOGET_VSCREENINFO, &vscri) < 0) { GP_DEBUG(1, "Failed to ioctl FBIOGET_VSCREENINFO: %s", strerror(errno)); goto err3; } GP_DEBUG(1, "Have framebufer %ix%i %s %ibpp", vscri.xres, vscri.yres, vscri.grayscale ? "Gray" : "RGB", vscri.bits_per_pixel); /* * Framebuffer is grayscale. */ if (vscri.grayscale) { GP_WARN("Grayscale not implemented!"); goto err3; } enum GP_PixelType pixel_type; pixel_type = GP_PixelRGBLookup(vscri.red.length, vscri.red.offset, vscri.green.length, vscri.green.offset, vscri.blue.length, vscri.blue.offset, vscri.transp.length, vscri.transp.offset, vscri.bits_per_pixel); if (pixel_type == GP_PIXEL_UNKNOWN) { GP_DEBUG(1, "Unknown pixel type\n"); goto err3; } if (flags & GP_FB_SHADOW) { fb->context.pixels = malloc(fscri.smem_len); if (!fb->context.pixels) { GP_DEBUG(1, "Malloc failed :("); goto err3; } } fb->fb_mem = mmap(NULL, fscri.smem_len, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0); if (fb->fb_mem == MAP_FAILED) { GP_DEBUG(1, "mmaping framebuffer failed: %s", strerror(errno)); goto err4; } fb->fb_fd = fd; fb->bsize = fscri.smem_len; strcpy(fb->path, path); fb->flags = flags; if (!(flags & GP_FB_SHADOW)) fb->context.pixels = fb->fb_mem; fb->context.w = vscri.xres; fb->context.h = vscri.yres; fb->context.axes_swap = 0; fb->context.x_swap = 0; fb->context.y_swap = 0; fb->context.bpp = vscri.bits_per_pixel; fb->context.bytes_per_row = fscri.line_length; fb->context.pixel_type = pixel_type; int shadow = flags & GP_FB_SHADOW; int kbd = flags & GP_FB_INPUT_KBD; /* update API */ backend->name = "Linux FB"; backend->context = &fb->context; backend->Flip = shadow ? fb_flip_shadow : NULL; backend->UpdateRect = shadow ? fb_update_rect_shadow : NULL; backend->Exit = fb_exit; backend->SetAttributes = NULL; backend->ResizeAck = NULL; backend->Poll = kbd ? fb_poll : NULL; backend->Wait = kbd ? fb_wait : NULL; backend->fd = fb->con_fd; backend->timers = NULL; GP_EventQueueInit(&backend->event_queue, vscri.xres, vscri.yres, 0); return backend; err4: if (flags & GP_FB_SHADOW) free(fb->context.pixels); err3: close(fd); err2: if (flags & GP_FB_INPUT_KBD) exit_kbd(fb); err1: free_console(fb); err0: free(backend); return NULL; }