Skip to content

Commit

Permalink
[libc] Switch signal and termios to libc_errno.
Browse files Browse the repository at this point in the history
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D145274
  • Loading branch information
Siva Chandra Reddy committed Mar 5, 2023
1 parent 77d2f26 commit 7abf6c2
Show file tree
Hide file tree
Showing 28 changed files with 58 additions and 67 deletions.
5 changes: 0 additions & 5 deletions libc/src/signal/linux/CMakeLists.txt
Expand Up @@ -15,7 +15,6 @@ add_entrypoint_object(
../kill.h
DEPENDS
libc.include.signal
libc.include.errno
libc.src.errno.errno
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
Expand Down Expand Up @@ -100,7 +99,6 @@ add_entrypoint_object(
../sigemptyset.h
DEPENDS
.signal_utils
libc.include.errno
libc.include.signal
libc.src.errno.errno
)
Expand All @@ -113,7 +111,6 @@ add_entrypoint_object(
../sigaddset.h
DEPENDS
.signal_utils
libc.include.errno
libc.include.signal
libc.src.errno.errno
)
Expand All @@ -137,7 +134,6 @@ add_entrypoint_object(
../sigfillset.h
DEPENDS
.signal_utils
libc.include.errno
libc.include.signal
libc.src.errno.errno
)
Expand All @@ -150,7 +146,6 @@ add_entrypoint_object(
../sigdelset.h
DEPENDS
.signal_utils
libc.include.errno
libc.include.signal
libc.src.errno.errno
)
7 changes: 3 additions & 4 deletions libc/src/signal/linux/kill.cpp
Expand Up @@ -9,11 +9,10 @@
#include "src/signal/kill.h"

#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/signal/linux/signal_utils.h"

#include "src/__support/common.h"
#include "src/errno/libc_errno.h"
#include "src/signal/linux/signal_utils.h"

#include <errno.h>
#include <signal.h>
#include <sys/syscall.h> // For syscall numbers.

Expand All @@ -25,7 +24,7 @@ LLVM_LIBC_FUNCTION(int, kill, (pid_t pid, int sig)) {
// A negative return value indicates an error with the magnitude of the
// value being the error code.
if (ret != 0) {
errno = (ret > 0 ? ret : -ret);
libc_errno = (ret > 0 ? ret : -ret);
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions libc/src/signal/linux/sigaction.cpp
Expand Up @@ -7,11 +7,11 @@
//===----------------------------------------------------------------------===//

#include "src/signal/sigaction.h"
#include "src/errno/libc_errno.h"
#include "src/signal/linux/signal_utils.h"

#include "src/__support/common.h"

#include <errno.h>
#include <signal.h>

namespace __llvm_libc {
Expand All @@ -38,7 +38,7 @@ LLVM_LIBC_FUNCTION(int, sigaction,
SYS_rt_sigaction, signal, libc_new ? &kernel_new : nullptr,
libc_old ? &kernel_old : nullptr, sizeof(sigset_t));
if (ret) {
errno = -ret;
libc_errno = -ret;
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions libc/src/signal/linux/sigaddset.cpp
Expand Up @@ -8,17 +8,17 @@

#include "src/signal/sigaddset.h"
#include "src/__support/common.h"
#include "src/errno/libc_errno.h"
#include "src/signal/linux/signal_utils.h"

#include <errno.h>
#include <signal.h>

namespace __llvm_libc {

LLVM_LIBC_FUNCTION(int, sigaddset, (sigset_t * set, int signum)) {
if (set != nullptr && add_signal(*set, signum))
return 0;
errno = EINVAL;
libc_errno = EINVAL;
return -1;
}

Expand Down
8 changes: 4 additions & 4 deletions libc/src/signal/linux/sigaltstack.cpp
Expand Up @@ -7,11 +7,11 @@
//===----------------------------------------------------------------------===//

#include "src/signal/sigaltstack.h"
#include "src/errno/libc_errno.h"
#include "src/signal/linux/signal_utils.h"

#include "src/__support/common.h"

#include <errno.h>
#include <signal.h>
#include <sys/syscall.h>

Expand All @@ -25,18 +25,18 @@ LLVM_LIBC_FUNCTION(int, sigaltstack,
// Flags cannot have anything other than SS_DISABLE set.
// We do the type-casting to unsigned because the |ss_flags|
// field of stack_t is of type "int".
errno = EINVAL;
libc_errno = EINVAL;
return -1;
}
if (ss->ss_size < MINSIGSTKSZ) {
errno = ENOMEM;
libc_errno = ENOMEM;
return -1;
}
}

int ret = __llvm_libc::syscall_impl(SYS_sigaltstack, ss, oss);
if (ret < 0) {
errno = -ret;
libc_errno = -ret;
return -1;
}
return 0;
Expand Down
4 changes: 2 additions & 2 deletions libc/src/signal/linux/sigdelset.cpp
Expand Up @@ -8,17 +8,17 @@

#include "src/signal/sigdelset.h"
#include "src/__support/common.h"
#include "src/errno/libc_errno.h"
#include "src/signal/linux/signal_utils.h"

#include <errno.h>
#include <signal.h>

namespace __llvm_libc {

LLVM_LIBC_FUNCTION(int, sigdelset, (sigset_t * set, int signum)) {
if (set != nullptr && delete_signal(*set, signum))
return 0;
errno = EINVAL;
libc_errno = EINVAL;
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions libc/src/signal/linux/sigemptyset.cpp
Expand Up @@ -7,18 +7,18 @@
//===----------------------------------------------------------------------===//

#include "src/signal/sigemptyset.h"
#include "src/errno/libc_errno.h"
#include "src/signal/linux/signal_utils.h"

#include "src/__support/common.h"

#include <errno.h>
#include <signal.h>

namespace __llvm_libc {

LLVM_LIBC_FUNCTION(int, sigemptyset, (sigset_t * set)) {
if (!set) {
errno = EINVAL;
libc_errno = EINVAL;
return -1;
}
*set = empty_set();
Expand Down
4 changes: 2 additions & 2 deletions libc/src/signal/linux/sigfillset.cpp
Expand Up @@ -8,16 +8,16 @@

#include "src/signal/sigfillset.h"
#include "src/__support/common.h"
#include "src/errno/libc_errno.h"
#include "src/signal/linux/signal_utils.h"

#include <errno.h>
#include <signal.h>

namespace __llvm_libc {

LLVM_LIBC_FUNCTION(int, sigfillset, (sigset_t * set)) {
if (!set) {
errno = EINVAL;
libc_errno = EINVAL;
return -1;
}
*set = full_set();
Expand Down
4 changes: 2 additions & 2 deletions libc/src/signal/linux/sigprocmask.cpp
Expand Up @@ -9,11 +9,11 @@
#include "src/signal/sigprocmask.h"
#include "include/sys/syscall.h" // For syscall numbers.
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/errno/libc_errno.h"
#include "src/signal/linux/signal_utils.h"

#include "src/__support/common.h"

#include <errno.h>
#include <signal.h>

namespace __llvm_libc {
Expand All @@ -26,7 +26,7 @@ LLVM_LIBC_FUNCTION(int, sigprocmask,
if (!ret)
return 0;

errno = -ret;
libc_errno = -ret;
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions libc/src/termios/linux/cfsetispeed.cpp
Expand Up @@ -9,8 +9,8 @@
#include "src/termios/cfsetispeed.h"

#include "src/__support/common.h"
#include "src/errno/libc_errno.h"

#include <errno.h>
#include <termios.h>

namespace __llvm_libc {
Expand All @@ -19,7 +19,7 @@ LLVM_LIBC_FUNCTION(int, cfsetispeed, (struct termios * t, speed_t speed)) {
constexpr speed_t NOT_SPEED_MASK = ~speed_t(CBAUD);
// A speed value is valid only if it is equal to one of the B<NN+> values.
if (t == nullptr || ((speed & NOT_SPEED_MASK) != 0)) {
errno = EINVAL;
libc_errno = EINVAL;
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions libc/src/termios/linux/cfsetospeed.cpp
Expand Up @@ -7,10 +7,10 @@
//===----------------------------------------------------------------------===//

#include "src/termios/cfsetospeed.h"
#include "src/errno/libc_errno.h"

#include "src/__support/common.h"

#include <errno.h>
#include <termios.h>

namespace __llvm_libc {
Expand All @@ -19,7 +19,7 @@ LLVM_LIBC_FUNCTION(int, cfsetospeed, (struct termios * t, speed_t speed)) {
constexpr speed_t NOT_SPEED_MASK = ~speed_t(CBAUD);
// A speed value is valid only if it is equal to one of the B<NN+> values.
if (t == nullptr || ((speed & NOT_SPEED_MASK) != 0)) {
errno = EINVAL;
libc_errno = EINVAL;
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion libc/src/termios/linux/tcdrain.cpp
Expand Up @@ -10,9 +10,9 @@

#include "src/__support/OSUtil/syscall.h"
#include "src/__support/common.h"
#include "src/errno/libc_errno.h"

#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
#include <errno.h>
#include <sys/syscall.h> // For syscall numbers
#include <termios.h>

Expand Down
4 changes: 2 additions & 2 deletions libc/src/termios/linux/tcflow.cpp
Expand Up @@ -10,9 +10,9 @@

#include "src/__support/OSUtil/syscall.h"
#include "src/__support/common.h"
#include "src/errno/libc_errno.h"

#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
#include <errno.h>
#include <sys/syscall.h> // For syscall numbers
#include <termios.h>

Expand All @@ -21,7 +21,7 @@ namespace __llvm_libc {
LLVM_LIBC_FUNCTION(int, tcflow, (int fd, int action)) {
long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCXONC, action);
if (ret < 0) {
errno = -ret;
libc_errno = -ret;
return -1;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion libc/src/termios/linux/tcflush.cpp
Expand Up @@ -10,9 +10,9 @@

#include "src/__support/OSUtil/syscall.h"
#include "src/__support/common.h"
#include "src/errno/libc_errno.h"

#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
#include <errno.h>
#include <sys/syscall.h> // For syscall numbers
#include <termios.h>

Expand Down
4 changes: 2 additions & 2 deletions libc/src/termios/linux/tcgetattr.cpp
Expand Up @@ -11,9 +11,9 @@

#include "src/__support/OSUtil/syscall.h"
#include "src/__support/common.h"
#include "src/errno/libc_errno.h"

#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
#include <errno.h>
#include <sys/syscall.h> // For syscall numbers
#include <termios.h>

Expand All @@ -23,7 +23,7 @@ LLVM_LIBC_FUNCTION(int, tcgetattr, (int fd, struct termios *t)) {
__llvm_libc::kernel_termios kt;
long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCGETS, &kt);
if (ret < 0) {
errno = -ret;
libc_errno = -ret;
return -1;
}
t->c_iflag = kt.c_iflag;
Expand Down
2 changes: 1 addition & 1 deletion libc/src/termios/linux/tcgetsid.cpp
Expand Up @@ -10,9 +10,9 @@

#include "src/__support/OSUtil/syscall.h"
#include "src/__support/common.h"
#include "src/errno/libc_errno.h"

#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
#include <errno.h>
#include <sys/syscall.h> // For syscall numbers
#include <termios.h>

Expand Down
4 changes: 2 additions & 2 deletions libc/src/termios/linux/tcsendbreak.cpp
Expand Up @@ -10,9 +10,9 @@

#include "src/__support/OSUtil/syscall.h"
#include "src/__support/common.h"
#include "src/errno/libc_errno.h"

#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
#include <errno.h>
#include <sys/syscall.h> // For syscall numbers
#include <termios.h>

Expand All @@ -24,7 +24,7 @@ LLVM_LIBC_FUNCTION(pid_t, tcsendbreak, (int fd, int /* unused duration */)) {
// zero. So, we just pass zero to the syscall.
long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCSBRK, 0);
if (ret < 0) {
errno = -ret;
libc_errno = -ret;
return -1;
}
return 0;
Expand Down
6 changes: 3 additions & 3 deletions libc/src/termios/linux/tcsetattr.cpp
Expand Up @@ -11,9 +11,9 @@

#include "src/__support/OSUtil/syscall.h"
#include "src/__support/common.h"
#include "src/errno/libc_errno.h"

#include <asm/ioctls.h> // Safe to include without the risk of name pollution.
#include <errno.h>
#include <sys/syscall.h> // For syscall numbers
#include <termios.h>

Expand All @@ -35,7 +35,7 @@ LLVM_LIBC_FUNCTION(int, tcsetattr,
cmd = TCSETSF;
break;
default:
errno = EINVAL;
libc_errno = EINVAL;
return -1;
}

Expand All @@ -53,7 +53,7 @@ LLVM_LIBC_FUNCTION(int, tcsetattr,

long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, cmd, &kt);
if (ret < 0) {
errno = -ret;
libc_errno = -ret;
return -1;
}
return 0;
Expand Down

0 comments on commit 7abf6c2

Please sign in to comment.