Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 May 2016 21:25:18 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r300080 - head/sys/boot/ficl
Message-ID:  <201605172125.u4HLPI32093069@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Tue May 17 21:25:18 2016
New Revision: 300080
URL: https://svnweb.freebsd.org/changeset/base/300080

Log:
  Implement uuid-to-string and uuid-from-string. uuid-from-string takes
  a string, interprets it as a standard UUID, and returns a binary from
  of the UUID. uuid-to-string does the reverse. The binary UUID is in
  allocated memory, so you'll need to free it with 'free' after you are
  done using it. It won't be automatically garbage collected. Likewise
  with the string...
  
  MFC After: 3 days

Modified:
  head/sys/boot/ficl/loader.c

Modified: head/sys/boot/ficl/loader.c
==============================================================================
--- head/sys/boot/ficl/loader.c	Tue May 17 21:24:10 2016	(r300079)
+++ head/sys/boot/ficl/loader.c	Tue May 17 21:25:18 2016	(r300080)
@@ -45,6 +45,7 @@
 #endif
 #include "bootstrap.h"
 #include <string.h>
+#include <uuid.h>
 #include "ficl.h"
 
 /*		FreeBSD's loader interaction words and extras
@@ -59,6 +60,8 @@
  * 		pnpdevices  ( -- addr )
  * 		pnphandlers ( -- addr )
  * 		ccall       ( [[...[p10] p9] ... p1] n addr -- result )
+ *		uuid-from-string ( addr n -- addr' )
+ *		uuid-to-string ( addr' -- addr n )
  * 		.#	    ( value -- )
  */
 
@@ -350,6 +353,75 @@ ficlCcall(FICL_VM *pVM)
 	return;
 }
 
+void
+ficlUuidFromString(FICL_VM *pVM)
+{
+#ifndef	TESTMAIN
+	char	*uuid;
+	uint32_t status;
+#endif
+	char	*uuidp;
+	int	uuids;
+	uuid_t	*u;
+
+#if FICL_ROBUST > 1
+	vmCheckStack(pVM, 2, 0);
+#endif
+
+	uuids = stackPopINT(pVM->pStack);
+	uuidp = (char *) stackPopPtr(pVM->pStack);
+
+#ifndef	TESTMAIN
+	uuid = (char *)ficlMalloc(uuids + 1);
+	if (!uuid)
+		vmThrowErr(pVM, "Error: out of memory");
+	strncpy(uuid, uuidp, uuids);
+	uuid[uuids] = '\0';
+
+	u = (uuid_t *)ficlMalloc(sizeof (*u));
+
+	uuid_from_string(uuid, u, &status);
+	ficlFree(uuid);
+	if (status != uuid_s_ok) {
+		ficlFree(u);
+		u = NULL;
+	}
+#else
+	u = NULL;
+#endif
+	stackPushPtr(pVM->pStack, u);
+
+
+	return;
+}
+
+void
+ficlUuidToString(FICL_VM *pVM)
+{
+#ifndef	TESTMAIN
+	char	*uuid;
+	uint32_t status;
+#endif
+	uuid_t	*u;
+
+#if FICL_ROBUST > 1
+	vmCheckStack(pVM, 1, 0);
+#endif
+
+	u = (uuid_t *)stackPopPtr(pVM->pStack);
+
+#ifndef	TESTMAIN
+	uuid_to_string(u, &uuid, &status);
+	if (status != uuid_s_ok) {
+		stackPushPtr(pVM->pStack, uuid);
+		stackPushINT(pVM->pStack, strlen(uuid));
+	} else
+#endif
+		stackPushINT(pVM->pStack, -1);
+
+	return;
+}
+
 /**************************************************************************
                         f i c l E x e c F D
 ** reads in text from file fd and passes it to ficlExec()
@@ -920,6 +992,8 @@ void ficlCompilePlatform(FICL_SYSTEM *pS
     dictAppendWord(dp, "copyout",   ficlCopyout,    FW_DEFAULT);
     dictAppendWord(dp, "findfile",  ficlFindfile,   FW_DEFAULT);
     dictAppendWord(dp, "ccall",	    ficlCcall,	    FW_DEFAULT);
+    dictAppendWord(dp, "uuid-from-string", ficlUuidFromString, FW_DEFAULT);
+    dictAppendWord(dp, "uuid-to-string", ficlUuidToString, FW_DEFAULT);
 #ifndef TESTMAIN
 #ifdef __i386__
     dictAppendWord(dp, "outb",      ficlOutb,       FW_DEFAULT);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605172125.u4HLPI32093069>