static int GGIopen(ggi_visual * vis, struct ggi_dlhandle *dlh, const char *args, void *argptr, uint32_t * dlret) { int err = GGI_OK; directx_priv *priv; GGIGII ggigii; gg_option options[NUM_OPTS]; DPRINT("DirectX-target starting\n"); memcpy(options, optlist, sizeof(options)); priv = malloc(sizeof(directx_priv)); if (priv == NULL) { err = GGI_ENOMEM; goto err0; } if ((LIBGGI_GC(vis) = malloc(sizeof(ggi_gc))) == NULL) { err = GGI_ENOMEM; goto err1; } memset(priv, 0, sizeof(directx_priv)); LIBGGI_PRIVATE(vis) = priv; priv->cs = GGI_directx_LockCreate(); if (priv->cs == NULL) { err = GGI_ENOMEM; goto err2; } priv->spincs = GGI_directx_LockCreate(); if (priv->spincs == NULL) { err = GGI_ENOMEM; goto err3; } priv->redraw = 1; priv->setpalette = 1; priv->sizingcs = GGI_directx_LockCreate(); if (priv->sizingcs == NULL) { err = GGI_ENOMEM; goto err4; } priv->xmin = 0; priv->ymin = 0; priv->xmax = 0; priv->ymax = 0; priv->xstep = -1; priv->ystep = -1; if (args) { args = ggParseOptions(args, options, NUM_OPTS); if (args == NULL) { fprintf(stderr, "display-directx: error in " "arguments.\n"); } } if (_ggi_physz_parse_option(options[OPT_PHYSZ].result, &(priv->physzflags), &(priv->physz))) { err = GGI_EARGINVAL; goto err5; } if (options[OPT_KEEPCURSOR].result[0] == 'n') { priv->cursortype = (options[OPT_NOCURSOR].result[0] == 'n') ? 1 : 0; } else { priv->cursortype = 2; } if (options[OPT_INWIN].result[0] != 'n') { if (strcmp(options[OPT_INWIN].result, "root")) { priv->hParent = (HANDLE) strtoul(options[OPT_INWIN].result, NULL, 0); if (!IsWindow(priv->hParent)) { fprintf(stderr, "0x%08x " "is not a valid window handle.\n", (unsigned) priv->hParent); priv->hParent = NULL; } } else priv->hParent = GetDesktopWindow(); } if (options[OPT_FULLSCREEN].result[0] == 'n') { priv->fullscreen = 0; } else { priv->fullscreen = 1; } if (!DDInit(vis)) { err = GGI_ENODEVICE; goto err3; } ggigii.hWnd = priv->hWnd; ggigii.hInstance = priv->hInstance; if (tolower((uint8_t) options[OPT_NOINPUT].result[0]) == 'n' && /* FIXME: dxinput doesn't work with -inwin yet; the following condition disables the default input target if -inwin has been specified */ (!priv->hParent || getenv("GGI_INPUT") || getenv("GGI_INPUT_directx"))) { gii_input *inp; inp = giiOpen("directx", &ggigii, NULL); if (inp == NULL) { DPRINT_MISC("Unable to open directx inputlib\n"); GGIclose(vis, dlh); err = GGI_ENODEVICE; goto err3; } priv->inp = inp; /* Now join the new event source in. */ vis->input = giiJoinInputs(vis->input, inp); } else { priv->inp = NULL; } vis->opdisplay->setmode = GGI_directx_setmode; vis->opdisplay->getmode = GGI_directx_getmode; vis->opdisplay->setflags = GGI_directx_setflags; vis->opdisplay->checkmode = GGI_directx_checkmode; vis->opdisplay->flush = GGI_directx_flush; vis->opdisplay->getapi = GGI_directx_getapi; *dlret = GGI_DL_OPDISPLAY | GGI_DL_OPDRAW; return GGI_OK; err5: GGI_directx_LockDestroy(priv->cs); err4: GGI_directx_LockDestroy(priv->spincs); err3: GGI_directx_LockDestroy(priv->sizingcs); err2: free(LIBGGI_GC(vis)); err1: free(priv); err0: return err; }
static int GGIopen(struct ggi_visual *vis, struct ggi_dlhandle *dlh, const char *args, void *argptr, uint32_t_t_t *dlret) { ggi_mode mode; void *memptr=NULL; suid_hook *priv; int x, err = GGI_ENOMEM; LIBGGI_GC(vis) = malloc(sizeof(ggi_gc)); if (LIBGGI_GC(vis) == NULL) { return GGI_ENOMEM; } priv = LIBGGI_PRIVATE(vis) = malloc(sizeof(suid_hook)); if (priv == NULL) { goto out_freegc; } priv->is_up=0; priv->dev_mem=_suidtarget_dev_mem=-1; priv->mmap_length=0; /* Open GII for input */ vis->input = giiOpen("input-linux-kbd", NULL); if (vis->input == NULL) { fprintf(stderr, "display-suidkgi: Couldn't open kbd.\n"); goto out_freepriv; } /* Has mode management */ vis->opdisplay->getmode=GGI_suidkgi_getmode; vis->opdisplay->setmode=GGI_suidkgi_setmode; vis->opdisplay->checkmode=GGI_suidkgi_checkmode; vis->opdisplay->flush=GGI_suidkgi_flush; vis->opdisplay->kgicommand=GGI_suidkgi_kgicommand; vis->opdisplay->setflags=GGI_suidkgi_setflags; vis->opdraw->setorigin=GGI_suidkgi_setorigin; vis->w_frame = malloc(sizeof(ggi_directbuffer)); /* FIXME ! */ vis->r_frame = malloc(sizeof(ggi_directbuffer)); /* FIXME ! */ LIBGGI_CURWRITE(vis)=NULL; LIBGGI_CURREAD(vis)=NULL; if (iopl(3)) {perror("iopl");exit(2); } DPRINT("IOPL is here.\n"); if (-1 == (priv->dev_mem = _suidtarget_dev_mem = open("/dev/mem",O_RDWR))) { perror("opening /dev/mem");exit(3); } memptr=mmap(NULL,64*1024,PROT_READ|PROT_WRITE,MAP_SHARED,priv->dev_mem,0xa0000); DPRINT("Have mmap at %p.\n",memptr); /* law_base=0xf3000000; */ if (suidkgi_init_module()) {DPRINT("Init has failed. Tough luck.\n");exit(1); } DPRINT("Init was o.k.\n"); signal(SIGSEGV,get_killed); signal(SIGINT,get_killed); signal(SIGTERM,get_killed); priv->is_up=1; #if 1 /* Not sure, if this is needed, but ... */ mode.frames=1; mode.graphtype=GT_TEXT16; mode.visible.x=mode.virt.x=80; mode.visible.y=mode.virt.y=25; mode.dpp.x = 8;mode.dpp.y =16; x=GGI_suidkgi_checkmode(vis,&mode); DPRINT("TESTMODE1 says %d.\n",x); x=GGI_suidkgi_setmode(vis,&mode); DPRINT("SETMODE1 says %d.\n",x); #endif #undef TESTING_THE_SUID_TARGET #ifdef TESTING_THE_SUID_TARGET #ifdef GoneByeBye for(x=0;x<480;x++) { GGI_suidkgi_setsplitline(vis, x); ggUSleep(100000); } #endif mode.frames=1; mode.graphtype=GT_8BIT; mode.visible.x=mode.virt.x=320; mode.visible.y=mode.virt.y=200; mode.dpp.x =mode.dpp.y =1; x=ggiCheckMode(vis,&mode); DPRINT("TESTMODE3 says %d.\n",x); x=ggiSetMode(vis,&mode); DPRINT("SETMODE3 says %d.\n",x); sleep(1); { int y; for(y=0;y<200;y++) { for(x=0;x<320;x++) { *((unsigned char *)memptr+x+y*320)=x+y; } ggUSleep(1); } } sleep(1); mode.frames=1; mode.graphtype=GT_TEXT16; mode.visible.x=mode.virt.x=80; mode.visible.y=mode.virt.y=25; mode.dpp.x = 8;mode.dpp.y =16; x=GGI_suidkgi_checkmode(vis,&mode); DPRINT("TESTMODE4 says %d.\n",x); x=GGI_suidkgi_setmode(vis,&mode); DPRINT("SETMODE4 says %d.\n",x); sleep(1); suidkgi_cleanup_module(); DPRINT("Cleanup went well.\n"); close(priv->dev_mem); exit(1); #endif *dlret = GGI_DL_OPDISPLAY|GGI_DL_OPDRAW; return 0; out_freepriv: free(priv); out_freegc: free(LIBGGI_GC(vis); return err; }