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_synonyms.h" 36 #include <fenv.h> 37 #include <ucontext.h> 38 #include <thread.h> 39 #include "fex_handler.h" 40 41 int fex_get_handling(int e) 42 { 43 struct fex_handler_data *thr_handlers; 44 int i; 45 46 thr_handlers = __fex_get_thr_handlers(); 47 for (i = 0; i < FEX_NUM_EXC; i++) 48 if (e & (1 << i)) 49 return thr_handlers[i].__mode; 50 return FEX_NOHANDLER; 51 } 52 53 int fex_set_handling(int e, int mode, void (*handler)()) 54 { 55 struct fex_handler_data *thr_handlers; 56 int i; 57 58 if (e & ~((1 << FEX_NUM_EXC) - 1)) 59 return 0; 60 thr_handlers = __fex_get_thr_handlers(); 61 for (i = 0; i < FEX_NUM_EXC; i++) { 62 if (e & (1 << i)) { 63 thr_handlers[i].__mode = mode; 64 thr_handlers[i].__handler = handler; 65 } 66 } 67 __fex_update_te(); 68 return 1; 69 } 70 71 void fex_getexcepthandler(fex_handler_t *buf, int e) 72 { 73 struct fex_handler_data *thr_handlers; 74 int i; 75 76 thr_handlers = __fex_get_thr_handlers(); 77 for (i = 0; i < FEX_NUM_EXC; i++) 78 if (e & (1 << i)) 79 (*buf)[i] = thr_handlers[i]; 80 } 81 82 void fex_setexcepthandler(const fex_handler_t *buf, int e) 83 { 84 struct fex_handler_data *thr_handlers; 85 int i; 86 87 thr_handlers = __fex_get_thr_handlers(); 88 for (i = 0; i < FEX_NUM_EXC; i++) 89 if (e & (1 << i)) 90 thr_handlers[i] = (*buf)[i]; 91 __fex_update_te(); 92 }