shithub: mc

Download patch

ref: 0060152b535f0376265f0fe46bba45964fe1a8b0
parent: 4868e3b769c7b0d4c77c715df641219010be835b
author: Ori Bernstein <ori@eigenstate.org>
date: Sun May 8 14:14:07 EDT 2016

We now can build and install on openbsd.

--- a/6/gengas.c
+++ b/6/gengas.c
@@ -373,7 +373,8 @@
 
 	ty->isemitted = 1;
 	b = tydescblob(ty);
-	b->iscomdat = 1;
+	if (b->isglobl)
+		b->iscomdat = 1;
 	writeblob(fd, b);
 	blobfree(b);
 }
--- a/configure
+++ b/configure
@@ -83,7 +83,7 @@
         ;;
     *OpenBSD*)
         echo '#define Symprefix ""' >> config.h
-        echo '#define Defaultasm Gnugas' >> config.h
+        echo '#define Defaultasm Gnugaself' >> config.h
         echo 'export SYS=openbsd' >> config.mk
         echo 'const Linkcmd = ["ld", "-static", "-nopie", "-o"]' >> mbld/config.myr
         echo 'const Sys = "OpenBSD"' >> mbld/config.myr
--- a/lib/std/alloc.myr
+++ b/lib/std/alloc.myr
@@ -289,7 +289,7 @@
 	*/
 	p = getmem(Slabsz*2)
 	if p == Failmem
