On Tue, May 10, 2005 at 09:38:37AM +0100, Nicholas Clark wrote:
> On Mon, May 09, 2005 at 09:10:49PM -0500, Steve Peters wrote:
> 
> > The attached patch initializes the structs with a memzero() prior to 
> > calling getprotobyname_r() and getservbyname_r().  These changes have 
> > been tested and clear up the issues on OpenBSD.  
> > 
> > Steve Peters
> > [EMAIL PROTECTED] 
> 
> > --- reentr.h.old    Wed Apr  6 10:39:35 2005
> > +++ reentr.h        Mon May  9 19:25:26 2005
> 
> I don't think that you want to do that there:
> 
> /*
>  *    reentr.h
>  *
>  *    Copyright (C) 2002, 2003, by Larry Wall and others
>  *
>  *    You may distribute under the terms of either the GNU General Public
>  *    License or the Artistic License, as specified in the README file.
>  *
>  *  !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
>  *  This file is built by reentr.pl from data in reentr.pl.
>  */
> 

Gak!  Attached are changes to reentr.pl then.  The changes there let me 
do a few things there probably better than the previous patch.  The changes
include

* A new macro for reentr.h, REENTR_MEMZERO, that only defines the C<memzero()>
processing for OpenBSD.
* memzero processing added to all reentrant functions that could be effected by
this issues on OpenBSD (i.e. I don't want to fix this for every OpenBSD
release where a reentrant function is "fixed").
* Since this incompatibility affects all previous Perl releases on OpenBSD, I
added a README.openbsd to document this problem.
* Bumped copyright dates on reentr.h.

Steve Peters
[EMAIL PROTECTED]
--- /dev/null   Tue May 10 12:42:56 2005
+++ README.openbsd      Tue May 10 12:42:49 2005
@@ -0,0 +1,30 @@
+If you read this file _as_is_, just ignore the funny characters you
+see.  It is written in the POD format (see pod/perlpod.pod) which is
+specifically designed to be readable as is.
+
+=head1 NAME
+
+README.openbsd - Perl version 5 on OpenBSD systems
+
+=head1 DESCRIPTION
+
+This document describes various features of OpenBSD that will affect how Perl
+version 5 (hereafter just Perl) is compiled and/or runs.
+
+=head2 OpenBSD core dumps from getprotobyname_r and getservbyname_r with 
ithreads
+
+When Perl is configured to use ithreads, it will use re-entrant library calls
+in preference to non-re-entrant versions.  There is an incompatability in
+OpenBSD's C<getprotobyname_r> and C<getservbyname_r> function in versions 3.7
+and later that will cause a SEGV when called without doing a C<bzero> on
+their return structs prior to calling these functions.  Current Perl's
+should handle this problem correctly.  Older threaded Perls (5.8.6 or earlier)
+will run into this problem.  If you want to run a threaded Perl on OpenBSD
+3.7 or higher, you will need to upgrade to at least Perl 5.8.7.
+
+=head1 AUTHOR
+
+Steve Peters <[EMAIL PROTECTED]>
+
+Please report any errors, updates, or suggestions to F<[EMAIL PROTECTED]>.
+
--- reentr.pl.old       Thu Apr 21 11:05:31 2005
+++ reentr.pl   Tue May 10 11:26:12 2005
@@ -41,7 +41,7 @@
 /*
  *    reentr.h
  *
- *    Copyright (C) 2002, 2003, by Larry Wall and others
+ *    Copyright (C) 2002, 2003, 2005 by Larry Wall and others
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -80,6 +80,17 @@
 #   define NETDB_R_OBSOLETE
 #endif
 
+/*
+ * As of OpenBSD 3.7, reentrant functions are now working, they just are
+ * incompatible with everyone else.  To make OpenBSD happy, we have to
+ * memzero out certain structures before calling the functions.
+ */
+#if defined(__OpenBSD__)
+#    define REENTR_MEMZERO(a,b) memzero(a,b),
+#else
+#    define REENTR_MEMZERO(a,b)
+#endif 
+
 #ifdef NETDB_R_OBSOLETE
 #   undef HAS_ENDHOSTENT_R
 #   undef HAS_ENDNETENT_R
@@ -679,6 +690,13 @@
                $w = ", $w" if length $v;
            }
            my $call = "${func}_r($v$w)";
+
+            # Must make OpenBSD happy
+            my $memzero = '';
+            if($p =~ /D$/ &&
+                ($genfunc eq 'protoent' || $genfunc eq 'servent')) {
+                $memzero = 'REENTR_MEMZERO(&PL_reentrant_buffer->_' . $genfunc 
. '_data, sizeof(PL_reentrant_buffer->_' . $genfunc . '_data))';
+            }
            push @wrap, <<EOF;
 #   if !defined($func) && ${FUNC}_R_PROTO == REENTRANT_PROTO_$p
 EOF
@@ -691,7 +709,7 @@
                    my $rv = $v ? ", $v" : "";
                    if ($r eq 'I') {
                        push @wrap, <<EOF;
-#       define $func($v) ((PL_reentrant_retint = $call)$test ? $true : 
(((PL_reentrant_retint == ERANGE) || (errno == ERANGE)) ? ($seent{$func} *) 
Perl_reentrant_retry("$func"$rv) : 0))
+#       define $func($v) ($memzero(PL_reentrant_retint = $call)$test ? $true : 
(((PL_reentrant_retint == ERANGE) || (errno == ERANGE)) ? ($seent{$func} *) 
Perl_reentrant_retry("$func"$rv) : 0))
 EOF
                    } else {
                        push @wrap, <<EOF;

Reply via email to