Change the definition of NULL on ia64 (for LP64 compilations) from

an int constant to a long constant. This change improves consistency
in the following two ways:
1. The first 8 arguments are always passed in registers on ia64, which
   by virtue of the generated code implicitly widens ints to longs and
   allows the use of an 32-bit integral type for 64-bit arguments.
   Subsequent arguments are passed onto the memory stack, which does
   not exhibit the same behaviour and consequently do not allow this.
   In practice this means that variadic functions taking pointers
   and given NULL (without cast) work as long as the NULL is passed
   in one of the first 8 arguments. A SIGSEGV is more likely the
   result if such would be done for stack-based arguments. This is
   due to the fact that the upper 4 bytes remain undefined.
2. All 64-bit platforms that FreeBSD supports, with the obvious
   exception of ia64, allow 32-bit integral types (specifically NULL)
   when 64-bit pointers are expected in variadic functions by way of
   how the compiler generates code. As such, code that works correctly
   (whether rightfully so or not) on any platform other than ia64, may
   fail on ia64.

To more easily allow tweaking of the definition of NULL, this commit
removes the 12 definitions in the various headers and puts it in a
new header that can be included whenever NULL is to be made visible.

This commit fixes GNOME, emacs, xemacs and a whole bunch of ports
that I don't particularly care about at this time...
This commit is contained in:
Marcel Moolenaar 2003-12-07 21:10:06 +00:00
parent 4fb638c329
commit 12eb46c8bb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=123257
14 changed files with 53 additions and 50 deletions

View File

