- 
                Notifications
    
You must be signed in to change notification settings  - Fork 712
 
Partial OpenBSD support. #3394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            3405691582
  wants to merge
  12
  commits into
  apple:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
3405691582:openbsd
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Partial OpenBSD support. #3394
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            12 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      c7863d9
              
                Partial OpenBSD support.
              
              
                3405691582 e6c20c2
              
                update: set explicit permissions for GitHub workflows - cxx-interop (…
              
              
                incertum 6646550
              
                update: set explicit permissions for GitHub workflows - benchmarks (#…
              
              
                incertum 6ca63a1
              
                update: set explicit permissions for GitHub workflows - release-build…
              
              
                incertum e47bcfc
              
                Apply suggestions from code review
              
              
                3405691582 6c97c72
              
                Merge branch 'main' into openbsd
              
              
                rnro 25343db
              
                Merge branch 'main' into openbsd
              
              
                3405691582 360935c
              
                Rename CNIOBSD to CNIOOpenBSD.
              
              
                3405691582 4d84fae
              
                Merge branch 'main' into openbsd
              
              
                Lukasa f53474d
              
                Reorder from rename.
              
              
                3405691582 c6c8469
              
                Only build CNIOOpenBSD on OpenBSD.
              
              
                3405691582 39373cf
              
                Merge branch 'main' into openbsd
              
              
                Lukasa File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the SwiftNIO open source project | ||
| // | ||
| // Copyright (c) 2017-2025 Apple Inc. and the SwiftNIO project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| #ifndef C_NIO_OPENBSD_H | ||
| #define C_NIO_OPENBSD_H | ||
| 
     | 
||
| #if defined(__OpenBSD__) | ||
| #include <sys/types.h> | ||
| #include <sys/event.h> | ||
| #include <pthread_np.h> | ||
| #include <sys/types.h> | ||
| #include <sys/socket.h> | ||
| #include <sys/stat.h> | ||
| #include <sys/time.h> | ||
| #include <sys/un.h> | ||
| #include <sys/utsname.h> | ||
| #include <dirent.h> | ||
| #include <fts.h> | ||
| #include <ifaddrs.h> | ||
| #include <net/if.h> | ||
| #include <netinet/in.h> | ||
| #include <netinet/ip.h> | ||
| #include <pthread.h> | ||
| #include <stdbool.h> | ||
| 
     | 
||
| 
     | 
||
| // Some explanation is required here. | ||
| // | ||
| // Due to SR-6772, we cannot get Swift code to directly see any of the mmsg structures or | ||
| // functions. However, we *can* get C code built by SwiftPM to see them. For this reason we | ||
| // elect to provide a selection of shims to enable Swift code to use recv_mmsg and send_mmsg. | ||
| // Mostly this is fine, but to minimise the overhead we want the Swift code to be able to | ||
| // create the msgvec directly without requiring further memory fussiness in our C shim. | ||
| // That requires us to also construct a C structure that has the same layout as struct mmsghdr. | ||
| // | ||
| // Conveniently glibc has pretty strict ABI stability rules, and this structure is part of the | ||
| // glibc ABI, so we can just reproduce the structure definition here and feel confident that it | ||
| // will be sufficient. | ||
| // | ||
| // If SR-6772 ever gets resolved we can remove this shim. | ||
| // | ||
| // https://bugs.swift.org/browse/SR-6772 | ||
| 
     | 
||
| typedef struct { | ||
| struct msghdr msg_hdr; | ||
| unsigned int msg_len; | ||
| } CNIOOpenBSD_mmsghdr; | ||
| 
     | 
||
| typedef struct { | ||
| struct in6_addr ipi6_addr; | ||
| unsigned int ipi6_ifindex; | ||
| } CNIOOpenBSD_in6_pktinfo; | ||
| 
     | 
||
| int CNIOOpenBSD_sendmmsg(int sockfd, CNIOOpenBSD_mmsghdr *msgvec, unsigned int vlen, int flags); | ||
| int CNIOOpenBSD_recvmmsg(int sockfd, CNIOOpenBSD_mmsghdr *msgvec, unsigned int vlen, int flags, struct timespec *timeout); | ||
| 
     | 
||
| int CNIOOpenBSD_pthread_set_name_np(pthread_t thread, const char *name); | ||
| int CNIOOpenBSD_pthread_get_name_np(pthread_t thread, char *name, size_t len); | ||
| 
     | 
||
| // Non-standard socket stuff. | ||
| int CNIOOpenBSD_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags); | ||
| 
     | 
||
| // cmsghdr handling | ||
| struct cmsghdr *CNIOOpenBSD_CMSG_FIRSTHDR(const struct msghdr *); | ||
| struct cmsghdr *CNIOOpenBSD_CMSG_NXTHDR(struct msghdr *, struct cmsghdr *); | ||
| const void *CNIOOpenBSD_CMSG_DATA(const struct cmsghdr *); | ||
| void *CNIOOpenBSD_CMSG_DATA_MUTABLE(struct cmsghdr *); | ||
| size_t CNIOOpenBSD_CMSG_LEN(size_t); | ||
| size_t CNIOOpenBSD_CMSG_SPACE(size_t); | ||
| 
     | 
||
| // awkward time_T pain | ||
| extern const int CNIOOpenBSD_SO_TIMESTAMP; | ||
| extern const int CNIOOpenBSD_SO_RCVTIMEO; | ||
| 
     | 
||
| int CNIOOpenBSD_system_info(struct utsname *uname_data); | ||
| 
     | 
||
| extern const unsigned long CNIOOpenBSD_IOCTL_VM_SOCKETS_GET_LOCAL_CID; | ||
| 
     | 
||
| const char* CNIOOpenBSD_dirent_dname(struct dirent *ent); | ||
| 
     | 
||
| extern const unsigned long CNIOOpenBSD_UTIME_OMIT; | ||
| extern const unsigned long CNIOOpenBSD_UTIME_NOW; | ||
| 
     | 
||
| extern const long CNIOOpenBSD_UDP_MAX_SEGMENTS; | ||
| 
     | 
||
| // A workaround for incorrect nullability annotations in the Android SDK. | ||
| // Probably unnecessary on BSD, but copying for consistency for now. | ||
| FTS *CNIOOpenBSD_fts_open(char * const *path_argv, int options, int (*compar)(const FTSENT **, const FTSENT **)); | ||
| 
     | 
||
| #endif | ||
| #endif | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the SwiftNIO open source project | ||
| // | ||
| // Copyright (c) 2017-2025 Apple Inc. and the SwiftNIO project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| 
     | 
||
| // Xcode's Archive builds with Xcode's Package support struggle with empty .c files | ||
| // (https://bugs.swift.org/browse/SR-12939). | ||
| void CNIOOpenBSD_i_do_nothing_just_working_around_a_darwin_toolchain_bug(void) {} | ||
| 
     | 
||
| #if defined(__OpenBSD__) | ||
| 
     | 
||
| #include <CNIOOpenBSD.h> | ||
| #include <pthread.h> | ||
| #include <assert.h> | ||
| #include <unistd.h> | ||
| 
     | 
||
| int CNIOOpenBSD_pthread_set_name_np(pthread_t thread, const char *name) { | ||
| pthread_set_name_np(thread, name); | ||
| return 0; | ||
| } | ||
| 
     | 
||
| int CNIOOpenBSD_pthread_get_name_np(pthread_t thread, char *name, size_t len) { | ||
| pthread_get_name_np(thread, name, len); | ||
| return 0; | ||
| } | ||
| 
     | 
||
| int CNIOOpenBSD_sendmmsg(int sockfd, CNIOOpenBSD_mmsghdr *msgvec, unsigned int vlen, int flags) { | ||
| // This is technically undefined behaviour, but it's basically fine because these types are the same size, and we | ||
| // don't think the compiler is inclined to blow anything up here. | ||
| // This comment is from CNIOLinux, but I haven't reverified this applies for OpenBSD. | ||
| return sendmmsg(sockfd, (struct mmsghdr *)msgvec, vlen, flags); | ||
| } | ||
| 
     | 
||
| int CNIOOpenBSD_recvmmsg(int sockfd, CNIOOpenBSD_mmsghdr *msgvec, unsigned int vlen, int flags, struct timespec *timeout) { | ||
| // This is technically undefined behaviour, but it's basically fine because these types are the same size, and we | ||
| // don't think the compiler is inclined to blow anything up here. | ||
| // This comment is from CNIOLinux, but I haven't reverified this applies for OpenBSD. | ||
| return recvmmsg(sockfd, (struct mmsghdr *)msgvec, vlen, flags, timeout); | ||
| } | ||
| 
     | 
||
| int CNIOOpenBSD_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) { | ||
| return accept4(sockfd, addr, addrlen, flags); | ||
| } | ||
| 
     | 
||
| struct cmsghdr *CNIOOpenBSD_CMSG_FIRSTHDR(const struct msghdr *mhdr) { | ||
| assert(mhdr != NULL); | ||
| return CMSG_FIRSTHDR(mhdr); | ||
| } | ||
| 
     | 
||
| struct cmsghdr *CNIOOpenBSD_CMSG_NXTHDR(struct msghdr *mhdr, struct cmsghdr *cmsg) { | ||
| assert(mhdr != NULL); | ||
| assert(cmsg != NULL); | ||
| return CMSG_NXTHDR(mhdr, cmsg); | ||
| } | ||
| 
     | 
||
| const void *CNIOOpenBSD_CMSG_DATA(const struct cmsghdr *cmsg) { | ||
| assert(cmsg != NULL); | ||
| return CMSG_DATA(cmsg); | ||
| } | ||
| 
     | 
||
| void *CNIOOpenBSD_CMSG_DATA_MUTABLE(struct cmsghdr *cmsg) { | ||
| assert(cmsg != NULL); | ||
| return CMSG_DATA(cmsg); | ||
| } | ||
| 
     | 
||
| size_t CNIOOpenBSD_CMSG_LEN(size_t payloadSizeBytes) { | ||
| return CMSG_LEN(payloadSizeBytes); | ||
| } | ||
| 
     | 
