ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libcoro/coro.h
(Generate patch)

Comparing libcoro/coro.h (file contents):
Revision 1.52 by root, Fri Dec 7 14:21:09 2012 UTC vs.
Revision 1.59 by root, Fri Nov 18 05:45:00 2016 UTC

1/* 1/*
2 * Copyright (c) 2001-2012 Marc Alexander Lehmann <schmorp@schmorp.de> 2 * Copyright (c) 2001-2012,2015 Marc Alexander Lehmann <schmorp@schmorp.de>
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without modifica- 4 * Redistribution and use in source and binary forms, with or without modifica-
5 * tion, are permitted provided that the following conditions are met: 5 * tion, are permitted provided that the following conditions are met:
6 * 6 *
7 * 1. Redistributions of source code must retain the above copyright notice, 7 * 1. Redistributions of source code must retain the above copyright notice,
76 * 2011-07-03 rely on __GCC_HAVE_DWARF2_CFI_ASM for cfi detection. 76 * 2011-07-03 rely on __GCC_HAVE_DWARF2_CFI_ASM for cfi detection.
77 * 2011-08-08 cygwin trashes stacks, use pthreads with double stack on cygwin. 77 * 2011-08-08 cygwin trashes stacks, use pthreads with double stack on cygwin.
78 * 2012-12-04 reduce misprediction penalty for x86/amd64 assembly switcher. 78 * 2012-12-04 reduce misprediction penalty for x86/amd64 assembly switcher.
79 * 2012-12-05 experimental fiber backend (allocates stack twice). 79 * 2012-12-05 experimental fiber backend (allocates stack twice).
80 * 2012-12-07 API version 3 - add coro_stack_alloc/coro_stack_free. 80 * 2012-12-07 API version 3 - add coro_stack_alloc/coro_stack_free.
81 * 2012-12-21 valgrind stack registering was broken.
82 * 2015-12-05 experimental asm be for arm7, based on a patch by Nick Zavaritsky.
83 * use __name__ for predefined symbols, as in libecb.
84 * enable guard pages on arm, aarch64 and mips.
85 * 2016-08-27 try to disable _FORTIFY_SOURCE with CORO_SJLJ, as it
86 * breaks setjmp/longjmp. Also disable CORO_ASM for asm by default,
87 * as it was reported to crash.
88 * 2016-11-18 experimental fix for gcc 6 on amd64 (missing cfi_startproc).
81 */ 89 */
82 90
83#ifndef CORO_H 91#ifndef CORO_H
84#define CORO_H 92#define CORO_H
85 93
137 * For SGI's version of Microsoft's NT ;) 145 * For SGI's version of Microsoft's NT ;)
138 * 146 *
139 * -DCORO_ASM 147 * -DCORO_ASM
140 * 148 *
141 * Hand coded assembly, known to work only on a few architectures/ABI: 149 * Hand coded assembly, known to work only on a few architectures/ABI:
142 * GCC + x86/IA32 and amd64/x86_64 + GNU/Linux and a few BSDs. Fastest choice, 150 * GCC + arm7/x86/IA32/amd64/x86_64 + GNU/Linux and a few BSDs. Fastest
143 * if it works. 151 * choice, if it works.
144 * 152 *
145 * -DCORO_PTHREAD 153 * -DCORO_PTHREAD
146 * 154 *
147 * Use the pthread API. You have to provide <pthread.h> and -lpthread. 155 * Use the pthread API. You have to provide <pthread.h> and -lpthread.
148 * This is likely the slowest backend, and it also does not support fork(), 156 * This is likely the slowest backend, and it also does not support fork(),
296 304
297#if !defined CORO_LOSER && !defined CORO_UCONTEXT \ 305#if !defined CORO_LOSER && !defined CORO_UCONTEXT \
298 && !defined CORO_SJLJ && !defined CORO_LINUX \ 306 && !defined CORO_SJLJ && !defined CORO_LINUX \
299 && !defined CORO_IRIX && !defined CORO_ASM \ 307 && !defined CORO_IRIX && !defined CORO_ASM \
300 && !defined CORO_PTHREAD && !defined CORO_FIBER 308 && !defined CORO_PTHREAD && !defined CORO_FIBER
301# if defined WINDOWS && (defined __x86 || defined __amd64 || defined _M_IX86 || defined _M_AMD64) 309# if defined WINDOWS && (defined __i386__ || (__x86_64__ || defined _M_IX86 || defined _M_AMD64)
302# define CORO_ASM 1 310# define CORO_ASM 1
303# elif defined WINDOWS || defined _WIN32 311# elif defined WINDOWS || defined _WIN32
304# define CORO_LOSER 1 /* you don't win with windoze */ 312# define CORO_LOSER 1 /* you don't win with windoze */
305# elif defined __linux && (defined __x86 || defined __amd64) 313# elif __linux && (__i386__ || (__x86_64__ && !__ILP32__) /*|| (__arm__ && __ARM_ARCH == 7)), not working */
306# define CORO_ASM 1 314# define CORO_ASM 1
307# elif defined HAVE_UCONTEXT_H 315# elif defined HAVE_UCONTEXT_H
308# define CORO_UCONTEXT 1 316# define CORO_UCONTEXT 1
309# elif defined HAVE_SETJMP_H && defined HAVE_SIGALTSTACK 317# elif defined HAVE_SETJMP_H && defined HAVE_SIGALTSTACK
310# define CORO_SJLJ 1 318# define CORO_SJLJ 1
329 337
330#elif CORO_SJLJ || CORO_LOSER || CORO_LINUX || CORO_IRIX 338#elif CORO_SJLJ || CORO_LOSER || CORO_LINUX || CORO_IRIX
331 339
332# if defined(CORO_LINUX) && !defined(_GNU_SOURCE) 340# if defined(CORO_LINUX) && !defined(_GNU_SOURCE)
333# define _GNU_SOURCE /* for glibc */ 341# define _GNU_SOURCE /* for glibc */
342# endif
343
344/* try to disable well-meant but buggy checks in some libcs */
345# ifdef _FORTIFY_SOURCE
346# undef _FORTIFY_SOURCE
347# undef __USE_FORTIFY_LEVEL /* helps some more when too much has been included already */
334# endif 348# endif
335 349
336# if !CORO_LOSER 350# if !CORO_LOSER
337# include <unistd.h> 351# include <unistd.h>
338# endif 352# endif
372struct coro_context 386struct coro_context
373{ 387{
374 void **sp; /* must be at offset 0 */ 388 void **sp; /* must be at offset 0 */
375}; 389};
376 390
391#if __i386__ || __x86_64__
377void __attribute__ ((__noinline__, __regparm__(2))) 392void __attribute__ ((__noinline__, __regparm__(2)))
393#else
394void __attribute__ ((__noinline__))
395#endif
378coro_transfer (coro_context *prev, coro_context *next); 396coro_transfer (coro_context *prev, coro_context *next);
379 397
380# define coro_destroy(ctx) (void *)(ctx) 398# define coro_destroy(ctx) (void *)(ctx)
381 399
382#elif CORO_PTHREAD 400#elif CORO_PTHREAD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines