Chameleon

Chameleon Commit Details

Date:2011-12-24 11:53:06 (12 years 4 months ago)
Author:JrCs
Commit:1746
Parents: 1745
Message:Replace buggy strlcpy function with klibc one
Changes:
A/trunk/i386/klibc
A/trunk/i386/klibc/strlcpy.c
A/trunk/i386/klibc/LICENSE
A/trunk/i386/include/klibc
A/trunk/i386/include/klibc/compiler.h
A/trunk/i386/klibc/Makefile
M/trunk/i386/Makefile
M/trunk/i386/libsa/string.c
M/trunk/i386/boot2/Makefile

File differences

trunk/i386/include/klibc/compiler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* klibc/compiler.h
*
* Various compiler features
*/
#ifndef _KLIBC_COMPILER_H
#define _KLIBC_COMPILER_H
/* Specific calling conventions */
/* __cdecl is used when we want varadic and non-varadic functions to have
the same binary calling convention. */
#ifdef __i386__
# ifdef __GNUC__
# define __cdecl __attribute__((cdecl,regparm(0)))
# else
/* Most other C compilers have __cdecl as a keyword */
# endif
#else
# define __cdecl/* Meaningless on non-i386 */
#endif
/*
* How to declare a function which should be inlined or instantiated locally
*/
#ifdef __GNUC__
# ifdef __GNUC_STDC_INLINE__
# define __static_inline static __inline__ __attribute__((__gnu_inline__))
# else
# define __static_inline static __inline__
# endif
#else
# define __static_inline inline/* Just hope this works... */
#endif
/*
* How to declare a function which should be inlined or have a call to
* an external module
*/
#ifdef __GNUC__
# ifdef __GNUC_STDC_INLINE__
# define __extern_inline extern __inline__ __attribute__((__gnu_inline__))
# else
# define __extern_inline extern __inline__
# endif
#else
# define __extern_inline inline/* Just hope this works... */
#endif
/* How to declare a function that *must* be inlined */
/* Use "extern inline" even in the gcc3+ case to avoid warnings in ctype.h */
#ifdef __GNUC__
# if __GNUC__ >= 3
# define __must_inline __extern_inline __attribute__((__always_inline__))
# else
# define __must_inline extern __inline__
# endif
#else
# define __must_inline inline/* Just hope this works... */
#endif
/* How to declare a function that does not return */
#ifdef __GNUC__
# define __noreturn void __attribute__((noreturn))
#else
# define __noreturn void
#endif
/* "const" function:
Many functions do not examine any values except their arguments,
and have no effects except the return value. Basically this is
just slightly more strict class than the `pure' attribute above,
since function is not allowed to read global memory.
Note that a function that has pointer arguments and examines the
data pointed to must _not_ be declared `const'. Likewise, a
function that calls a non-`const' function usually must not be
`const'. It does not make sense for a `const' function to return
`void'.
*/
#ifdef __GNUC__
# define __constfunc __attribute__((const))
#else
# define __constfunc
#endif
#undef __attribute_const__
#define __attribute_const__ __constfunc
/* "pure" function:
Many functions have no effects except the return value and their
return value depends only on the parameters and/or global
variables. Such a function can be subject to common subexpression
elimination and loop optimization just as an arithmetic operator
would be. These functions should be declared with the attribute
`pure'.
*/
#ifdef __GNUC__
# define __purefunc __attribute__((pure))
#else
# define __purefunc
#endif
#undef __attribute_pure__
#define __attribute_pure__ __purefunc
/* Format attribute */
#ifdef __GNUC__
# define __formatfunc(t,f,a) __attribute__((format(t,f,a)))
#else
# define __formatfunc(t,f,a)
#endif
/* malloc() function (returns unaliased pointer) */
#if defined(__GNUC__) && (__GNUC__ >= 3)
# define __mallocfunc __attribute__((malloc))
#else
# define __mallocfunc
#endif
/* likely/unlikely */
#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
# define __likely(x) __builtin_expect(!!(x), 1)
# define __unlikely(x) __builtin_expect(!!(x), 0)
#else
# define __likely(x) (!!(x))
# define __unlikely(x) (!!(x))
#endif
/* Possibly unused function */
#ifdef __GNUC__
# define __unusedfunc__attribute__((unused))
#else
# define __unusedfunc
#endif
/* It's all user space... */
#define __user
/* The bitwise attribute: disallow arithmetric operations */
#ifdef __CHECKER__/* sparse only */
# define __bitwise__attribute__((bitwise))
#else
# define __bitwise
#endif
/* Shut up unused warnings */
#ifdef __GNUC__
# define __attribute_used__ __attribute__((used))
#else
# define __attribute_used__
#endif
/* Compiler pragma to make an alias symbol */
#define __ALIAS(__t, __f, __p, __a) \
__t __f __p __attribute__((weak, alias(#__a)));
#endif
trunk/i386/klibc/strlcpy.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
* strlcpy.c
*/
#include <string.h>
#include <klibc/compiler.h>
size_t strlcpy(char *dst, const char *src, size_t size)
{
size_t bytes = 0;
char *q = dst;
const char *p = src;
char ch;
while ((ch = *p++)) {
if (bytes + 1 < size)
*q++ = ch;
bytes++;
}
/* If size == 0 there is no space for a final null... */
if (size)
*q = '\0';
return bytes;
}
trunk/i386/klibc/LICENSE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
This license applies to all files in directory and its subdirectories,
unless otherwise noted in individual files.
Some files are derived from files derived from the include/ directory
of the Linux kernel, and are licensed under the terms of the GNU
General Public License, version 2, as released by the Free Software
Foundation, Inc.; incorporated herein by reference.
-----
Some files are derived from files copyrighted by the Regents of The
University of California, and are available under the following
license:
Note: The advertising clause in the license appearing on BSD Unix
files was officially rescinded by the Director of the Office of
Technology Licensing of the University of California on July 22
1999. He states that clause 3 is "hereby deleted in its entirety."
* Copyright (c)
*The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
*This product includes software developed by the University of
*California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
-----
For all remaining files, the following license applies:
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* Any copyright notice(s) and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
trunk/i386/klibc/Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
SRCROOT = $(abspath $(CURDIR)/../..)
OBJROOT = $(SRCROOT)/obj/i386/klibc
SYMROOT = $(SRCROOT)/sym/i386
DSTROOT = $(SRCROOT)/dst/i386
DOCROOT = $(SRCROOT)/doc
IMGROOT = $(SRCROOT)/sym/cache
IMGSKELROOT = $(SRCROOT)/imgskel
CDBOOT = ${IMGROOT}/usr/standalone/i386/cdboot
DIR = klibc
include ${SRCROOT}/Make.rules
# LIBSAIODIR = ../libsaio
CFLAGS:= $(CFLAGS) $(RC_CFLAGS) $(MORECPP) -arch i386 \
-fno-builtin -static $(OMIT_FRAME_POINTER_CFLAG) \
-mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \
-march=pentium4 -msse2 -mfpmath=sse -msoft-float \
-nostdinc -include $(SRCROOT)/autoconf.h
CPPFLAGS := $(CPPFLAGS) -nostdinc++
INC = -I. -I$(SYMROOT) -I${SRCROOT}/i386/include
OBJS = strlcpy.o
OBJS := $(addprefix $(OBJROOT)/, $(OBJS))
LIBS = libklibc.a
LIBS := $(addprefix $(SYMROOT)/, $(LIBS))
DIRS_NEEDED = $(OBJROOT) $(SYMROOT)
all embedtheme: $(DIRS_NEEDED) $(LIBS)
$(LIBS): $(OBJS)
@echo "\t[RM] $@"
@rm -f $@
@echo "\t[AR] $(@F)"
@ar q $@ $^ &> /dev/null
@echo "\t[RANLIB] $(@F)"
@ranlib $@
# dependencies
-include $(OBJROOT)/Makedep
clean-local:
@for o in $(OBJS); do if [ -f "$${o}" ];then echo "\t[RM] $${o}"; fi; done
@for l in $(LIBS); do if [ -f "$${l}" ];then echo "\t[RM] $${l}"; fi; done
@rm -f $(LIBS) $(OBJS)
trunk/i386/boot2/Makefile
3535
3636
3737
38
39
38
39
4040
4141
4242
THEMEDIR = ../../artwork/themes/$(THEME)
INC = -I. -I$(SRCROOT) -I$(SYMDIR) -I$(LIBSADIR) -I$(LIBSAIODIR) -I${SRCROOT}/i386/include
LIBS= -L$(SYMDIR) -lsaio -lsa
LIBDEP= libsaio.a libsa.a
LIBS= -L$(SYMDIR) -lsaio -lsa -lklibc
LIBDEP= libsaio.a libsa.a libklibc.a
OTHER_FILES =
trunk/i386/libsa/string.c
165165
166166
167167
168
169
170
171
172
173
174
175
176
177168
178169
179170
return ret;
}
size_t
strlcpy(char * s1, const char * s2, size_t n)
{
while (n && (*s1++ = *s2++))
n--;
if (!n) *--s1=0;
return strlen(s2);
}
char *
strstr(const char *in, const char *str)
{
trunk/i386/Makefile
1616
1717
1818
19
19
2020
2121
2222
# The order of building is important.
SUBDIRS_PRE = util
SUBDIRS = $(SUBDIRS_PRE) libsa libsaio boot0 boot1 boot2 cdboot modules
SUBDIRS = $(SUBDIRS_PRE) klibc libsa libsaio boot0 boot1 boot2 cdboot modules
modules-builtin:
@cd modules; ${MAKE} BUILT_IN=yes

Archive Download the corresponding diff file

Revision: 1746