||
| size_t CNIOOpenBSD_CMSG_SPACE(size_t payloadSizeBytes) { | ||
| return CMSG_SPACE(payloadSizeBytes); | ||
| } | ||
| 
     | 
||
| const int CNIOOpenBSD_SO_TIMESTAMP = SO_TIMESTAMP; | ||
| const int CNIOOpenBSD_SO_RCVTIMEO = SO_RCVTIMEO; | ||
| 
     | 
||
| bool supports_udp_sockopt(int opt, int value) { | ||
| int fd = socket(AF_INET, SOCK_DGRAM, 0); | ||
| if (fd == -1) { | ||
| return false; | ||
| } | ||
| int rc = setsockopt(fd, IPPROTO_UDP, opt, &value, sizeof(value)); | ||
| close(fd); | ||
| return rc == 0; | ||
| } | ||
| 
     | 
||
| bool CNIOOpenBSD_supports_udp_segment() { | ||
| #ifndef UDP_SEGMENT | ||
| return false; | ||
| #else | ||
| return supports_udp_sockopt(UDP_SEGMENT, 512); | ||
| #endif | ||
| } | ||
| 
     | 
||
| bool CNIOOpenBSD_supports_udp_gro() { | ||
| #ifndef UDP_GRO | ||
| return false; | ||
| #else | ||
| return supports_udp_sockopt(UDP_GRO, 1); | ||
| #endif | ||
| } | ||
| 
     | 
||
| int CNIOOpenBSD_system_info(struct utsname* uname_data) { | ||
| return uname(uname_data); | ||
| } | ||
| 
     | 
||
| const char* CNIOOpenBSD_dirent_dname(struct dirent* ent) { | ||
| return ent->d_name; | ||
| } | ||
| 
     | 
||
| const unsigned long CNIOOpenBSD_UTIME_OMIT = UTIME_OMIT; | ||
| const unsigned long CNIOOpenBSD_UTIME_NOW = UTIME_NOW; | ||
| 
     | 
||
| #ifdef UDP_MAX_SEGMENTS | ||
| const long CNIOOpenBSD_UDP_MAX_SEGMENTS = UDP_MAX_SEGMENTS; | ||
| #endif | ||
| const long CNIOOpenBSD_UDP_MAX_SEGMENTS = -1; | ||
| 
     | 
||
| FTS *CNIOOpenBSD_fts_open(char * const *path_argv, int options, int (*compar)(const FTSENT **, const FTSENT **)) { | ||
| return fts_open(path_argv, options, compar); | ||
| } | ||
| #endif | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.