From: zrj Date: Sat, 5 Oct 2019 10:04:12 +0000 (+0300) Subject: libc: Add __errno_location() for language binding benefits. X-Git-Tag: v5.8.0rc1~755 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/60d311380ff2bf02a87700a0f3e6eb53e6034920 libc: Add __errno_location() for language binding benefits. Some languages have restrictions when it comes to C style TLS handling (thread local might be feature-gated) or simply it is inconvenient to add various OS specific binding wrappers just to access C errno values. The __errno_location() symbol provides externally callable version of __error() inline function. While there, add __WANT_NO_INLINED___ERROR guard for few python parsers in DPorts that are unable to parse inlined __error() code yet. --- diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 32176113ba..838feaf880 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -8,8 +8,9 @@ CFLAGS+=-I${.CURDIR}/../libc/sysvipc CMAPS+= ${.CURDIR}/gen/Symbol.map -SRCS+= _once_stub.c _pthread_stubs.c _rand48.c _spinlock_stub.c \ - _thread_init.c alarm.c arc4random.c assert.c basename.c \ +SRCS+= __errno_location.c _once_stub.c _pthread_stubs.c _rand48.c \ + _spinlock_stub.c _thread_init.c \ + alarm.c arc4random.c assert.c basename.c \ clock.c clock_getcpuclockid.c closedir.c confstr.c creat.c \ ctermid.c daemon.c devname.c dirfd.c dirname.c disklabel.c disktab.c \ dlfcn.c drand48.c dup3.c elf_utils.c erand48.c err.c errlst.c exec.c \ diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map index 564888885f..72423e5b9c 100644 --- a/lib/libc/gen/Symbol.map +++ b/lib/libc/gen/Symbol.map @@ -490,6 +490,7 @@ DF506.0 { }; DF508.0 { + __errno_location; getutxuser; }; diff --git a/lib/libc/gen/__errno_location.c b/lib/libc/gen/__errno_location.c new file mode 100644 index 0000000000..163f26fdad --- /dev/null +++ b/lib/libc/gen/__errno_location.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 The DragonFly Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +/* + * This function to fetch errno is provided for language binding only. + */ +int * +__errno_location(void) +{ + return (__error()); +} diff --git a/sys/sys/errno.h b/sys/sys/errno.h index 657e5ec267..2bfa6a9b5c 100644 --- a/sys/sys/errno.h +++ b/sys/sys/errno.h @@ -43,15 +43,23 @@ #if !defined(_KERNEL) || defined(_KERNEL_VIRTUAL) __BEGIN_DECLS extern __thread int errno; + +int * __errno_location(void); /* For language bindings only */ __END_DECLS +/* + * Some python parsers unable to parse such __error() inline. + */ +#ifdef __WANT_NO_INLINED___ERROR +#define errno (* __errno_location()) +#else static __inline int *__error(void) { return (&errno); } - #define errno (* __error()) #endif +#endif #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */