Fix the stat(2) ABI problem noticed by Curt Sampson and Chris Demetriou.

The problem is that the timespec structures now how 7 32-bit values before
them, which causes them to be implicitly padded on the Alpha (because the
timespecs have an alignment of 64 bits).  However, the alignment constraints
changed if _POSIX_SOURCE was defined (thus replacing the timespecs with
time_ts and longs).  This had no effect on 32-bit architectures, but changed
the offsets of several stat structure members on the Alpha.

XXX The ABI has not changed; explicit padding is added in the _POSIX_SOURCE
XXX case, enabled by an #ifdef __alpha__.  This should be changed if the
XXX stat(2) ABI is ever changed again (e.g. if we change time_t to 64 bits).
This commit is contained in:
thorpej 1998-01-05 02:23:43 +00:00
parent d07708b38e
commit fb74151eaf

View File

@ -1,4 +1,4 @@
/* $NetBSD: stat.h,v 1.30 1997/11/23 20:40:42 kleink Exp $ */
/* $NetBSD: stat.h,v 1.31 1998/01/05 02:23:43 thorpej Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@ -85,6 +85,20 @@ struct stat12 { /* NetBSD-1.2 stat struct */
int64_t st_qspare[2];
};
/*
* On systems with 8 byte longs and 4 byte time_ts, padding the time_ts
* is required in order to have a consistent ABI. This is because the
* stat structure used to contain timespecs, which had different
* alignment constraints than a time_t and a long alone. The padding
* should be removed the next time the stat structure ABI is changed.
* (This will happen whever we change to 8 byte time_t.)
*/
#if defined(__alpha__) /* XXX XXX XXX */
#define __STATPAD(x) int x;
#else
#define __STATPAD(x) /* nothing */
#endif
struct stat {
dev_t st_dev; /* inode's device */
ino_t st_ino; /* inode's number */
@ -98,11 +112,15 @@ struct stat {
struct timespec st_mtimespec;/* time of last data modification */
struct timespec st_ctimespec;/* time of last file status change */
#else
__STATPAD(__pad0)
time_t st_atime; /* time of last access */
__STATPAD(__pad1)
long st_atimensec; /* nsec of last access */
time_t st_mtime; /* time of last data modification */
__STATPAD(__pad2)
long st_mtimensec; /* nsec of last data modification */
time_t st_ctime; /* time of last file status change */
__STATPAD(__pad3)
long st_ctimensec; /* nsec of last file status change */
#endif
off_t st_size; /* file size, in bytes */
@ -113,6 +131,8 @@ struct stat {
int64_t st_qspare[2];
};
#undef __STATPAD
#ifndef _POSIX_SOURCE
#define st_atime st_atimespec.tv_sec
#define st_atimensec st_atimespec.tv_nsec