mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
This commit implements the build fixes required to get ksh running on
Haiku. Note that while ksh does compile, it has a ton of regression test
failures on Haiku.
src/cmd/ksh93/data/signals.c,
src/lib/libast/features/signal.c:
- Add support for the SIGKILLTHR signal, which is supported by BeOS and
Haiku.
- SIGINFO was missing an entry in the libast feature test, so add one
(re: 658bba74
).
src/cmd/ksh93/RELEASE:
- Add an entry noting that ksh now compiles on Haiku, albeit with many
regression test failures.
src/cmd/ksh93/{include/terminal.h,sh/path.c}:
- Silence compiler warnings on Haiku.
src/lib/libast/features/mmap:
- The mmap feature test freezes on Haiku, so modify the test to fail
immediately on that OS.
src/lib/libast/misc/signal.c:
- Avoid redefining the signal definition on Haiku to fix a compiler
error.
src/lib/libast/features/nl_types:
- For some reason the nl_item typedef on Haiku doesn't work correctly.
Work around that by creating the nl_item type in the libast nl_types
feature test.
336 lines
7.6 KiB
Text
336 lines
7.6 KiB
Text
ref -D_def_map_ast=1
|
|
|
|
sys mman
|
|
|
|
tst lib_mmap note{ standard mmap interface that works }end execute{
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <sys/types.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/times.h>
|
|
|
|
#define MAPSIZE (64*1024)
|
|
#define BUFSIZE (8*1024)
|
|
#define WRITE (64)
|
|
|
|
#define Failed(file) (remove(file),1)
|
|
|
|
int
|
|
main(int argc, char** argv)
|
|
{
|
|
#ifdef __HAIKU__
|
|
return 1; /* don't even bother, on Haiku it freezes the system */
|
|
#endif
|
|
caddr_t mm;
|
|
char *t, *u, *f;
|
|
int i, fd, okfixed;
|
|
char file[1024], buf[MAPSIZE];
|
|
struct tms stm, etm;
|
|
clock_t rdtm, mmtm;
|
|
|
|
/* create data file in a local fs if possible */
|
|
t = file;
|
|
if (access(f = "/tmp", 0) == 0 ||
|
|
access(f = "/var/tmp", 0) == 0)
|
|
{
|
|
while (*t = *f++)
|
|
t++;
|
|
*t++ = '/';
|
|
}
|
|
u = t;
|
|
f = argv[0];
|
|
while (*t = *f++)
|
|
if (*t == '/')
|
|
t = u;
|
|
else if (*t != '.')
|
|
t++;
|
|
*t++ = '.'; *t++ = 'D'; *t = 0;
|
|
if ((fd = open(file, O_CREAT|O_TRUNC|O_WRONLY, 0666)) < 0)
|
|
return 1;
|
|
|
|
for (i = 0; i < sizeof(buf); ++i)
|
|
buf[i] = '0' + (i%10);
|
|
for (i = 0; i < WRITE; ++i)
|
|
if (write(fd,buf,sizeof(buf)) != sizeof(buf))
|
|
return Failed(file);
|
|
close(fd);
|
|
|
|
/* see if can overwrite fixed map */
|
|
#ifndef MAP_VARIABLE
|
|
#define MAP_VARIABLE 0
|
|
#endif
|
|
if ((fd = open(file, O_RDWR)) < 0)
|
|
return Failed(file);
|
|
|
|
mm = mmap((caddr_t)0, sizeof(buf), (PROT_READ|PROT_WRITE),
|
|
(MAP_PRIVATE|MAP_VARIABLE), fd, 0);
|
|
if(mm == (caddr_t)0 || mm == (caddr_t)(-1))
|
|
return Failed(file);
|
|
mm = mmap(mm, sizeof(buf), (PROT_READ|PROT_WRITE),
|
|
(MAP_PRIVATE|MAP_FIXED), fd, 0);
|
|
okfixed = (mm == (caddr_t)0 || mm == (caddr_t)(-1)) ? 0 : 1;
|
|
munmap(mm, sizeof(buf));
|
|
close(fd);
|
|
|
|
/* read time */
|
|
if((fd = open(file, O_RDWR)) < 0)
|
|
return Failed(file);
|
|
times(&stm);
|
|
for (i = 0; i < WRITE; ++i)
|
|
if (read(fd,buf,BUFSIZE) != BUFSIZE)
|
|
return Failed(file);
|
|
times(&etm);
|
|
close(fd);
|
|
rdtm = (etm.tms_utime-stm.tms_utime) + (etm.tms_stime-stm.tms_stime);
|
|
|
|
/* mmap time */
|
|
if ((fd = open(file, O_RDWR)) < 0)
|
|
return Failed(file);
|
|
times(&stm);
|
|
for(i = 0, mm = (caddr_t)0; i < WRITE; ++i)
|
|
{ if(okfixed)
|
|
{ mm = (caddr_t)mmap(mm, MAPSIZE,
|
|
(PROT_READ|PROT_WRITE),
|
|
(MAP_PRIVATE | (mm ? MAP_FIXED : MAP_VARIABLE)),
|
|
fd, i*MAPSIZE );
|
|
}
|
|
else
|
|
{ if(mm)
|
|
munmap(mm, MAPSIZE);
|
|
mm = (caddr_t)mmap((caddr_t)0, MAPSIZE,
|
|
(PROT_READ|PROT_WRITE),
|
|
(MAP_PRIVATE|MAP_VARIABLE),
|
|
fd, i*MAPSIZE );
|
|
}
|
|
if(mm == (caddr_t)(-1) || mm == (caddr_t)0)
|
|
return Failed(file);
|
|
}
|
|
times(&etm);
|
|
close(fd);
|
|
remove(file);
|
|
mmtm = (etm.tms_utime-stm.tms_utime) + (etm.tms_stime-stm.tms_stime);
|
|
|
|
return rdtm+60 < mmtm ? 1 : 0;
|
|
}
|
|
}end
|
|
|
|
tst lib_mmap64 note{ mmap64 interface and implementation work }end execute{
|
|
#if !_lib_mmap
|
|
(
|
|
#endif
|
|
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <sys/types.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/stat.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int
|
|
main()
|
|
{
|
|
off64_t off;
|
|
int fd;
|
|
int n;
|
|
char* s;
|
|
struct stat64 st;
|
|
char file[32] = {'/','t','m','p','/','m','m','X','X','X','X','X','X'};
|
|
|
|
/* hey, stubs are supposed to fail! */
|
|
if (stat64(".", &st) || !st.st_mode || !st.st_mtime)
|
|
return 1;
|
|
if (!mktemp(file) || (fd = open64(file, O_CREAT|O_WRONLY, 0600)) < 0)
|
|
{
|
|
remove(file);
|
|
return 1;
|
|
}
|
|
off = (1<<8);
|
|
off *= off;
|
|
if (lseek64(fd, off, SEEK_SET) != off)
|
|
{
|
|
remove(file);
|
|
return 1;
|
|
}
|
|
n = strlen(file) + 1;
|
|
if (write(fd, file, n) != n)
|
|
{
|
|
remove(file);
|
|
return 1;
|
|
}
|
|
if (close(fd) < 0 || (fd = open64(file, O_RDWR)) < 0)
|
|
{
|
|
remove(file);
|
|
return 1;
|
|
}
|
|
if (!(s = mmap64((caddr_t)0, (size_t)n, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, off)))
|
|
{
|
|
remove(file);
|
|
return 1;
|
|
}
|
|
if (strcmp(s, file))
|
|
{
|
|
remove(file);
|
|
return 1;
|
|
}
|
|
close(fd);
|
|
remove(file);
|
|
return 0;
|
|
}
|
|
}end
|
|
|
|
tst mmap_anon note{ use mmap MAP_ANON to get raw memory }end execute{
|
|
#if !_lib_mmap
|
|
(
|
|
#endif
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <sys/types.h>
|
|
#include <sys/mman.h>
|
|
#if defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
|
|
#define MAP_ANON MAP_ANONYMOUS
|
|
#endif
|
|
int
|
|
main()
|
|
{ void *addr;
|
|
addr = mmap(0,1024*1024,PROT_READ|PROT_WRITE,MAP_ANON|MAP_PRIVATE,-1,0);
|
|
return (addr && addr != (void*)(-1)) ? 0 : 1;
|
|
}
|
|
}end
|
|
|
|
tst mmap_devzero note{ use mmap on /dev/zero to get raw memory }end execute{
|
|
#if !_lib_mmap
|
|
(
|
|
#endif
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <sys/types.h>
|
|
#include <sys/mman.h>
|
|
int
|
|
main()
|
|
{ int fd;
|
|
void *addr;
|
|
if((fd = open("/dev/zero", O_RDWR)) < 0)
|
|
return 1;
|
|
addr = mmap(0,1024*1024,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0);
|
|
return (addr && addr != (void*)(-1)) ? 0 : 1;
|
|
}
|
|
}end
|
|
|
|
tst note{ mmap is fast enough to be worth using }end output{
|
|
#if !_lib_mmap
|
|
(
|
|
#endif
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/times.h>
|
|
|
|
#define MAPSIZE (64*1024)
|
|
#define BUFSIZE (MAPSIZE/8)
|
|
#define WRITE (64)
|
|
#define RUN (64)
|
|
|
|
#define Failed(file) (remove(file),1)
|
|
|
|
int
|
|
main(int argc, char** argv)
|
|
{
|
|
caddr_t mm;
|
|
char *t, *f;
|
|
int i, fd, k, run;
|
|
char file[1024], buf[MAPSIZE];
|
|
struct tms stm, etm;
|
|
clock_t rdtm, mmtm;
|
|
|
|
/* create data file */
|
|
f = argv[0]; t = file;
|
|
while (*t = *f++)
|
|
t++;
|
|
*t++ = '.'; *t++ = 'D'; *t = 0;
|
|
if ((fd = open(file, O_CREAT|O_TRUNC|O_WRONLY, 0666)) < 0)
|
|
return 1;
|
|
|
|
for (i = 0; i < sizeof(buf); ++i)
|
|
buf[i] = '0' + (i%10);
|
|
for (i = 0; i < WRITE; ++i)
|
|
if (write(fd,buf,sizeof(buf)) != sizeof(buf))
|
|
return Failed(file);
|
|
close(fd);
|
|
|
|
/* read time */
|
|
times(&stm);
|
|
for(run = 0; run < RUN; ++run)
|
|
{ if((fd = open(file, O_RDWR)) < 0)
|
|
return Failed(file);
|
|
for (i = 0; i < WRITE; ++i)
|
|
{ for(k = 0; k < MAPSIZE; k += BUFSIZE)
|
|
if (read(fd,buf,BUFSIZE) != BUFSIZE)
|
|
return Failed(file);
|
|
}
|
|
close(fd);
|
|
}
|
|
times(&etm);
|
|
rdtm = (etm.tms_utime-stm.tms_utime) + (etm.tms_stime-stm.tms_stime);
|
|
|
|
/* mmap time */
|
|
times(&stm);
|
|
for(run = 0; run < RUN; ++run)
|
|
{ if ((fd = open(file, O_RDWR)) < 0)
|
|
return Failed(file);
|
|
for(i = 0, mm = (caddr_t)0; i < WRITE; ++i)
|
|
{ if(mm)
|
|
munmap(mm, MAPSIZE);
|
|
mm = (caddr_t)mmap((caddr_t)0, MAPSIZE,
|
|
(PROT_READ|PROT_WRITE),
|
|
MAP_PRIVATE, fd, i*MAPSIZE );
|
|
if(mm == (caddr_t)(-1) || mm == (caddr_t)0)
|
|
return Failed(file);
|
|
|
|
/* the memcpy is < BUFSIZE to simulate the
|
|
fact that functions like sfreserve/sfgetr do
|
|
not do buffer copying.
|
|
*/
|
|
t = (char*)mm;
|
|
for(k = 0; k < MAPSIZE; k += BUFSIZE, t += BUFSIZE)
|
|
memcpy(buf,t,(3*BUFSIZE)/4);
|
|
}
|
|
close(fd);
|
|
}
|
|
times(&etm);
|
|
mmtm = (etm.tms_utime-stm.tms_utime) + (etm.tms_stime-stm.tms_stime);
|
|
|
|
remove(file);
|
|
|
|
if(4*mmtm <= 3*rdtm)
|
|
printf("#define _mmap_worthy 2 /* mmap is great */\n");
|
|
else if(4*mmtm <= 5*rdtm)
|
|
printf("#define _mmap_worthy 1 /* mmap is good */\n");
|
|
|
|
else
|
|
return 1;
|
|
return 0;
|
|
}
|
|
}end
|
|
|
|
cat{
|
|
|
|
/* some systems get it wrong but escape concise detection */
|
|
#ifndef _NO_MMAP
|
|
#if __CYGWIN__
|
|
#define _NO_MMAP 1
|
|
#endif
|
|
#endif
|
|
|
|
#if _NO_MMAP
|
|
#undef _lib_mmap
|
|
#undef _lib_mmap64
|
|
#undef _mmap_anon
|
|
#undef _mmap_devzero
|
|
#undef _mmap_worthy
|
|
#endif
|
|
}end
|