Beispiel #1
0
int init(int w, int h) {
    int ret = setup_shm(w, h);
	if (ret != 0) {
		return ret;
	}
	setup_texture(w, h);
	setup_viewport(w, h);

    // Set the clear color to black
    glClearColor(0.0f, 0.0f, 0.0f, 1);

    // Create the shaders
    int vertex_shader = load_shader(GL_VERTEX_SHADER, vs_image);
    int fragment_shader = load_shader(GL_FRAGMENT_SHADER, fs_image);

    sp_image = glCreateProgram();              // create empty OpenGL ES Program
    glAttachShader(sp_image, vertex_shader);   // add the vertex shader to program
    glAttachShader(sp_image, fragment_shader); // add the fragment shader to program
    glLinkProgram(sp_image);                   // creates OpenGL ES program executables

    // Set our shader program
    glUseProgram(sp_image);

	width = w;
	height = h;

	return 0; // do we need more error handling code??
}
Beispiel #2
0
int main(int argc, char *argv[]) {
	int retcode;
	LOG_TRACE(LOG_INFORMATIONAL, "\nServer started. Is now initializing the setup...\n");

	signal(SIGINT, my_handler);

	LOG_TRACE(LOG_INFORMATIONAL, "Setting up the valid arguments...");
	setValidServerArguments(); //setting up all valid arguments
	LOG_TRACE(LOG_INFORMATIONAL, "... Done\n");

	retcode = setup_shm();
	handle_error(retcode, "Shared Memory could not be created.\n", PROCESS_EXIT);

	char *shm_start = shmat(shm_id, NULL, 0);
	LOG_TRACE(LOG_INFORMATIONAL, "... Done\n");

	/* init shared memory control*/
	retcode = initshm(shm_start);
	handle_error(retcode, "Could not create Shared Memory Control Set...\n", PROCESS_EXIT);

	/* init struct for PThread handling Clients */
	myPThreadStruct = (struct pthread_struct *) malloc(sizeof(struct pthread_struct));
	myPThreadStruct->isLast = 1;
	myPThreadStruct->nextClient = myPThreadStruct;

	/* if no arguments is chosen, output the usage of the Server */
	if (argc == 1) {
		usage();
		exit(1);
	}
	/* if arguments are chosen, validate the arguments */
	else {
		printf("Verify valid arguments ...\n");
		initValidServerArguments(argc, argv);
	}
	/* if no port for the server was chosen, set it to default port = 7000 */
	if (validArguments[1].isSet == 0) {
		printf("There was no argument for the Server-Port. It will no be set to default = 7000\n");
		ServerPort = 7000;
		validArguments[1].isSet = 1;
	}

	retcode = setTCPServer();
	handle_error(retcode, "TCP Server settings could not be established!\n", PROCESS_EXIT);
	ServerListen();

	/* clean up shared memory */
	cleanup(shm_id);
}
int main(int argc, char **argv)
{
	struct test test;
	unsigned op, src, mask;

	test_init(&test, argc, argv);

	setup_shm(&test);

	for (op = 0; op < sizeof(ops)/sizeof(ops[0]); op++) {
		for (src = 0; src < sizeof(source)/sizeof(source[0]); src++)
			bench_source(&test, ROOT, op, src);
		fprintf (stdout, "\n");

		for (src = 0; src < sizeof(source)/sizeof(source[0]); src++)
			for (mask = 0; mask < sizeof(source)/sizeof(source[0]); mask++)
				bench_mask(&test, ROOT, op, src, mask);
		fprintf (stdout, "\n");
	}

	return 0;
}
Beispiel #4
0
int main(int argc, char** argv) {

  s32 opt;
  u8  mem_limit_given = 0, timeout_given = 0, qemu_mode = 0;
  u32 tcnt;
  char** use_argv;

  doc_path = access(DOC_PATH, F_OK) ? "docs" : DOC_PATH;

  while ((opt = getopt(argc,argv,"+o:m:t:A:eqZQ")) > 0)

    switch (opt) {

      case 'o':

        if (out_file) FATAL("Multiple -o options not supported");
        out_file = optarg;
        break;

      case 'm': {

          u8 suffix = 'M';

          if (mem_limit_given) FATAL("Multiple -m options not supported");
          mem_limit_given = 1;

          if (!strcmp(optarg, "none")) {

            mem_limit = 0;
            break;

          }

          if (sscanf(optarg, "%llu%c", &mem_limit, &suffix) < 1 ||
              optarg[0] == '-') FATAL("Bad syntax used for -m");

          switch (suffix) {

            case 'T': mem_limit *= 1024 * 1024; break;
            case 'G': mem_limit *= 1024; break;
            case 'k': mem_limit /= 1024; break;
            case 'M': break;

            default:  FATAL("Unsupported suffix or bad syntax for -m");

          }

          if (mem_limit < 5) FATAL("Dangerously low value of -m");

          if (sizeof(rlim_t) == 4 && mem_limit > 2000)
            FATAL("Value of -m out of range on 32-bit systems");

        }

        break;

      case 't':

        if (timeout_given) FATAL("Multiple -t options not supported");
        timeout_given = 1;

        if (strcmp(optarg, "none")) {
          exec_tmout = atoi(optarg);

          if (exec_tmout < 20 || optarg[0] == '-')
            FATAL("Dangerously low value of -t");

        }

        break;

      case 'e':

        if (edges_only) FATAL("Multiple -e options not supported");
        edges_only = 1;
        break;

      case 'q':

        if (quiet_mode) FATAL("Multiple -q options not supported");
        quiet_mode = 1;
        break;

      case 'Z':

        /* This is an undocumented option to write data in the syntax expected
           by afl-cmin. Nobody else should have any use for this. */

        cmin_mode  = 1;
        quiet_mode = 1;
        break;

      case 'A':

        /* Another afl-cmin specific feature. */
        at_file = optarg;
        break;

      case 'Q':

        if (qemu_mode) FATAL("Multiple -Q options not supported");
        if (!mem_limit_given) mem_limit = MEM_LIMIT_QEMU;

        qemu_mode = 1;
        break;

      default:

        usage(argv[0]);

    }

  if (optind == argc || !out_file) usage(argv[0]);

  setup_shm();
  setup_signal_handlers();

  set_up_environment();

  find_binary(argv[optind]);

  if (!quiet_mode) {
    show_banner();
    ACTF("Executing '%s'...\n", target_path);
  }

  detect_file_args(argv + optind);

  if (qemu_mode)
    use_argv = get_qemu_argv(argv[0], argv + optind, argc - optind);
  else
    use_argv = argv + optind;

  run_target(use_argv);

  tcnt = write_results();

  if (!quiet_mode) {

    if (!tcnt) FATAL("No instrumentation detected" cRST);
    OKF("Captured %u tuples in '%s'." cRST, tcnt, out_file);

  }

  exit(child_crashed * 2 + child_timed_out);

}
Beispiel #5
0
/**
 * Initialize the x11 grab device demuxer (public device demuxer API).
 *
 * @param s1 Context from avformat core
 * @return <ul>
 *          <li>AVERROR(ENOMEM) no memory left</li>
 *          <li>AVERROR(EIO) other failure case</li>
 *          <li>0 success</li>
 *         </ul>
 */
