shithub: mc

Download patch

ref: 71af8b2acb1e7eefa2101f0074e4fe0a631a6220
parent: fb8cbb2339df748749c588b20f787e2973c2fd36
author: Michael Forney <mforney@mforney.org>
date: Sat Jun 24 20:22:48 EDT 2017

Add sendmsg/recvmsg for linux-x64

Also, make sockproto int32 so that the level field in cmsghdr has the correct
size.

--- a/lib/sys/sys+linux-x64.myr
+++ b/lib/sys/sys+linux-x64.myr
@@ -17,9 +17,11 @@
 	type mprot	= int64	/* memory protection */
 	type mopt	= int64	/* memory mapping options */
 	type socktype	= int64	/* socket type */
-	type sockproto	= int64	/* socket protocol */
+	type sockproto	= int32	/* socket protocol */
 	type sockfam	= uint16	/* socket family */
 	type sockopt	= int64
+	type msgflags	= uint32
+	type cmsgtype	= uint32
 
 	type epollflags	= uint32
 	type epollop	= uint32
@@ -154,6 +156,28 @@
 		revents	: pollevt
 	;;
 
+	type iovec = struct
+		base	: byte#
+		len	: uint64
+	;;
+
+	type msghdr = struct
+		name		: sockaddr#
+		namelen		: int32
+		iov		: iovec#
+		iovlen		: uint64
+		control		: byte#
+		controllen	: uint64
+		flags		: msgflags
+	;;
+
+	type cmsghdr = struct
+		len	: uint64
+		level	: sockproto
+		cmtype	: cmsgtype
+		data	: byte[...]
+	;;
+
 	/* clone options */
 	const Clonesignal	: cloneopt = 0xff
 	const Clonevm		: cloneopt = 0x100
@@ -273,6 +297,19 @@
 	const Ipproto_udp	: sockproto = 17
 	const Ipproto_raw	: sockproto = 255
 
+	/* message flags */
+	const Msgoob		: msgflags = 0x0001
+	const Msgpeek		: msgflags = 0x0002
+	const Msgdontroute	: msgflags = 0x0004
+	const Msgctrunc		: msgflags = 0x0008
+	const Msgtrunc		: msgflags = 0x0020
+	const Msgeor		: msgflags = 0x0080
+	const Msgwaitall	: msgflags = 0x0100
+	const Msgnosignal	: msgflags = 0x4000
+
+	/* ancillary data */
+	const Scmrights		: cmsgtype = 1
+
 	/* epoll flags */
 	const Epollcloexec	: epollflags	= 0o2000000
 
@@ -747,6 +784,8 @@
 	const getdents64	: (fd:fd, buf : byte[:] -> int64)
 	const chdir	: (p : byte[:] -> int64)
 	const getcwd	: (buf : byte[:] -> int64)
+	const sendmsg	: (fd:fd, msg:msghdr#, flags:msgflags -> int64)
+	const recvmsg	: (fd:fd, msg:msghdr#, flags:msgflags -> int64)
 
 	/* signals */
 	const sigaction	: (sig : signo, act : sigaction#, oact : sigaction# -> int)
@@ -877,6 +916,8 @@
 const getdents64	= {fd, buf;	-> syscall(Sysgetdents64, a(fd), (buf : byte#), a(buf.len))}
 const chdir	= {dir;	-> syscall(Syschdir, cstring(dir))}
 const getcwd	= {buf;	-> syscall(Sysgetcwd, a(buf), a(buf.len))}
+const sendmsg	= {fd, msg, flags;	-> syscall(Syssendmsg, a(fd), msg, a(flags))}
+const recvmsg	= {fd, msg, flags;	-> syscall(Sysrecvmsg, a(fd), msg, a(flags))}
 
 /* file stuff */
 const pipe	= {fds;	-> syscall(Syspipe, a(fds))}