Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.geteuid
libc.src.unistd.getpid
libc.src.unistd.getppid
libc.src.unistd.getsid
libc.src.unistd.gettid
libc.src.unistd.getuid
libc.src.unistd.isatty
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.geteuid
libc.src.unistd.getpid
libc.src.unistd.getppid
libc.src.unistd.getsid
libc.src.unistd.gettid
libc.src.unistd.getuid
libc.src.unistd.isatty
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.geteuid
libc.src.unistd.getpid
libc.src.unistd.getppid
libc.src.unistd.getsid
libc.src.unistd.gettid
libc.src.unistd.getuid
libc.src.unistd.isatty
Expand Down
6 changes: 6 additions & 0 deletions libc/include/unistd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ functions:
return_type: int
arguments:
- type: void
- name: getsid
standards:
- POSIX
return_type: pid_t
arguments:
- type: pid_t
- name: gettid
standards:
- Linux
Expand Down
7 changes: 7 additions & 0 deletions libc/src/unistd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ add_entrypoint_object(
.${LIBC_TARGET_OS}.getppid
)

add_entrypoint_object(
getsid
ALIAS
DEPENDS
.${LIBC_TARGET_OS}.getsid
)

add_entrypoint_object(
geteuid
ALIAS
Expand Down
21 changes: 21 additions & 0 deletions libc/src/unistd/getsid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation header for getsid ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_UNISTD_GETSID_H
#define LLVM_LIBC_SRC_UNISTD_GETSID_H

#include "hdr/types/pid_t.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

pid_t getsid(pid_t);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_UNISTD_GETSID_H
13 changes: 13 additions & 0 deletions libc/src/unistd/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,19 @@ add_entrypoint_object(
libc.src.__support.OSUtil.osutil
)

add_entrypoint_object(
getsid
SRCS
getsid.cpp
HDRS
../getsid.h
DEPENDS
libc.hdr.types.pid_t
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
libc.src.errno.errno
)

add_entrypoint_object(
getuid
SRCS
Expand Down
29 changes: 29 additions & 0 deletions libc/src/unistd/linux/getsid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- Linux implementation of getsid-------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/unistd/getsid.h"

#include "hdr/types/pid_t.h"
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/errno/libc_errno.h"
#include <sys/syscall.h> // For syscall numbers.

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(pid_t, getsid, (pid_t pid)) {
pid_t ret = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_getsid, pid);
if (ret < 0) {
libc_errno = static_cast<int>(-ret);
return -1;
}
return ret;
}

} // namespace LIBC_NAMESPACE_DECL
10 changes: 10 additions & 0 deletions libc/test/src/unistd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,16 @@ add_libc_unittest(
libc.src.unistd.getppid
)

add_libc_unittest(
getsid_test
SUITE
libc_unistd_unittests
SRCS
getsid_test.cpp
DEPENDS
libc.src.unistd.getsid
)

add_libc_unittest(
getuid_test
SUITE
Expand Down
21 changes: 21 additions & 0 deletions libc/test/src/unistd/getsid_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Unittests for getsid ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/errno/libc_errno.h"
#include "src/unistd/getsid.h"
#include "test/UnitTest/Test.h"

TEST(LlvmLibcGetPidTest, GetCurrSID) {
pid_t sid = LIBC_NAMESPACE::getsid(0);
ASSERT_NE(sid, -1);
ASSERT_ERRNO_SUCCESS();

pid_t nonexist_sid = LIBC_NAMESPACE::getsid(999999);
ASSERT_EQ(nonexist_sid, -1);
ASSERT_ERRNO_FAILURE();
}
Loading