-		die("Unable to mmap")
+		die("Unable to get memory")
 	;;
 
 	s = align(p castto(size), Slabsz) castto(slab#)
--- a/lib/std/syswrap+posixy.myr
+++ b/lib/std/syswrap+posixy.myr
@@ -105,7 +105,10 @@
 const execve	= {cmd, args, env;	-> sys.execve(cmd, args, env) castto(errno)}
 
 /* memory stuff */
-const getmem	= {sz;		-> sys.mmap(0 castto(byte#), sz castto(sys.size), sys.Mprotrw, sys.Mpriv | sys.Manon, -1, 0)}
+const getmem	= {sz;		
+	sz = (sz + 4095) & ~4095
+	-> sys.mmap(0 castto(byte#), sz castto(sys.size), sys.Mprotrw, sys.Mpriv | sys.Manon, -1, 0)
+}
 const freemem	= {p, sz;	sys.munmap(p, sz castto(sys.size))}
 const curtime = {
 	var tm, sec, nsec
--- a/lib/sys/bld.sub
+++ b/lib/sys/bld.sub
@@ -1,22 +1,29 @@
 lib sys =
+	systypes.myr
+
 	sys+freebsd-x64.myr
 	sys+linux-x64.myr
 	sys+osx-x64.myr
+	sys+openbsd-x64.myr
 	sys+plan9-x64.myr
+
 	syscall+freebsd-x64.s
 	syscall+linux-x64.s
 	syscall+osx-x64.s
 	syscall+plan9-x64.s
+	syscall+openbsd-x64.s
+
 	syserrno+linux.myr
 	syserrno+osx.myr
 	syserrno+freebsd.myr
-	systypes.myr
+	syserrno+openbsd.myr
+
 	ifreq+freebsd.myr
 	ifreq+linux.myr
 	ifreq+osx.myr
 	ifreq+openbsd.myr
 	ifreq+plan9.myr
-	ifreq.myr	# dummy file: plan9 doesn't have ifreq
+
 	util+plan9-x64.s
 	util+posixy-x64.s
 ;;
--- a/lib/sys/sys+freebsd-x64.myr
+++ b/lib/sys/sys+freebsd-x64.myr
@@ -256,7 +256,6 @@
 	const Sobintime		: sockopt = 0x2000	/* timestamp received dgram traffic */
 	const Sonooffload	: sockopt = 0x4000	/* socket cannot be offloaded */
 	const Sonoddp		: sockopt = 0x8000	/* disable direct data placement */
-	
 
 	/* network protocols */
 	const Ipproto_ip	: sockproto = 0
--- a/lib/sys/sys+openbsd-x64.myr
+++ b/lib/sys/sys+openbsd-x64.myr
@@ -10,6 +10,7 @@
 	type mopt	= int64	/* memory mapping options */
 	type socktype	= int64	/* socket type */
 	type sockproto	= int64	/* socket protocol */
+	type sockopt	= int32	/* socket option */
 	type sockfam	= uint8	/* socket family */
 	type filemode	= uint32
 	type filetype	= uint8
@@ -218,7 +219,33 @@
 	const Sockraw		: socktype = 3
 	const Sockrdm		: socktype = 4
 	const Sockseqpacket	: socktype = 5
+	const Solsock	: socktype =	0xffff
 
+	const Sodebug		: sockopt = 0x0001	/* turn on debugging info recording */
+	const Soacceptconn	: sockopt = 0x0002	/* socket has had listen() */
+	const Soreuseaddr	: sockopt = 0x0004	/* allow local address reuse */
+	const Sokeepalive	: sockopt = 0x0008	/* keep connections alive */
+	const Sodontroute	: sockopt = 0x0010	/* just use interface addresses */
+	const Sobroadcast	: sockopt = 0x0020	/* permit sending of broadcast msgs */
+	const Souseloopback	: sockopt = 0x0040	/* bypass hardware when possible */
+	const Solinger		: sockopt = 0x0080	/* linger on close if data present */
+	const Sooobinline	: sockopt = 0x0100	/* leave received OOB data in line */
+	const Soreuseport	: sockopt = 0x0200	/* allow local address & port reuse */
+	const Sotimestamp	: sockopt = 0x0800	/* timestamp received dgram traffic */
+	const Sobindany		: sockopt = 0x1000	/* allow bind to any address */
+	const Sosndbuf		: sockopt = 0x1001	/* send buffer size */
+	const Sorcvbuf		: sockopt = 0x1002	/* receive buffer size */
+	const Sosndlowat	: sockopt = 0x1003	/* send low-water mark */
+	const Sorcvlowat	: sockopt = 0x1004	/* receive low-water mark */
+	const Sosndtimeo	: sockopt = 0x1005	/* send timeout */
+	const Sorcvtimeo	: sockopt = 0x1006	/* receive timeout */
+	const Soerror		: sockopt = 0x1007	/* get error status and clear */
+	const Sotype		: sockopt = 0x1008	/* get socket type */
+	const Sonetproc		: sockopt = 0x1020	/* multiplex; network processing */
+	const Sortable		: sockopt = 0x1021	/* routing table to be used */
+	const Sopeercred	: sockopt = 0x1022	/* get connect-time credentials */
+	const Sosplice		: sockopt = 0x1023	/* splice data to other socket */
+
 	/* network protocols */
 	const Ipproto_ip	: sockproto = 0
 	const Ipproto_icmp	: sockproto = 1
@@ -537,6 +564,8 @@
 	const accept	: (sock : fd, addr : sockaddr#, len : size# -> fd)
 	const listen	: (sock : fd, backlog : int	-> int)
 	const bind	: (sock : fd, addr : sockaddr#, len : size -> int)
+	const setsockopt	: (sock : fd, lev : socktype, opt : sockopt, val : void#, len : size -> int)
+	const getsockopt	: (sock : fd, lev : socktype, opt : sockopt, val : void#, len : size# -> int)
 
 	/* memory mapping */
 	const munmap	: (addr:byte#, len:size -> int64)
@@ -651,11 +680,14 @@
 const accept	= {sock, addr, len;	-> syscall(Sysaccept, a(sock), a(addr), a(len)) castto(fd)}
 const listen	= {sock, backlog;	-> syscall(Syslisten, a(sock), a(backlog)) castto(int)}
 const bind	= {sock, addr, len;	-> syscall(Sysbind, a(sock), a(addr), a(len)) castto(int)}
+const setsockopt	= {sock, lev, opt, val, len;	-> syscall(Syssetsockopt, a(sock), a(lev), a(opt), a(val), a(len)) castto(int)}
+const getsockopt	= {sock, lev, opt, val, len;	-> syscall(Syssetsockopt, a(sock), a(lev), a(opt), a(val), a(len)) castto(int)}
 
 /* memory management */
 const munmap	= {addr, len;		-> syscall(Sysmunmap, a(addr), a(len))}
 const mmap	= {addr, len, prot, flags, fd, off;
-	-> syscall(Sysmmap, a(addr), a(len), a(prot), a(flags), a(fd), a(off)) castto(byte#)}
+	-> syscall(Sysmmap, a(addr), a(len), a(prot), a(flags), a(fd), a(off)) castto(byte#)
+}
 
 /* time */
 const clock_getres = {clk, ts;	-> syscall(Sysclock_getres, clockid(clk), a(ts)) castto(int32)}
--- a/lib/thread/bld.sub
+++ b/lib/thread/bld.sub
@@ -25,6 +25,10 @@
 	spawn+plan9.myr
 	atomic-impl+plan9-x64.s
 
+	# openbsd impl of thread primitives
+	spawn+openbsd.myr
+
+
 	atomic-impl+x64.s
 	atomic.myr
 
--- /dev/null
+++ b/lib/thread/spawn+openbsd.myr
@@ -1,0 +1,12 @@
+use std
+
+pkg thread =
+	type tid = uint64
+
+	const spawn : (fn : (-> void) -> std.result(tid, byte[:]))
+;;
+
+const spawn = {fn;
+	std.die("threads not supported yet on openbsd\n")
+	-> `std.Fail "not supported"
+}