Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 May 2014 18:05:26 +0000 (UTC)
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r266662 - user/dchagin/lemul/sys/compat/linux
Message-ID:  <201405251805.s4PI5QwO085461@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dchagin
Date: Sun May 25 18:05:26 2014
New Revision: 266662
URL: http://svnweb.freebsd.org/changeset/base/266662

Log:
  Where possible we will use M_LINUX malloc(9) type.
  For event-driven code add and use M_EPOLL type.
  Move M_FUTEX defines to the linux_common.ko.

Modified:
  user/dchagin/lemul/sys/compat/linux/linux_emul.c
  user/dchagin/lemul/sys/compat/linux/linux_event.c
  user/dchagin/lemul/sys/compat/linux/linux_file.c
  user/dchagin/lemul/sys/compat/linux/linux_futex.c
  user/dchagin/lemul/sys/compat/linux/linux_getcwd.c
  user/dchagin/lemul/sys/compat/linux/linux_misc.c
  user/dchagin/lemul/sys/compat/linux/linux_socket.c
  user/dchagin/lemul/sys/compat/linux/linux_sysctl.c
  user/dchagin/lemul/sys/compat/linux/linux_uid16.c
  user/dchagin/lemul/sys/compat/linux/linux_util.c
  user/dchagin/lemul/sys/compat/linux/linux_util.h

Modified: user/dchagin/lemul/sys/compat/linux/linux_emul.c
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_emul.c	Sun May 25 18:03:26 2014	(r266661)
+++ user/dchagin/lemul/sys/compat/linux/linux_emul.c	Sun May 25 18:05:26 2014	(r266662)
@@ -161,7 +161,7 @@ linux_proc_init(struct thread *td, struc
 
 			em->em_tid = newtd->td_proc->p_pid;
 
-			pem = malloc(sizeof(*pem), M_TEMP, M_WAITOK | M_ZERO);
+			pem = malloc(sizeof(*pem), M_LINUX, M_WAITOK | M_ZERO);
 			sx_init(&pem->pem_sx, "lpemlk");
 			newtd->td_proc->p_emuldata = pem;
 		}
@@ -221,7 +221,7 @@ linux_common_execve(struct thread *td, s
 		epoll_destroy_emuldata(pem);
 
 		sx_destroy(&pem->pem_sx);
-		free(pem, M_TEMP);
+		free(pem, M_LINUX);
 		free(em, M_TEMP);
 	}
 	return (0);
@@ -406,6 +406,6 @@ linux_proc_exit(void *arg, struct proc *
 	epoll_destroy_emuldata(pem);
 
 	sx_destroy(&pem->pem_sx);
-	free(pem, M_TEMP);
+	free(pem, M_LINUX);
 }
 

