Bug#788102: The code doesn't compile on kfreebsd

2016-02-23 Thread Steven Chamberlain
Mathieu Malaterre wrote:
> Thanks a lot for the update. Could you send me the actual full debdiff
> you used. Here is what I get from fall.d.o when I use your patch:
> 
> [...]
> IexMathFpu.cpp: In function 'void
> Iex_2_2::setFpExceptionHandler(Iex_2_2::FpExceptionHandler)':
> IexMathFpu.cpp:482:9: error: 'struct sigaction' has no member named
> 'sa_restorer'
>   action.sa_restorer = 0;
>  ^
> [...]

Sorry, I forgot about that part.  sa_restorer is not used on kfreebsd so
I guarded that with ifdefs.  Attached is a diff against 2.2.0-9 of what
I actually tested.

Thanks!
Regards,
-- 
Steven Chamberlain
ste...@pyro.eu.org
--- a/IexMath/IexMathFpu.cpp
+++ b/IexMath/IexMathFpu.cpp
@@ -52,7 +52,7 @@
 #define debug(x)
 #endif
 
-#if defined(HAVE_UCONTEXT_H) && (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)) && (defined(ILMBASE_HAVE_CONTROL_REGISTER_SUPPORT) || defined(HAVE_ASM_SIGCONTEXT_H))
+#if defined(HAVE_UCONTEXT_H) && (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86))
 
 #include 
 #include 
@@ -264,6 +264,18 @@
 setMxcsr (ucon.uc_mcontext.fpregs->mxcsr, clearExceptions);
 }
 
+#elif defined(__FreeBSD_kernel__)
+
+#include 
+
+inline void
+restoreControlRegs (const ucontext_t & ucon, bool clearExceptions)
+{
+struct envxmm *ex = (struct envxmm *)(ucon.uc_mcontext.mc_fpstate);
+setCw ((ex->en_cw & cwRestoreMask) | cwRestoreVal);
+setMxcsr (ex->en_mxcsr, clearExceptions);
+}
+
 #else
 
 //
@@ -463,8 +475,9 @@
 	sigemptyset (_mask);
 	action.sa_flags = SA_SIGINFO | SA_NOMASK;
 	action.sa_sigaction = (void (*) (int, siginfo_t *, void *)) catchSigFpe;
+#ifndef __FreeBSD_kernel__
 	action.sa_restorer = 0;
-
+#endif
 	sigaction (SIGFPE, , 0);
 }
 


signature.asc
Description: Digital signature


Bug#788102: The code doesn't compile on kfreebsd

2016-02-23 Thread Mathieu Malaterre
On Tue, Feb 23, 2016 at 5:17 AM, Steven Chamberlain  wrote:
> Hi,
>
> Mathieu Malaterre wrote:
>> Steven Chamberlain  wrote:
>> > Gianfranco Costamagna wrote:
>> >> file.c:5:38: error: ‘mcontext_t’ has no member named ‘fpregs’
>> >> uint32_t mxcsr = ucon.uc_mcontext.fpregs->mxcsr;
>> >
>> > FreeBSD doesn't seem to have fpregs in mcontext_t or sigcontext.
>> > But I think mc_fpstate might be the same thing;  but that isn't
>> > implemented as a struct...
>>
>> Correct. Looks like other are handling it this way also
>> https://github.com/fukamachi/clozure-cl/blob/master/level-1/x86-trap-support.lisp
>
> For future reference, I came up with this alternate implementation of
> restoreControlRegs() for kFreeBSD (untested, except it builds and passes
> the testsuite):
>
> #include 
>
> inline void
> restoreControlRegs (const ucontext_t & ucon, bool clearExceptions)
> {
> struct envxmm *ex = (struct envxmm *)(ucon.uc_mcontext.mc_fpstate);
> setCw ((ex->en_cw & cwRestoreMask) | cwRestoreVal);
> setMxcsr (ex->en_mxcsr, clearExceptions);
> }


Thanks a lot for the update. Could you send me the actual full debdiff
you used. Here is what I get from fall.d.o when I use your patch:

[...]
IexMathFpu.cpp: In function 'void
Iex_2_2::setFpExceptionHandler(Iex_2_2::FpExceptionHandler)':
IexMathFpu.cpp:482:9: error: 'struct sigaction' has no member named
'sa_restorer'
  action.sa_restorer = 0;
 ^
