[openssl-dev] Testing for a type with a define in e_os2.h?

Jeffrey Walton noloader at gmail.com
Sun Mar 27 00:45:15 UTC 2016


On Sat, Mar 26, 2016 at 6:44 PM, Viktor Dukhovni
<openssl-users at dukhovni.org> wrote:
> On Sat, Mar 26, 2016 at 06:14:05PM -0400, Jeffrey Walton wrote:
>
>> e_os2.h has this around line 260:
>>
>> # if defined(OPENSSL_SYS_UEFI) && !defined(ssize_t)
>> #  define ossl_ssize_t int
>> #  define OSSL_SSIZE_MAX INT_MAX
>> # endif
>>
>> I don't believe you can test for a type by using 'defined(t)'. Also
>> see http://stackoverflow.com/questions/12558538/how-can-i-check-a-certain-type-is-already-defined-in-c-compiler.
>
> Thanks for the heads-up.  Perhaps that condition should have been
> defined(ossl_ssize_t).  In any case, if UEFI code runs in 32-bit
> mode, then likely the additional condition is not (or rarely) needed
> at present.

I think the one to focus on is "define ossl_ssize_t ssize_t".
SSIZE_MAX should be defined when ssize_t is available. If SSIZE_MAX in
not defined, then both ssize_t and SSIZE_MAX need a definition.

So something like:

diff --git a/include/openssl/e_os2.h b/include/openssl/e_os2.h
index bbd6116..216aebf 100644
--- a/include/openssl/e_os2.h
+++ b/include/openssl/e_os2.h
@@ -257,14 +257,20 @@ extern "C" {
 #  endif
 # endif

-# if defined(OPENSSL_SYS_UEFI) && !defined(ssize_t)
-#  define ossl_ssize_t int
-#  define OSSL_SSIZE_MAX INT_MAX
-# endif
-
-# ifndef ossl_ssize_t
+# if defined(SSIZE_MAX)
 #  define ossl_ssize_t ssize_t
 #  define OSSL_SSIZE_MAX SSIZE_MAX
+# else /* not SSIZE_MAX */
+#  if (__WORDSIZE == 64) || (__SIZEOF_PTRDIFF_T__ == 8) || (__LP64__ == 1)
+#   define ossl_ssize_t long
+#   define OSSL_SSIZE_MAX LONG_MAX
+#  elif (__WORDSIZE == 32) || (__SIZEOF_PTRDIFF_T__ == 4)
+#   define ossl_ssize_t int
+#   define OSSL_SSIZE_MAX INT_MAX
+#  else
+#   define ossl_ssize_t ssize_t
+#   define OSSL_SSIZE_MAX SSIZE_MAX
+#  endif
 # endif

 # ifdef DEBUG_UNUSED


The last two defines only serve to provide a file and line number for
a compile error. If omitted, someone will have to go hunting for the
reason ossl_ssize_t and OSSL_SSIZE_MAX are not defined. When
ossl_ssize_t and OSSL_SSIZE_MAX defined, it will point to the file and
line number of the offenders ssize_t and SSIZE_MAX.

+#   define ossl_ssize_t ssize_t
+#   define OSSL_SSIZE_MAX SSIZE_MAX

**********

$ grep -IR ossl_ssize_t * | egrep '(typedef|define)'
include/openssl/e_os2.h:#   define ossl_ssize_t __int64
include/openssl/e_os2.h:#   define ossl_ssize_t int
include/openssl/e_os2.h:#  define ossl_ssize_t int
include/openssl/e_os2.h:#  define ossl_ssize_t ssize_t
ms/uplink.h:#define UP_read   (*(ossl_ssize_t (*)(int,void
*,size_t))OPENSSL_UplinkTable[APPLINK_READ])
ms/uplink.h:#define UP_write  (*(ossl_ssize_t (*)(int,const void
*,size_t))OPENSSL_UplinkTable[APPLINK_WRITE])


More information about the openssl-dev mailing list