diff options
-rw-r--r-- | include/sys/socket.h (renamed from userland/libc/include/socket.h) | 21 | ||||
-rw-r--r-- | kernel/cpu/syscall.c | 6 | ||||
-rw-r--r-- | kernel/socket.c | 51 | ||||
-rw-r--r-- | kernel/socket.h | 4 | ||||
-rw-r--r-- | kernel/syscalls/lseek.c | 34 | ||||
-rw-r--r-- | userland/irc/irc.c | 87 | ||||
-rw-r--r-- | userland/libc/Makefile | 2 | ||||
-rw-r--r-- | userland/libc/include/sys/socket.h | 11 | ||||
-rw-r--r-- | userland/libc/include/syscall.h | 3 | ||||
-rw-r--r-- | userland/libc/sys/socket/connect.c | 6 | ||||
-rw-r--r-- | userland/libc/sys/socket/setsockopt.c | 8 | ||||
-rw-r--r-- | userland/libc/unistd/lseek.c | 7 |
12 files changed, 168 insertions, 72 deletions
diff --git a/userland/libc/include/socket.h b/include/sys/socket.h index bee592b..eab62eb 100644 --- a/userland/libc/include/socket.h +++ b/include/sys/socket.h @@ -1,5 +1,5 @@ -#ifndef SOCKET_H -#define SOCKET_H +#ifndef SYS_SOCKET_H +#define SYS_SOCKET_H #include <stddef.h> #include <stdint.h> @@ -9,9 +9,15 @@ #define SOCK_DGRAM 0 #define SOCK_STREAM 1 +#define MSG_WAITALL 1 #define INADDR_ANY 0 +#define IPPROTO_TCP 0 +#define TCP_NODELAY 0 + +#ifndef KERNEL + typedef struct { int domain; int type; @@ -54,4 +60,13 @@ struct sockaddr_un { int socket(int domain, int type, int protocol); int accept(int socket, struct sockaddr *address, socklen_t *address_len); int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); -#endif // SOCKET_H +size_t recvfrom(int socket, void *buffer, size_t length, int flags, + struct sockaddr *address, socklen_t *address_len); +size_t sendto(int socket, const void *message, size_t length, int flags, + const struct sockaddr *dest_addr, socklen_t dest_len); +int listen(int socket, int backlog); +int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); +int setsockopt(int socket, int level, int option_name, const void *option_value, + socklen_t option_len); +#endif // KERNEL +#endif // SYS_SOCKET_H diff --git a/kernel/cpu/syscall.c b/kernel/cpu/syscall.c index 84faa16..b72beff 100644 --- a/kernel/cpu/syscall.c +++ b/kernel/cpu/syscall.c @@ -145,6 +145,11 @@ int syscall_connect(int sockfd, const struct sockaddr *addr, return connect(sockfd, addr, addrlen); } +int syscall_setsockopt(int socket, int level, int option_name, + const void *option_value, socklen_t option_len) { + return setsockopt(socket, level, option_name, option_value, option_len); +} + int (*syscall_functions[])() = { (void(*))syscall_open, (void(*))syscall_mread, @@ -198,6 +203,7 @@ int (*syscall_functions[])() = { (void(*))syscall_open_process, (void(*))syscall_lseek, (void(*))syscall_connect, + (void(*))syscall_setsockopt, }; void int_syscall(reg_t *r); diff --git a/kernel/socket.c b/kernel/socket.c index fbc0648..d952052 100644 --- a/kernel/socket.c +++ b/kernel/socket.c @@ -8,6 +8,7 @@ #include <poll.h> #include <sched/scheduler.h> #include <socket.h> +#include <sys/socket.h> struct list open_tcp_connections; struct list open_tcp_listen; @@ -70,6 +71,7 @@ struct TcpConnection *internal_tcp_incoming(u32 src_ip, u16 src_port, con->outgoing_port = src_port; con->incoming_ip = dst_ip; con->incoming_port = dst_port; + con->no_delay = 0; ringbuffer_init(&con->incoming_buffer, 8192); ringbuffer_init(&con->outgoing_buffer, 8192); @@ -126,6 +128,11 @@ int tcp_write(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) { return -EBADF; // TODO: Check if this is correct. } + if (con->no_delay) { + send_tcp_packet(con, buffer, len); + return len; + } + struct ringbuffer *rb = &con->outgoing_buffer; if (ringbuffer_unused(rb) < len) { tcp_sync_buffer(fd); @@ -144,10 +151,8 @@ int tcp_has_data(vfs_inode_t *inode) { int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { vfs_fd_t *fd = get_vfs_fd(sockfd, NULL); - assert(fd); - - if (fd->inode->internal_object) { - return -EISCONN; + if (!fd) { + return -EBADF; } assert(AF_INET == addr->sa_family); @@ -159,7 +164,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { con->incoming_port = 1337; // TODO con->outgoing_ip = in_addr->sin_addr.s_addr; - con->outgoing_port = in_addr->sin_port; + con->outgoing_port = ntohs(in_addr->sin_port); ringbuffer_init(&con->incoming_buffer, 8192); ringbuffer_init(&con->outgoing_buffer, 8192); @@ -185,6 +190,35 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { return 0; } +int setsockopt(int socket, int level, int option_name, const void *option_value, + socklen_t option_len) { + vfs_fd_t *fd = get_vfs_fd(socket, NULL); + if (!fd) { + return -EBADF; + } + // TODO: Check that it is actually a TCP socket + if (IPPROTO_TCP == level) { + struct TcpConnection *tcp_connection = fd->inode->internal_object; + switch (option_name) { + case TCP_NODELAY: { + if (sizeof(int) != option_len) { + return -EINVAL; + } + if (!mmu_is_valid_userpointer(option_value, option_len)) { + return -EPERM; // TODO: Check if this is correct + } + int value = *(int *)option_value; + tcp_connection->no_delay = value; + } break; + default: + return -ENOPROTOOPT; + break; + } + return 0; + } + return -ENOPROTOOPT; +} + int uds_open(const char *path) { // FIXME: This is super ugly @@ -268,10 +302,9 @@ int accept(int socket, struct sockaddr *address, socklen_t *address_len) { stack_pop(&tcp_listen->incoming_connections); assert(connection); vfs_inode_t *inode = vfs_create_inode( - 0 /*inode_num*/, FS_TYPE_UNIX_SOCKET, tcp_has_data, - always_can_write, 1, connection, 0 /*file_size*/, NULL /*open*/, - NULL /*create_file*/, tcp_read, tcp_write, - tcp_close /*close*/, NULL /*create_directory*/, + 0 /*inode_num*/, FS_TYPE_UNIX_SOCKET, tcp_has_data, always_can_write, 1, + connection, 0 /*file_size*/, NULL /*open*/, NULL /*create_file*/, + tcp_read, tcp_write, tcp_close /*close*/, NULL /*create_directory*/, NULL /*get_vm_object*/, NULL /*truncate*/, NULL /*stat*/, NULL /*send_signal*/); assert(inode); diff --git a/kernel/socket.h b/kernel/socket.h index b542c87..3d1025d 100644 --- a/kernel/socket.h +++ b/kernel/socket.h @@ -38,6 +38,8 @@ struct TcpConnection { struct ringbuffer incoming_buffer; struct ringbuffer outgoing_buffer; + int no_delay; + u32 seq; u32 ack; @@ -116,4 +118,6 @@ struct INCOMING_TCP_CONNECTION *get_incoming_tcp_connection(u8 ip[4], int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); void global_socket_init(void); u16 tcp_get_free_port(void); +int setsockopt(int socket, int level, int option_name, const void *option_value, + socklen_t option_len); #endif diff --git a/kernel/syscalls/lseek.c b/kernel/syscalls/lseek.c new file mode 100644 index 0000000..3e38822 --- /dev/null +++ b/kernel/syscalls/lseek.c @@ -0,0 +1,34 @@ +#include <assert.h> +#include <errno.h> +#include <fs/vfs.h> + +// FIXME: These should be in a shared header file with libc +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 + +off_t syscall_lseek(int fd, off_t offset, int whence) { + vfs_fd_t *fd_ptr = get_vfs_fd(fd, NULL); + if (!fd_ptr) { + return -EBADF; + } + + off_t ret_offset = fd_ptr->offset; + switch (whence) { + case SEEK_SET: + ret_offset = offset; + break; + case SEEK_CUR: + ret_offset += offset; + break; + case SEEK_END: + assert(fd_ptr->inode); + ret_offset = fd_ptr->inode->file_size + offset; + break; + default: + return -EINVAL; + break; + } + fd_ptr->offset = ret_offset; + return ret_offset; +} diff --git a/userland/irc/irc.c b/userland/irc/irc.c index a80a4dd..cd6f990 100644 --- a/userland/irc/irc.c +++ b/userland/irc/irc.c @@ -1,5 +1,6 @@ #include "sb.h" #include "sv.h" +#include <arpa/inet.h> #include <assert.h> #include <ctype.h> #include <fcntl.h> @@ -7,12 +8,12 @@ #include <math.h> #include <poll.h> #include <pty.h> -#include <socket.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/socket.h> #include <syscall.h> #include <unistd.h> @@ -48,18 +49,6 @@ void irc_add_message(struct irc_server *server, struct sv channel_name, void irc_add_message_to_channel(struct irc_channel *chan, struct sv sender, struct sv msg_text); -u32 tcp_connect_ipv4(u32 ip, u16 port, int *err) { - return (u32)syscall(SYS_TCP_CONNECT, ip, port, err, 0, 0); -} - -int tcp_write(u32 socket, const u8 *buffer, u64 len, u64 *out) { - return (int)syscall(SYS_TCP_WRITE, socket, buffer, len, out, 0); -} - -int tcp_read(u32 socket, u8 *buffer, u64 buffer_size, u64 *out) { - return (int)syscall(SYS_TCP_READ, socket, buffer, buffer_size, out, 0); -} - u32 gen_ipv4(u8 i1, u8 i2, u8 i3, u8 i4) { return i4 << (32 - 8) | i3 << (32 - 16) | i2 << (32 - 24) | i1 << (32 - 32); } @@ -69,25 +58,13 @@ struct event { u32 internal_id; }; -int queue_create(u32 *id) { - return (int)syscall(SYS_QUEUE_CREATE, id, 0, 0, 0, 0); -} - -int queue_add(u32 queue_id, struct event *ev, u32 size) { - return (int)syscall(SYS_QUEUE_ADD, queue_id, ev, size, 0, 0); -} - -int queue_wait(u32 queue_id) { - return (int)syscall(SYS_QUEUE_WAIT, queue_id, 0, 0, 0, 0); -} - -int tcp_fmt(u32 socket, const char *fmt, ...) { +int tcp_fmt(int socket, const char *fmt, ...) { va_list ap; char cmd_str[512]; va_start(ap, fmt); int rc = vsnprintf(cmd_str, 512, fmt, ap); va_end(ap); - return tcp_write(socket, (u8 *)cmd_str, rc, NULL); + return write(socket, cmd_str, rc); } int message_pos_x = 0; @@ -228,7 +205,7 @@ void handle_msg(struct irc_server *server, struct sv msg) { sb_free(&join_message); } HANDLE_CMD(C_TO_SV("PING")) { - tcp_write(server->socket, "PONG", 4, NULL); + write(server->socket, "PONG", 4); } HANDLE_CMD(C_TO_SV("PRIVMSG")) { struct sv channel = sv_split_delim(command_parameters, &msg, ' '); @@ -296,7 +273,7 @@ void send_message(struct irc_server *server, struct irc_channel *chan, // TODO I am too lazy to add functionality to split msg right now assert(0); } - tcp_write(server->socket, s.string, s.length, NULL); + write(server->socket, s.string, s.length); irc_add_message(server, chan->name, server_nick, msg); sb_free(&s); } @@ -412,12 +389,31 @@ void irc_add_message(struct irc_server *server, struct sv channel_name, } int irc_connect_server(struct irc_server *server, u32 ip, u16 port) { - int err; - u32 socket = tcp_connect_ipv4(ip, port, &err); - if (err) { + (void)ip; + struct sockaddr_in servaddr; + int fd = socket(AF_INET, SOCK_STREAM, 0); + if (fd < 0) { + perror("socket"); return 0; } - server->socket = socket; + + memset(&servaddr, 0, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.a[0] = 10; + servaddr.sin_addr.a[1] = 0; + servaddr.sin_addr.a[2] = 2; + servaddr.sin_addr.a[3] = 2; + servaddr.sin_port = htons(port); + + if (connect(fd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) { + perror("connect"); + return 0; + } + int flag = 1; + assert(0 == + setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int))); + + server->socket = fd; irc_add_channel(server, C_TO_SV("*")); server->channels[0].can_send_message = 0; return 1; @@ -428,13 +424,11 @@ void refresh_screen(void) { } int main(void) { - u32 id; - queue_create(&id); + struct pollfd fds[2]; - struct event fd_ev; - fd_ev.type = 0; - fd_ev.internal_id = 0; - queue_add(id, &fd_ev, 1); + fds[0].fd = 0; + fds[0].events = POLLIN; + fds[0].revents = 0; u32 ip = gen_ipv4(10, 0, 2, 2); struct irc_server server_ctx; @@ -453,10 +447,9 @@ int main(void) { assert(tcp_fmt(server_ctx.socket, "USER %s * * :%s\n", nick, realname)); irc_join_channel(&server_ctx, "#secretclub"); - struct event socket_ev; - socket_ev.type = 1; - socket_ev.internal_id = server_ctx.socket; - queue_add(id, &socket_ev, 1); + fds[1].fd = server_ctx.socket; + fds[1].events = POLLIN; + fds[1].revents = 0; struct sb your_msg; sb_init(&your_msg); @@ -465,7 +458,7 @@ int main(void) { u32 msg_usage = 0; for (;;) { - queue_wait(id); + poll(fds, 2, 0); { char buffer[4096]; int rc = mread(0, buffer, 4096, 0); @@ -518,13 +511,13 @@ int main(void) { } } { - u64 out; char buffer[4096]; - if (!tcp_read(server_ctx.socket, buffer, 4096, &out)) { + int rc = mread(server_ctx.socket, buffer, 4096, 0); + if (rc < 0) { continue; } - for (u64 i = 0; i < out; i++) { + for (int i = 0; i < rc; i++) { assert(msg_usage < 512); if ('\n' == buffer[i] && i > 1 && '\r' == buffer[i - 1]) { handle_msg(&server_ctx, (struct sv){ diff --git a/userland/libc/Makefile b/userland/libc/Makefile index af65a56..2d301cb 100644 --- a/userland/libc/Makefile +++ b/userland/libc/Makefile @@ -2,7 +2,7 @@ CC="i686-sb-gcc" AR="i686-sb-ar" AS="i686-sb-as" CFLAGS = -ggdb -ffreestanding -O0 -Wall -Wextra -pedantic -Werror -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o fcntl/open_process.o tb/sb.o tb/sv.o string/memchr.o stdlib/atol.o stdlib/atoll.o stdlib/strtoll.o sys/stat/fstat.o unistd/lseek.o ctype/isupper.o ctype/islower.o ctype/isblank.o ctype/isgraph.o ctype/iscntrl.o math/ldexp.o sys/socket/connect.o +OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o fcntl/open_process.o tb/sb.o tb/sv.o string/memchr.o stdlib/atol.o stdlib/atoll.o stdlib/strtoll.o sys/stat/fstat.o unistd/lseek.o ctype/isupper.o ctype/islower.o ctype/isblank.o ctype/isgraph.o ctype/iscntrl.o math/ldexp.o sys/socket/connect.o sys/socket/setsockopt.o all: libc.a %.o: %.c diff --git a/userland/libc/include/sys/socket.h b/userland/libc/include/sys/socket.h deleted file mode 100644 index fb874a1..0000000 --- a/userland/libc/include/sys/socket.h +++ /dev/null @@ -1,11 +0,0 @@ -#include <socket.h> -#include <stddef.h> - -#define MSG_WAITALL 1 - -size_t recvfrom(int socket, void *buffer, size_t length, int flags, - struct sockaddr *address, socklen_t *address_len); -size_t sendto(int socket, const void *message, size_t length, int flags, - const struct sockaddr *dest_addr, socklen_t dest_len); -int listen(int socket, int backlog); -int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h index f318955..dcc4742 100644 --- a/userland/libc/include/syscall.h +++ b/userland/libc/include/syscall.h @@ -1,8 +1,8 @@ #ifndef SYSCALL_H #define SYSCALL_H -#include "socket.h" #include <stddef.h> #include <stdint.h> +#include <sys/socket.h> #include <sys/types.h> #define SYS_OPEN 0 @@ -60,6 +60,7 @@ #define SYS_OPEN_PROCESS 49 #define SYS_LSEEK 50 #define SYS_CONNECT 51 +#define SYS_SETSOCKOPT 52 int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx, uint32_t esi, uint32_t edi); diff --git a/userland/libc/sys/socket/connect.c b/userland/libc/sys/socket/connect.c new file mode 100644 index 0000000..9b692ef --- /dev/null +++ b/userland/libc/sys/socket/connect.c @@ -0,0 +1,6 @@ +#include <sys/socket.h> +#include <syscall.h> + +int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { + RC_ERRNO(syscall(SYS_CONNECT, sockfd, addr, addrlen, 0, 0)); +} diff --git a/userland/libc/sys/socket/setsockopt.c b/userland/libc/sys/socket/setsockopt.c new file mode 100644 index 0000000..3fa69d6 --- /dev/null +++ b/userland/libc/sys/socket/setsockopt.c @@ -0,0 +1,8 @@ +#include <sys/socket.h> +#include <syscall.h> + +int setsockopt(int socket, int level, int option_name, const void *option_value, + socklen_t option_len) { + RC_ERRNO(syscall(SYS_SETSOCKOPT, socket, level, option_name, option_value, + option_len)); +} diff --git a/userland/libc/unistd/lseek.c b/userland/libc/unistd/lseek.c new file mode 100644 index 0000000..2dcd661 --- /dev/null +++ b/userland/libc/unistd/lseek.c @@ -0,0 +1,7 @@ +#include <errno.h> +#include <unistd.h> +#include <syscall.h> + +off_t lseek(int fildes, off_t offset, int whence) { + RC_ERRNO(syscall(SYS_LSEEK, (u32)fildes, offset, whence, 0, 0)); +} |