diff options
Diffstat (limited to 'sys/include')
-rw-r--r-- | sys/include/arch/aarch64/param.h | 35 | ||||
-rw-r--r-- | sys/include/arch/amd64/param.h | 35 | ||||
-rw-r--r-- | sys/include/sys/limits.h | 1 | ||||
-rw-r--r-- | sys/include/sys/param.h | 10 | ||||
-rw-r--r-- | sys/include/sys/socket.h | 89 | ||||
-rw-r--r-- | sys/include/sys/syscall.h | 6 | ||||
-rw-r--r-- | sys/include/sys/uio.h | 58 |
7 files changed, 234 insertions, 0 deletions
diff --git a/sys/include/arch/aarch64/param.h b/sys/include/arch/aarch64/param.h new file mode 100644 index 0000000..c074ffb --- /dev/null +++ b/sys/include/arch/aarch64/param.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _AARCH64_PARAM_H_ +#define _AARCH64_PARAM_H_ + +#define M_WORD_SIZE 4 + +#endif /* !_AARCH64_PARAM_H_ */ diff --git a/sys/include/arch/amd64/param.h b/sys/include/arch/amd64/param.h new file mode 100644 index 0000000..6ea3fca --- /dev/null +++ b/sys/include/arch/amd64/param.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _AMD64_PARAM_H_ +#define _AMD64_PARAM_H_ + +#define M_WORD_SIZE 8 + +#endif /* !_AMD64_PARAM_H_ */ diff --git a/sys/include/sys/limits.h b/sys/include/sys/limits.h index 963d113..c0ce5af 100644 --- a/sys/include/sys/limits.h +++ b/sys/include/sys/limits.h @@ -38,4 +38,5 @@ #define CPU_MAX 256 #define VSR_MAX_DOMAIN 16 #define VSR_MAX_CAPSULE 16 +#define IOVEC_MAX 512 #endif /* !_SYS_LIMITS_H_ */ diff --git a/sys/include/sys/param.h b/sys/include/sys/param.h index 7331d5f..2bbbabd 100644 --- a/sys/include/sys/param.h +++ b/sys/include/sys/param.h @@ -30,11 +30,20 @@ #ifndef _SYS_PARAM_H_ #define _SYS_PARAM_H_ +#if defined(_KERNEL) +#include <machine/param.h> +#endif + /* Assumed cache line size */ #ifndef COHERENCY_UNIT #define COHERENCY_UNIT 64 #endif +/* Assumed machine word size */ +#ifndef M_WORD_SIZE +#define M_WORD_SIZE 4 +#endif + /* Bit related macros */ #define ISSET(v, f) ((v) & (f)) #define BIT(n) (1ULL << (n)) @@ -47,6 +56,7 @@ /* Align up/down a value */ #define ALIGN_DOWN(value, align) ((value) & ~((align)-1)) #define ALIGN_UP(value, align) (((value) + (align)-1) & ~((align)-1)) +#define MALIGN(value) ALIGN_UP((value), M_WORD_SIZE) /* Bitmap helper macros */ #define setbit(a, b) ((a)[(b) >> 3] |= BIT(b % 8)) diff --git a/sys/include/sys/socket.h b/sys/include/sys/socket.h index 7175da5..5ce1ec6 100644 --- a/sys/include/sys/socket.h +++ b/sys/include/sys/socket.h @@ -31,6 +31,9 @@ #define _SYS_SOCKET_H_ #include <sys/socketvar.h> +#include <sys/queue.h> +#include <sys/param.h> +#include <sys/uio.h> #if defined(_KERNEL) #include <sys/types.h> #include <sys/syscall.h> @@ -51,6 +54,11 @@ typedef uint32_t socklen_t; #endif /* !_SOCKLEN_T_DEFINED_ */ /* + * Socket level number + */ +#define SOL_SOCKET 0xFFFF + +/* * Address family defines */ #define AF_UNSPEC 0 @@ -70,17 +78,95 @@ struct sockaddr { char sa_data[14]; }; +/* + * POSIX message header for recvmsg() + * and sendmsg() calls. + */ +struct msghdr { + void *msg_name; /* Optional address */ + socklen_t msg_namelen; /* Size of address */ + struct iovec *msg_iov; /* Scatter/gather array */ + int msg_iovlen; /* Members in msg_iov */ + void *msg_control; /* Ancillary data, see below */ + socklen_t msg_controllen; /* Ancillary data buffer len */ + int msg_flags; /* Message flags */ +}; + +/* + * POSIX control message header for + * ancillary data objects. + */ +struct cmsghdr { + socklen_t cmsg_len; + int cmsg_level; + int cmsg_type; +}; + +#define CMSG_SPACE(len) (MALIGN(sizeof(struct cmsghdr)) + MALIGN(len)) + +/* Return pointer to cmsg data */ +#define CMSG_DATA(cmsg) PTR_OFFSET(cmsg, sizeof(struct cmsghdr)) + +/* Return length of control message */ +#define CMSG_LEN(len) (MALIGN(sizeof(struct cmsghdr)) + MALIGN(len)) + +/* Return pointer to next cmsghdr */ +#define CMSG_NXTHDR(mhdr, cmsg) \ + PTR_OFFSET(cmsg, MALIGN((cmsg)>cmsg_len)) + \ + MALIGN(sizeof(struct cmsghdr)) > \ + PTR_OFFSET((mhdr)->msg_control, (mhdr)->msg_controllen) ? \ + (struct cmsghdr *)NULL : \ + (struct cmsghdr *)PTR_OFFSET(cmsg, MALIGN((cmsg)->cmsg_len)) + +/* Return pointer to first header */ +#define CMSG_FIRSTHDR(mhdr) \ + ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ + (struct cmsghdr *)(mhdr)->msg_control : \ + (struct cmsghdr *)NULL); + +/* Socket level control messages */ +#define SCM_RIGHTS 0x01 + #if defined(_KERNEL) +struct cmsg { + union { + struct cmsghdr hdr; + uint8_t buf[CMSG_SPACE(sizeof(int))]; + }; + + size_t control_len; + TAILQ_ENTRY(cmsg) link; +}; + +/* + * List of cmsg headers and data, queued up + * during sendmsg() + */ +struct cmsg_list { + TAILQ_HEAD(, cmsg) list; + uint8_t is_init : 1; +}; + struct ksocket { int sockfd; union { struct sockaddr sockaddr; struct sockaddr_un un; }; + struct cmsg_list cmsg_list; struct sockbuf buf; struct mutex *mtx; }; + +scret_t sys_socket(struct syscall_args *scargs); +scret_t sys_bind(struct syscall_args *scargs); + +scret_t sys_recv(struct syscall_args *scargs); +scret_t sys_send(struct syscall_args *scargs); + +scret_t sys_recvmsg(struct syscall_args *scargs); +scret_t sys_sendmsg(struct syscall_args *scargs); #endif /* _KERNEL */ int socket(int domain, int type, int protocol); @@ -89,4 +175,7 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t len); ssize_t send(int sockfd, const void *buf, size_t size, int flags); ssize_t recv(int sockfd, void *buf, size_t len, int flags); +ssize_t sendmsg(int socket, const struct msghdr *msg, int flags); +ssize_t recvmsg(int socket, struct msghdr *msg, int flags); + #endif /* !_SYS_SOCKET_H_ */ diff --git a/sys/include/sys/syscall.h b/sys/include/sys/syscall.h index 02629a9..d79a697 100644 --- a/sys/include/sys/syscall.h +++ b/sys/include/sys/syscall.h @@ -59,6 +59,12 @@ #define SYS_setuid 18 #define SYS_getuid 19 #define SYS_waitpid 20 +#define SYS_socket 21 +#define SYS_bind 22 +#define SYS_recv 23 +#define SYS_send 24 +#define SYS_sendmsg 25 +#define SYS_recvmsg 26 #if defined(_KERNEL) /* Syscall return value and arg type */ diff --git a/sys/include/sys/uio.h b/sys/include/sys/uio.h new file mode 100644 index 0000000..4318a53 --- /dev/null +++ b/sys/include/sys/uio.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_UIO_H_ +#define _SYS_UIO_H_ + +#if defined(_KERNEL) +#include <sys/types.h> +#else +#include <stdint.h> +#include <stddef.h> +#endif /* _KERNEL */ + +/* + * POSIX I/O vector + */ +struct iovec { + void *iov_base; + size_t iov_len; +}; + +ssize_t readv(int filedes, const struct iovec *iov, int iovcnt); +ssize_t writev(int filedes, const struct iovec *iov, int iovcnt); + +#if defined(_KERNEL) + +int uio_copyin(const struct iovec *u_iov, struct iovec *k_iov, int iovcnt); +int uio_copyout(const struct iovec *k_iov, struct iovec *u_iov, int iovcnt); +void uio_copyin_clean(struct iovec *copy, int iovcnt); + +#endif /* _KERNEL */ +#endif /* !_SYS_UIO_H_ */ |