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

2016-03-28 Thread Salz, Rich
> > Is this a real problem or a theoretical one?
> 
> UEFI will be a problem on non 32-bit systems as it assume 32-bit
> environment. I don't know if there are any of them in the wild, however.

Okay, theoretical.  I assume the UEFI folks, who are VERY active here, will let 
us know.
 
> non-UEFI code is a problem in some restricted environments, like ANSI.
> It will affect 32-bit and 64-bit code.

I repeat my question.  Does it break in -ansi?  
-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev


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

2016-03-27 Thread Jeffrey Walton
> # if defined(OPENSSL_SYS_UEFI) && !defined(ssize_t) #  define ossl_ssize_t
> int #  define OSSL_SSIZE_MAX INT_MAX # endif
>
> It's testing for a #define, not a typedef.
>
>
> Then I suppose this comes down to understanding precisely what the test is
> trying to achieve. Do you mean it's explicitly checking for ssize_t being a
> macro rather than the usual typedef? Does OpenSSL create it as a macro
> somewhere?

If I am parsing things correctly (in the big picture), ossl_ssize_t
and OSSL_SSIZE_MAX are trying to bootstrap themselves. If ssize_t and
SSIZE_MAX are available, ossl_ssize_t and OSSL_SSIZE_MAX should set
themselves to existing types and define. Otherwise, ossl_ssize_t and
OSSL_SSIZE_MAX provide their own definition.

I think that's what's trying to be achieved.

I can kinda understand the "if defined(ossl_ssize_t)". However, the
base case - the first time its encountered undefined - may be missing
the point.

> POSIX requires ssize_t to be a type rather than a macro, defined in
>  among other places. I don't know it there are non-POSIX or
> vaguely-similar-to-POSIX environments which define it as a macro.

Its those non-Posix environments the pain point is experienced. ANSI
is one of them. That's because the bootstrapping isn't quite right.
I've also seem some interesting results on Android.

The test rig is simple enough. It seems some of the older environments
(maybe the newer ones too) don't undef SSIZE_MAX; rather, they set it
to 0.

Jeff

$ cat test.cc
#include 
#include 
#include 

/* gcc -x c -ansi test.cc -o test.exe */
int main(void)
{
#if defined(SSIZE_MAX) && (SSIZE_MAX != 0)
  #define my_ssize_t ssize_t
  #define MY_SSIZE_MAX SSIZE_MAX
  printf("SSIZE_MAX is defined, using ssize_t\n");
  my_ssize_t t = MY_SSIZE_MAX;
#else /* not SSIZE_MAX */
# if (__LP64__)
  #define my_ssize_t long
  #define MY_SSIZE_MAX LONG_MAX
  printf("SSIZE_MAX not defined, typing ssize_t to long\n");
  my_ssize_t t = MY_SSIZE_MAX;
# else
  #define my_ssize_t int
  #define MY_SSIZE_MAX INT_MAX
  printf("SSIZE_MAX not defined, typing ssize_t to int\n");
  my_ssize_t t = MY_SSIZE_MAX;
# endif
#endif /* SSIZE_MAX */
  return 0;
}

**
i686 without -ansi:

$ ./test.exe
SSIZE_MAX is defined, using ssize_t

i686 with -ansi:

$ ./test.exe
SSIZE_MAX not defined, typing ssize_t to int

x86_64 without -ansi:

$ ./test.exe
SSIZE_MAX is defined, using ssize_t

x86_64 with -ansi:

$ ./test.exe
SSIZE_MAX not defined, typing ssize_t to long
-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev


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

2016-03-27 Thread Jeffrey Walton
On Sun, Mar 27, 2016 at 10:41 AM, Salz, Rich  wrote:
> Is this a real problem or a theoretical one?

UEFI will be a problem on non 32-bit systems as it assume 32-bit
environment. I don't know if there are any of them in the wild,
however.

non-UEFI code is a problem in some restricted environments, like ANSI.
It will affect 32-bit and 64-bit code.

I believe "defined(ossl_sszie_t)" may be missing the point for the
non-UEFI code.

Both are easy enough to fix once we know what to look for.

Jeff
-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev


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

2016-03-27 Thread Jeremy Farrell

On 27/03/2016 14:59, Salz, Rich wrote:



# if defined(OPENSSL_SYS_UEFI) && !defined(ssize_t) #  define ossl_ssize_t
int #  define OSSL_SSIZE_MAX INT_MAX # endif

