Skip to content

Commit

Permalink
Merge pull request #936 from Qwinci/java
Browse files Browse the repository at this point in the history
  • Loading branch information
no92 authored Feb 17, 2024
2 parents 21d0b1b + f31f81e commit c96114c
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 6 deletions.
5 changes: 5 additions & 0 deletions abis/linux/in.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions abis/linux/ioctls.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
#define SIOCGIFINDEX 0x8933
#define SIOCATMARK 0x8905
#define SIOCGIFHWADDR 0x8927
#define SIOCGIFBRDADDR 0x8919
#define SIOCGIFNETMASK 0x891B

#endif /* _ABIBITS_IOCTLS_H */
4 changes: 4 additions & 0 deletions abis/linux/shm.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
extern "C" {
#endif

#include <unistd.h>

struct shm_info {
int used_ids;
unsigned long shm_tot;
Expand All @@ -14,6 +16,8 @@ struct shm_info {
unsigned long swap_successes;
};

#define SHMLBA (getpagesize())

#ifdef __cplusplus
}
#endif
Expand Down
7 changes: 7 additions & 0 deletions abis/linux/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
#include <abi-bits/uid_t.h>
#include <bits/size_t.h>

#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;
Expand Down
2 changes: 1 addition & 1 deletion options/ansi/include/setjmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions options/elf/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions options/glibc/include/sys/procfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions options/posix/generic/pthread-stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
16 changes: 13 additions & 3 deletions options/posix/generic/semaphore-stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
2 changes: 2 additions & 0 deletions options/posix/include/net/if.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions options/posix/include/netinet/icmp6.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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)

Expand Down
84 changes: 84 additions & 0 deletions options/posix/include/netinet/ip_icmp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#ifndef _NETINET_ICMP_H
#define _NETINET_ICMP_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <netinet/in.h>
#include <netinet/ip.h>

#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
1 change: 1 addition & 0 deletions options/posix/include/netinet/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions options/posix/include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions options/posix/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions sysdeps/managarm/generic/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c96114c

Please sign in to comment.