[...]



Bug#788102: The code doesn't compile on kfreebsd

2016-02-22 Thread Steven Chamberlain
Hi,

Mathieu Malaterre wrote:
> Steven Chamberlain  wrote:
> > Gianfranco Costamagna wrote:
> >> file.c:5:38: error: ‘mcontext_t’ has no member named ‘fpregs’
> >> uint32_t mxcsr = ucon.uc_mcontext.fpregs->mxcsr;
> >
> > FreeBSD doesn't seem to have fpregs in mcontext_t or sigcontext.
> > But I think mc_fpstate might be the same thing;  but that isn't
> > implemented as a struct...
> 
> Correct. Looks like other are handling it this way also
> https://github.com/fukamachi/clozure-cl/blob/master/level-1/x86-trap-support.lisp

For future reference, I came up with this alternate implementation of
restoreControlRegs() for kFreeBSD (untested, except it builds and passes
the testsuite):

#include 

inline void
restoreControlRegs (const ucontext_t & ucon, bool clearExceptions)
{
struct envxmm *ex = (struct envxmm *)(ucon.uc_mcontext.mc_fpstate);
setCw ((ex->en_cw & cwRestoreMask) | cwRestoreVal);
setMxcsr (ex->en_mxcsr, clearExceptions);
}

Regards,
-- 
Steven Chamberlain
ste...@pyro.eu.org


signature.asc
Description: Digital signature


Bug#788102: The code doesn't compile on kfreebsd

2015-09-15 Thread Mathieu Malaterre
Steven,

On Wed, Jul 22, 2015 at 6:55 PM, Steven Chamberlain  wrote:
> Hello,
>
> Gianfranco Costamagna wrote:
>> file.c:5:38: error: ‘mcontext_t’ has no member named ‘fpregs’
>> uint32_t mxcsr = ucon.uc_mcontext.fpregs->mxcsr;
>
> FreeBSD doesn't seem to have fpregs in mcontext_t or sigcontext.
> But I think mc_fpstate might be the same thing;  but that isn't
> implemented as a struct...
>
>> typedef struct
>>   {
> ...
>> int mc_fpstate[128] __attribute__((aligned(16)));
>> int mc_spare2[8];
>>   } mcontext_t;
>
> I see that FreeBSD Ports has ilmbase-2.20 and succeeded building
> libIexMath, yet they don't seem to have patched this source file.
> I should try building it on a real FreeBSD system, to compare the
> build log with that of a GNU/kFreeBSD system.

We've just tested here. None of the code path in ilmbase compile with
a kFreeBSD distribution. Since FreeBSD uses a cmake based build:

https://svnweb.freebsd.org/ports/head/graphics/ilmbase/

we know for sure that the following function *does* compile on a real
FreeBSD system:

https://github.com/openexr/openexr/blob/master/IlmBase/IexMath/IexMathFpu.cpp#L260

[...]
inline void
restoreControlRegs (const ucontext_t & ucon, bool clearExceptions)
{
setCw ((ucon.uc_mcontext.fpregs->cwd & cwRestoreMask) | cwRestoreVal);
setMxcsr (ucon.uc_mcontext.fpregs->mxcsr, clearExceptions);
}
[...]

So kFreeBSD and FreeBSD do not use the same libc (where ucontext.h is provided).



Bug#788102: The code doesn't compile on kfreebsd

2015-09-14 Thread Mathieu Malaterre
On Wed, Jul 22, 2015 at 6:55 PM, Steven Chamberlain  wrote:
> Hello,
>
> Gianfranco Costamagna wrote:
>> file.c:5:38: error: ‘mcontext_t’ has no member named ‘fpregs’
>> uint32_t mxcsr = ucon.uc_mcontext.fpregs->mxcsr;
>
> FreeBSD doesn't seem to have fpregs in mcontext_t or sigcontext.
> But I think mc_fpstate might be the same thing;  but that isn't
> implemented as a struct...

Correct. Looks like other are handling it this way also

https://github.com/fukamachi/clozure-cl/blob/master/level-1/x86-trap-support.lisp



Bug#788102: The code doesn't compile on kfreebsd

