1230429Skib/* 2230429Skib * Copyright (c) 2011 Konstantin Belousov <kib@FreeBSD.org> 3230429Skib * All rights reserved. 4230429Skib * 5230429Skib * Redistribution and use in source and binary forms, with or without 6230429Skib * modification, are permitted provided that the following conditions 7230429Skib * are met: 8230429Skib * 9230429Skib * 1. Redistributions of source code must retain the above copyright 10230429Skib * notice, this list of conditions and the following disclaimer. 11230429Skib * 2. Redistributions in binary form must reproduce the above copyright 12230429Skib * notice, this list of conditions and the following disclaimer in the 13230429Skib * documentation and/or other materials provided with the distribution. 14230429Skib * 15230429Skib * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16230429Skib * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17230429Skib * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18230429Skib * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19230429Skib * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20230429Skib * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21230429Skib * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22230429Skib * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23230429Skib * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24230429Skib * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25230429Skib */ 26230429Skib 27230429Skib#include <sys/cdefs.h> 28230429Skib__FBSDID("$FreeBSD$"); 29230429Skib 30230429Skib#include <sys/types.h> 31230429Skib#include <sys/ucontext.h> 32230429Skib#include <errno.h> 33230429Skib#include <stdlib.h> 34230429Skib 35231981Skibint 36230429Skib__getcontextx_size(void) 37230429Skib{ 38230429Skib 39230429Skib return (sizeof(ucontext_t)); 40230429Skib} 41230429Skib 42230429Skibint 43251365Skib__fillcontextx2(char *ctx) 44251365Skib{ 45251365Skib 46251365Skib return (0); 47251365Skib} 48251365Skib 49251365Skibint 50230429Skib__fillcontextx(char *ctx) 51230429Skib{ 52230429Skib ucontext_t *ucp; 53230429Skib 54230429Skib ucp = (ucontext_t *)ctx; 55230429Skib return (getcontext(ucp)); 56230429Skib} 57230429Skib 58230429Skib__weak_reference(__getcontextx, getcontextx); 59230429Skib 60230429Skibucontext_t * 61230429Skib__getcontextx(void) 62230429Skib{ 63230429Skib char *ctx; 64230429Skib int error; 65230429Skib 66230429Skib ctx = malloc(__getcontextx_size()); 67230429Skib if (ctx == NULL) 68230429Skib return (NULL); 69230429Skib if (__fillcontextx(ctx) == -1) { 70230429Skib error = errno; 71230429Skib free(ctx); 72230429Skib errno = error; 73230429Skib return (NULL); 74230429Skib } 75230429Skib return ((ucontext_t *)ctx); 76230429Skib} 77