[BACK]Return to patch-aj CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / emulators / ski / patches

File: [cvs.NetBSD.org] / pkgsrc / emulators / ski / patches / patch-aj (download)

Revision 1.1.1.1 (vendor branch), Wed Jul 27 10:23:49 2011 UTC (6 years, 11 months ago) by cherry
Branch: TNF, MAIN
CVS Tags: pkgsrc-base, pkgsrc-2018Q2-base, pkgsrc-2018Q2, pkgsrc-2018Q1-base, pkgsrc-2018Q1, pkgsrc-2017Q4-base, pkgsrc-2017Q4, pkgsrc-2017Q3-base, pkgsrc-2017Q3, pkgsrc-2017Q2-base, pkgsrc-2017Q2, pkgsrc-2017Q1-base, pkgsrc-2017Q1, pkgsrc-2016Q4-base, pkgsrc-2016Q4, pkgsrc-2016Q3-base, pkgsrc-2016Q3, pkgsrc-2016Q2-base, pkgsrc-2016Q2, pkgsrc-2016Q1-base, pkgsrc-2016Q1, pkgsrc-2015Q4-base, pkgsrc-2015Q4, pkgsrc-2015Q3-base, pkgsrc-2015Q3, pkgsrc-2015Q2-base, pkgsrc-2015Q2, pkgsrc-2015Q1-base, pkgsrc-2015Q1, pkgsrc-2014Q4-base, pkgsrc-2014Q4, pkgsrc-2014Q3-base, pkgsrc-2014Q3, pkgsrc-2014Q2-base, pkgsrc-2014Q2, pkgsrc-2014Q1-base, pkgsrc-2014Q1, pkgsrc-2013Q4-base, pkgsrc-2013Q4, pkgsrc-2013Q3-base, pkgsrc-2013Q3, pkgsrc-2013Q2-base, pkgsrc-2013Q2, pkgsrc-2013Q1-base, pkgsrc-2013Q1, pkgsrc-2012Q4-base, pkgsrc-2012Q4, pkgsrc-2012Q3-base, pkgsrc-2012Q3, pkgsrc-2012Q2-base, pkgsrc-2012Q2, pkgsrc-2012Q1-base, pkgsrc-2012Q1, pkgsrc-2011Q4-base, pkgsrc-2011Q4, pkgsrc-2011Q3-base, pkgsrc-2011Q3, pkgsrc-, HEAD
Changes since 1.1: +0 -0 lines

import wip/ski

$NetBSD: patch-aj,v 1.1.1.1 2011/07/27 10:23:49 cherry Exp $

--- src/netbsd/misc-netbsd.c.orig	2009-12-16 12:47:32.000000000 +0000
+++ src/netbsd/misc-netbsd.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 1995-2007, Hewlett-Packard Development Company, L.P.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or 
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <sys/time.h>
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "std.h"
+#include "types.h"
+#include "state.h"
+
+#include "netbsd/machdep-netbsd.h"
+
+int _close(int);
+int _open(const char *, int, int);
+
+CTR prof_insts = ~0ULL;
+char *src_root;
+
+#define	SKI_NFDS	20
+int fdlimit;
+int fdmap[SKI_NFDS];
+
+void setFdmap(int fd1, int fd2)
+{
+	assert(0);
+}
+
+void profCnt(void)
+{
+	assert(0);
+}
+
+void saveOpenFiles(FILE *f)
+{
+}
+
+void restoreOpenFile(char *name, unsigned flag, unsigned mode, unsigned offset)
+{
+}
+
+/*
+ * We use our own implementation of open to force file descriptors
+ * opened by ski for ski to be larger than what we allow for the
+ * simulated process. This avoids nasty mappings...
+ */
+int open(const char *path, int flags, int mode)
+{
+	int res, fd;
+
+	if (!unixABI)
+		return (_open(path, flags, mode));
+
+	if (fdlimit == 0) {
+		fdlimit = getdtablesize() - SKI_NFDS;
+		if (fdlimit < 20) {
+			fprintf(stderr, "FD table size underflow\n");
+			abort();
+		}
+		dup2(0, fdlimit);
+		dup2(1, fdlimit + 1);
+		dup2(2, fdlimit + 2);
+		fdmap[0] = fdmap[1] = fdmap[2] = 1;
+		/* XXX we shouldn't go under the hood */
+		stdin->_file += fdlimit;
+		stdout->_file += fdlimit;
+		stderr->_file += fdlimit;
+	}
+
+	res = _open(path, flags, mode);
+	if (res >= fdlimit) {
+		_close(res);
+		errno = EMFILE;
+		return (-1);
+	} else if (res == -1)
+		return (res);
+
+	fd = 0;
+	while (fd < SKI_NFDS && fdmap[fd])
+		fd++;
+	if (fd == SKI_NFDS) {
+		_close(res);
+		errno = EMFILE;
+		return (-1);
+	}
+	if (dup2(res, fd + fdlimit) == -1) {
+		_close(res);
+		errno = EMFILE;
+		return (-1);
+	}
+	_close(res);
+	fdmap[fd] = 1;
+	return (fd + fdlimit);
+}
+
+int close(int fd)
+{
+	if (fd >= fdlimit && fdlimit != 0)
+		fdmap[fd - fdlimit] = 0;
+	_close(fd);
+}