2015-09-14 Thread Mathieu Malaterre
On Mon, Sep 14, 2015 at 2:33 PM, Mathieu Malaterre  wrote:
> On Wed, Jul 22, 2015 at 6:55 PM, Steven Chamberlain  
> wrote:
>> Hello,
>>
>> Gianfranco Costamagna wrote:
>>> file.c:5:38: error: ‘mcontext_t’ has no member named ‘fpregs’
>>> uint32_t mxcsr = ucon.uc_mcontext.fpregs->mxcsr;
>>
>> FreeBSD doesn't seem to have fpregs in mcontext_t or sigcontext.
>> But I think mc_fpstate might be the same thing;  but that isn't
>> implemented as a struct...
>
> Correct. Looks like other are handling it this way also
>
> https://github.com/fukamachi/clozure-cl/blob/master/level-1/x86-trap-support.lisp

I still fail to understand how ilmbase can compile on FreeBSD without
any patch to this particular section of code.

ref:
https://svnweb.freebsd.org/ports/head/graphics/ilmbase/files/



Bug#788102: The code doesn't compile on kfreebsd

2015-08-08 Thread Andreas Metzler
On 2015-07-22 Steven Chamberlain ste...@pyro.eu.org wrote:
[...]
 I see that FreeBSD Ports has ilmbase-2.20 and succeeded building
 libIexMath, yet they don't seem to have patched this source file.
 I should try building it on a real FreeBSD system, to compare the
 build log with that of a GNU/kFreeBSD system.

IexMath/IexMathFpu.cpp
static inline void
setCw (uint16_t cw)
{
asm volatile (fldcw %0 : : m (cw) );
}
[...]
static inline void
setMxcsr (uint32_t mxcsr, bool clearExceptions)
{
mxcsr = clearExceptions ? 0xffc0 : 0x;
asm volatile (ldmxcsr %0 : : m (mxcsr) );
}

[...]
#ifdef ILMBASE_HAVE_CONTROL_REGISTER_SUPPORT

inline void
restoreControlRegs (const ucontext_t  ucon, bool clearExceptions)
{
setCw ((ucon.uc_mcontext.fpregs-cwd  cwRestoreMask) | cwRestoreVal);
setMxcsr (ucon.uc_mcontext.fpregs-mxcsr, clearExceptions);
}

#else
[ the failing code ]

and while autoconf tests for ILMBASE_HAVE_CONTROL_REGISTER_SUPPORT
with

AC_MSG_CHECKING(for fpe support handling)
control_register_support=no
AC_TRY_COMPILE([
#include stdint.h
#include ucontext.h
],[
ucontext_t ucon;
uint32_t mxcsr = ucon.uc_mcontext.fpregs-mxcsr;
uint16_t cw= ucon.uc_mcontext.fpregs-cwd;

],
AC_DEFINE(ILMBASE_HAVE_CONTROL_REGISTER_SUPPORT) control_register_support=yes)
AC_MSG_RESULT($control_register_support)

This test fails on kfreebsd-x (and also on e.g. i386).


the respective part of the cmake setup simply looks like this:
IF (WIN32)
[...]
ELSE ()
  IF (APPLE)
[...]
  ELSE ()
FILE ( APPEND ${CMAKE_CURRENT_BINARY_DIR}/config/IlmBaseConfig.h #define 
ILMBASE_HAVE_CONTROL_REGISTER_SUPPORT 1\n)
  ENDIF ()
ENDIF ()

FreeBSD Ports uses cmake instead of autoconf (which Debian uses) and
therefore ILMBASE_HAVE_CONTROL_REGISTER_SUPPORT is #defined. 

I do not know whether
a) the autoconf test for ILMBASE_HAVE_CONTROL_REGISTER_SUPPORT is
broken and should actually succeed and kfreebsd (and any other Debian
architecture or
b) the cmake setup is broken and incorrecty enables
ILMBASE_HAVE_CONTROL_REGISTER_SUPPORT and causes broken code.

cu Andreas
-- 
`What a good friend you are to him, Dr. Maturin. His other friends are
so grateful to you.'
`I sew his ears on from time to time, sure'


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Bug#788102: The code doesn't compile on kfreebsd

2015-07-22 Thread Steven Chamberlain
Hello,

Gianfranco Costamagna wrote:
 file.c:5:38: error: ‘mcontext_t’ has no member named ‘fpregs’
 uint32_t mxcsr = ucon.uc_mcontext.fpregs-mxcsr;

