• Andrew Morton's avatar
    [PATCH] posix message queues: implementation · be94d44e
    Andrew Morton authored
    From: Manfred Spraul <manfred@colorfullife.com>
    
    Actual implementation of the posix message queues, written by Krzysztof
    Benedyczak and Michal Wronski.  The complete implementation is dependant on
    CONFIG_POSIX_MQUEUE.
    
    It passed the openposix test suite with two exceptions: one mq_unlink test
    was bad and tested undefined behavior.  And Linux succeeds
    mq_close(open(,,,)).  The spec mandates EBADF, but we have decided to ignore
    that: we would have to add a new syscall just for the right error code.
    
    The patch intentionally doesn't use all helpers from fs/libfs for kernel-only
    filesystems: step 5 allows user space mounts of the file system.
    
    
    
    Signal changes:
    
    The patch redefines SI_MESGQ using __SI_CODE: The generic Linux ABI uses
    a negative value (i.e.  from user) for SI_MESGQ, but the kernel internal
    value must be posive to pass check_kill_value.  Additionally, the patch
    adds support into copy_siginfo_to_user to copy the "new" signal type to
    user space.
    
    
    
    Changes in signal code caused by POSIX message queues patch:
    
    General & rationale:
    
      mqueues generated signals (only upon notification) must have si_code
      == SI_MESGQ.  In fact such a signal is send from one process which
      caused notification (== sent message to empty message queue) to
      another which requested it.  Both processes can be of course unrelated
      in terms of uids/euids.  So SI_MESGQ signals must be classified as
      SI_FROMKERNEL to pass check_kill_permissions (not need to say that
      this signals ARE from kernel).
    
      Signals generated by message queues notification need the same
      fields in siginfo struct's union _sifields as POSIX.1b signals and we
      can reuse its union entry.
    
      SI_MESGQ was previously defined to -3 in kernel and also in glibc. 
      So in userspace SI_MESGQ must be still visible as -3.
    
    Solution:
    
      SI_MESGQ is defined in the same style as SI_TIMER using __SI_CODE macro.
    
      Details:
    
        Fortunately copy_siginfo_to_user copies si_code as short.  So we
        can use remaining part of int value freely.  __SI_CODE does the
        work.  SI_MESGQ is in kernel:
    
     		6<<16 | (-3 & 0xffff) what is > 0
    
        but to userspace is copied
    
     		(short) SI_MESGQ == -3
    
    Actual changes:
    
      Changes in include/asm-generic/siginfo.h
    
      __SI_MESGQ added in signal.h to represent inside-kernel prefix of
      SI_MESGQ.  SI_MESGQ is redefined from -3 to __SI_CODE(__SI_MESGQ, -3)
    
      Except mips architecture those changes should be arch independent
      (asm-generic/siginfo.h is included in arch versions).  On mips
      SI_MESGQ is redefined to -4 in order to be compatible with IRIX.  But
      the same schema can be used.
    
      Change in copy_siginfo_to_user: We only add one line to order the
      same copy semantics as for _SI_RT.
    
      This change isn't very portable - some arch have its own
      copy_siginfo_to_user.  All those should have similar change (but
      possibly not one-line as _SI_RT case was sometimes ignored because i
      wasn't used yet, e.g.  see ia64 signal.c).
    
    Update:
    mq: only fail with invalid timespec if mq_timed{send,receive} needs to block
    From: Jakub Jelinek <jakub@redhat.com>
    
    POSIX requires EINVAL to be set if:
    "The process or thread would have blocked, and the abs_timeout parameter
    specified a nanoseconds field value less than zero or greater than or equal
    to 1000 million."
    but 2.6.5-mm3 returns -EINVAL even if the process or thread would not block
    (if the queue is not empty for timedreceive or not full for timedsend).
    be94d44e
Kconfig 12.1 KB