Modified: user/dchagin/lemul/sys/compat/linux/linux_event.c
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_event.c	Sun May 25 18:03:26 2014	(r266661)
+++ user/dchagin/lemul/sys/compat/linux/linux_event.c	Sun May 25 18:05:26 2014	(r266662)
@@ -182,13 +182,13 @@ epoll_fd_install(struct thread *td, int 
 
 	LINUX_PEM_XLOCK(pem);
 	if (pem->epoll == NULL) {
-		emd = malloc(EPOLL_SIZE(fd), M_TEMP, M_WAITOK);
+		emd = malloc(EPOLL_SIZE(fd), M_EPOLL, M_WAITOK);
 		emd->fdc = fd;
 		pem->epoll = emd;
 	} else {
 		emd = pem->epoll;
 		if (fd > emd->fdc) {
-			emd = realloc(emd, EPOLL_SIZE(fd), M_TEMP, M_WAITOK);
+			emd = realloc(emd, EPOLL_SIZE(fd), M_EPOLL, M_WAITOK);
 			emd->fdc = fd;
 			pem->epoll = emd;
 		}
@@ -325,7 +325,7 @@ epoll_kev_copyout(void *arg, struct keve
 	int error, fd, i;
 
 	args = (struct epoll_copyout_args*) arg;
-	eep = malloc(sizeof(*eep) * count, M_TEMP, M_WAITOK | M_ZERO);
+	eep = malloc(sizeof(*eep) * count, M_EPOLL, M_WAITOK | M_ZERO);
 
 	pem = pem_find(args->p);
 	KASSERT(pem != NULL, ("epoll proc emuldata not found.\n"));
@@ -350,7 +350,7 @@ epoll_kev_copyout(void *arg, struct keve
 	} else if (args->error == 0)
 		args->error = error;
 
-	free(eep, M_TEMP);
+	free(eep, M_EPOLL);
 	return (error);
 }
 
@@ -558,7 +558,7 @@ epoll_destroy_emuldata(struct linux_pemu
 	if (pem->epoll == NULL)
 		return;
 	emd = pem->epoll;
-	free(emd, M_TEMP);
+	free(emd, M_EPOLL);
 }
 
 static int
@@ -578,7 +578,7 @@ eventfd_create(struct thread *td, uint32
 	if (error)
 		return (error);
 
-	efd = malloc(sizeof(*efd), M_TEMP, M_WAITOK | M_ZERO);
+	efd = malloc(sizeof(*efd), M_EPOLL, M_WAITOK | M_ZERO);
 	efd->efd_flags = flags;
 	efd->efd_count = initval;
 	mtx_init(&efd->efd_lock, "eventfd", NULL, MTX_DEF);
@@ -627,7 +627,7 @@ eventfd_close(struct file *fp, struct th
 
 	fp->f_ops = &badfileops;
 	mtx_destroy(&efd->efd_lock);
-	free(efd, M_TEMP);
+	free(efd, M_EPOLL);
 
 	return (0);
 }

Modified: user/dchagin/lemul/sys/compat/linux/linux_file.c
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_file.c	Sun May 25 18:03:26 2014	(r266661)
+++ user/dchagin/lemul/sys/compat/linux/linux_file.c	Sun May 25 18:05:26 2014	(r266662)
@@ -373,8 +373,8 @@ getdents_common(struct thread *td, struc
 
 	buflen = max(LINUX_DIRBLKSIZ, nbytes);
 	buflen = min(buflen, MAXBSIZE);
-	buf = malloc(buflen, M_TEMP, M_WAITOK);
-	lbuf = malloc(LINUX_MAXRECLEN, M_TEMP, M_WAITOK | M_ZERO);
+	buf = malloc(buflen, M_LINUX, M_WAITOK);
+	lbuf = malloc(LINUX_MAXRECLEN, M_LINUX, M_WAITOK | M_ZERO);
 	vn_lock(vp, LK_SHARED | LK_RETRY);
 
 	aiov.iov_base = buf;
@@ -525,8 +525,8 @@ out:
 	VOP_UNLOCK(vp, 0);
 	foffset_unlock(fp, off, 0);
 	fdrop(fp, td);
-	free(buf, M_TEMP);
-	free(lbuf, M_TEMP);
+	free(buf, M_LINUX);
+	free(lbuf, M_LINUX);
 	return (error);
 }
 

Modified: user/dchagin/lemul/sys/compat/linux/linux_futex.c
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_futex.c	Sun May 25 18:03:26 2014	(r266661)
+++ user/dchagin/lemul/sys/compat/linux/linux_futex.c	Sun May 25 18:05:26 2014	(r266662)
@@ -183,9 +183,6 @@ LIN_SDT_PROBE_DEFINE2(futex, release_fut
 LIN_SDT_PROBE_DEFINE1(futex, release_futexes, copyin_error, "int");
 LIN_SDT_PROBE_DEFINE0(futex, release_futexes, return);
 
-static MALLOC_DEFINE(M_FUTEX, "futex", "Linux futexes");
-static MALLOC_DEFINE(M_FUTEX_WP, "futex wp", "Linux futexes wp");
-
 struct futex;
 
 struct waiting_proc {

Modified: user/dchagin/lemul/sys/compat/linux/linux_getcwd.c
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_getcwd.c	Sun May 25 18:03:26 2014	(r266661)
+++ user/dchagin/lemul/sys/compat/linux/linux_getcwd.c	Sun May 25 18:05:26 2014	(r266662)
@@ -186,7 +186,7 @@ linux_getcwd_scandir(lvpp, uvpp, bpp, bu
 	dirbuflen = DIRBLKSIZ;
 	if (dirbuflen < va.va_blocksize)
 		dirbuflen = va.va_blocksize;
-	dirbuf = (char *)malloc(dirbuflen, M_TEMP, M_WAITOK);
+	dirbuf = (char *)malloc(dirbuflen, M_LINUX, M_WAITOK);
 
 #if 0
 unionread:
@@ -274,7 +274,7 @@ unionread:
 out:
 	vput(lvp);
 	*lvpp = NULL;
-	free(dirbuf, M_TEMP);
+	free(dirbuf, M_LINUX);
 	return error;
 }
 
@@ -428,7 +428,7 @@ linux_getcwd(struct thread *td, struct l
 	else if (len < 2)
 		return ERANGE;
 
-	path = (char *)malloc(len, M_TEMP, M_WAITOK);
+	path = (char *)malloc(len, M_LINUX, M_WAITOK);
 
 	error = kern___getcwd(td, path, UIO_SYSSPACE, len);
 	if (!error) {
@@ -463,7 +463,7 @@ linux_getcwd(struct thread *td, struct l
 		error = copyout(bp, args->buf, lenused);
 	}
 out:
-	free(path, M_TEMP);
+	free(path, M_LINUX);
 	return (error);
 }
 

Modified: user/dchagin/lemul/sys/compat/linux/linux_misc.c
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_misc.c	Sun May 25 18:03:26 2014	(r266661)
+++ user/dchagin/lemul/sys/compat/linux/linux_misc.c	Sun May 25 18:05:26 2014	(r266662)
@@ -1090,7 +1090,7 @@ linux_setgroups(struct thread *td, struc
 	ngrp = args->gidsetsize;
 	if (ngrp < 0 || ngrp >= ngroups_max + 1)
 		return (EINVAL);
-	linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_TEMP, M_WAITOK);
+	linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK);
 	error = copyin(args->grouplist, linux_gidset, ngrp * sizeof(l_gid_t));
 	if (error)
 		goto out;
@@ -1129,7 +1129,7 @@ linux_setgroups(struct thread *td, struc
 	crfree(oldcred);
 	error = 0;
 out:
-	free(linux_gidset, M_TEMP);
+	free(linux_gidset, M_LINUX);
 	return (error);
 }
 
@@ -1161,14 +1161,14 @@ linux_getgroups(struct thread *td, struc
 
 	ngrp = 0;
 	linux_gidset = malloc(bsd_gidsetsz * sizeof(*linux_gidset),
-	    M_TEMP, M_WAITOK);
+	    M_LINUX, M_WAITOK);
 	while (ngrp < bsd_gidsetsz) {
 		linux_gidset[ngrp] = bsd_gidset[ngrp + 1];
 		ngrp++;
 	}
 
 	error = copyout(linux_gidset, args->grouplist, ngrp * sizeof(l_gid_t));
-	free(linux_gidset, M_TEMP);
+	free(linux_gidset, M_LINUX);
 	if (error)
 		return (error);
 

Modified: user/dchagin/lemul/sys/compat/linux/linux_socket.c
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_socket.c	Sun May 25 18:03:26 2014	(r266661)
+++ user/dchagin/lemul/sys/compat/linux/linux_socket.c	Sun May 25 18:05:26 2014	(r266662)
@@ -608,7 +608,7 @@ linux_sendto_hdrincl(struct thread *td, 
 	    linux_args->len > IP_MAXPACKET)
 		return (EINVAL);
 
-	packet = (struct ip *)malloc(linux_args->len, M_TEMP, M_WAITOK);
+	packet = (struct ip *)malloc(linux_args->len, M_LINUX, M_WAITOK);
 
 	/* Make kernel copy of the packet to be sent */
 	if ((error = copyin(PTRIN(linux_args->msg), packet,
@@ -631,7 +631,7 @@ linux_sendto_hdrincl(struct thread *td, 
 	error = linux_sendit(td, linux_args->s, &msg, linux_args->flags,
 	    NULL, UIO_SYSSPACE);
 goout:
-	free(packet, M_TEMP);
+	free(packet, M_LINUX);
 	return (error);
 }
 
@@ -1122,7 +1122,7 @@ linux_sendmsg(struct thread *td, struct 
 		free(sa, M_SONAME);
 
 		error = ENOBUFS;
-		cmsg = malloc(CMSG_HDRSZ, M_TEMP, M_WAITOK | M_ZERO);
+		cmsg = malloc(CMSG_HDRSZ, M_LINUX, M_WAITOK | M_ZERO);
 		control = m_get(M_WAITOK, MT_CONTROL);
 		if (control == NULL)
 			goto bad;
@@ -1200,7 +1200,7 @@ linux_sendmsg(struct thread *td, struct 
 bad:
 	free(iov, M_IOV);
 	if (cmsg)
-		free(cmsg, M_TEMP);
+		free(cmsg, M_LINUX);
 	return (error);
 }
 
@@ -1273,7 +1273,7 @@ linux_recvmsg(struct thread *td, struct 
 	outlen = 0;
 
 	if (control) {
-		linux_cmsg = malloc(L_CMSG_HDRSZ, M_TEMP, M_WAITOK | M_ZERO);
+		linux_cmsg = malloc(L_CMSG_HDRSZ, M_LINUX, M_WAITOK | M_ZERO);
 
 		msg.msg_control = mtod(control, struct cmsghdr *);
 		msg.msg_controllen = control->m_len;
@@ -1366,7 +1366,7 @@ out:
 bad:
 	free(iov, M_IOV);
 	m_freem(control);
-	free(linux_cmsg, M_TEMP);
+	free(linux_cmsg, M_LINUX);
 
 	return (error);
 }

Modified: user/dchagin/lemul/sys/compat/linux/linux_sysctl.c
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_sysctl.c	Sun May 25 18:03:26 2014	(r266661)
+++ user/dchagin/lemul/sys/compat/linux/linux_sysctl.c	Sun May 25 18:05:26 2014	(r266662)
@@ -140,12 +140,12 @@ linux_sysctl(struct thread *td, struct l
 		return (ENOTDIR);
 	}
 
-	mib = malloc(la.nlen * sizeof(l_int), M_TEMP, M_WAITOK);
+	mib = malloc(la.nlen * sizeof(l_int), M_LINUX, M_WAITOK);
 	error = copyin(PTRIN(la.name), mib, la.nlen * sizeof(l_int));
 	if (error) {
 		LIN_SDT_PROBE1(sysctl, linux_sysctl, copyin_error, error);
 		LIN_SDT_PROBE1(sysctl, linux_sysctl, return, error);
-		free(mib, M_TEMP);
+		free(mib, M_LINUX);
 		return (error);
 	}
 
@@ -157,7 +157,7 @@ linux_sysctl(struct thread *td, struct l
 		switch (mib[1]) {
 		case LINUX_KERN_VERSION:
 			error = handle_string(&la, version);
-			free(mib, M_TEMP);
+			free(mib, M_LINUX);
 			LIN_SDT_PROBE1(sysctl, linux_sysctl, return, error);
 			return (error);
 		default:
@@ -186,7 +186,7 @@ linux_sysctl(struct thread *td, struct l
 		sbuf_delete(sb);
 	}
 
-	free(mib, M_TEMP);
+	free(mib, M_LINUX);
 
 	LIN_SDT_PROBE1(sysctl, linux_sysctl, return, ENOTDIR);
 	return (ENOTDIR);

Modified: user/dchagin/lemul/sys/compat/linux/linux_uid16.c
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_uid16.c	Sun May 25 18:03:26 2014	(r266661)
+++ user/dchagin/lemul/sys/compat/linux/linux_uid16.c	Sun May 25 18:05:26 2014	(r266662)
@@ -171,12 +171,13 @@ linux_setgroups16(struct thread *td, str
 		LIN_SDT_PROBE1(uid16, linux_setgroups16, return, EINVAL);
 		return (EINVAL);
 	}
-	linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_TEMP, M_WAITOK);
+	linux_gidset = malloc(ngrp * sizeof(*linux_gidset),
+	    M_LINUX, M_WAITOK);
 	error = copyin(args->gidset, linux_gidset, ngrp * sizeof(l_gid16_t));
 	if (error) {
 		LIN_SDT_PROBE1(uid16, linux_setgroups16, copyin_error, error);
 		LIN_SDT_PROBE1(uid16, linux_setgroups16, return, error);
-		free(linux_gidset, M_TEMP);
+		free(linux_gidset, M_LINUX);
 		return (error);
 	}
 	newcred = crget();
@@ -218,7 +219,7 @@ linux_setgroups16(struct thread *td, str
 	crfree(oldcred);
 	error = 0;
 out:
-	free(linux_gidset, M_TEMP);
+	free(linux_gidset, M_LINUX);
 
 	LIN_SDT_PROBE1(uid16, linux_setgroups16, return, error);
 	return (error);
@@ -259,14 +260,14 @@ linux_getgroups16(struct thread *td, str
 
 	ngrp = 0;
 	linux_gidset = malloc(bsd_gidsetsz * sizeof(*linux_gidset),
-	    M_TEMP, M_WAITOK);
+	    M_LINUX, M_WAITOK);
 	while (ngrp < bsd_gidsetsz) {
 		linux_gidset[ngrp] = bsd_gidset[ngrp + 1];
 		ngrp++;
 	}
 
 	error = copyout(linux_gidset, args->gidset, ngrp * sizeof(l_gid16_t));
-	free(linux_gidset, M_TEMP);
+	free(linux_gidset, M_LINUX);
 	if (error) {
 		LIN_SDT_PROBE1(uid16, linux_getgroups16, copyout_error, error);
 		LIN_SDT_PROBE1(uid16, linux_getgroups16, return, error);

Modified: user/dchagin/lemul/sys/compat/linux/linux_util.c
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_util.c	Sun May 25 18:03:26 2014	(r266661)
+++ user/dchagin/lemul/sys/compat/linux/linux_util.c	Sun May 25 18:05:26 2014	(r266662)
@@ -54,6 +54,9 @@ __FBSDID("$FreeBSD$");
 #include <compat/linux/linux_util.h>
 
 MALLOC_DEFINE(M_LINUX, "linux", "Linux mode structures");
+MALLOC_DEFINE(M_EPOLL, "lepoll", "Linux event structures");
+MALLOC_DEFINE(M_FUTEX, "futex", "Linux futexes");
+MALLOC_DEFINE(M_FUTEX_WP, "futex wp", "Linux futexes wp");
 
 const char      linux_emul_path[] = "/compat/linux";
 

Modified: user/dchagin/lemul/sys/compat/linux/linux_util.h
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_util.h	Sun May 25 18:03:26 2014	(r266661)
+++ user/dchagin/lemul/sys/compat/linux/linux_util.h	Sun May 25 18:05:26 2014	(r266662)
@@ -45,6 +45,9 @@
 #include <sys/uio.h>
 
 MALLOC_DECLARE(M_LINUX);
+MALLOC_DECLARE(M_EPOLL);
+MALLOC_DECLARE(M_FUTEX);
+MALLOC_DECLARE(M_FUTEX_WP);
 
 extern const char linux_emul_path[];
 



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