[+] UNIX: AuProcesses should always try to close leaked fds
This commit is contained in:
parent
2e06094e46
commit
730465ca2b
@ -11,6 +11,10 @@
|
||||
|
||||
#define AURORA_IS_GLIBC
|
||||
|
||||
#if !defined(__NR_close_range)
|
||||
#define __NR_close_range 436
|
||||
#endif
|
||||
|
||||
namespace Aurora
|
||||
{
|
||||
#define read_barrier() __asm__ __volatile__("lfence" ::: "memory")
|
||||
@ -58,29 +62,29 @@ namespace Aurora
|
||||
int pidfd_getfd(int pidfd, int targetfd,
|
||||
unsigned int flags)
|
||||
{
|
||||
return syscallFuckYou(SYS_pidfd_getfd, pidfd, targetfd, flags);
|
||||
return syscallFuckYou(__NR_pidfd_getfd, pidfd, targetfd, flags);
|
||||
}
|
||||
|
||||
int pidfd_open(pid_t pid, unsigned int flags)
|
||||
{
|
||||
return syscallFuckYou(SYS_pidfd_open, pid, flags);
|
||||
return syscallFuckYou(__NR_pidfd_open, pid, flags);
|
||||
}
|
||||
|
||||
long set_robust_list(struct robust_list_head *head, size_t len)
|
||||
{
|
||||
return syscallFuckYou(SYS_set_robust_list, head, len);
|
||||
return syscallFuckYou(__NR_set_robust_list, head, len);
|
||||
}
|
||||
|
||||
long get_robust_list(int pid, struct robust_list_head **head_ptr, size_t *len_ptr)
|
||||
{
|
||||
return syscallFuckYou(SYS_get_robust_list, pid, head_ptr, len_ptr);
|
||||
return syscallFuckYou(__NR_get_robust_list, pid, head_ptr, len_ptr);
|
||||
}
|
||||
|
||||
static int futex(uint32_t *uaddr, int futex_op, uint32_t val,
|
||||
const struct timespec *timeout,
|
||||
uint32_t *uaddr2, uint32_t val3)
|
||||
{
|
||||
return syscallFuckYou(SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
|
||||
return syscallFuckYou(__NR_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
|
||||
}
|
||||
|
||||
int futex_wait(uint32_t *addr, uint32_t expected)
|
||||
@ -247,7 +251,7 @@ namespace Aurora
|
||||
int io_cancel(aio_context_t ctx_id, struct iocb *iocb,
|
||||
struct io_event *result)
|
||||
{
|
||||
return syscallFuckYou(SYS_io_cancel, ctx_id, iocb, result);
|
||||
return syscallFuckYou(__NR_io_cancel, ctx_id, iocb, result);
|
||||
}
|
||||
|
||||
ssize_t sys_getrandom(void *pBuffer, size_t uLength)
|
||||
@ -260,7 +264,7 @@ namespace Aurora
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
ret = syscallFuckYou(SYS_getrandom, pBuffer, uLength, 1);
|
||||
ret = syscallFuckYou(__NR_getrandom, pBuffer, uLength, 1);
|
||||
if (ret == -ENOSYS)
|
||||
{
|
||||
gShouldNotGetRand = 1;
|
||||
@ -268,4 +272,20 @@ namespace Aurora
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int close_range(unsigned int first, unsigned int last,
|
||||
unsigned int flags)
|
||||
{
|
||||
|
||||
auto &platform = AuSwInfo::GetPlatformInfo();
|
||||
if (platform.uKernelMajor > 5 ||
|
||||
(platform.uKernelMajor == 5 && platform.uKernelMajor >= 9))
|
||||
{
|
||||
return syscallFuckYou(__NR_close_range, first, last, flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
}
|
||||
}
|
@ -57,4 +57,7 @@ namespace Aurora
|
||||
struct timespec *timeout);
|
||||
|
||||
ssize_t sys_getrandom(void *pBuffer, size_t uLength);
|
||||
|
||||
int close_range(unsigned int first, unsigned int last,
|
||||
unsigned int flags);
|
||||
}
|
@ -568,6 +568,12 @@ namespace Aurora::Processes
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(AURORA_IS_BSD_DERIVED)
|
||||
closefrom(STDERR_FILENO + 1);
|
||||
#elif defined(AURORA_IS_LINUX_DERIVED)
|
||||
close_range(STDERR_FILENO + 1, UINT_MAX, 0);
|
||||
#endif
|
||||
|
||||
if (this->startup_.environmentVariables.size())
|
||||
{
|
||||
SysAssert(AuProcess::EnvironmentSetMany(this->startup_.environmentVariables));
|
||||
|
Loading…
Reference in New Issue
Block a user