Add pipe2(2).
This commit is contained in:
parent
eaf1618537
commit
a0a8ed61d8
|
@ -146,6 +146,7 @@
|
|||
#define SYSCALL_DUP3 122
|
||||
#define SYSCALL_SYMLINKAT 123
|
||||
#define SYSCALL_TCGETWINCURPOS 124
|
||||
#define SYSCALL_MAX_NUM 125 /* index of highest constant + 1 */
|
||||
#define SYSCALL_PIPE2 125
|
||||
#define SYSCALL_MAX_NUM 126 /* index of highest constant + 1 */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -318,8 +318,16 @@ int PipeNode::poll(ioctx_t* ctx, PollNode* node)
|
|||
|
||||
namespace Pipe {
|
||||
|
||||
static int sys_pipe(int pipefd[2])
|
||||
static int sys_pipe2(int pipefd[2], int flags)
|
||||
{
|
||||
int fdflags = 0;
|
||||
if ( flags & O_CLOEXEC ) fdflags |= FD_CLOEXEC;
|
||||
if ( flags & O_CLOFORK ) fdflags |= FD_CLOFORK;
|
||||
flags &= ~(O_CLOEXEC | O_CLOFORK);
|
||||
|
||||
if ( flags & ~(O_NONBLOCK) )
|
||||
return errno = EINVAL, -1;
|
||||
|
||||
Process* process = CurrentProcess();
|
||||
uid_t uid = process->uid;
|
||||
uid_t gid = process->gid;
|
||||
|
@ -344,9 +352,9 @@ static int sys_pipe(int pipefd[2])
|
|||
Ref<DescriptorTable> dtable = process->GetDTable();
|
||||
|
||||
int recv_index, send_index;
|
||||
if ( 0 <= (recv_index = dtable->Allocate(recv_desc, 0)) )
|
||||
if ( 0 <= (recv_index = dtable->Allocate(recv_desc, fdflags)) )
|
||||
{
|
||||
if ( 0 <= (send_index = dtable->Allocate(send_desc, 0)) )
|
||||
if ( 0 <= (send_index = dtable->Allocate(send_desc, fdflags)) )
|
||||
{
|
||||
int ret[2] = { recv_index, send_index };
|
||||
if ( CopyToUser(pipefd, ret, sizeof(ret)) )
|
||||
|
@ -360,9 +368,16 @@ static int sys_pipe(int pipefd[2])
|
|||
return -1;
|
||||
}
|
||||
|
||||
// TODO: This system call is replaced by pipe2, will be removed soon.
|
||||
static int sys_pipe(int pipefd[2])
|
||||
{
|
||||
return sys_pipe2(pipefd, 0);
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
Syscall::Register(SYSCALL_PIPE, (void*) sys_pipe);
|
||||
Syscall::Register(SYSCALL_PIPE2, (void*) sys_pipe2);
|
||||
}
|
||||
|
||||
} // namespace Pipe
|
||||
|
|
|
@ -507,6 +507,7 @@ unistd/lseek.o \
|
|||
unistd/memstat.o \
|
||||
unistd/mkpartition.o \
|
||||
unistd/pathconf.o \
|
||||
unistd/pipe2.o \
|
||||
unistd/pipe.o \
|
||||
unistd/pread.o \
|
||||
unistd/pwrite.o \
|
||||
|
|
|
@ -369,6 +369,7 @@ int linkat(int, const char*, int, const char*, int);
|
|||
off_t lseek(int, off_t, int);
|
||||
long pathconf(const char*, int);
|
||||
int pipe(int [2]);
|
||||
int pipe2(int [2], int);
|
||||
ssize_t pread(int, void*, size_t, off_t);
|
||||
ssize_t pwrite(int, const void*, size_t, off_t);
|
||||
ssize_t readlink(const char* __restrict, char* __restrict, size_t);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
|
@ -22,13 +22,9 @@
|
|||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
DEFN_SYSCALL1(int, sys_pipe, SYSCALL_PIPE, int*);
|
||||
|
||||
extern "C" int pipe(int pipefd[2])
|
||||
{
|
||||
return sys_pipe(pipefd);
|
||||
return pipe2(pipefd, 0);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2014.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
unistd/pipe2.cpp
|
||||
Creates a pair of file descriptors with a reading and writing end.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
DEFN_SYSCALL2(int, sys_pipe2, SYSCALL_PIPE2, int*, int);
|
||||
|
||||
extern "C" int pipe2(int pipefd[2], int flags)
|
||||
{
|
||||
return sys_pipe2(pipefd, flags);
|
||||
}
|
Loading…
Reference in New Issue