Fwd: Re: [PATCH] Steal all string functions from the libc

2014-04-03 Thread dardevelin

The lost message due to redirect mistake on my part

Date: 2014-03-31 01:09
From: dardeve...@cidadecool.com
To: Justus Winter 4win...@informatik.uni-hamburg.de

Hi everyone, Sorry I tend to be a standby watcher of the mailing list
however I could not avoid seeing strcmp function not checking for '\0'
in s2 and just s1, this means that if s1 is bigger then s2, strcmp will
compare garbage to content, of course a match is an extremely rare 
scenario,

we ought to avoid it. :)

Appears to me that this patch actually removes this, but still though 
was worth
mentioning and maybe some further checking should be made on the newly 
inserted ones.


Cheers
Darcy Brás da Silva

On 2014-03-28 15:22, Justus Winter wrote:

Steal all string functions previously implemented in kern/strings.c
from the libc.  Those are most likely more optimized than our simple
implementations.

* Makefile.am (clib_routines): Add memset, strcmp, strncmp, strcpy,
strncpy, and strlen.
* Makefrag.am (libkernel_a_SOURCES): Drop kern/strings.c.
* kern/strings.c: Remove file.
---
 Makefile.am|   3 +-
 Makefrag.am|   1 -
 kern/strings.c | 193 
-

 3 files changed, 2 insertions(+), 195 deletions(-)
 delete mode 100644 kern/strings.c

diff --git a/Makefile.am b/Makefile.am
index 918cdc3..6e5207e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -156,7 +156,8 @@ noinst_PROGRAMS += \
gnumach.o

 # This is the list of routines we decide is OK to steal from the C 
library.

-clib_routines := memcmp memcpy memmove \
+clib_routines := memcmp memcpy memmove memset  \
+strcmp strncmp strcpy strncpy strlen   \
 strchr strstr strsep strtok\
 htonl htons ntohl ntohs\
 udivdi3 __udivdi3  \
diff --git a/Makefrag.am b/Makefrag.am
index c1387bd..de020fc 100644
--- a/Makefrag.am
+++ b/Makefrag.am
@@ -193,7 +193,6 @@ libkernel_a_SOURCES += \
kern/shuttle.h \
kern/startup.c \
kern/startup.h \
-   kern/strings.c \
kern/syscall_emulation.c \
kern/syscall_emulation.h \
kern/syscall_subr.c \
diff --git a/kern/strings.c b/kern/strings.c
deleted file mode 100644
index c77ae4f..000
--- a/kern/strings.c
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Mach Operating System
- * Copyright (c) 1993 Carnegie Mellon University
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and 
its

- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS AS IS
- * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
- * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- *  Software Distribution Coordinator  or  
software.distribut...@cs.cmu.edu

- *  School of Computer Science
- *  Carnegie Mellon University
- *  Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie 
Mellon

- * the rights to redistribute these changes.
- */
-/*
- * File: strings.c
- * Author: Robert V. Baron, Carnegie Mellon University
- * Date:   ??/92
- *
- * String functions.
- */
-
-#include string.h
-
-#ifdef strcpy
-#undef strcmp
-#undef strncmp
-#undef strcpy
-#undef strncpy
-#undef strlen
-#endif
-
-/*
- * Abstract:
- * strcmp (s1, s2) compares the strings s1 and s2.
- * It returns 0 if the strings are identical. It returns
- *  0 if the first character that differs in the two strings
- * is larger in s1 than in s2 or if s1 is longer than s2 and
- * the contents are identical up to the length of s2.
- * It returns  0 if the first differing character is smaller
- * in s1 than in s2 or if s1 is shorter than s2 and the
- * contents are identical upto the length of s1.
- */
-
-int __attribute__ ((pure))
-strcmp(
-   const char *s1,
-   const char *s2)
-{
-   unsigned int a, b;
-
-   do {
-   a = *s1++;
-   b = *s2++;
-   if (a != b)
-   return a-b; /* includes case when
-  'a' is zero and 'b' is not zero
-  or vice versa */
-   } while (a != '\0');
-
-   return 0;   /* both are zero */
-}
-
-
-/*
- * Abstract:
- * strncmp (s1, s2, n) compares the strings s1 and s2
- * in exactly the same way as strcmp does.  Except the
- * comparison runs for at most n characters.
- */
-
-int __attribute__ ((pure))
-strncmp(
-   const char *s1,
-   

Re: Fwd: Re: [PATCH] Steal all string functions from the libc

2014-04-03 Thread Samuel Thibault
dardeve...@cidadecool.com, le Thu 03 Apr 2014 00:37:05 +0200, a écrit :
 however I could not avoid seeing strcmp function not checking for '\0'
 in s2 and just s1,

No: if b happens to be 0 while a is not, then the if (a!=b) is true and
we return a-b.

Samuel



Re: Fwd: Re: [PATCH] Steal all string functions from the libc

2014-04-03 Thread dardevelin

You are totally right. my fault on missing that detail.

On 2014-04-03 08:25, Samuel Thibault wrote:

dardeve...@cidadecool.com, le Thu 03 Apr 2014 00:37:05 +0200, a écrit :

however I could not avoid seeing strcmp function not checking for '\0'
in s2 and just s1,


No: if b happens to be 0 while a is not, then the if (a!=b) is true and
we return a-b.

Samuel