1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24  */
  25 /*
  26  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  27  * Use is subject to license terms.
  28  */
  29 
  30 #pragma weak __fex_get_handling = fex_get_handling
  31 #pragma weak __fex_set_handling = fex_set_handling
  32 #pragma weak __fex_getexcepthandler = fex_getexcepthandler
  33 #pragma weak __fex_setexcepthandler = fex_setexcepthandler
  34 
  35 #include <fenv.h>
  36 #include <ucontext.h>
  37 #include <thread.h>
  38 #include "fex_handler.h"
  39 
  40 int fex_get_handling(int e)
  41 {
  42         struct fex_handler_data *thr_handlers;
  43         int                                             i;
  44 
  45         thr_handlers = __fex_get_thr_handlers();
  46         for (i = 0; i < FEX_NUM_EXC; i++)
  47                 if (e & (1 << i))
  48                         return thr_handlers[i].__mode;
  49         return FEX_NOHANDLER;
  50 }
  51 
  52 int fex_set_handling(int e, int mode, void (*handler)())
  53 {
  54         struct fex_handler_data *thr_handlers;
  55         int                                             i;
  56 
  57         if (e & ~((1 << FEX_NUM_EXC) - 1))
  58                 return 0;
  59         thr_handlers = __fex_get_thr_handlers();
  60         for (i = 0; i < FEX_NUM_EXC; i++) {
  61                 if (e & (1 << i)) {
  62                         thr_handlers[i].__mode = mode;
  63                         thr_handlers[i].__handler = handler;
  64                 }
  65         }
  66         __fex_update_te();
  67         return 1;
  68 }
  69 
  70 void fex_getexcepthandler(fex_handler_t *buf, int e)
  71 {
  72         struct fex_handler_data *thr_handlers;
  73         int                                             i;
  74 
  75         thr_handlers = __fex_get_thr_handlers();
  76         for (i = 0; i < FEX_NUM_EXC; i++)
  77                 if (e & (1 << i))
  78                         (*buf)[i] = thr_handlers[i];
  79 }
  80 
  81 void fex_setexcepthandler(const fex_handler_t *buf, int e)
  82 {
  83         struct fex_handler_data *thr_handlers;
  84         int                                             i;
  85 
  86         thr_handlers = __fex_get_thr_handlers();
  87         for (i = 0; i < FEX_NUM_EXC; i++)
  88                 if (e & (1 << i))
  89                         thr_handlers[i] = (*buf)[i];
  90         __fex_update_te();
  91 }