123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- /*
- * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
- *
- * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
- */
- #include <sys/syscall.h>
- #include <sys/socket.h>
- #include <cancel.h>
- #ifdef __NR_socketcall
- /* Various socketcall numbers */
- #define SYS_SOCKET 1
- #define SYS_BIND 2
- #define SYS_CONNECT 3
- #define SYS_LISTEN 4
- #define SYS_ACCEPT 5
- #define SYS_GETSOCKNAME 6
- #define SYS_GETPEERNAME 7
- #define SYS_SOCKETPAIR 8
- #define SYS_SEND 9
- #define SYS_RECV 10
- #define SYS_SENDTO 11
- #define SYS_RECVFROM 12
- #define SYS_SHUTDOWN 13
- #define SYS_SETSOCKOPT 14
- #define SYS_GETSOCKOPT 15
- #define SYS_SENDMSG 16
- #define SYS_RECVMSG 17
- #define SYS_ACCEPT4 18
- #endif
- #ifdef L_accept
- static int __NC(accept)(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
- {
- # ifdef __NR_accept
- return INLINE_SYSCALL(accept, 3, sockfd, addr, addrlen);
- # else
- unsigned long args[3];
- args[0] = sockfd;
- args[1] = (unsigned long) addr;
- args[2] = (unsigned long) addrlen;
- return __socketcall(SYS_ACCEPT, args);
- # endif
- }
- CANCELLABLE_SYSCALL(int, accept, (int sockfd, struct sockaddr *addr, socklen_t *addrlen),
- (sockfd, addr, addrlen))
- lt_libc_hidden(accept)
- #endif
- #ifdef L_accept4
- #ifdef __NR_accept4
- # define __NR___sys_accept4 __NR_accept4
- static _syscall4(int, __sys_accept4, int, fd, struct sockaddr *, addr, socklen_t *, addrlen, int, flags)
- int accept4(int fd, struct sockaddr *addr, socklen_t * addrlen, int flags)
- {
- if (SINGLE_THREAD_P)
- return __sys_accept4(fd, addr, addrlen, flags);
- #ifdef __UCLIBC_HAS_THREADS_NATIVE__
- else {
- int oldtype = LIBC_CANCEL_ASYNC ();
- int result = __sys_accept4(fd, addr, addrlen, flags);
- LIBC_CANCEL_RESET (oldtype);
- return result;
- }
- #endif
- }
- #elif defined(__NR_socketcall)
- int accept4(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags)
- {
- unsigned long args[4];
- args[0] = fd;
- args[1] = (unsigned long) addr;
- args[2] = (unsigned long) addrlen;
- args[3] = flags;
- if (SINGLE_THREAD_P)
- return __socketcall(SYS_ACCEPT4, args);
- #ifdef __UCLIBC_HAS_THREADS_NATIVE__
- else {
- int oldtype = LIBC_CANCEL_ASYNC ();
- int result = __socketcall(SYS_ACCEPT4, args);
- LIBC_CANCEL_RESET (oldtype);
- return result;
- }
- #endif
- }
- #endif
- #endif
- #ifdef L_bind
- int bind(int sockfd, const struct sockaddr *myaddr, socklen_t addrlen)
- {
- # ifdef __NR_bind
- return INLINE_SYSCALL(bind, 3, sockfd, myaddr, addrlen);
- # else
- unsigned long args[3];
- args[0] = sockfd;
- args[1] = (unsigned long) myaddr;
- args[2] = addrlen;
- return __socketcall(SYS_BIND, args);
- # endif
- }
- libc_hidden_def(bind)
- #endif
- #ifdef L_connect
- static int __NC(connect)(int sockfd, const struct sockaddr *saddr, socklen_t addrlen)
- {
- # ifdef __NR_connect
- return INLINE_SYSCALL(connect, 3, sockfd, saddr, addrlen);
- # else
- unsigned long args[3];
- args[0] = sockfd;
- args[1] = (unsigned long) saddr;
- args[2] = addrlen;
- return __socketcall(SYS_CONNECT, args);
- # endif
- }
- CANCELLABLE_SYSCALL(int, connect, (int sockfd, const struct sockaddr *saddr, socklen_t addrlen),
- (sockfd, saddr, addrlen))
- lt_libc_hidden(connect)
- #endif
- #ifdef L_getpeername
- int getpeername(int sockfd, struct sockaddr *addr, socklen_t *paddrlen)
- {
- # ifdef __NR_getpeername
- return INLINE_SYSCALL(getpeername, 3, sockfd, addr, paddrlen);
- # else
- unsigned long args[3];
- args[0] = sockfd;
- args[1] = (unsigned long) addr;
- args[2] = (unsigned long) paddrlen;
- return __socketcall(SYS_GETPEERNAME, args);
- # endif
- }
- #endif
- #ifdef L_getsockname
- int getsockname(int sockfd, struct sockaddr *addr, socklen_t * paddrlen)
- {
- # ifdef __NR_getsockname
- return INLINE_SYSCALL(getsockname, 3, sockfd, addr, paddrlen);
- # else
- unsigned long args[3];
- args[0] = sockfd;
- args[1] = (unsigned long) addr;
- args[2] = (unsigned long) paddrlen;
- return __socketcall(SYS_GETSOCKNAME, args);
- # endif
- }
- libc_hidden_def(getsockname)
- #endif
- #ifdef L_getsockopt
- int getsockopt(int fd, int level, int optname, void *optval,
- socklen_t *optlen)
- {
- # ifdef __NR_getsockopt
- return INLINE_SYSCALL(getsockopt, 5, fd, level, optname, optval, optlen);
- # else
- unsigned long args[5];
- args[0] = fd;
- args[1] = level;
- args[2] = optname;
- args[3] = (unsigned long) optval;
- args[4] = (unsigned long) optlen;
- return (__socketcall(SYS_GETSOCKOPT, args));
- # endif
- }
- #endif
- #ifdef L_listen
- int listen(int sockfd, int backlog)
- {
- # ifdef __NR_listen
- return INLINE_SYSCALL(listen, 2, sockfd, backlog);
- # else
- unsigned long args[2];
- args[0] = sockfd;
- args[1] = backlog;
- return __socketcall(SYS_LISTEN, args);
- # endif
- }
- libc_hidden_def(listen)
- #endif
- #ifdef L_recv
- static ssize_t __NC(recv)(int sockfd, void *buffer, size_t len, int flags)
- {
- # ifdef __NR_recv
- return (ssize_t)INLINE_SYSCALL(recv, 4, sockfd, buffer, len, flags);
- # elif defined __NR_recvfrom && defined _syscall6
- return __NC(recvfrom)(sockfd, buffer, len, flags, NULL, NULL);
- # else
- unsigned long args[4];
- args[0] = sockfd;
- args[1] = (unsigned long) buffer;
- args[2] = len;
- args[3] = flags;
- return (ssize_t)__socketcall(SYS_RECV, args);
- # endif
- }
- CANCELLABLE_SYSCALL(ssize_t, recv, (int sockfd, void *buffer, size_t len, int flags),
- (sockfd, buffer, len, flags))
- lt_libc_hidden(recv)
- #endif
- #ifdef L_recvfrom
- ssize_t __NC(recvfrom)(int sockfd, void *buffer, size_t len, int flags,
- struct sockaddr *to, socklen_t *tolen)
- {
- # if defined __NR_recvfrom && defined _syscall6
- return (ssize_t)INLINE_SYSCALL(recvfrom, 6, sockfd, buffer, len,
- flags, to, tolen);
- # else
- unsigned long args[6];
- args[0] = sockfd;
- args[1] = (unsigned long) buffer;
- args[2] = len;
- args[3] = flags;
- args[4] = (unsigned long) to;
- args[5] = (unsigned long) tolen;
- return (ssize_t)__socketcall(SYS_RECVFROM, args);
- # endif
- }
- CANCELLABLE_SYSCALL(ssize_t, recvfrom, (int sockfd, void *buffer, size_t len,
- int flags, struct sockaddr *to, socklen_t *tolen),
- (sockfd, buffer, len, flags, to, tolen))
- lt_libc_hidden(recvfrom)
- #endif
- #ifdef L_recvmsg
- static ssize_t __NC(recvmsg)(int sockfd, struct msghdr *msg, int flags)
- {
- # ifdef __NR_recvmsg
- return (ssize_t)INLINE_SYSCALL(recvmsg, 3, sockfd, msg, flags);
- # else
- unsigned long args[3];
- args[0] = sockfd;
- args[1] = (unsigned long) msg;
- args[2] = flags;
- return (ssize_t)__socketcall(SYS_RECVMSG, args);
- # endif
- }
- CANCELLABLE_SYSCALL(ssize_t, recvmsg, (int sockfd, struct msghdr *msg, int flags),
- (sockfd, msg, flags))
- lt_libc_hidden(recvmsg)
- #endif
- #ifdef L_send
- static ssize_t __NC(send)(int sockfd, const void *buffer, size_t len, int flags)
- {
- # ifdef __NR_send
- return (ssize_t)INLINE_SYSCALL(send, 4, sockfd, buffer, len, flags);
- # elif defined __NR_sendto && defined _syscall6
- return __NC(sendto)(sockfd, buffer, len, flags, NULL, 0);
- # else
- unsigned long args[4];
- args[0] = sockfd;
- args[1] = (unsigned long) buffer;
- args[2] = len;
- args[3] = flags;
- return (ssize_t)__socketcall(SYS_SEND, args);
- # endif
- }
- CANCELLABLE_SYSCALL(ssize_t, send, (int sockfd, const void *buffer, size_t len, int flags),
- (sockfd, buffer, len, flags))
- lt_libc_hidden(send)
- #endif
- #ifdef L_sendmsg
- static ssize_t __NC(sendmsg)(int sockfd, const struct msghdr *msg, int flags)
- {
- # ifdef __NR_sendmsg
- return (ssize_t)INLINE_SYSCALL(sendmsg, 3, sockfd, msg, flags);
- # else
- unsigned long args[3];
- args[0] = sockfd;
- args[1] = (unsigned long) msg;
- args[2] = flags;
- return (ssize_t)__socketcall(SYS_SENDMSG, args);
- # endif
- }
- CANCELLABLE_SYSCALL(ssize_t, sendmsg, (int sockfd, const struct msghdr *msg, int flags),
- (sockfd, msg, flags))
- lt_libc_hidden(sendmsg)
- #endif
- #ifdef L_sendto
- ssize_t __NC(sendto)(int sockfd, const void *buffer, size_t len, int flags,
- const struct sockaddr *to, socklen_t tolen)
- {
- # if defined __NR_sendto && defined _syscall6
- return (ssize_t)INLINE_SYSCALL(sendto, 6, sockfd, buffer, len, flags, to, tolen);
- # else
- unsigned long args[6];
- args[0] = sockfd;
- args[1] = (unsigned long) buffer;
- args[2] = len;
- args[3] = flags;
- args[4] = (unsigned long) to;
- args[5] = tolen;
- return (ssize_t)__socketcall(SYS_SENDTO, args);
- # endif
- }
- CANCELLABLE_SYSCALL(ssize_t, sendto, (int sockfd, const void *buffer, size_t len,
- int flags, const struct sockaddr *to, socklen_t tolen),
- (sockfd, buffer, len, flags, to, tolen))
- lt_libc_hidden(sendto)
- #endif
- #ifdef L_setsockopt
- int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
- {
- # ifdef __NR_setsockopt
- return INLINE_SYSCALL(setsockopt, 5, fd, level, optname, optval, optlen);
- # else
- unsigned long args[5];
- args[0] = fd;
- args[1] = level;
- args[2] = optname;
- args[3] = (unsigned long) optval;
- args[4] = optlen;
- return __socketcall(SYS_SETSOCKOPT, args);
- # endif
- }
- libc_hidden_def(setsockopt)
- #endif
- #ifdef L_shutdown
- int shutdown(int sockfd, int how)
- {
- # ifdef __NR_shutdown
- return INLINE_SYSCALL(shutdown, 2, sockfd, how);
- # else
- unsigned long args[2];
- args[0] = sockfd;
- args[1] = how;
- return __socketcall(SYS_SHUTDOWN, args);
- # endif
- }
- #endif
- #ifdef L_socket
- int socket(int family, int type, int protocol)
- {
- # ifdef __NR_socket
- return INLINE_SYSCALL(socket, 3, family, type, protocol);
- # else
- unsigned long args[3];
- args[0] = family;
- args[1] = type;
- args[2] = (unsigned long) protocol;
- return __socketcall(SYS_SOCKET, args);
- # endif
- }
- libc_hidden_def(socket)
- #endif
- #ifdef L_socketpair
- int socketpair(int family, int type, int protocol, int sockvec[2])
- {
- # ifdef __NR_socketpair
- return INLINE_SYSCALL(socketpair, 4, family, type, protocol, sockvec);
- # else
- unsigned long args[4];
- args[0] = family;
- args[1] = type;
- args[2] = protocol;
- args[3] = (unsigned long) sockvec;
- return __socketcall(SYS_SOCKETPAIR, args);
- # endif
- }
- #endif
|