@ -54,6 +54,8 @@
#if __BSD_VISIBLE
#include <sys/_null.h>
/* definitions for library routines operating on directories. */
#define DIRBLKSIZ 1024
@ -81,10 +83,6 @@ typedef struct _dirdesc {
#define DTF_REWIND 0x0004 /* rewind after reading union stack */
#define __DTF_READALL 0x0008 /* everything has been read */
#ifndef NULL
#define NULL 0
#endif
#else /* !__BSD_VISIBLE */
typedef void * DIR;

View File

@ -37,6 +37,8 @@
#ifndef _LOCALE_H_
#define _LOCALE_H_
#include <sys/_null.h>
struct lconv {
char *decimal_point;
char *thousands_sep;
@ -64,10 +66,6 @@ struct lconv {
char int_n_sign_posn;
};
#ifndef NULL
#define NULL 0
#endif
#define LC_ALL 0
#define LC_COLLATE 1
#define LC_CTYPE 2

View File

@ -40,6 +40,7 @@
#define _RPC_TYPES_H
#include <sys/types.h>
#include <sys/_null.h>
typedef int32_t bool_t;
typedef int32_t enum_t;
@ -59,9 +60,6 @@ typedef int32_t rpc_inline_t;
#ifndef TRUE
# define TRUE (1)
#endif
#ifndef NULL
# define NULL 0
#endif
#define mem_alloc(bsize) calloc(1, bsize)
#define mem_free(ptr, bsize) free(ptr)

View File

@ -39,6 +39,7 @@
#define _STDDEF_H_
#include <sys/cdefs.h>
#include <sys/_null.h>
#include <sys/_types.h>
typedef __ptrdiff_t ptrdiff_t;
@ -62,10 +63,6 @@ typedef __wchar_t wchar_t;
#endif
#endif
#ifndef NULL
#define NULL 0
#endif
#define offsetof(type, member) __offsetof(type, member)
#endif /* _STDDEF_H_ */

View File

@ -41,6 +41,7 @@
#define _STDIO_H_
#include <sys/cdefs.h>
#include <sys/_null.h>
#include <sys/_types.h>
typedef __off_t fpos_t;
@ -57,10 +58,6 @@ typedef __va_list va_list;
#endif
#endif
#ifndef NULL
#define NULL 0
#endif
#define _FSTDIO /* Define for new stdio with functions. */
/*

View File

@ -38,6 +38,7 @@
#define _STDLIB_H_
#include <sys/cdefs.h>
#include <sys/_null.h>
#include <sys/_types.h>
#if __BSD_VISIBLE
@ -69,10 +70,6 @@ typedef struct {
long rem;
} ldiv_t;
#ifndef NULL
#define NULL 0
#endif
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0

View File

@ -38,6 +38,7 @@
#define _STRING_H_
#include <sys/cdefs.h>
#include <sys/_null.h>
#include <sys/_types.h>
/*
@ -53,10 +54,6 @@ typedef __size_t size_t;
#define _SIZE_T_DECLARED
#endif
#ifndef NULL
#define NULL 0
#endif
__BEGIN_DECLS
#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
void *memccpy(void * __restrict, const void * __restrict, int, size_t);

View File

@ -46,6 +46,7 @@
#define _TIME_H_
#include <sys/cdefs.h>
#include <sys/_null.h>
#include <sys/_types.h>
#if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE
@ -59,10 +60,6 @@
/* Frequency of the clock ticks reported by clock(). */
#define CLOCKS_PER_SEC 128
#ifndef NULL
#define NULL 0
#endif
#ifndef _CLOCK_T_DECLARED
typedef __clock_t clock_t;
#define _CLOCK_T_DECLARED

View File

@ -40,6 +40,7 @@
#include <sys/cdefs.h>
#include <sys/types.h> /* XXX adds too much pollution. */
#include <sys/unistd.h>
#include <sys/_null.h>
#include <sys/_types.h>
#ifndef _GID_T_DECLARED
@ -81,10 +82,6 @@ typedef __useconds_t useconds_t;
#define STDOUT_FILENO 1 /* standard output file descriptor */
#define STDERR_FILENO 2 /* standard error file descriptor */
#ifndef NULL
#define NULL 0 /* null pointer constant */
#endif
#if __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
#define F_ULOCK 0 /* unlock locked section */
#define F_LOCK 1 /* lock a section for exclusive use */

View File

@ -68,13 +68,10 @@
#define _WCHAR_H_
#include <sys/cdefs.h>
#include <sys/_null.h>
#include <sys/_types.h>
#include <machine/_limits.h>
#ifndef NULL
#define NULL 0
#endif
#ifndef _MBSTATE_T_DECLARED
typedef __mbstate_t mbstate_t;
#define _MBSTATE_T_DECLARED

View File

@ -40,6 +40,7 @@
#define _RPC_TYPES_H
#include <sys/types.h>
#include <sys/_null.h>
typedef int32_t bool_t;
typedef int32_t enum_t;
@ -59,9 +60,6 @@ typedef int32_t rpc_inline_t;
#ifndef TRUE
# define TRUE (1)
#endif
#ifndef NULL
# define NULL 0
#endif
#define mem_alloc(bsize) calloc(1, bsize)
#define mem_free(ptr, bsize) free(ptr)

37
sys/sys/_null.h Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2003 Marcel Moolenaar
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* $FreeBSD$
*/
#ifndef NULL
#ifdef __LP64__
#define NULL 0L
#else
#define NULL 0
#endif
#endif

View File

@ -42,6 +42,8 @@
#ifndef _SYS_PARAM_H_
#define _SYS_PARAM_H_
#include <sys/_null.h>
#define BSD 199506 /* System version (year & month). */
#define BSD4_3 1
#define BSD4_4 1
@ -59,10 +61,6 @@
#undef __FreeBSD_version
#define __FreeBSD_version 502100 /* Master, propagated to newvers */
#ifndef NULL
#define NULL 0
#endif
#ifndef LOCORE
#include <sys/types.h>
#endif

View File

@ -30,14 +30,11 @@
#define _SYS_STDDEF_H_
#include <sys/cdefs.h>
#include <sys/_null.h>
#include <machine/_types.h>
typedef __ptrdiff_t ptrdiff_t;
#define offsetof(type, field) __offsetof(type, field)
#ifndef NULL
#define NULL 0
#endif
#endif /* !_SYS_STDDEF_H_ */