linux-um archives
 help / color / mirror / Atom feed
From: Oleg Drokin <green@linuxhacker.ru>
To: jdike@karaya.com, umka@namesys.com,
	user-mode-linux-devel@lists.sourceforge.net, sikkh@wp.pl
Subject: [uml-devel] Re: [PATCH] Fix for annoying problem with hostfs readdir problems.
Date: Fri, 16 Apr 2004 00:46:29 +0300	[thread overview]
Message-ID: <20040415214629.GB207748@linuxhacker.ru> (raw)
In-Reply-To: <20040415210318.GA205486@linuxhacker.ru>

[-- Attachment #1: Type: text/plain, Size: 608 bytes --]

Hello!

On Fri, Apr 16, 2004 at 12:03:18AM +0300, Oleg Drokin wrote:
>    So the annoying problem with readdir not working on hostfs (on 2.6 host
>    kernel only for me) was finally hunted to memory allocation
>    problem during opendir.
> 
>    The patch below is a working and tested attempt at fixing it.
>    It is againt 2.4.20-something, but is pretty straightforward and
>    probably should apply everywhere else.

This is corrected version that sets errno on malloc failure and as a bonus -
um_vmalloc is now also declared in header file and therefore no edtra warning in
main.c ;)

Bye,
    Oleg

[-- Attachment #2: malloc_fix.diff --]
[-- Type: text/plain, Size: 2043 bytes --]

--- uml-2.4/arch/um/kernel/process_kern.c.orig	2004-04-15 23:26:49.000000000 +0300
+++ uml-2.4/arch/um/kernel/process_kern.c	2004-04-15 23:49:38.312250576 +0300
@@ -16,6 +16,7 @@
 #include "linux/module.h"
 #include "linux/init.h"
 #include "linux/capability.h"
+#include "linux/vmalloc.h"
 #include "asm/unistd.h"
 #include "asm/mman.h"
 #include "asm/segment.h"
@@ -279,6 +280,11 @@ void *um_kmalloc(int size)
 	return(kmalloc(size, GFP_KERNEL));
 }
 
+void *um_vmalloc(int size)
+{
+	return(vmalloc(size));
+}
+
 void *um_kmalloc_atomic(int size)
 {
 	return(kmalloc(size, GFP_ATOMIC));
--- uml-2.4/arch/um/main.c.orig	2004-04-15 23:58:28.786606216 +0300
+++ uml-2.4/arch/um/main.c	2004-04-16 00:35:35.074159064 +0300
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
+#include <errno.h>
 #include <sys/resource.h>
 #include <sys/mman.h>
 #include <sys/user.h>
@@ -160,10 +161,16 @@ extern void *__real_malloc(int);
 
 void *__wrap_malloc(int size)
 {
-	if(CAN_KMALLOC())
-		return(um_kmalloc(size));
-	else
+	if(CAN_KMALLOC()) {
+		/* glibc people insist that if malloc fails, errno should be
+		   set by malloc as well. So we do. */
+		void *ret = um_vmalloc(size);
+		if (!ret)
+			errno = ENOMEM;
+		return(ret);
+	} else {
 		return(__real_malloc(size));
+	}
 }
 
 void *__wrap_calloc(int n, int size)
@@ -179,7 +186,7 @@ extern void __real_free(void *);
 
 void __wrap_free(void *ptr)
 {
-	if(CAN_KMALLOC()) kfree(ptr);
+	if(CAN_KMALLOC()) vfree(ptr);
 	else __real_free(ptr);
 }
 
--- uml-2.4/arch/um/include/user.h.orig	2004-04-15 23:41:57.000000000 +0300
+++ uml-2.4/arch/um/include/user.h	2004-04-16 00:36:24.806598584 +0300
@@ -10,8 +10,10 @@ extern void panic(const char *fmt, ...);
 extern int printk(const char *fmt, ...);
 extern void schedule(void);
 extern void *um_kmalloc(int size);
+extern void *um_vmalloc(int size);
 extern void *um_kmalloc_atomic(int size);
 extern void kfree(void *ptr);
+extern void vfree(void *ptr);
 extern int in_aton(char *str);
 extern int open_gdb_chan(void);
 

  reply	other threads:[~2004-04-15 21:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-15 21:03 [uml-devel] [PATCH] Fix for annoying problem with hostfs readdir problems Oleg Drokin
2004-04-15 21:46 ` Oleg Drokin [this message]
2004-04-18 15:26   ` [uml-devel] " BlaisorBlade
2004-04-18 22:26     ` Oleg Drokin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040415214629.GB207748@linuxhacker.ru \
    --to=green@linuxhacker.ru \
    --cc=jdike@karaya.com \
    --cc=sikkh@wp.pl \
    --cc=umka@namesys.com \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox