@@ -66,6 +66,7 @@ static __thread struct ff_getsockname_args *getsockname_args = NULL;
6666static __thread struct ff_getpeername_args * getpeername_args = NULL ;
6767static __thread struct ff_setsockopt_args * setsockopt_args = NULL ;
6868static __thread struct ff_accept_args * accept_args = NULL ;
69+ static __thread struct ff_accept4_args * accept4_args = NULL ;
6970static __thread struct ff_connect_args * connect_args = NULL ;
7071static __thread struct ff_recvfrom_args * recvfrom_args = NULL ;
7172static __thread struct ff_recvmsg_args * recvmsg_args = NULL ;
@@ -680,8 +681,62 @@ ff_hook_accept4(int fd, struct sockaddr *addr,
680681
681682 CHECK_FD_OWNERSHIP (accept4 , (fd , addr , addrlen , flags ));
682683
683- errno = ENOSYS ;
684- return -1 ;
684+ DEFINE_REQ_ARGS_STATIC (accept4 );
685+ static __thread struct sockaddr * sh_addr = NULL ;
686+ static __thread socklen_t sh_addr_len = 0 ;
687+ static __thread socklen_t * sh_addrlen = NULL ;
688+
689+ if (addr != NULL ) {
690+ if (sh_addr == NULL || sh_addr_len < * addrlen ) {
691+ if (sh_addr ) {
692+ share_mem_free (sh_addr );
693+ }
694+
695+ sh_addr_len = * addrlen ;
696+ sh_addr = share_mem_alloc (sh_addr_len );
697+ if (sh_addr == NULL ) {
698+ RETURN_ERROR_NOFREE (ENOMEM );
699+ }
700+ }
701+
702+ if (sh_addrlen == NULL ) {
703+ sh_addrlen = share_mem_alloc (sizeof (socklen_t ));
704+ if (sh_addrlen == NULL ) {
705+ //share_mem_free(sh_addr); // Don't free
706+ RETURN_ERROR_NOFREE (ENOMEM );
707+ }
708+ }
709+ * sh_addrlen = * addrlen ;
710+
711+ args -> addr = sh_addr ;
712+ args -> addrlen = sh_addrlen ;
713+ args -> flags = flags ;
714+ }else {
715+ args -> addr = NULL ;
716+ args -> addrlen = NULL ;
717+ args -> flags = flags ;
718+ }
719+
720+ args -> fd = fd ;
721+
722+ SYSCALL (FF_SO_ACCEPT4 , args );
723+
724+ if (ret > 0 ) {
725+ ret = convert_fstack_fd (ret );
726+ }
727+
728+ if (addr ) {
729+ if (ret > 0 ) {
730+ socklen_t cplen = * sh_addrlen > * addrlen ?
731+ * addrlen : * sh_addrlen ;
732+ rte_memcpy (addr , sh_addr , cplen );
733+ * addrlen = * sh_addrlen ;
734+ }
735+ //share_mem_free(sh_addr); // Don't free
736+ //share_mem_free(sh_addrlen);
737+ }
738+
739+ RETURN_NOFREE ();
685740}
686741
687742int
0 commit comments