setsockopt was `return 0;` and getsockopt wrote a zero for whatever was asked. The comment said it was so a server setting SO_REUSEADDR and treating failure as fatal would not fail. That trade is the wrong way round: a caller told "no" adapts, a caller told "yes" changes its behaviour on the strength of it -- sets SO_RCVTIMEO and then blocks forever in a read it believes will time out, sets TCP_NODELAY and reports latency numbers that measure Nagle. The failure is silent, remote from the call, and indistinguishable from a bug in the stack. Six options are honoured now and everything else is ENOPROTOOPT. SO_REUSEADDR, SO_KEEPALIVE, SO_BROADCAST and TCP_NODELAY reach lwIP's pcb; SO_SNDBUF/SO_RCVBUF are accepted and report the real size on read. SO_REUSEADDR is implemented rather than refused precisely because of the original comment's concern -- it is the one option a server really does set and really does check. accept4 becomes its own table entry rather than an alias for accept. It has to be: accept takes three arguments, so a shared handler reading a fourth register reads whatever the caller last left there and invents a SOCK_NONBLOCK out of stack litter. SOCK_CLOEXEC and SOCK_NONBLOCK are now honoured by socket(), socketpair() and accept4() -- a dropped CLOEXEC leaks a listening socket across every exec, and a dropped NONBLOCK has the caller block forever in what it believes is a poll loop. ICMP ping sockets: socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP), on lwIP's raw API, with the callback stripping the variable-length IP header. Only echo replies are eaten, and that restriction is load-bearing -- raw_input runs before lwIP's own icmp_input, so consuming every ICMP message would swallow the echo *requests* and this machine would silently stop answering pings from outside. Loopback, so 127.0.0.1 is a real destination. LWIP_NETIF_LOOPBACK is the half that is easy to miss: without it a packet addressed to an interface's own address goes out of the wire and never comes back. With NO_SYS=1 nothing drains the loopback queue, so the network thread calls netif_poll_all(). cmd/ping is first-party rather than toybox's, and the reason is a limitation not a preference: toybox reads replies with recvmsg(2) and wants the TTL through an IP_RECVTTL control message, and SchOS has neither. recvmsg is item 1 of docs/plan/foundations.md, where it is wanted for SCM_RIGHTS anyway, and should not be rushed to make one applet run. Two bugs found on the way. Every AF_INET socket failed with ENFILE until DHCP bound, because inet_new() demanded an *address* before handing out a socket and reported it as "file table overflow"; net_is_ready() (lwIP up) is now distinct from net_is_up() (DHCP bound). And that bug was hiding a bad test: socktest asserted "AF_INET is refused, not faked", true when written, false since AF_INET landed, and green the whole time because the suite runs before DHCP binds and the ENFILE made the refusal look real. Fixing the kernel is what turned it red. Verified: ping to 127.0.0.1, localhost, the gateway, 1.1.1.1 and 9.9.9.9, all 0% loss; socktest ALL CHECKS PASSED with ten new checks, including a setsockopt round trip and an unknown option that must be refused -- a permissive stub cannot pass both at once. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
150 lines
No EOL
4.8 KiB
C
150 lines
No EOL
4.8 KiB
C
#pragma once
|
|
#ifndef USER_H
|
|
#define USER_H
|
|
|
|
#include "types.h"
|
|
#include "date.h"
|
|
|
|
struct stat;
|
|
struct rtcdate;
|
|
struct mouse_data;
|
|
|
|
// --- system calls ---
|
|
int fork(void);
|
|
void exit(void) __attribute__((noreturn));
|
|
int wait(void);
|
|
int pipe(int*);
|
|
int write(int, void*, int);
|
|
int read(int, void*, int);
|
|
int close(int);
|
|
int kill(int);
|
|
int exec(char*, char**);
|
|
int open(char*, int);
|
|
int mknod(char*, short, short);
|
|
int unlink(char*);
|
|
int fstat(int fd, struct stat*);
|
|
int link(char*, char*);
|
|
int mkdir(char*);
|
|
int chdir(char*);
|
|
int dup(int);
|
|
int dup2(int, int);
|
|
int fcntl(int, int, int);
|
|
long lseek(int, long, int);
|
|
int getpid(void);
|
|
char* sbrk(uint64);
|
|
int sleep(int);
|
|
int uptime(void);
|
|
int vga_sync(void*); // legacy no-op syscall; the name is ABI, not this layer
|
|
int getmouse(struct mouse_data*);
|
|
int reboot(void);
|
|
int shutdown(void);
|
|
int sigfillset(sigset_t *set);
|
|
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
|
|
int sigwait(const sigset_t *set, int *sig);
|
|
int alarm(int seconds);
|
|
int waitpid(int pid, int *status, int options);
|
|
int setsid(void);
|
|
void* mmap(void*, uint64, int, int, int, uint64);
|
|
// Shared memory. shmat returns the attach address, or a small negative value
|
|
// on failure — there is no errno in this runtime, so check for < 0.
|
|
int shmget(int key, uint64 size, int flags);
|
|
void* shmat(int id, void *addr, int flags);
|
|
int shmdt(void *addr);
|
|
int munmap(void*, uint64);
|
|
int delete(char*);
|
|
int show(char*);
|
|
int showstat(char*, struct stat*);
|
|
int ftruncate(int, int);
|
|
int truncate(char*, int);
|
|
int rename(const char*, const char*);
|
|
int symlink(char*, char*);
|
|
int readlink(char*, char*, int);
|
|
int getuid(void);
|
|
int geteuid(void);
|
|
int nanosleep(void*);
|
|
int mprotect(void*, uint64, int);
|
|
int ioctl(int, uint64, void*);
|
|
|
|
// Attributes on a file, and the index over them. Only SchFS carries these;
|
|
// anything else answers EOPNOTSUPP.
|
|
//
|
|
// schfs_query returns how many object ids it wrote, or -1 if the attribute has
|
|
// no index -- it will not fall back to walking the filesystem, because a query
|
|
// that silently becomes a full scan is worse than one that says it cannot help.
|
|
int setxattr(const char *path, const char *name, const void *val, int size,
|
|
int flags);
|
|
int getxattr(const char *path, const char *name, void *val, int size);
|
|
int removexattr(const char *path, const char *name);
|
|
int schfs_index(const char *name);
|
|
int schfs_query(const char *name, const char *value,
|
|
unsigned long long *out, int cap);
|
|
char* getcwd(char*, int);
|
|
int arch_prctl(int, uint64);
|
|
int set_tid_address(int*);
|
|
int set_robust_list(void*, int);
|
|
int futex(int*, int, int, void*, int*, int);
|
|
int clone(uint64, void*, void*, void*, void*);
|
|
void exit_group(int) __attribute__((noreturn));
|
|
int wait4(int, int*, int, void*);
|
|
int getgid(void);
|
|
int getegid(void);
|
|
int umask(int);
|
|
int writev(int, void*, int);
|
|
int readv(int, void*, int);
|
|
void* brk(void*);
|
|
int prlimit(int, int, void*, void*);
|
|
int lstat(const char*, struct stat*);
|
|
int access(const char*, int);
|
|
int openat(int, const char*, int, ...);
|
|
int fchdir(int);
|
|
int enable_linux_abi(void);
|
|
int getrlimit(int, void*);
|
|
int setuid(int);
|
|
int setgid(int);
|
|
int getsid(int);
|
|
int dup3(int, int, int);
|
|
int pipe2(int*, int);
|
|
int clock_gettime(int, void*);
|
|
int getppid(void);
|
|
int rt_sigaction(int, void*, void*, uint64);
|
|
int mount(const char *src, const char *tgt, const char *fstype, uint64 flags, void *data);
|
|
|
|
// Directory reading. The kernel has had getdents64 since the Linux ABI landed,
|
|
// but nothing declared it here, so first-party programs had no way to list a
|
|
// directory at all -- which is what schinit needs to find its job files.
|
|
//
|
|
// Records are packed: step by d_reclen, never by sizeof, because d_name is a
|
|
// flexible array and each record is only as long as its name needs.
|
|
struct dirent64 {
|
|
uint64 d_ino;
|
|
int64 d_off;
|
|
ushort d_reclen;
|
|
uchar d_type;
|
|
char d_name[];
|
|
};
|
|
#define DT_DIR 4
|
|
#define DT_REG 8
|
|
|
|
int getdents64(int fd, void *buf, int count);
|
|
|
|
// Sockets. `struct sockaddr` and the AF_*/SOCK_* constants are in socket.h;
|
|
// include it as well as this header to use them.
|
|
struct sockaddr;
|
|
int socket(int domain, int type, int protocol);
|
|
int bind(int fd, const struct sockaddr *addr, int addrlen);
|
|
int listen(int fd, int backlog);
|
|
int accept(int fd, struct sockaddr *addr, int *addrlen);
|
|
int accept4(int fd, struct sockaddr *addr, int *addrlen, int flags);
|
|
int connect(int fd, const struct sockaddr *addr, int addrlen);
|
|
int socketpair(int domain, int type, int protocol, int sv[2]);
|
|
int sendto(int fd, const void *buf, int len, int flags, const struct sockaddr*, int);
|
|
int recvfrom(int fd, void *buf, int len, int flags, struct sockaddr*, int*);
|
|
int sockshutdown(int fd, int how);
|
|
int setsockopt(int fd, int level, int opt, const void *val, int len);
|
|
int getsockopt(int fd, int level, int opt, void *val, int *len);
|
|
|
|
// --- ulib.c ---
|
|
int stat(const char*, struct stat*);
|
|
char* gets(char*, int max);
|
|
|
|
#endif // USER_H
|