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 /* 27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 28 * Use is subject to license terms. 29 */ 30 31 #pragma weak __fex_get_handling = fex_get_handling 32 #pragma weak __fex_set_handling = fex_set_handling 33 #pragma weak __fex_getexcepthandler = fex_getexcepthandler 34 #pragma weak __fex_setexcepthandler = fex_setexcepthandler 35 36 #include <fenv.h> 37 #include <ucontext.h> 38 #include <thread.h> 39 #include "fex_handler.h" 40 41 int 42 fex_get_handling(int e) 43 { 44 struct fex_handler_data *thr_handlers; 45 int i; 46 47 thr_handlers = __fex_get_thr_handlers(); 48 49 for (i = 0; i < FEX_NUM_EXC; i++) 50 if (e & (1 << i)) 51 return (thr_handlers[i].__mode); 52 53 return (FEX_NOHANDLER); 54 } 55 56 int 57 fex_set_handling(int e, int mode, void (*handler)()) 58 { 59 struct fex_handler_data *thr_handlers; 60 int i; 61 62 if (e & ~((1 << FEX_NUM_EXC) - 1)) 63 return (0); 64 65 thr_handlers = __fex_get_thr_handlers(); 66 67 for (i = 0; i < FEX_NUM_EXC; i++) { 68 if (e & (1 << i)) { 69 thr_handlers[i].__mode = mode; 70 thr_handlers[i].__handler = handler; 71 } 72 } 73 74 __fex_update_te(); 75 return (1); 76 } 77 78 void 79 fex_getexcepthandler(fex_handler_t *buf, int e) 80 { 81 struct fex_handler_data *thr_handlers; 82 int i; 83 84 thr_handlers = __fex_get_thr_handlers(); 85 86 for (i = 0; i < FEX_NUM_EXC; i++) 87 if (e & (1 << i)) 88 (*buf)[i] = thr_handlers[i]; 89 } 90 91 void 92 fex_setexcepthandler(const fex_handler_t *buf, int e) 93 { 94 struct fex_handler_data *thr_handlers; 95 int i; 96 97 thr_handlers = __fex_get_thr_handlers(); 98 99 for (i = 0; i < FEX_NUM_EXC; i++) 100 if (e & (1 << i)) 101 thr_handlers[i] = (*buf)[i]; 102 103 __fex_update_te(); 104 }