LCOV - code coverage report
Current view: directory - src/trusted/service_runtime - nacl_size_t.h (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 2 2 100.0 %
Date: 2014-07-02 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright (c) 2014 The Native Client Authors. All rights reserved.
       3                 :  * Use of this source code is governed by a BSD-style license that can be
       4                 :  * found in the LICENSE file.
       5                 :  */
       6                 : 
       7                 : #ifndef NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_NACL_SIZE_T_H
       8                 : #define NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_NACL_SIZE_T_H
       9                 : 
      10                 : #include "native_client/src/include/portability.h"
      11                 : #include "native_client/src/trusted/service_runtime/include/machine/_types.h"
      12                 : 
      13                 : /*
      14                 :  * WORDSIZE is defined by service_runtime/include/machine/_types.h.  It is
      15                 :  * defined as NACL_ABI_WORDSIZE before it is munged by export_header.py.
      16                 :  */
      17                 : #if defined(__native_client__) && !defined(NACL_ABI_WORDSIZE)
      18                 : #define NACL_ABI_WORDSIZE WORDSIZE
      19                 : #endif  /* defined(__native_client__) && !defined(NACL_ABI_WORDSIZE) */
      20                 : 
      21                 : #ifndef nacl_abi_size_t_defined
      22                 : #define nacl_abi_size_t_defined
      23                 : typedef uint32_t nacl_abi_size_t;
      24                 : #endif
      25                 : 
      26                 : #define NACL_ABI_SIZE_T_MIN ((nacl_abi_size_t) 0)
      27                 : #define NACL_ABI_SIZE_T_MAX ((nacl_abi_size_t) -1)
      28                 : 
      29                 : #ifndef nacl_abi_ssize_t_defined
      30                 : #define nacl_abi_ssize_t_defined
      31                 : typedef int32_t nacl_abi_ssize_t;
      32                 : #endif
      33                 : 
      34                 : #define NACL_ABI_SSIZE_T_MAX \
      35                 :   ((nacl_abi_ssize_t) (NACL_ABI_SIZE_T_MAX >> 1))
      36                 : #define NACL_ABI_SSIZE_T_MIN \
      37                 :   (~NACL_ABI_SSIZE_T_MAX)
      38                 : 
      39                 : #define NACL_PRIdNACL_SIZE NACL_PRI_(d, NACL_ABI_WORDSIZE)
      40                 : #define NACL_PRIiNACL_SIZE NACL_PRI_(i, NACL_ABI_WORDSIZE)
      41                 : #define NACL_PRIoNACL_SIZE NACL_PRI_(o, NACL_ABI_WORDSIZE)
      42                 : #define NACL_PRIuNACL_SIZE NACL_PRI_(u, NACL_ABI_WORDSIZE)
      43                 : #define NACL_PRIxNACL_SIZE NACL_PRI_(x, NACL_ABI_WORDSIZE)
      44                 : #define NACL_PRIXNACL_SIZE NACL_PRI_(X, NACL_ABI_WORDSIZE)
      45                 : 
      46                 : /**
      47                 :  * Inline functions to aid in conversion between system (s)size_t and
      48                 :  * nacl_abi_(s)size_t
      49                 :  *
      50                 :  * These are defined as inline functions only if __native_client__ is
      51                 :  * undefined, since in a nacl module size_t and nacl_abi_size_t are always
      52                 :  * the same (and we don't have a definition for INLINE, so these won't compile)
      53                 :  *
      54                 :  * If __native_client__ *is* defined, these turn into no-ops.
      55                 :  */
      56                 : #ifdef __native_client__
      57                 :   /**
      58                 :    * NB: The "no-op" version of these functions does NO type conversion.
      59                 :    * Please DO NOT CHANGE THIS. If you get a type error using these functions
      60                 :    * in a NaCl module, it's a real error and should be fixed in your code.
      61                 :    */
      62                 :   #define nacl_abi_size_t_saturate(x) (x)
      63                 :   #define nacl_abi_ssize_t_saturate(x) (x)
      64                 : #else /* __native_client */
      65             264 :   static INLINE nacl_abi_size_t nacl_abi_size_t_saturate(size_t x) {
      66                 :     if (x > NACL_ABI_SIZE_T_MAX) {
      67                 :       return NACL_ABI_SIZE_T_MAX;
      68                 :     } else {
      69             264 :       return (nacl_abi_size_t)x;
      70                 :     }
      71                 :   }
      72                 : 
      73                 :   static INLINE nacl_abi_ssize_t nacl_abi_ssize_t_saturate(ssize_t x) {
      74                 :     if (x > NACL_ABI_SSIZE_T_MAX) {
      75                 :       return NACL_ABI_SSIZE_T_MAX;
      76                 :     } else if (x < NACL_ABI_SSIZE_T_MIN) {
      77                 :       return NACL_ABI_SSIZE_T_MIN;
      78                 :     } else {
      79                 :       return (nacl_abi_ssize_t) x;
      80                 :     }
      81                 :   }
      82                 : #endif /* __native_client */
      83                 : 
      84                 : #endif

Generated by: LCOV version 1.7