FreeBSD doesn't seem to have fpregs in mcontext_t or sigcontext.
But I think mc_fpstate might be the same thing;  but that isn't
implemented as a struct...

 typedef struct
   {
...
 int mc_fpstate[128] __attribute__((aligned(16)));
 int mc_spare2[8];
   } mcontext_t;

I see that FreeBSD Ports has ilmbase-2.20 and succeeded building
libIexMath, yet they don't seem to have patched this source file.
I should try building it on a real FreeBSD system, to compare the
build log with that of a GNU/kFreeBSD system.

Regards,
-- 
Steven Chamberlain
ste...@pyro.eu.org


signature.asc
Description: Digital signature


Bug#788102: The code doesn't compile on kfreebsd

2015-07-22 Thread Gianfranco Costamagna
Hi Malat


Could someone please let me know if the following is valid on kFreeBSD ?

#include stdint.h
#include ucontext.h
int main()
ucontext_t ucon;
uint32_t mxcsr = ucon.uc_mcontext.fpregs-mxcsr;
uint16_t cw= ucon.uc_mcontext.fpregs-cwd;
}

missing {, anyway:


file.c:5:38: error: ‘mcontext_t’ has no member named ‘fpregs’
uint32_t mxcsr = ucon.uc_mcontext.fpregs-mxcsr;
^
file.c:6:35: error: ‘mcontext_t’ has no member named ‘fpregs’
uint16_t cw = ucon.uc_mcontext.fpregs-cwd;

#uname -a
GNU/kFreeBSD kfreebsd32 10.1-0-686 #0 Wed, 25 Feb 2015 12:39:32 + i386 i386 
Intel(R) Core(TM) i7-4702MQ CPU @ 2.20GHz GNU/kFreeBSD



I checked /usr/include/i386-kfreebsd-gnu/bits/mcontext.h (the content of struct 
uc_mcontext) and it is not there the fpregs variable

I'm attaching that file to this mail.

HTH

cheers,

Gianfranco
/* Machine-dependent processor state structure for FreeBSD.
   Copyright (C) 2002 Free Software Foundation, Inc.
   This file is part of the GNU C Library.  i386 version.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#if !defined _SYS_UCONTEXT_H
# error Never use bits/mcontext.h directly; include sys/ucontext.h instead.
#endif

/*-
 * Copyright (c) 1999 Marcel Moolenaar
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *notice, this list of conditions and the following disclaimer
 *in this position and unchanged.
 * 2. Redistributions in binary form must reproduce the above copyright
 *notice, this list of conditions and the following disclaimer in the
 *documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * based on $FreeBSD: src/sys/i386/include/ucontext.h,v 1.10 2002/12/02 19:58:55 deischen Exp $
 */

/* Whole processor state.  */
typedef struct
  {
/*
 * The first 20 fields must match the definition of
 * sigcontext. So that we can support sigcontext
 * and ucontext_t at the same time.
 */

int mc_onstack;		/* Nonzero if running on sigstack.  */

/* Segment registers.  */
int mc_gs;
int mc_fs;
int mc_es;
int mc_ds;

/* General registers.  These members are in the order that the i386
   `pusha' and `popa' instructions use (`popa' ignores %esp).  */
int mc_edi;
int mc_esi;
int mc_ebp;
int mc_isp;			/* Not used; sc_esp is used instead.  */
int mc_ebx;
int mc_edx;
int mc_ecx;
int mc_eax;

int mc_trapno;
int mc_err;

int mc_eip;			/* Instruction pointer.  */
int mc_cs;			/* Code segment register.  */

int mc_efl;			/* Processor flags.  */

int mc_esp;			/* This stack pointer is used.  */
int mc_ss;			/* Stack segment register.  */

int mc_len;			/* sizeof(mcontext_t) */
#define	_MC_FPFMT_NODEV		0x1	/* device not present or configured */
#define	_MC_FPFMT_387		0x10001
#define	_MC_FPFMT_XMM		0x10002
int mc_fpformat;
#define	_MC_FPOWNED_NONE	0x2	/* FP state not used */
#define	_MC_FPOWNED_FPU		0x20001	/* FP state came from FPU */
#define	_MC_FPOWNED_PCB		0x20002	/* FP state came from PCB */
int mc_ownedfp;
int mc_spare1[1];		/* align next field to 16 bytes */
/*
 * See machine/npx.h for the internals of mc_fpstate[].
 */
int mc_fpstate[128]