static int x11grab_read_header(AVFormatContext *s1)
{
    X11GrabContext *x11grab = s1->priv_data;
    Display *dpy;
    AVStream *st = NULL;
    XImage *image;
    int x_off = 0, y_off = 0, ret = 0, screen, use_shm;
    char *param, *offset;
    AVRational framerate;

    param = av_strdup(s1->filename);
    if (!param)
        goto out;

    offset = strchr(param, '+');
    if (offset) {
        sscanf(offset, "%d,%d", &x_off, &y_off);
        x11grab->draw_mouse = !strstr(offset, "nomouse");
        *offset = 0;
    }

    ret = av_parse_video_size(&x11grab->width, &x11grab->height,
                              x11grab->video_size);
    if (ret < 0) {
        av_log(s1, AV_LOG_ERROR, "Couldn't parse video size.\n");
        goto out;
    }

    ret = av_parse_video_rate(&framerate, x11grab->framerate);
    if (ret < 0) {
        av_log(s1, AV_LOG_ERROR, "Could not parse framerate: %s.\n",
               x11grab->framerate);
        goto out;
    }
    av_log(s1, AV_LOG_INFO,
           "device: %s -> display: %s x: %d y: %d width: %d height: %d\n",
           s1->filename, param, x_off, y_off, x11grab->width, x11grab->height);

    dpy = XOpenDisplay(param);
    if (!dpy) {
        av_log(s1, AV_LOG_ERROR, "Could not open X display.\n");
        ret = AVERROR(EIO);
        goto out;
    }

    st = avformat_new_stream(s1, NULL);
    if (!st) {
        ret = AVERROR(ENOMEM);
        goto out;
    }
    avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */

    screen = DefaultScreen(dpy);

    if (x11grab->follow_mouse) {
        int screen_w, screen_h;
        Window w;

        screen_w = DisplayWidth(dpy, screen);
        screen_h = DisplayHeight(dpy, screen);
        XQueryPointer(dpy, RootWindow(dpy, screen), &w, &w, &x_off, &y_off,
                      &ret, &ret, &ret);
        x_off -= x11grab->width / 2;
        y_off -= x11grab->height / 2;
        x_off  = FFMIN(FFMAX(x_off, 0), screen_w - x11grab->width);
        y_off  = FFMIN(FFMAX(y_off, 0), screen_h - x11grab->height);
        av_log(s1, AV_LOG_INFO,
               "followmouse is enabled, resetting grabbing region to x: %d y: %d\n",
               x_off, y_off);
    }

    use_shm = XShmQueryExtension(dpy);
    av_log(s1, AV_LOG_INFO,
           "shared memory extension %sfound\n", use_shm ? "" : "not ");

    if (use_shm && setup_shm(s1, dpy, &image) < 0) {
        av_log(s1, AV_LOG_WARNING, "Falling back to XGetImage\n");
        use_shm = 0;
    }

    if (!use_shm) {
        image = XGetImage(dpy, RootWindow(dpy, screen),
                          x_off, y_off,
                          x11grab->width, x11grab->height,
                          AllPlanes, ZPixmap);
    }

    if (x11grab->draw_mouse && setup_mouse(dpy, screen) < 0) {
        av_log(s1, AV_LOG_WARNING,
               "XFixes not available, cannot draw the mouse cursor\n");
        x11grab->draw_mouse = 0;
    }

    x11grab->frame_size = x11grab->width * x11grab->height * image->bits_per_pixel / 8;
    x11grab->dpy        = dpy;
    x11grab->time_base  = (AVRational) { framerate.den, framerate.num };
    x11grab->time_frame = av_gettime() / av_q2d(x11grab->time_base);
    x11grab->x_off      = x_off;
    x11grab->y_off      = y_off;
    x11grab->image      = image;
    x11grab->use_shm    = use_shm;

    ret = pixfmt_from_image(s1, image, &st->codec->pix_fmt);
    if (ret < 0)
        goto out;

    st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
    st->codec->codec_id   = AV_CODEC_ID_RAWVIDEO;
    st->codec->width      = x11grab->width;
    st->codec->height     = x11grab->height;
    st->codec->time_base  = x11grab->time_base;
    st->codec->bit_rate   = x11grab->frame_size * 1 / av_q2d(x11grab->time_base) * 8;

out:
    av_free(param);
    return ret;
}
Beispiel #6
0
int buf_ctor(struct buf_s *buf, size_t bsiz, size_t rblk, size_t wblk, int rline, int wline, size_t hpage, size_t ioar, size_t ioaw)
{
	int ret = -1;
	size_t adj, page, idx, rblki, wblki, bsiza, csiza;

	if (!buf) {
		fputs("buf: no buf ?\n", stderr);
		return -1;
	}

	if (bsiz < 2*rblk || bsiz < 2*wblk) {
		fputs("buf: 'buffer size' must be at least 2*max('read block, 'write block'),\n"
		      "     to avoid corner case starvations.\n", stderr);
		return -1;
	}
	memset(buf, 0, sizeof *buf);

#ifndef h_mingw
	page = sysconf(_SC_PAGESIZE);
	if (page == hpage) {
		hpage = 0;
	}
	page = hpage ? hpage : page;
	adj = MAX(page, SHMLBA);
#else
	hpage = 0;
	adj = page = 4096;
#endif

	bsiza = ALIGN(bsiz, adj);
	if (!(idx = is_pow2(bsiza))) {
		fprintf(stderr, "buf: 'aligned buffer size' must be power of 2, but is: 0x%zX\n", bsiza);
		goto out;
	}
	buf->mask = (((size_t)1 << idx) - 1);
	rblki = ALIGN(rblk, ioar);
	wblki = ALIGN(wblk, ioaw);
	csiza = ALIGN(rblki + wblki, adj);
	buf->size = bsiza;

	preset_shm(buf);
	if (setup_shm(buf, bsiza, csiza, hpage) < 0) {
		fputs("buf: falling back to regular malloc()\n", stderr);
		ret = 1;
		detach_shm(buf);
		rm_shm(buf);
		preset_mal(buf);
		if (setup_mal(buf, bsiza, csiza, adj) < 0) {
			detach_mal(buf);
			ret = -1;
			goto out;
		}
	} else
		ret = 0;

	buf->rchunk = buf->chk;
	buf->wchunk = buf->chk + rblki;

	buf->flags |= hpage && buf->mapW ? M_HUGE : 0;
	buf->flags |= rline ? M_LINER : 0;
	buf->flags |= wline ? M_LINEW : 0;
//	buf->page = page;
	buf->ioar = ioar;
	buf->ioaw = ioaw;
	buf->rblk = rblk;
	buf->wblk = wblk;
	buf->crcw = crc_beg();
	buf->crcr = buf->crcw;
#if 0
	if (rblk < wblk && rline && !wline) {
		fputs("buf: 'read block' must be greater or equal to 'write block',\n"
		      "     if the left side is in the line mode,\n"
		      "     and the right side is in the reblocking mode.\n", stderr);
		goto out;
	}
#endif

	DEB("\nbuf map: C:%p, B:%p, B+S:%p, W:%p\n", buf->mapC, buf->mapB, buf->mapB + buf->size, buf->mapW);
	DEB("buf buf: C:%p, B:%p\n", buf->chk, buf->buf);
out:
	if (ret < 0)
		buf_dtor(buf);
	fputc('\n', stderr);
	return ret;
}