It's testing for a #define, not a typedef.


Then I suppose this comes down to understanding precisely what the test 
is trying to achieve. Do you mean it's explicitly checking for ssize_t 
being a macro rather than the usual typedef? Does OpenSSL create it as a 
macro somewhere?


POSIX requires ssize_t to be a type rather than a macro, defined in 
 among other places. I don't know it there are non-POSIX or 
vaguely-similar-to-POSIX environments which define it as a macro.


--
J. J. Farrell
Not speaking for Oracle.

-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev


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

2016-03-27 Thread Salz, Rich
Is this a real problem or a theoretical one?
-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev


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

2016-03-27 Thread Salz, Rich

> # if defined(OPENSSL_SYS_UEFI) && !defined(ssize_t) #  define ossl_ssize_t
> int #  define OSSL_SSIZE_MAX INT_MAX # endif

It's testing for a #define, not a typedef.

-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev


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

2016-03-27 Thread Jeffrey Walton
>> noloader> I don't believe you can test for a type by using 'defined(t)'. Also
>> noloader> see 
>> http://stackoverflow.com/questions/12558538/how-can-i-check-a-certain-type-is-already-defined-in-c-compiler.
>>
>> ... unless it's defined with a macro
>
> Yeah, I kind of knew about that. But a type like ssize_t defined with
> a typedef won't pass that test. It will degenerate into:
>
>#if defined(OPENSSL_SYS_UEFI) && /*TRUE*/
>  ...
>#endif
>
> That brings up the thing I was wondering about. I followed the pattern
> in my diffs, but did not feel it was quite right (I might be missing
> something obvious)... Why isn't ossl_ssize_t a typedef?

I'm not finding a compelling reason to define something that's usually
typedef'd. Also see
http://programmers.stackexchange.com/questions/130679/typedefs-and-defines
and 
http://stackoverflow.com/questions/1666353/are-typedef-and-define-the-same-in-c.

Does anyone know why things are done that way?

Jeff
-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev


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

2016-03-26 Thread Jeffrey Walton
On Sat, Mar 26, 2016 at 11:10 PM, Richard Levitte  wrote:
> In message 
>  on Sat, 
> 26 Mar 2016 18:14:05 -0400, Jeffrey Walton  said:
>
> noloader> e_os2.h has this around line 260:
> noloader>
> noloader> # if defined(OPENSSL_SYS_UEFI) && !defined(ssize_t)
> noloader> #  define ossl_ssize_t int
> noloader> #  define OSSL_SSIZE_MAX INT_MAX
> noloader> # endif
> noloader>
> noloader> I don't believe you can test for a type by using 'defined(t)'. Also
> noloader> see 
> http://stackoverflow.com/questions/12558538/how-can-i-check-a-certain-type-is-already-defined-in-c-compiler.
>
> ... unless it's defined with a macro

Yeah, I kind of knew about that. But a type like ssize_t defined with
a typedef won't pass that test. It will degenerate into:

   #if defined(OPENSSL_SYS_UEFI) && /*TRUE*/
 ...
   #endif

That brings up the thing I was wondering about. I followed the pattern
in my diffs, but did not feel it was quite right (I might be missing
something obvious)... Why isn't ossl_ssize_t a typedef?

Jeff
-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev


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

2016-03-26 Thread Richard Levitte
In message 
 on Sat, 
26 Mar 2016 18:14:05 -0400, Jeffrey Walton  said:

noloader> e_os2.h has this around line 260:
noloader> 
noloader> # if defined(OPENSSL_SYS_UEFI) && !defined(ssize_t)
noloader> #  define ossl_ssize_t int
noloader> #  define OSSL_SSIZE_MAX INT_MAX
noloader> # endif
noloader> 
noloader> I don't believe you can test for a type by using 'defined(t)'. Also
noloader> see 
http://stackoverflow.com/questions/12558538/how-can-i-check-a-certain-type-is-already-defined-in-c-compiler.

... unless it's defined with a macro

-- 
Richard Levitte levi...@openssl.org
OpenSSL Project http://www.openssl.org/~levitte/


-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev


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

2016-03-26 Thread Jeffrey Walton
On Sat, Mar 26, 2016 at 6:44 PM, Viktor Dukhovni
 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])
-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev


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

2016-03-26 Thread Viktor Dukhovni
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.

-- 
Viktor.
-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev


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

2016-03-26 Thread Jeffrey Walton
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.

Jeff
-- 
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev