Skip to content

Commit

Permalink
Fix AST singal(3) name conflict with ASan (#712)
Browse files Browse the repository at this point in the history
This commit fixes multiple test failures when the coprocess, io and
pty tests are run under ASan.

The signal(3) wrapper causes a name conflict, similar to how the
AST glob functions did before being fixed in 01c01fe. Renaming the
wrapper function to _ast_signal allows ksh to use sigaction(3) via
AST signal(3) under ASan without encountering a name conflict.

src/lib/libast/features/map.c:
- Rename the signal function to _ast_signal via a #define (subject
  to the same preprocessor conditions that trigger the define of
  AST signal(3) in signal.c).
- Add necessary sig.h include for the _std_signal iffe test result
  (the Mamfile was also updated to account for this).
  • Loading branch information
JohnoKing authored and McDutchie committed Feb 9, 2024
1 parent b35b1c8 commit 1a3e247
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
15 changes: 8 additions & 7 deletions src/lib/libast/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ make install virtual
prev features/options
exec - iffe ${IFFEFLAGS} -v -X ast -X std -c "${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS}" run features/options
done
make sig.h implicit
make FEATURE/sig
prev features/sig.sh
exec - iffe ${IFFEFLAGS} -v -X ast -X std -c "${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS}" run features/sig.sh
done
exec - ${STDCP} -f FEATURE/sig sig.h
done
prev FEATURE/mmap
prev FEATURE/lib
done
Expand Down Expand Up @@ -1088,13 +1095,7 @@ make install virtual
make signal.o
make misc/signal.c
prev ast_map.h
make sig.h implicit
make FEATURE/sig
prev features/sig.sh
exec - iffe ${IFFEFLAGS} -v -X ast -X std -c "${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS}" run features/sig.sh
done
exec - ${STDCP} -f FEATURE/sig sig.h
done
prev sig.h
prev include/ast.h
done
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Icomp -Iinclude -Istd -c misc/signal.c
Expand Down
10 changes: 7 additions & 3 deletions src/lib/libast/features/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -31,6 +31,7 @@
#include "FEATURE/vmalloc"
#include "FEATURE/eaccess"
#include "FEATURE/api"
#include <sig.h>

#if _opt_map_libc && !defined(_map_libc)
#define _map_libc 1
Expand Down Expand Up @@ -134,6 +135,11 @@ main(void)
printf("#define glob _ast_glob\n");
printf("#undef globfree\n");
printf("#define globfree _ast_globfree\n");
#if _map_libc || (!_std_signal && (_lib_sigaction && defined(SA_NOCLDSTOP) || _lib_sigvec && defined(SV_INTERRUPT)))
/* use the libast signal() function (aka sigaction) when applicable */
printf("#undef signal\n");
printf("#define signal _ast_signal\n");
#endif
#if _map_libc
printf("#undef memdup\n");
printf("#define memdup _ast_memdup\n");
Expand Down Expand Up @@ -293,8 +299,6 @@ main(void)
printf("#define setenviron _ast_setenviron\n");
printf("#undef sigcritical\n");
printf("#define sigcritical _ast_sigcritical\n");
printf("#undef signal\n");
printf("#define signal _ast_signal\n");
printf("#undef sigunblock\n");
printf("#define sigunblock _ast_sigunblock\n");
printf("#undef stracmp\n");
Expand Down
5 changes: 3 additions & 2 deletions src/lib/libast/features/sig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# #
# This software is part of the ast package #
# Copyright (c) 1985-2011 AT&T Intellectual Property #
# Copyright (c) 2020-2023 Contributors to ksh 93u+m #
# Copyright (c) 2020-2024 Contributors to ksh 93u+m #
# and is licensed under the #
# Eclipse Public License, Version 2.0 #
# #
Expand Down Expand Up @@ -105,4 +105,5 @@ extern int sigflag(int, int, int);
extern int sigflag(int, int, int);
#endif
extern int sigcritical(int);
extern int sigunblock(int);'
extern int sigunblock(int);
extern Sig_handler_t _ast_signal(int, Sig_handler_t);'
13 changes: 2 additions & 11 deletions src/lib/libast/misc/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1985-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand All @@ -23,18 +23,9 @@
* fun==SIG_DFL also unblocks signal
*/

#if !__HAIKU__

#undef signal
#define signal ______signal

#endif

#include <ast.h>
#include <sig.h>

#undef signal

#undef _def_map_ast
#include <ast_map.h>

Expand All @@ -60,7 +51,7 @@
#define sa_mask sv_mask
#endif

extern Sig_handler_t
Sig_handler_t
signal(int sig, Sig_handler_t fun)
{
struct sigaction na;
Expand Down

0 comments on commit 1a3e247

Please sign in to comment.