/* state.c -- Create the backtrace state.1Copyright (C) 2012-2021 Free Software Foundation, Inc.2Written by Ian Lance Taylor, Google.34Redistribution and use in source and binary forms, with or without5modification, are permitted provided that the following conditions are6met:78(1) Redistributions of source code must retain the above copyright9notice, this list of conditions and the following disclaimer.1011(2) Redistributions in binary form must reproduce the above copyright12notice, this list of conditions and the following disclaimer in13the documentation and/or other materials provided with the14distribution.1516(3) The name of the author may not be used to17endorse or promote products derived from this software without18specific prior written permission.1920THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR21IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED22WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE23DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,24INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES25(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR26SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,28STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING29IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE30POSSIBILITY OF SUCH DAMAGE. */3132#include "config.h"3334#include <string.h>35#include <sys/types.h>3637#include "backtrace.h"38#include "backtrace-supported.h"39#include "internal.h"4041/* Create the backtrace state. This will then be passed to all the42other routines. */4344struct backtrace_state *45backtrace_create_state (const char *filename, int threaded,46backtrace_error_callback error_callback,47void *data)48{49struct backtrace_state init_state;50struct backtrace_state *state;5152#ifndef HAVE_SYNC_FUNCTIONS53if (threaded)54{55error_callback (data, "backtrace library does not support threads", 0);56return NULL;57}58#endif5960memset (&init_state, 0, sizeof init_state);61init_state.filename = filename;62init_state.threaded = threaded;6364state = ((struct backtrace_state *)65backtrace_alloc (&init_state, sizeof *state, error_callback, data));66if (state == NULL)67return NULL;68*state = init_state;6970return state;71}727374