diff --git a/abis/linux/in.h b/abis/linux/in.h index 610afc0702..2ef45859c9 100644 --- a/abis/linux/in.h +++ b/abis/linux/in.h @@ -178,6 +178,9 @@ struct group_source_req { #define IPV6_RECVHOPLIMIT 51 #define IPV6_HOPLIMIT 52 +#define IPV6_RECVTCLASS 66 +#define IPV6_TCLASS 67 + #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP @@ -188,6 +191,8 @@ struct group_source_req { #define IP_PMTUDISC_INTERFACE 4 #define IP_PMTUDISC_OMIT 5 +#define MCAST_BLOCK_SOURCE 43 +#define MCAST_UNBLOCK_SOURCE 44 #define MCAST_JOIN_SOURCE_GROUP 46 #define MCAST_LEAVE_SOURCE_GROUP 47 diff --git a/abis/linux/ioctls.h b/abis/linux/ioctls.h index c39abb5065..3a957bfc97 100644 --- a/abis/linux/ioctls.h +++ b/abis/linux/ioctls.h @@ -9,5 +9,7 @@ #define SIOCGIFINDEX 0x8933 #define SIOCATMARK 0x8905 #define SIOCGIFHWADDR 0x8927 +#define SIOCGIFBRDADDR 0x8919 +#define SIOCGIFNETMASK 0x891B #endif /* _ABIBITS_IOCTLS_H */ diff --git a/abis/linux/shm.h b/abis/linux/shm.h index 93fb01bbc7..bf71c8c6e5 100644 --- a/abis/linux/shm.h +++ b/abis/linux/shm.h @@ -5,6 +5,8 @@ extern "C" { #endif +#include + struct shm_info { int used_ids; unsigned long shm_tot; @@ -14,6 +16,8 @@ struct shm_info { unsigned long swap_successes; }; +#define SHMLBA (getpagesize()) + #ifdef __cplusplus } #endif diff --git a/abis/linux/signal.h b/abis/linux/signal.h index 3a85e4647c..d83b4011fc 100644 --- a/abis/linux/signal.h +++ b/abis/linux/signal.h @@ -7,6 +7,13 @@ #include #include +#define POLL_IN 1 +#define POLL_OUT 2 +#define POLL_MSG 3 +#define POLL_ERR 4 +#define POLL_PRI 5 +#define POLL_HUP 6 + union sigval { int sival_int; void *sival_ptr; diff --git a/options/ansi/include/setjmp.h b/options/ansi/include/setjmp.h index 81cc1ce79d..30346f08bb 100644 --- a/options/ansi/include/setjmp.h +++ b/options/ansi/include/setjmp.h @@ -25,7 +25,7 @@ __attribute__((__noreturn__)) void longjmp(jmp_buf buffer, int value); // POSIX Non-local jumps signal extensions -typedef struct { +typedef struct __sigjmp_buf { struct __mlibc_jmpbuf_register_state reg_state; int savesigs; sigset_t sigset; diff --git a/options/elf/include/elf.h b/options/elf/include/elf.h index 00a84524cc..68d70c2e0c 100644 --- a/options/elf/include/elf.h +++ b/options/elf/include/elf.h @@ -23,6 +23,8 @@ extern "C" { #define SHF_INFO_LINK 64 #define SHF_TLS 1024 +#define NT_AUXV 6 + typedef uint64_t Elf64_Addr; typedef uint64_t Elf64_Off; typedef uint16_t Elf64_Half; diff --git a/options/glibc/include/sys/procfs.h b/options/glibc/include/sys/procfs.h index c4b71eb625..b13a81d6c5 100644 --- a/options/glibc/include/sys/procfs.h +++ b/options/glibc/include/sys/procfs.h @@ -15,6 +15,8 @@ typedef unsigned long long elf_greg_t; typedef elf_greg_t elf_gregset_t[ELF_NGREG]; typedef struct user_fpregs_struct elf_fpregset_t; +typedef struct user_regs_struct prgregset_t; +typedef struct user_fpregs_struct prfpregset_t; #define ELF_PRARGSZ 80 @@ -41,6 +43,10 @@ struct elf_prstatus { int pr_fpvalid; }; +typedef pid_t lwpid_t; +typedef void *psaddr_t; +typedef struct elf_prstatus prstatus_t; + #ifdef __cplusplus } #endif diff --git a/options/posix/generic/pthread-stubs.cpp b/options/posix/generic/pthread-stubs.cpp index b7f5fc666f..9720bc2059 100644 --- a/options/posix/generic/pthread-stubs.cpp +++ b/options/posix/generic/pthread-stubs.cpp @@ -1420,6 +1420,7 @@ int pthread_rwlock_unlock(pthread_rwlock_t *rw) { } int pthread_getcpuclockid(pthread_t, clockid_t *) { - __ensure(!"Not implemented"); - __builtin_unreachable(); + mlibc::infoLogger() << "mlibc: pthread_getcpuclockid() always returns ENOENT" + << frg::endlog; + return ENOENT; } diff --git a/options/posix/generic/semaphore-stubs.cpp b/options/posix/generic/semaphore-stubs.cpp index 1faa55f588..d41eccb72b 100644 --- a/options/posix/generic/semaphore-stubs.cpp +++ b/options/posix/generic/semaphore-stubs.cpp @@ -98,7 +98,17 @@ int sem_unlink(const char *) { __builtin_unreachable(); } -int sem_trywait(sem_t *) { - __ensure(!"Not implemented"); - __builtin_unreachable(); +int sem_trywait(sem_t *sem) { + while (true) { + auto state = __atomic_load_n(&sem->__mlibc_count, __ATOMIC_ACQUIRE); + + if (state & semaphoreHasWaiters) { + return EAGAIN; + } + + auto desired = state - 1; + if (__atomic_compare_exchange_n(&sem->__mlibc_count, &state, desired, false, __ATOMIC_RELEASE, __ATOMIC_RELAXED)) { + return 0; + } + } } diff --git a/options/posix/include/net/if.h b/options/posix/include/net/if.h index 6e45f97c81..10016fd07b 100644 --- a/options/posix/include/net/if.h +++ b/options/posix/include/net/if.h @@ -85,6 +85,8 @@ unsigned int if_nametoindex(const char *); #endif /* !__MLIBC_ABI_ONLY */ +#define IFHWADDRLEN 6 + #define IFF_UP 0x1 #define IFF_BROADCAST 0x2 #define IFF_DEBUG 0x4 diff --git a/options/posix/include/netinet/icmp6.h b/options/posix/include/netinet/icmp6.h index 63733122dc..93f539f0d3 100644 --- a/options/posix/include/netinet/icmp6.h +++ b/options/posix/include/netinet/icmp6.h @@ -14,6 +14,7 @@ extern "C" { #define ICMP6_FILTER_PASS 2 #define ICMP6_FILTER_BLOCKOTHERS 3 #define ICMP6_FILTER_PASSONLY 4 +#define ICMP6_ECHO_REQUEST 128 struct icmp6_filter { uint32_t icmp6_filt[8]; @@ -34,6 +35,12 @@ struct icmp6_hdr { #define icmp6_data16 icmp6_dataun.icmp6_un_data16 #define icmp6_data8 icmp6_dataun.icmp6_un_data8 +#define icmp6_pptr icmp6_data32[0] +#define icmp6_mtu icmp6_data32[0] +#define icmp6_id icmp6_data16[0] +#define icmp6_seq icmp6_data16[1] +#define icmp6_maxdelay icmp6_data16[0] + #define ICMP6_FILTER_WILLPASS(type, filterp) \ ((((filterp)->icmp6_filt[(type) >> 5]) & (1U << ((type) & 31))) == 0) diff --git a/options/posix/include/netinet/ip_icmp.h b/options/posix/include/netinet/ip_icmp.h new file mode 100644 index 0000000000..56615e4cfb --- /dev/null +++ b/options/posix/include/netinet/ip_icmp.h @@ -0,0 +1,84 @@ +#ifndef _NETINET_ICMP_H +#define _NETINET_ICMP_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define ICMP_ECHOREPLY 0 +#define ICMP_ECHO 8 +#define ICMP_ADVLENMIN (8 + sizeof(struct ip) + 8) + +struct icmp_ra_addr { + uint32_t ira_addr; + uint32_t ira_preference; +}; + +struct icmp { + uint8_t icmp_type; + uint8_t icmp_code; + uint16_t icmp_cksum; + union { + unsigned char ih_pptr; + struct in_addr ih_gwaddr; + struct ih_idseq { + uint16_t icd_id; + uint16_t icd_seq; + } ih_idseq; + uint32_t ih_void; + + struct ih_pmtu { + uint16_t ipm_void; + uint16_t ipm_nextmtu; + } ih_pmtu; + + struct ih_rtradv { + uint8_t irt_num_addrs; + uint8_t irt_wpa; + uint16_t irt_lifetime; + } ih_rtradv; + } icmp_hun; + union { + struct { + uint32_t its_otime; + uint32_t its_rtime; + uint32_t its_ttime; + } id_ts; + struct { + struct ip idi_ip; + } id_ip; + struct icmp_ra_addr id_radv; + uint32_t id_mask; + uint8_t id_data[1]; + } icmp_dun; +}; + +#define icmp_pptr icmp_hun.ih_pptr +#define icmp_gwaddr icmp_hun.ih_gwaddr +#define icmp_id icmp_hun.ih_idseq.icd_id +#define icmp_seq icmp_hun.ih_idseq.icd_seq +#define icmp_void icmp_hun.ih_void +#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void +#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu +#define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs +#define icmp_wpa icmp_hun.ih_rtradv.irt_wpa +#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime + +#define icmp_otime icmp_dun.id_ts.its_otime +#define icmp_rtime icmp_dun.id_ts.its_rtime +#define icmp_ttime icmp_dun.id_ts.its_ttime +#define icmp_ip icmp_dun.id_ip.idi_ip +#define icmp_radv icmp_dun.id_radv +#define icmp_mask icmp_dun.id_mask +#define icmp_data icmp_dun.id_data + +#ifdef __cplusplus +} +#endif + +#endif // _NETINET_ICMP_H diff --git a/options/posix/include/netinet/tcp.h b/options/posix/include/netinet/tcp.h index 91ce1326bf..9d64d7af97 100644 --- a/options/posix/include/netinet/tcp.h +++ b/options/posix/include/netinet/tcp.h @@ -26,6 +26,7 @@ extern "C" { #define TCP_LAST_ACK 9 #define TCP_LISTEN 10 #define TCP_CLOSING 11 +#define TCP_QUICKACK 12 #define SOL_TCP 6 diff --git a/options/posix/include/unistd.h b/options/posix/include/unistd.h index 4cc750763a..d29257d365 100644 --- a/options/posix/include/unistd.h +++ b/options/posix/include/unistd.h @@ -191,6 +191,7 @@ extern "C" { #define _SC_MQ_PRIO_MAX 78 #define _SC_RTSIG_MAX 79 #define _SC_SIGQUEUE_MAX 80 +#define _SC_IOV_MAX 81 #define STDERR_FILENO 2 #define STDIN_FILENO 0 diff --git a/options/posix/meson.build b/options/posix/meson.build index ad68600117..038dd2c99e 100644 --- a/options/posix/meson.build +++ b/options/posix/meson.build @@ -121,6 +121,7 @@ if not no_headers 'include/netinet/if_ether.h', 'include/netinet/udp.h', 'include/netinet/ip6.h', + 'include/netinet/ip_icmp.h', subdir: 'netinet' ) install_headers( diff --git a/sysdeps/managarm/generic/socket.cpp b/sysdeps/managarm/generic/socket.cpp index 86a9373b4b..5bdc1fc513 100644 --- a/sysdeps/managarm/generic/socket.cpp +++ b/sysdeps/managarm/generic/socket.cpp @@ -297,6 +297,10 @@ int sys_getsockopt(int fd, int layer, int number, mlibc::infoLogger() << "\e[31mmlibc: getsockopt() call with SOL_SOCKET and SO_KEEPALIVE is unimplemented, hardcoding 0\e[39m" << frg::endlog; *(int *)buffer = 0; return 0; + }else if(layer == SOL_SOCKET && number == SO_LINGER) { + mlibc::infoLogger() << "\e[31mmlibc: getsockopt() call with SOL_SOCKET and SO_LINGER is unimplemented, hardcoding 0\e[39m" << frg::endlog; + *(int *)buffer = 0; + return 0; }else{ mlibc::panicLogger() << "\e[31mmlibc: Unexpected getsockopt() call, layer: " << layer << " number: " << number << "\e[39m" << frg::endlog; __builtin_unreachable(); @@ -352,6 +356,9 @@ int sys_setsockopt(int fd, int layer, int number, }else if(layer == SOL_SOCKET && number == SO_REUSEADDR) { mlibc::infoLogger() << "\e[31mmlibc: setsockopt() call with SOL_SOCKET and SO_REUSEADDR is unimplemented\e[39m" << frg::endlog; return 0; + }else if(layer == SOL_SOCKET && number == SO_REUSEPORT) { + mlibc::infoLogger() << "\e[31mmlibc: setsockopt() call with SOL_SOCKET and SO_REUSEPORT is unimplemented\e[39m" << frg::endlog; + return 0; }else if(layer == SOL_SOCKET && number == SO_RCVBUF) { mlibc::infoLogger() << "\e[31mmlibc: setsockopt() call with SOL_SOCKET and SO_RCVBUF is unimplemented\e[39m" << frg::endlog; return 0;