Exemplo n.º 1
0
int init_iothread(/*out*/iothread_t* iothr)
{
   int err;
   thread_t* old_thread = iothr->thread;
   thread_t* thread;

   // DESIGN-TASK:::
   // TODO: implement thread pool / one thread per io device !
   // - move thread into thread pool
   // - remove old_thread and iothr->thread = 0 assignment ! after thread pool creation
   // - use iothread pool
   iothr->thread = 0;
   if (! PROCESS_testerrortimer(&s_iothread_errtimer, &err)) {
      err = newgeneric_thread(&thread, &ioop_worker_thread, iothr);
   }
   if (err) goto ONERR;

   // set out

   iothr->request_stop = 0;
   init_iolist(&iothr->iolist);
   write_atomicint(&iothr->thread, thread);

   // start worker
   resume_thread(thread);

   return 0;
ONERR:
   iothr->thread = old_thread;
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 2
0
int init_filereader(/*out*/filereader_t * frd, const char * filepath, const struct directory_t * relative_to/*0 => current working dir*/)
{
   int err;
   size_t bufsize = sizebuffer_filereader();

   initvariables_filereader(frd);

   err = initfile_filereader(&frd->file, &frd->filesize, filepath, relative_to);
   if (err) goto ONERR;

   if (castPoff_size(frd->filesize) <= bufsize) {
      err = initsinglebuffer_filereader(frd->page, (size_t)frd->filesize);
      if (err) goto ONERR;

   } else {
      err = initdoublebuffer_filereader(frd->page, bufsize);
      if (err) goto ONERR;
   }

   return 0;
ONERR:
   (void) free_filereader(frd);
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 3
0
int initPid_eglconfig(/*out*/eglconfig_t * eglconf, struct opengl_display_t * egldisp, const uint32_t id)
{
   int err;
   EGLint egl_attrib_list[] = {
      EGL_CONFIG_ID, (int32_t) id,
      EGL_NONE
   };

   EGLint      num_config;
   EGLConfig   eglconfig[1];
   EGLBoolean  isOK = eglChooseConfig( egldisp,
                                       egl_attrib_list, eglconfig, lengthof(eglconfig), &num_config);

   if (!isOK) {
      err = EINVAL;
      goto ONERR;
   }

   if (0 == num_config) {
      return ESRCH;
   }

   *eglconf = eglconfig[0];

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 4
0
int switchpermanent_syslogin(syslogin_t* syslogin, sys_userid_t uid)
{
   int err;

   VALIDATE_INPARAM_TEST(uid != sys_userid_FREE, ONERR, );

   err = switchuser(syslogin, uid);
   if (err) goto ONERR;

   err = setreuid(uid, uid);
   if (err) {
      err = errno;
      TRACESYSCALL_ERRLOG("setreuid(uid,uid)", err);
      PRINTUINT32_ERRLOG(uid);
      goto ONERR;
   }

   // syslogin->currentuser // set in switchuser
   syslogin->realuser     = uid;
   syslogin->privilegeduser = uid;

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 5
0
int init_eglconfig(/*out*/eglconfig_t * eglconf, opengl_display_t * egldisp, const int32_t config_attributes[])
{
   int err;
   EGLint   egl_attrib_list[2*gconfig__NROF];

   err = convertConfigListToEGL_eglconfig(&egl_attrib_list, config_attributes);
   if (err) goto ONERR;

   EGLint      num_config;
   EGLConfig   eglconfig;
   EGLBoolean  isOK = eglChooseConfig( egldisp,
                                       egl_attrib_list, &eglconfig, 1, &num_config);

   if (!isOK) {
      err = EINVAL;
      goto ONERR;
   }

   if (!num_config) {
      return ESRCH;
   }

   *eglconf = eglconfig;

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 6
0
void errorstring_x11display(const x11display_t * x11disp, int x11_errcode, char * buffer, uint8_t buffer_size)
{
   int err ;
   int x11_err ;

   if (!buffer_size) {
      err = EINVAL ;
      PRINTUINT8_ERRLOG(buffer_size) ;
      goto ONERR;
   }

   x11_err = XGetErrorText(x11disp->sys_display, x11_errcode, buffer, buffer_size) ;
   if (x11_err) {
      err = EINVAL ;
      TRACESYSCALL_ERRLOG("XGetErrorText", err) ;
      PRINTINT_ERRLOG(x11_err) ;
      goto ONERR;
   }

   buffer[buffer_size-1] = 0 ;
   return ;
ONERR:
   if (buffer_size) {
      snprintf(buffer, buffer_size, "%d", x11_errcode) ;
      buffer[buffer_size-1] = 0 ;
   }
   TRACEEXIT_ERRLOG(err);
   return ;
}
Exemplo n.º 7
0
int configid_eglconfig(eglconfig_t eglconf, struct opengl_display_t * egldisp, /*out*/uint32_t * id)
{
   int err;

   GETVALUE(eglconf, egldisp, EGL_CONFIG_ID, (int32_t*)id);

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 8
0
int visualconfigid_eglconfig(eglconfig_t eglconf, struct opengl_display_t * egldisp, /*out*/int32_t * visualid)
{
   int err;

   GETVALUE(eglconf, egldisp, EGL_NATIVE_VISUAL_ID, visualid);

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 9
0
int init2_x11display(/*out*/x11display_t * x11disp, const char * display_server_name, bool isInitExtension)
{
   int  err ;

   err = initprivate_x11display(x11disp, display_server_name, isInitExtension);
   if (err) goto ONERR;

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 10
0
int switchtorealuser_syslogin(syslogin_t* syslogin)
{
   int err;

   err = switchuser(syslogin, syslogin->realuser);
   if (err) goto ONERR;

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 11
0
int removeobject_x11display(x11display_t * x11disp, uint32_t objectid)
{
   int err ;

   err = remove_x11windowmap(x11disp->idmap, objectid) ;
   if (err) goto ONERR;

   return 0 ;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err ;
}
Exemplo n.º 12
0
int init_x11display(/*out*/x11display_t * x11disp, const char * display_server_name)
{
   int  err ;

   err = initprivate_x11display(x11disp, display_server_name, true);
   if (err) goto ONERR;

   return 0 ;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err ;
}
Exemplo n.º 13
0
int set_x11videomode(const x11videomode_t * xvidmode, x11screen_t * x11screen)
{
    int err ;
    XRRScreenConfiguration * screen_config = 0 ;

    if (!isextxrandr_x11display(display_x11screen(x11screen))) {
        err = ENOSYS ;
        goto ONERR;
    }

    Display * sys_display = display_x11screen(x11screen)->sys_display ;
    screen_config = XRRGetScreenInfo(sys_display, RootWindow(sys_display, number_x11screen(x11screen))) ;
    if (!screen_config) {
        err = ENOSYS ;
        goto ONERR;
    }

    Rotation current_rotation ;
    uint16_t current_size = XRRConfigCurrentConfiguration(screen_config, &current_rotation) ;

    int            sizes_count ;
    XRRScreenSize  * sizes = XRRConfigSizes(screen_config, &sizes_count) ;
    if (  !sizes
            || (current_size >= sizes_count)) {
        err = EOVERFLOW ;
        goto ONERR;
    }

    if (  xvidmode->modeid > sizes_count
            || xvidmode->width_in_pixel  != (uint32_t) sizes[xvidmode->modeid].width
            || xvidmode->height_in_pixel != (uint32_t) sizes[xvidmode->modeid].height) {
        err = EINVAL ;
        goto ONERR;
    }

    if (XRRSetScreenConfig( sys_display, screen_config,
                            RootWindow(sys_display, number_x11screen(x11screen)),
                            xvidmode->modeid, current_rotation, CurrentTime)) {
        err = EOPNOTSUPP ;
        goto ONERR;
    }

    XRRFreeScreenConfigInfo(screen_config) ;

    return 0 ;
ONERR:
    if (screen_config) {
        XRRFreeScreenConfigInfo(screen_config) ;
    }
    TRACEEXIT_ERRLOG(err);
    return err ;
}
Exemplo n.º 14
0
int insertobject_x11display(x11display_t * x11disp, struct x11window_t * object, uint32_t objectid)
{
   int err ;

   VALIDATE_INPARAM_TEST(object != 0, ONERR, );

   err = insert_x11windowmap(x11disp->idmap, objectid, object);
   if (err) goto ONERR;

   return 0 ;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err ;
}
Exemplo n.º 15
0
int initfiltered_eglconfig(/*out*/eglconfig_t * eglconf, struct opengl_display_t * egldisp, const int32_t config_attributes[], eglconfig_filter_f filter, void * user)
{
   int err;
   EGLint      egl_attrib_list[2*gconfig__NROF];
   EGLConfig * eglconfig = 0;
   memblock_t  mblock;

   err = convertConfigListToEGL_eglconfig(&egl_attrib_list, config_attributes);
   if (err) goto ONERR;

   EGLint      num_config;
   EGLBoolean  isOK = eglChooseConfig( egldisp, egl_attrib_list, 0, 0, &num_config);
   if (!isOK) {
      err = EINVAL;
      goto ONERR;
   }

   // TODO: implement tempstack_memory_allocator
   //       allocate memory from tempstack instead of real stack
   err = ALLOC_ERR_MM(&s_eglconfig_errtimer, sizeof(EGLConfig) * (unsigned)num_config, &mblock);
   if (err) goto ONERR;

   eglconfig = (EGLConfig *) mblock.addr;
   isOK = eglChooseConfig( egldisp, egl_attrib_list, eglconfig, num_config, &num_config);
   if (!isOK) {
      err = EINVAL;
      goto ONERR;
   }

   EGLint i;
   for (i = 0; i < num_config; ++i) {
      EGLint visualid;
      isOK = eglGetConfigAttrib( egldisp, eglconfig[i], EGL_NATIVE_VISUAL_ID, &visualid);
      if (filter(eglconfig[i], visualid, user)) {
         // set out param
         *eglconf = eglconfig[i];
         break;
      }
   }

   (void) FREE_ERR_MM(&s_eglconfig_errtimer, &mblock);

   if (i == num_config) return ESRCH;

   return 0;
ONERR:
   if (eglconfig) (void) FREE_MM(&mblock);
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 16
0
static int initprivate_x11display(/*out*/x11display_t * x11disp, const char * display_server_name, bool isInitExtension)
{
   int  err ;
   x11display_t   newdisp = x11display_FREE;
   memblock_t     mblock;

   if (!display_server_name) {
      display_server_name = getenv("DISPLAY") ;
      if (!display_server_name) {
         err = EINVAL;
         TRACE_NOARG_ERRLOG(log_flags_NONE, X11_DISPLAY_NOT_SET);
         goto ONERR;
      }
   }

   // create new x11_display

   err = ALLOC_MM(sizeof(x11windowmap_t), &mblock);
   if (err) goto ONERR;

   newdisp.idmap       = (x11windowmap_t*) mblock.addr;
   memset(newdisp.idmap->entries, 0, sizeof(newdisp.idmap->entries));
   newdisp.sys_display = XOpenDisplay(display_server_name);
   if (!newdisp.sys_display) {
      err = ECONNREFUSED;
      TRACE_ERRLOG(log_flags_NONE, X11_NO_CONNECTION, display_server_name);
      goto ONERR;
   }

#define SETATOM(NAME)   newdisp.atoms.NAME = XInternAtom(newdisp.sys_display, #NAME, False); \
                        static_assert(sizeof(newdisp.atoms.NAME) == sizeof(uint32_t), "same type")
   SETATOM(WM_PROTOCOLS);
   SETATOM(WM_DELETE_WINDOW);
   SETATOM(_NET_FRAME_EXTENTS);
   SETATOM(_NET_WM_WINDOW_OPACITY);
#undef  SETATOM

   if (isInitExtension) {
      err = queryextensions_x11display(&newdisp);
      if (err) goto ONERR;
   }

   *x11disp = newdisp;

   return 0;
ONERR:
   free_x11display(&newdisp);
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 17
0
int readnext_filereader(filereader_t * frd, /*out*/struct memstream_ro_t * buffer)
{
   int err;

   if (frd->ioerror) {
      // never logged twice
      return frd->ioerror;
   }

   off_t unreadsize = frd->filesize - frd->fileoffset;

   if (0 == unreadsize) {
      // ENODATA is not logged
      return ENODATA;
   }

   if (! frd->nrfreebuffer) {
      err = ENOBUFS;
      goto ONERR;
   }

   uint8_t * bufferaddr = frd->page[frd->nextindex].addr;
   size_t    buffersize = frd->page[frd->nextindex].size;
   if (castPoff_size(unreadsize) < buffersize) {
      buffersize = (size_t) unreadsize;
   }

   if (! frd->unreadsize) {
      err = readall_iochannel(frd->file, buffersize, bufferaddr, -1);
      if (err) {
         frd->ioerror = err;
         goto ONERR;
      }
      frd->unreadsize = buffersize;
   }

   frd->unreadsize -= buffersize;
   frd->nextindex = ! frd->nextindex;
   -- frd->nrfreebuffer;
   frd->fileoffset += (off_t) buffersize;

   // set out param
   init_memstream(buffer, bufferaddr, bufferaddr + buffersize);

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 18
0
int replaceobject_x11display(x11display_t * x11disp, struct x11window_t * object, uint32_t objectid)
{
   int err ;
   x11windowmap_entry_t * found_node;

   err = find_x11windowmap(x11disp->idmap, objectid, &found_node) ;
   if (err) goto ONERR;

   found_node->object = object;

   return 0 ;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err ;
}
Exemplo n.º 19
0
int init_module(/*out*/module_t * mod, const char * modulename)
{
   int err;
   directory_t *  dir = 0;
   vmpage_t       module_page = vmpage_FREE;
   size_t         code_size;

   err = new_directory(&dir, module_DIRECTORY, 0);
   if (err) goto ONERR;

   {
      off_t file_size;
      err = filesize_directory(dir, modulename, &file_size);
      if (err) goto ONERR;

      if (file_size < 0 || (OFF_MAX > SIZE_MAX && file_size >= SIZE_MAX)) {
         err = ENOMEM;
         goto ONERR;
      }

      code_size = (size_t) file_size;
   }

   err = init2_vmpage(&module_page, code_size, accessmode_RDWR);
   if (err) goto ONERR;

   {
      wbuffer_t wbuf = wbuffer_INIT_STATIC(code_size, module_page.addr);
      err = load_file(modulename, &wbuf, dir);
      if (err) goto ONERR;
   }

   err = protect_vmpage(&module_page, accessmode_RDEX);
   if (err) goto ONERR;

   err = delete_directory(&dir);
   if (err) goto ONERR;

   *cast_vmpage(mod, page_) = module_page;
   mod->code_size = code_size;

   return 0;
ONERR:
   free_vmpage(&module_page);
   delete_directory(&dir);
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 20
0
int init_pipe(/*out*/pipe_t* pipe)
{
   int err;

   static_assert(1 + &pipe->read == &pipe->write, "Arrayzugriff möglich");

   if (/*Fehler?*/ pipe2(&pipe->read, O_NONBLOCK|O_CLOEXEC)) {
      err = errno;
      goto ONERR;
   }

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 21
0
int init_logbuffer(/*out*/logbuffer_t * logbuf, size_t buffer_size, uint8_t buffer_addr[buffer_size], sys_iochannel_t io)
{
   int err;

   VALIDATE_INPARAM_TEST(buffer_size > log_config_MINSIZE, ONERR,);

   logbuf->addr = buffer_addr;
   logbuf->size = buffer_size;
   logbuf->logsize = 0;
   logbuf->io   = io;
   logbuf->addr[0] = 0;

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 22
0
int configid_eglpbuffer(const eglpbuffer_t eglpbuf, struct opengl_display_t * egldisp, /*out*/uint32_t * configid)
{
   int err;
   EGLint value;
   static_assert(sizeof(EGLint) <= sizeof(uint32_t), "attribute type can be converted to returned type");

   if (!eglQuerySurface(egldisp, eglpbuf, EGL_CONFIG_ID, &value)) {
      goto ONERR;
   }

   *configid = (uint32_t) value;

   return 0;
ONERR:
   err = convert2errno_egl(eglGetError());
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 23
0
int tryfindobject_x11display(x11display_t * x11disp, /*out*/struct x11window_t ** object, uint32_t objectid)
{
   int err ;
   x11windowmap_entry_t * found_node ;

   err = find_x11windowmap(x11disp->idmap, objectid, &found_node) ;
   if (err) goto ONERR;

   if (object) {
      *object = found_node->object ;
   }

   return 0 ;
ONERR:
   if (err != ESRCH) {
      TRACEEXIT_ERRLOG(err);
   }
   return err ;
}
Exemplo n.º 24
0
int initcurrent_x11videomode(/*out*/x11videomode_t * current_xvidmode, x11screen_t * x11screen)
{
    int err ;
    XRRScreenConfiguration * screen_config = 0 ;

    if (!isextxrandr_x11display(display_x11screen(x11screen))) {
        err = ENOSYS ;
        goto ONERR;
    }

    Display * sys_display = display_x11screen(x11screen)->sys_display ;
    screen_config = XRRGetScreenInfo(sys_display, RootWindow(sys_display, number_x11screen(x11screen))) ;
    if (!screen_config) {
        err = ENOSYS ;
        goto ONERR;
    }

    Rotation current_rotation ;
    uint16_t current_size = XRRConfigCurrentConfiguration(screen_config, &current_rotation) ;

    int           sizes_count ;
    XRRScreenSize * sizes = XRRConfigSizes(screen_config, &sizes_count) ;
    if (  !sizes
            || (current_size >= sizes_count)) {
        err = EOVERFLOW ;
        goto ONERR;
    }

    current_xvidmode->modeid          = current_size ;
    current_xvidmode->width_in_pixel  = (uint32_t) sizes[current_size].width ;
    current_xvidmode->height_in_pixel = (uint32_t) sizes[current_size].height ;

    XRRFreeScreenConfigInfo(screen_config) ;

    return 0 ;
ONERR:
    if (screen_config) {
        XRRFreeScreenConfigInfo(screen_config) ;
    }
    TRACEEXIT_ERRLOG(err);
    return err ;
}
Exemplo n.º 25
0
int size_eglpbuffer(const eglpbuffer_t eglpbuf, struct opengl_display_t * egldisp, /*out*/uint32_t * width, /*out*/uint32_t * height)
{
   int err;
   EGLint attr_value;
   static_assert(sizeof(EGLint) <= sizeof(uint32_t), "attribute type can be converted to returned type");
   if (!eglQuerySurface(egldisp, eglpbuf, EGL_WIDTH, &attr_value)) {
      goto ONERR;
   }
   *width = (uint32_t) attr_value;
   if (!eglQuerySurface(egldisp, eglpbuf, EGL_HEIGHT, &attr_value)) {
      goto ONERR;
   }
   *height = (uint32_t) attr_value;

   return 0;
ONERR:
   err = convert2errno_egl(eglGetError());
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 26
0
int init_eglwindow(/*out*/eglwindow_t * eglwin, egldisplay_t egldisp, eglconfig_t eglconf, struct sys_window_t * syswin)
{
   int err;

   VALIDATE_INPARAM_TEST(syswin != 0, ONERR, );

   EGLint     attrib[] = { EGL_NONE };
   EGLSurface window   = eglCreateWindowSurface(egldisp, eglconf, (EGLNativeWindowType) syswin, attrib);

   if (EGL_NO_SURFACE == window) {
      err = convert2errno_egl(eglGetError());
      goto ONERR;
   }

   *eglwin = window;

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 27
0
int init_syslogin(/*out*/syslogin_t* syslogin)
{
   int err;
   sys_userid_t uid;
   sys_userid_t euid;

   uid  = getuid();
   euid = geteuid();

   err = switchuser(syslogin, uid);
   if (err) goto ONERR;

   // syslogin->currentuser // already set in switchuser
   syslogin->realuser     = uid;
   syslogin->privilegeduser = euid;

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 28
0
int maxpbuffer_eglconfig(eglconfig_t eglconf, struct opengl_display_t * egldisp, /*out*/uint32_t * maxwidth, /*out*/uint32_t * maxheight, /*out*/uint32_t * maxpixels)
{
   int err;

   if (maxwidth) {
      GETVALUE(eglconf, egldisp, EGL_MAX_PBUFFER_WIDTH, (int32_t*)maxwidth);
   }

   if (maxheight) {
      GETVALUE(eglconf, egldisp, EGL_MAX_PBUFFER_HEIGHT, (int32_t*)maxheight);
   }

   if (maxpixels) {
      GETVALUE(eglconf, egldisp, EGL_MAX_PBUFFER_PIXELS, (int32_t*)maxpixels);
   }

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
Exemplo n.º 29
0
int init_systimer(/*out*/systimer_t* timer, sysclock_e clock_type)
{
   int err ;
   clockid_t   clockid = convertclockid(clock_type) ;
   int         fd ;

   fd = timerfd_create(clockid, TFD_NONBLOCK|TFD_CLOEXEC) ;
   if (-1 == fd) {
      err = errno ;
      TRACESYSCALL_ERRLOG("timerfd_create", err) ;
      PRINTINT_ERRLOG(clock_type) ;
      goto ONERR;
   } else {
      *timer = fd ;
   }

   return 0 ;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err ;
}
Exemplo n.º 30
0
int init_eglpbuffer(/*out*/eglpbuffer_t * eglpbuf, struct opengl_display_t * egldisp, struct opengl_config_t * eglconf, uint32_t width, uint32_t height)
{
   int err;
   EGLint attr[] = {
      EGL_HEIGHT, height > INT32_MAX ? INT32_MAX : (int32_t)height,
      EGL_WIDTH,  width  > INT32_MAX ? INT32_MAX : (int32_t)width,
      EGL_NONE
   };
   EGLSurface surface = eglCreatePbufferSurface(egldisp, eglconf, attr);

   if (EGL_NO_SURFACE == surface) {
      goto ONERR;
   }

   *eglpbuf = surface;

   return 0;
ONERR:
   err = convert2errno_egl(eglGetError());
   TRACEEXIT_ERRLOG(err);
   return err;
}