1. 08 1月, 2016 3 次提交
    • L
      linux-user: in poll(), if nfds is 0, pfd can be NULL · 3e24bb3f
      Laurent Vivier 提交于
      This problem appears with yum in Fedora 20 / PPC64 container.
      
      test case:
      
          #include <stdio.h>
          #include <poll.h>
      
          int main(void)
          {
              int ret;
      
              ret = poll(NULL, 0, 1000);
              printf("%d\n", ret);
          }
      
      target test environment: Fedora 20 / PPC64
      host test environment: Ubuntu 14.0.2 / x86_64
      
      original test result: -1
      
          13451 poll(0,0,1000,274886297496,268566664,268566648) = -1 errno=14 (Bad address)
      
      patched test result: 0
      
          13536 poll(0,0,1000,274886297496,268566664,268566648) = 0
      Signed-off-by: NLaurent Vivier <laurent@vivier.eu>
      Signed-off-by: NRiku Voipio <riku.voipio@linaro.org>
      3e24bb3f
    • L
      linux-user: correctly align target_epoll_event · 928bed6a
      Laurent Vivier 提交于
      According to comments in /usr/include/linux/eventpoll.h,
      poll_event is packed only on x86_64.
      
      And to be sure fields are correctly aligned in epoll_data,
      use abi_XXX types for all of them.
      
      Moreover, fd type is wrong: fd is int, not ulong.
      
      This has been tested with a ppc guest on an x86_64 host:
      without this patch, systemd crashes (core).
      
      CC: Alexander Graf <agraf@suse.de>
      CC: Peter Maydell <peter.maydell@linaro.org>
      Signed-off-by: NLaurent Vivier <laurent@vivier.eu>
      Signed-off-by: NRiku Voipio <riku.voipio@linaro.org>
      928bed6a
    • L
      linux-user: add signalfd/signalfd4 syscalls · e36800c9
      Laurent Vivier 提交于
      This patch introduces a system very similar to the one used in the kernel
      to attach specific functions to a given file descriptor.
      
      In this case, we attach a specific "host_to_target()" translator to the fd
      returned by signalfd() to be able to byte-swap the signalfd_siginfo
      structure provided by read().
      
      This patch allows to execute the example program given by
      man signalfd(2):
      
       #include <sys/signalfd.h>
       #include <signal.h>
       #include <unistd.h>
       #include <stdlib.h>
       #include <stdio.h>
      
       #define handle_error(msg) \
           do { perror(msg); exit(EXIT_FAILURE); } while (0)
      
       int
       main(int argc, char *argv[])
       {
           sigset_t mask;
           int sfd;
           struct signalfd_siginfo fdsi;
           ssize_t s;
      
           sigemptyset(&mask);
           sigaddset(&mask, SIGINT);
           sigaddset(&mask, SIGQUIT);
      
           /* Block signals so that they aren't handled
              according to their default dispositions */
      
           if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1)
               handle_error("sigprocmask");
      
           sfd = signalfd(-1, &mask, 0);
           if (sfd == -1)
               handle_error("signalfd");
      
           for (;;) {
               s = read(sfd, &fdsi, sizeof(struct signalfd_siginfo));
               if (s != sizeof(struct signalfd_siginfo))
                   handle_error("read");
      
               if (fdsi.ssi_signo == SIGINT) {
                   printf("Got SIGINT\n");
               } else if (fdsi.ssi_signo == SIGQUIT) {
                   printf("Got SIGQUIT\n");
                   exit(EXIT_SUCCESS);
               } else {
                   printf("Read unexpected signal\n");
               }
           }
       }
      
       $ ./signalfd_demo
       ^CGot SIGINT
       ^CGot SIGINT
       ^\Got SIGQUIT
      Signed-off-by: NLaurent Vivier <laurent@vivier.eu>
      Signed-off-by: NRiku Voipio <riku.voipio@linaro.org>
      e36800c9
  2. 23 12月, 2015 37 次提交