shithub: mc

Download patch

ref: 4e4f36fcf5177b0c51c4bcb5a203c5f86edf6e00
parent: 63d9419c6b72ef4ba813b0e8c6f234b9ab843d27
author: Ryan Gonzalez <rymg19@gmail.com>
date: Tue Aug 1 13:46:05 EDT 2017

Add set/getuid and set/getgid syscalls

Also my editor may or may not have stripped some whitespace...

--- a/lib/sys/sys+linux-x64.myr
+++ b/lib/sys/sys+linux-x64.myr
@@ -242,7 +242,7 @@
 	const Mprotwr	: mprot = 0x2
 	const Mprotexec	: mprot = 0x4
 	const Mprotrw	: mprot = 0x3 /* convenience */
-	
+
 	/* mmap options */
 	const Mshared	: mopt = 0x1
 	const Mpriv	: mopt = 0x2
@@ -337,7 +337,7 @@
 	const Epollwakeup	: epollevttype = 1 << 29
 	const Epolloneshot	: epollevttype = 1 << 30
 	const Epolledge	: epollevttype = 1 << 31
-	
+
 	/* futex ops */
 	const Futexwait	: futexop = 0
 	const Futexwake	: futexop = 1
@@ -791,7 +791,7 @@
 				tls : byte#, \
 				ctid : pid#, \
 				ptreg : byte#, \
-				fn : void# \	/* we need a raw pointer */ 
+				fn : void# \	/* we need a raw pointer */
 				-> pid)
 	const wait4	: (pid:pid, loc:int32#, opt : int64, usage:rusage#	-> int64)
 	const waitpid	: (pid:pid, loc:int32#, opt : int64	-> int64)
@@ -863,6 +863,12 @@
 	const clock_settime	: (clk : clock, ts : timespec# -> int32)
 	const nanosleep	: (req : timespec#, rem : timespec# -> int32)
 
+	/* user/group management */
+	const getuid : ( -> uint32)
+	const getgid : ( -> uint32)
+	const setuid : (uid : uint32 -> int32)
+	const setgid : (gid : uint32 -> int32)
+
 	/* system information */
 	const uname 	: (buf : utsname# -> int)
 
@@ -870,7 +876,7 @@
 	extern var __cenvp : byte##
 ;;
 
-/* 
+/*
 wraps a syscall argument, converting it to 64 bits for the syscall function.
 This is the same as casting, but more concise than writing a cast to int64.
 */
@@ -922,7 +928,7 @@
 	/*
 	 copy the env.
 	 of course we fucking have to duplicate this code everywhere,
-	 since we want to stack allocate... 
+	 since we want to stack allocate...
 	*/
 	ep = alloca((env.len + 1)*sizeof(byte#))
 	cenv = (ep : byte##)[:env.len]
@@ -1005,6 +1011,12 @@
 const clock_gettime = {clk, ts;	-> (syscall(Sysclock_gettime, clockid(clk), a(ts)) : int32)}
 const clock_settime = {clk, ts;	-> (syscall(Sysclock_settime, clockid(clk), a(ts)) : int32)}
 const nanosleep	= {req, rem;	-> (syscall(Sysnanosleep, a(req), a(rem)) : int32)}
+
+/* user/group management */
+const getuid = {; -> (syscall(Sysgetuid) : uint32)}
+const getgid = {; -> (syscall(Sysgetgid) : uint32)}
+const setuid = {uid; -> (syscall(Syssetuid, a(uid)) : int32)}
+const setgid = {gid; -> (syscall(Syssetgid, a(gid)) : int32)}
 
 /* system information */
 const uname	= {buf;	-> (syscall(Sysuname, buf) : int)}