@@ -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,61 @@ 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+ }
718+
719+ args -> fd = fd ;
720+
721+ SYSCALL (FF_SO_ACCEPT4 , args );
722+
723+ if (ret > 0 ) {
724+ ret = convert_fstack_fd (ret );
725+ }
726+
727+ if (addr ) {
728+ if (ret > 0 ) {
729+ socklen_t cplen = * sh_addrlen > * addrlen ?
730+ * addrlen : * sh_addrlen ;
731+ rte_memcpy (addr , sh_addr , cplen );
732+ * addrlen = * sh_addrlen ;
733+ }
734+ //share_mem_free(sh_addr); // Don't free
735+ //share_mem_free(sh_addrlen);
736+ }
737+
738+ RETURN_NOFREE ();
685739}
686740
687741int
0 commit comments