11801c356SMichael Jones //===-- Linux implementation of syscall -----------------------------------===// 21801c356SMichael Jones // 31801c356SMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 41801c356SMichael Jones // See https://llvm.org/LICENSE.txt for license information. 51801c356SMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 61801c356SMichael Jones // 71801c356SMichael Jones //===----------------------------------------------------------------------===// 81801c356SMichael Jones 91801c356SMichael Jones #include "src/unistd/syscall.h" 101801c356SMichael Jones 111801c356SMichael Jones #include "src/__support/OSUtil/syscall.h" // For internal syscall function. 121801c356SMichael Jones #include "src/__support/common.h" 131801c356SMichael Jones 14*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 15803437dbSMichael Jones #include "src/errno/libc_errno.h" 161801c356SMichael Jones #include <stdarg.h> 171801c356SMichael Jones 18*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 191801c356SMichael Jones 20d4041301Salfredfo LLVM_LIBC_FUNCTION(long, __llvm_libc_syscall, 211801c356SMichael Jones (long number, long arg1, long arg2, long arg3, long arg4, 221801c356SMichael Jones long arg5, long arg6)) { 23b6bc9d72SGuillaume Chatelet long ret = LIBC_NAMESPACE::syscall_impl<long>(number, arg1, arg2, arg3, arg4, 24f0a3954eSMichael Jones arg5, arg6); 251801c356SMichael Jones // Syscalls may return large positive values that overflow, but will never 261801c356SMichael Jones // return values between -4096 and -1 271801c356SMichael Jones if (static_cast<unsigned long>(ret) > -4096UL) { 28f0a3954eSMichael Jones libc_errno = static_cast<int>(-ret); 291801c356SMichael Jones return -1; 301801c356SMichael Jones } 311801c356SMichael Jones return ret; 321801c356SMichael Jones } 331801c356SMichael Jones 34*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 35