xpcom/io/nsIStreamBufferAccess.idl

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsISupports.idl"
     8 /**
     9  * An interface for access to a buffering stream implementation's underlying
    10  * memory buffer.
    11  *
    12  * Stream implementations that QueryInterface to nsIStreamBufferAccess must
    13  * ensure that all buffers are aligned on the most restrictive type size for
    14  * the current architecture (e.g., sizeof(double) for RISCy CPUs).  malloc(3)
    15  * satisfies this requirement.
    16  */
    17 [scriptable, uuid(ac923b72-ac87-4892-ac7a-ca385d429435)]
    18 interface nsIStreamBufferAccess : nsISupports
    19 {
    20     /**
    21      * Get access to a contiguous, aligned run of bytes in the stream's buffer.
    22      * Exactly one successful getBuffer call must occur before a putBuffer call
    23      * taking the non-null pointer returned by the successful getBuffer.
    24      *
    25      * The run of bytes are the next bytes (modulo alignment padding) to read
    26      * for an input stream, and the next bytes (modulo alignment padding) to
    27      * store before (eventually) writing buffered data to an output stream.
    28      * There can be space beyond this run of bytes in the buffer for further
    29      * accesses before the fill or flush point is reached.
    30      *
    31      * @param aLength
    32      *    Count of contiguous bytes requested at the address A that satisfies
    33      *    (A & aAlignMask) == 0 in the buffer, starting from the current stream
    34      *    position, mapped to a buffer address B.  The stream implementation
    35      *    must pad from B to A by skipping bytes (if input stream) or storing
    36      *    zero bytes (if output stream).
    37      *
    38      * @param aAlignMask
    39      *    Bit-mask computed by subtracting 1 from the power-of-two alignment
    40      *    modulus (e.g., 3 or sizeof(uint32_t)-1 for uint32_t alignment).
    41      *
    42      * @return
    43      *    The aligned pointer to aLength bytes in the buffer, or null if the
    44      *    buffer has no room for aLength bytes starting at the next address A
    45      *    after the current position that satisfies (A & aAlignMask) == 0.
    46      */
    47     [notxpcom,noscript] charPtr getBuffer(in uint32_t aLength, in uint32_t aAlignMask);
    49     /**
    50      * Relinquish access to the stream's buffer, filling if at end of an input
    51      * buffer, flushing if completing an output buffer.  After a getBuffer call
    52      * that returns non-null, putBuffer must be called.
    53      *
    54      * @param aBuffer
    55      *    A non-null pointer returned by getBuffer on the same stream buffer
    56      *    access object.
    57      *
    58      * @param aLength
    59      *    The same count of contiguous bytes passed to the getBuffer call that
    60      *    returned aBuffer.
    61      */
    62     [notxpcom,noscript] void putBuffer(in charPtr aBuffer, in uint32_t aLength);
    64     /**
    65      * Disable and enable buffering on the stream implementing this interface.
    66      * DisableBuffering flushes an output stream's buffer, and invalidates an
    67      * input stream's buffer.
    68      */
    69     void disableBuffering();
    70     void enableBuffering();
    72     /**
    73      * The underlying, unbuffered input or output stream.
    74      */
    75     readonly attribute nsISupports unbufferedStream;
    76 };
    78 %{C++
    80 /**
    81  * These macros get and put a buffer given either an sba parameter that may
    82  * point to an object implementing nsIStreamBufferAccess, nsIObjectInputStream,
    83  * or nsIObjectOutputStream.
    84  */
    85 #define NS_GET_BUFFER(sba,n,a)  ((sba)->GetBuffer(n, a))
    86 #define NS_PUT_BUFFER(sba,p,n)  ((sba)->PutBuffer(p, n))
    88 %}

mercurial