mirror of
https://github.com/postgres/postgres.git
synced 2025-11-13 16:22:44 +03:00
I have done the QNX4 port with the current source tree. The number of
backend/Makefiles to be patched could significantly be reduced since they have been adopted to the QNX4 needs. Andreas Kardos
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
# be converted to Method 2.
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql/src/backend/port/Attic/Makefile.in,v 1.19 1999/12/13 22:33:05 momjian Exp $
|
||||
# $Header: /cvsroot/pgsql/src/backend/port/Attic/Makefile.in,v 1.20 1999/12/16 01:25:02 momjian Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
@@ -25,11 +25,19 @@ CFLAGS+= -I..
|
||||
OBJS = dynloader.o @INET_ATON@ @STRERROR@ @MISSING_RANDOM@ @SRANDOM@
|
||||
OBJS+= @GETHOSTNAME@ @GETRUSAGE@ @STRCASECMP@ @STRDUP@ @TAS@ @ISINF@
|
||||
OBJS+= @STRTOL@ @STRTOUL@ @SNPRINTF@
|
||||
ifeq ($(PORTNAME), qnx4)
|
||||
OBJS += getrusage.o qnx4/SUBSYS.o
|
||||
endif
|
||||
all: SUBSYS.o
|
||||
|
||||
SUBSYS.o: $(OBJS)
|
||||
$(LD) $(LDREL) $(LDOUT) SUBSYS.o $(OBJS)
|
||||
|
||||
qnx4/SUBSYS.o: qnx4.dir
|
||||
|
||||
qnx4.dir:
|
||||
$(MAKE) -C qnx4 all
|
||||
|
||||
.PHONY: clean dep
|
||||
|
||||
distclean clean:
|
||||
|
||||
BIN
src/backend/port/dynloader/ID
Normal file
BIN
src/backend/port/dynloader/ID
Normal file
Binary file not shown.
50
src/backend/port/dynloader/qnx4.c
Normal file
50
src/backend/port/dynloader/qnx4.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* dynloader.c
|
||||
* dynamic loader for QNX4 using the shared library mechanism
|
||||
*
|
||||
* Copyright (c) 1999, repas AEG Automation GmbH
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/qnx4.c,v 1.1 1999/12/16 01:25:04 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
/* System includes */
|
||||
/*
|
||||
#include <stdio.h>
|
||||
#include <a.out.h>
|
||||
#include <dl.h>
|
||||
*/
|
||||
#include "postgres.h"
|
||||
#include "fmgr.h"
|
||||
#include "utils/dynamic_loader.h"
|
||||
#include "dynloader.h"
|
||||
|
||||
void *
|
||||
pg_dlopen(char *filename)
|
||||
{
|
||||
return (void *) NULL;
|
||||
}
|
||||
|
||||
func_ptr
|
||||
pg_dlsym(void *handle, char *funcname)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
pg_dlclose(void *handle)
|
||||
{
|
||||
}
|
||||
|
||||
char *
|
||||
pg_dlerror()
|
||||
{
|
||||
static char errmsg[] = "Failed to load shared library due to lack of shared library support.";
|
||||
|
||||
return errmsg;
|
||||
}
|
||||
20
src/backend/port/dynloader/qnx4.h
Normal file
20
src/backend/port/dynloader/qnx4.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* dynloader.h
|
||||
* dynamic loader for QNX4 using the shared library mechanism
|
||||
*
|
||||
* Copyright (c) 1999, repas AEG Automation GmbH
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/qnx4.h,v 1.1 1999/12/16 01:25:04 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
/* System includes */
|
||||
void *pg_dlopen(char *filename);
|
||||
func_ptr pg_dlsym(void *handle, char *funcname);
|
||||
void pg_dlclose(void *handle);
|
||||
char *pg_dlerror();
|
||||
11306
src/backend/port/dynloader/tags
Normal file
11306
src/backend/port/dynloader/tags
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
/* $Id: isinf.c,v 1.13 1999/07/30 03:45:44 momjian Exp $ */
|
||||
/* $Id: isinf.c,v 1.14 1999/12/16 01:25:02 momjian Exp $ */
|
||||
|
||||
#include <math.h>
|
||||
|
||||
@@ -51,7 +51,7 @@ double x;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else defined(HAVE_CLASS)
|
||||
#elif defined(HAVE_CLASS)
|
||||
int
|
||||
isinf(double x)
|
||||
{
|
||||
@@ -66,3 +66,18 @@ isinf(double x)
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __QNX__
|
||||
#include <float.h>
|
||||
|
||||
int
|
||||
isinf(double x)
|
||||
{
|
||||
if (x == HUGE_VAL)
|
||||
return 1;
|
||||
if (x == -HUGE_VAL)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
43
src/backend/port/qnx/Makefile
Normal file
43
src/backend/port/qnx/Makefile
Normal file
@@ -0,0 +1,43 @@
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile--
|
||||
# Makefile for port/sparc
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql/src/backend/port/qnx/Attic/Makefile,v 1.1 1999/12/16 01:25:06 momjian Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
SRCDIR = ../../..
|
||||
include ../../../Makefile.global
|
||||
|
||||
INCLUDE_OPT = -I../..
|
||||
|
||||
CFLAGS+=$(INCLUDE_OPT)
|
||||
|
||||
OBJS = isnan.o rint.o sem.o shm.o
|
||||
|
||||
all: SUBSYS.o tstrint tstsem tstshm
|
||||
|
||||
SUBSYS.o: $(OBJS)
|
||||
$(LD) $(LDREL) $(LDOUT) SUBSYS.o $(OBJS)
|
||||
|
||||
tstrint: tstrint.o rint.o
|
||||
$(CC) -o tstrint rint.o tstrint.o
|
||||
|
||||
tstsem: tstsem.o sem.o
|
||||
$(CC) -o tstsem sem.o tstsem.o
|
||||
|
||||
tstshm: tstshm.o shm.o
|
||||
$(CC) -o tstshm shm.o tstshm.o
|
||||
|
||||
depend dep:
|
||||
$(CC) -MM $(INCLUDE_OPT) *.c >depend
|
||||
|
||||
clean:
|
||||
rm -f SUBSYS.o $(OBJS) tstrint tstrint.o tstsem tstsem.o tstshm tstshm.o
|
||||
|
||||
ifeq (depend,$(wildcard depend))
|
||||
include depend
|
||||
endif
|
||||
|
||||
30
src/backend/port/qnx/ipc.h
Normal file
30
src/backend/port/qnx/ipc.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* ipc.h
|
||||
* System V IPC Emulation
|
||||
*
|
||||
* Copyright (c) 1999, repas AEG Automation GmbH
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/qnx/Attic/ipc.h,v 1.1 1999/12/16 01:25:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef _SYS_IPC_H
|
||||
#define _SYS_IPC_H
|
||||
|
||||
/* Common IPC definitions. */
|
||||
/* Mode bits. */
|
||||
#define IPC_CREAT 0001000 /* create entry if key doesn't exist */
|
||||
#define IPC_EXCL 0002000 /* fail if key exists */
|
||||
#define IPC_NOWAIT 0004000 /* error if request must wait */
|
||||
|
||||
/* Keys. */
|
||||
#define IPC_PRIVATE (key_t)0 /* private key */
|
||||
|
||||
/* Control Commands. */
|
||||
#define IPC_RMID 0 /* remove identifier */
|
||||
|
||||
#endif /* _SYS_IPC_H */
|
||||
22
src/backend/port/qnx/isnan.c
Normal file
22
src/backend/port/qnx/isnan.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* isnan.c
|
||||
* isnan() implementation
|
||||
*
|
||||
* Copyright (c) 1999, repas AEG Automation GmbH
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/qnx/Attic/isnan.c,v 1.1 1999/12/16 01:25:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "os.h"
|
||||
|
||||
unsigned char __nan[8] = __nan_bytes;
|
||||
|
||||
int isnan(double dsrc)
|
||||
{
|
||||
return !memcmp( &dsrc, &NAN, sizeof( double ) );
|
||||
}
|
||||
31
src/backend/port/qnx/rint.c
Normal file
31
src/backend/port/qnx/rint.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* rint.c
|
||||
* rint() implementation
|
||||
*
|
||||
* Copyright (c) 1999, repas AEG Automation GmbH
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/qnx/Attic/rint.c,v 1.1 1999/12/16 01:25:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include "os.h"
|
||||
|
||||
double rint(double x)
|
||||
{
|
||||
double f, n = 0.;
|
||||
|
||||
f = modf( x, &n );
|
||||
|
||||
if( x > 0. ) {
|
||||
if( f > .5 ) n += 1.;
|
||||
}
|
||||
else if( x < 0. ) {
|
||||
if( f < -.5 ) n -= 1.;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
261
src/backend/port/qnx/sem.c
Normal file
261
src/backend/port/qnx/sem.c
Normal file
@@ -0,0 +1,261 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* sem.c
|
||||
* System V Semaphore Emulation
|
||||
*
|
||||
* Copyright (c) 1999, repas AEG Automation GmbH
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/qnx/Attic/sem.c,v 1.1 1999/12/16 01:25:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <semaphore.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include "postgres.h"
|
||||
#include "storage/ipc.h"
|
||||
#include <sys/sem.h>
|
||||
|
||||
|
||||
#define SETMAX 32
|
||||
#define SEMMAX 16
|
||||
|
||||
#define MODE 0777
|
||||
#define SHM_INFO_NAME "SysV_Sem_Info"
|
||||
|
||||
|
||||
struct sem_info {
|
||||
sem_t sem;
|
||||
struct {
|
||||
key_t key;
|
||||
int nsems;
|
||||
sem_t sem[SEMMAX]; /* array of semaphores */
|
||||
pid_t pid[SEMMAX]; /* array of PIDs */
|
||||
} set[SETMAX];
|
||||
};
|
||||
|
||||
static struct sem_info *SemInfo = ( struct sem_info * )-1;
|
||||
|
||||
|
||||
int semctl( int semid, int semnum, int cmd, /*...*/union semun arg )
|
||||
{
|
||||
int r;
|
||||
|
||||
sem_wait( &SemInfo->sem );
|
||||
|
||||
if( semid < 0 || semid >= SETMAX ||
|
||||
semnum < 0 || semnum >= SemInfo->set[semid].nsems ) {
|
||||
sem_post( &SemInfo->sem );
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch( cmd ) {
|
||||
case GETPID:
|
||||
r = SemInfo->set[semid].pid[semnum];
|
||||
break;
|
||||
|
||||
case GETVAL:
|
||||
r = SemInfo->set[semid].sem[semnum].value;
|
||||
break;
|
||||
|
||||
case GETALL:
|
||||
for( semnum = 0; semnum < SemInfo->set[semid].nsems; semnum++ ) {
|
||||
arg.array[semnum] = SemInfo->set[semid].sem[semnum].value;
|
||||
}
|
||||
break;
|
||||
|
||||
case SETVAL:
|
||||
SemInfo->set[semid].sem[semnum].value = arg.val;
|
||||
break;
|
||||
|
||||
case SETALL:
|
||||
for( semnum = 0; semnum < SemInfo->set[semid].nsems; semnum++ ) {
|
||||
SemInfo->set[semid].sem[semnum].value = arg.array[semnum];
|
||||
}
|
||||
break;
|
||||
|
||||
case IPC_RMID:
|
||||
for( semnum = 0; semnum < SemInfo->set[semid].nsems; semnum++ ) {
|
||||
if( sem_destroy( &SemInfo->set[semid].sem[semnum] ) == -1 ) {
|
||||
r = -1;
|
||||
}
|
||||
}
|
||||
SemInfo->set[semid].key = -1;
|
||||
SemInfo->set[semid].nsems = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
sem_post( &SemInfo->sem );
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
sem_post( &SemInfo->sem );
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int semget( key_t key, int nsems, int semflg )
|
||||
{
|
||||
int fd, semid, semnum/*, semnum1*/;
|
||||
int exist = 0;
|
||||
|
||||
if( nsems < 0 || nsems > SEMMAX ) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* open and map shared memory */
|
||||
if( SemInfo == ( struct sem_info * )-1 ) {
|
||||
/* test if the shared memory already exists */
|
||||
fd = shm_open( SHM_INFO_NAME, O_RDWR | O_CREAT | O_EXCL, MODE );
|
||||
if( fd == -1 && errno == EEXIST ) {
|
||||
exist = 1;
|
||||
fd = shm_open( SHM_INFO_NAME, O_RDWR | O_CREAT, MODE );
|
||||
}
|
||||
if( fd == -1 ) return fd;
|
||||
/* The size may only be set once. Ignore errors. */
|
||||
ltrunc( fd, sizeof( struct sem_info ), SEEK_SET );
|
||||
SemInfo = mmap( NULL, sizeof( struct sem_info ),
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
|
||||
if( SemInfo == MAP_FAILED ) return -1;
|
||||
if( !exist ) {
|
||||
/* create semaphore for locking */
|
||||
sem_init( &SemInfo->sem, 1, 1 );
|
||||
sem_wait( &SemInfo->sem );
|
||||
/* initilize shared memory */
|
||||
memset( SemInfo->set, 0, sizeof( SemInfo->set ) );
|
||||
for( semid = 0; semid < SETMAX; semid++ ) {
|
||||
SemInfo->set[semid].key = -1;
|
||||
}
|
||||
sem_post( &SemInfo->sem );
|
||||
}
|
||||
}
|
||||
|
||||
sem_wait( &SemInfo->sem );
|
||||
|
||||
if( key != IPC_PRIVATE ) {
|
||||
/* search existing element */
|
||||
semid = 0;
|
||||
while( semid < SETMAX && SemInfo->set[semid].key != key ) semid++;
|
||||
if( !( semflg & IPC_CREAT ) && semid >= SETMAX ) {
|
||||
sem_post( &SemInfo->sem );
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
else if( semid < SETMAX ) {
|
||||
if( semflg & IPC_CREAT && semflg & IPC_EXCL ) {
|
||||
sem_post( &SemInfo->sem );
|
||||
errno = EEXIST;
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
if( nsems != 0 && SemInfo->set[semid].nsems < nsems ) {
|
||||
sem_post( &SemInfo->sem );
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
sem_post( &SemInfo->sem );
|
||||
return semid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* search first free element */
|
||||
semid = 0;
|
||||
while( semid < SETMAX && SemInfo->set[semid].key != -1 ) semid++;
|
||||
if( semid >= SETMAX ) {
|
||||
sem_post( &SemInfo->sem );
|
||||
errno = ENOSPC;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for( semnum = 0; semnum < nsems; semnum++ ) {
|
||||
sem_init( &SemInfo->set[semid].sem[semnum], 1, 0 );
|
||||
/* Currently sem_init always returns -1.
|
||||
if( sem_init( &SemInfo->set[semid].sem[semnum], 1, 0 ) == -1 ) {
|
||||
for( semnum1 = 0; semnum1 < semnum; semnum1++ ) {
|
||||
sem_destroy( &SemInfo->set[semid].sem[semnum1] );
|
||||
}
|
||||
sem_post( &SemInfo->sem );
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
SemInfo->set[semid].key = key;
|
||||
SemInfo->set[semid].nsems = nsems;
|
||||
|
||||
sem_post( &SemInfo->sem );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int semop( int semid, struct sembuf *sops, size_t nsops )
|
||||
{
|
||||
int i, j, r = 0, r1, errno1 = 0;
|
||||
|
||||
sem_wait( &SemInfo->sem );
|
||||
|
||||
if( semid < 0 || semid >= SETMAX ) {
|
||||
sem_post( &SemInfo->sem );
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
for( i = 0; i < nsops; i++ ) {
|
||||
if( /*sops[i].sem_num < 0 ||*/ sops[i].sem_num >= SemInfo->set[semid].nsems ) {
|
||||
sem_post( &SemInfo->sem );
|
||||
errno = EFBIG;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for( i = 0; i < nsops; i++ ) {
|
||||
if( sops[i].sem_op < 0 ) {
|
||||
if( sops[i].sem_flg & IPC_NOWAIT ) {
|
||||
for( j = 0; j < -sops[i].sem_op; j++ ) {
|
||||
if( sem_trywait( &SemInfo->set[semid].sem[sops[i].sem_num] ) ) {
|
||||
errno1 = errno;
|
||||
r = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for( j = 0; j < -sops[i].sem_op; j++ ) {
|
||||
sem_post( &SemInfo->sem ); /* avoid deadlock */
|
||||
r1 = sem_wait( &SemInfo->set[semid].sem[sops[i].sem_num] );
|
||||
sem_wait( &SemInfo->sem );
|
||||
if( r1 ) {
|
||||
errno1 = errno;
|
||||
r = r1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( sops[i].sem_op > 0 ) {
|
||||
for( j = 0; j < sops[i].sem_op; j++ ) {
|
||||
if( sem_post( &SemInfo->set[semid].sem[sops[i].sem_num] ) ) {
|
||||
errno1 = errno;
|
||||
r = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* sops[i].sem_op == 0 */ {
|
||||
/* not supported */
|
||||
}
|
||||
SemInfo->set[semid].pid[sops[i].sem_num] = getpid( );
|
||||
}
|
||||
|
||||
sem_post( &SemInfo->sem );
|
||||
|
||||
errno = errno1;
|
||||
return r;
|
||||
}
|
||||
54
src/backend/port/qnx/sem.h
Normal file
54
src/backend/port/qnx/sem.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* sem.h
|
||||
* System V Semaphore Emulation
|
||||
*
|
||||
* Copyright (c) 1999, repas AEG Automation GmbH
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/qnx/Attic/sem.h,v 1.1 1999/12/16 01:25:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef _SYS_SEM_H
|
||||
#define _SYS_SEM_H
|
||||
|
||||
#include <sys/ipc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Semctl Command Definitions.
|
||||
*/
|
||||
|
||||
#define GETNCNT 3 /* get semncnt */
|
||||
#define GETPID 4 /* get sempid */
|
||||
#define GETVAL 5 /* get semval */
|
||||
#define GETALL 6 /* get all semval's */
|
||||
#define GETZCNT 7 /* get semzcnt */
|
||||
#define SETVAL 8 /* set semval */
|
||||
#define SETALL 9 /* set all semval's */
|
||||
|
||||
/*
|
||||
* User semaphore template for semop system calls.
|
||||
*/
|
||||
|
||||
struct sembuf {
|
||||
ushort_t sem_num; /* semaphore # */
|
||||
short sem_op; /* semaphore operation */
|
||||
short sem_flg; /* operation flags */
|
||||
};
|
||||
|
||||
extern int semctl( int semid, int semnum, int cmd, /*...*/union semun arg );
|
||||
extern int semget( key_t key, int nsems, int semflg );
|
||||
extern int semop( int semid, struct sembuf *sops, size_t nsops );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_SEM_H */
|
||||
193
src/backend/port/qnx/shm.c
Normal file
193
src/backend/port/qnx/shm.c
Normal file
@@ -0,0 +1,193 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* shm.c
|
||||
* System V Shared Memory Emulation
|
||||
*
|
||||
* Copyright (c) 1999, repas AEG Automation GmbH
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/qnx/Attic/shm.c,v 1.1 1999/12/16 01:25:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
|
||||
#define MODE 0777
|
||||
|
||||
#define SHMMAX 1024
|
||||
|
||||
|
||||
struct shm_info {
|
||||
int shmid;
|
||||
key_t key;
|
||||
size_t size;
|
||||
void *addr;
|
||||
};
|
||||
|
||||
static struct shm_info *ShmInfo;
|
||||
|
||||
|
||||
static int shm_putinfo( struct shm_info *info );
|
||||
static int shm_updinfo( int i, struct shm_info *info );
|
||||
static int shm_getinfo( int shmid, struct shm_info *info );
|
||||
static int shm_getinfobyaddr( const void *addr, struct shm_info *info );
|
||||
|
||||
|
||||
static int shm_putinfo( struct shm_info *info )
|
||||
{
|
||||
int i;
|
||||
|
||||
if( ShmInfo == NULL ) {
|
||||
ShmInfo = calloc( SHMMAX, sizeof( struct shm_info ) );
|
||||
if( ShmInfo == NULL ) return -1;
|
||||
/* initialize ShmInfo */
|
||||
for( i = 0; i < SHMMAX; i++ ) {
|
||||
ShmInfo[i].shmid = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* search first free element */
|
||||
i = 0;
|
||||
while( i < SHMMAX && ShmInfo[i].shmid != -1 ) i++;
|
||||
if( i >= SHMMAX ) {
|
||||
errno = ENOSPC;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy( &ShmInfo[i], info, sizeof( struct shm_info ) );
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int shm_updinfo( int i, struct shm_info *info )
|
||||
{
|
||||
if( i >= SHMMAX ) return -1;
|
||||
if( ShmInfo == NULL ) return -1;
|
||||
|
||||
memcpy( &ShmInfo[i], info, sizeof( struct shm_info ) );
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int shm_getinfo( int shmid, struct shm_info *info )
|
||||
{
|
||||
int i;
|
||||
|
||||
if( ShmInfo == NULL ) return -1;
|
||||
|
||||
/* search element */
|
||||
i = 0;
|
||||
while( i < SHMMAX && ShmInfo[i].shmid != shmid ) i++;
|
||||
if( i >= SHMMAX ) return -1;
|
||||
|
||||
memcpy( info, &ShmInfo[i], sizeof( struct shm_info ) );
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int shm_getinfobyaddr( const void *addr, struct shm_info *info )
|
||||
{
|
||||
int i;
|
||||
|
||||
if( ShmInfo == ( struct shm_info * )-1 ) return -1;
|
||||
|
||||
/* search element */
|
||||
i = 0;
|
||||
while( i < SHMMAX && ShmInfo[i].addr != addr ) i++;
|
||||
if( i >= SHMMAX ) return -1;
|
||||
|
||||
memcpy( info, &ShmInfo[i], sizeof( struct shm_info ) );
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
void *shmat( int shmid, const void *shmaddr, int shmflg )
|
||||
{
|
||||
struct shm_info info;
|
||||
int i;
|
||||
|
||||
i = shm_getinfo( shmid, &info );
|
||||
if( i == -1 ) {
|
||||
errno = EACCES;
|
||||
return ( void * )-1;
|
||||
}
|
||||
|
||||
info.addr = mmap( ( void * )shmaddr, info.size,
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, shmid, 0 );
|
||||
if( info.addr == MAP_FAILED ) return info.addr;
|
||||
|
||||
if( shm_updinfo( i, &info ) == -1 ) {
|
||||
errno = EACCES;
|
||||
return ( void * )-1;
|
||||
}
|
||||
|
||||
return info.addr;
|
||||
}
|
||||
|
||||
int shmdt( const void *addr )
|
||||
{
|
||||
struct shm_info info;
|
||||
|
||||
if( shm_getinfobyaddr( addr, &info ) == -1 ) {
|
||||
errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return munmap( ( void * )addr, info.size );
|
||||
}
|
||||
|
||||
int shmctl( int shmid, int cmd, struct shmid_ds *buf )
|
||||
{
|
||||
struct shm_info info;
|
||||
char name[NAME_MAX+1];
|
||||
|
||||
/* IPC_RMID supported only */
|
||||
if( cmd != IPC_RMID ) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( shm_getinfo( shmid, &info ) == -1 ) {
|
||||
errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return shm_unlink( itoa( info.key, name, 16 ) );
|
||||
}
|
||||
|
||||
int shmget( key_t key, size_t size, int flags )
|
||||
{
|
||||
char name[NAME_MAX+1];
|
||||
int oflag = 0;
|
||||
struct shm_info info;
|
||||
|
||||
if( flags & IPC_CREAT ) oflag |= O_CREAT;
|
||||
if( flags & IPC_EXCL ) oflag |= O_EXCL;
|
||||
if( flags & SHM_R ) {
|
||||
if( flags & SHM_W ) oflag |= O_RDWR;
|
||||
else oflag |= O_RDONLY;
|
||||
}
|
||||
info.shmid = shm_open( itoa( key, name, 16 ), oflag, MODE );
|
||||
|
||||
/* store shared memory information */
|
||||
if( info.shmid != -1 ) {
|
||||
info.key = key;
|
||||
info.size = size;
|
||||
info.addr = NULL;
|
||||
if( shm_putinfo( &info ) == -1 ) return -1;
|
||||
}
|
||||
|
||||
/* The size may only be set once. Ignore errors. */
|
||||
ltrunc( info.shmid, size, SEEK_SET );
|
||||
|
||||
return info.shmid;
|
||||
}
|
||||
40
src/backend/port/qnx/shm.h
Normal file
40
src/backend/port/qnx/shm.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* shm.h
|
||||
* System V Shared Memory Emulation
|
||||
*
|
||||
* Copyright (c) 1999, repas AEG Automation GmbH
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/qnx/Attic/shm.h,v 1.1 1999/12/16 01:25:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef _SYS_SHM_H
|
||||
#define _SYS_SHM_H
|
||||
|
||||
#include <sys/ipc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SHM_R 0400 /* read permission */
|
||||
#define SHM_W 0200 /* write permission */
|
||||
|
||||
struct shmid_ds {
|
||||
int dummy;
|
||||
};
|
||||
|
||||
extern void *shmat( int shmid, const void *shmaddr, int shmflg );
|
||||
extern int shmdt( const void *addr );
|
||||
extern int shmctl( int shmid, int cmd, struct shmid_ds *buf );
|
||||
extern int shmget( key_t key, size_t size, int flags );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_SHM_H */
|
||||
31
src/backend/port/qnx/tstrint.c
Normal file
31
src/backend/port/qnx/tstrint.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* tstrint.c
|
||||
* rint() test
|
||||
*
|
||||
* Copyright (c) 1999, repas AEG Automation GmbH
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/qnx/Attic/tstrint.c,v 1.1 1999/12/16 01:25:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "os.h"
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
double x;
|
||||
|
||||
if( argc != 2 ) exit( 1 );
|
||||
|
||||
x = strtod( argv[1], NULL );
|
||||
printf( "rint( %f ) = %f\n", x, rint( x ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
135
src/backend/port/qnx/tstsem.c
Normal file
135
src/backend/port/qnx/tstsem.c
Normal file
@@ -0,0 +1,135 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* tstsem.c
|
||||
* Test of System V Semaphore Emulation
|
||||
*
|
||||
* Copyright (c) 1999, repas AEG Automation GmbH
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/qnx/Attic/tstsem.c,v 1.1 1999/12/16 01:25:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "postgres.h"
|
||||
#include "storage/ipc.h"
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sem.h>
|
||||
|
||||
|
||||
#define SEMMAX 1
|
||||
#define OPSMAX 1
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
int c, errflg = 0;
|
||||
char s[80];
|
||||
key_t key = IPC_PRIVATE;
|
||||
int nsems = SEMMAX;
|
||||
int semflg = 0;
|
||||
int unlink = 0;
|
||||
int semid, i;
|
||||
struct sembuf sops[OPSMAX];
|
||||
u_short array[SEMMAX];
|
||||
union semun arg;
|
||||
|
||||
optarg = NULL;
|
||||
while( !errflg && ( c = getopt( argc, argv, "k:n:cxu" ) ) != -1 ) {
|
||||
switch( c ) {
|
||||
case 'k': key = atoi( optarg ); break;
|
||||
case 'n': nsems = atoi( optarg ); break;
|
||||
case 'c': semflg |= IPC_CREAT; break;
|
||||
case 'x': semflg |= IPC_EXCL; break;
|
||||
case 'u': unlink = 1; break;
|
||||
default: errflg++;
|
||||
}
|
||||
}
|
||||
if( errflg ) {
|
||||
printf( "usage: tstsem [-k key] [-n nsems] [-cxu]\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
if( unlink ) {
|
||||
i = shm_unlink( "SysV_Sem_Info" );
|
||||
if( i == -1 ) perror( "shm_unlink" );
|
||||
exit( i );
|
||||
}
|
||||
|
||||
semid = semget( key, nsems, semflg );
|
||||
if( semid == -1 ) {
|
||||
perror( "semget" );
|
||||
exit( semid );
|
||||
}
|
||||
|
||||
do {
|
||||
printf( "(-)sem_op, (+)sem_op, (G)ETVAL, (S)ETVAL, GET(P)ID, GET(A)LL, SETA(L)L, e(x)it: " );
|
||||
scanf( "%s", s );
|
||||
switch( s[0] ) {
|
||||
case '-':
|
||||
case '+':
|
||||
sops[0].sem_num = 0;
|
||||
sops[0].sem_op = atoi( s );
|
||||
if( sops[0].sem_op == 0 ) sops[0].sem_op = s[0] == '+' ? +1 : -1;
|
||||
sops[0].sem_flg = 0;
|
||||
if( semop( semid, sops, 1 ) == -1 ) perror( "semop" );
|
||||
break;
|
||||
|
||||
case 'G':
|
||||
case 'g':
|
||||
i = semctl( semid, 0, GETVAL, arg );
|
||||
if( i == -1 ) perror( "semctl" );
|
||||
else printf( "semval = %d\n", i );
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
case 's':
|
||||
printf( "semval = " );
|
||||
scanf( "%d", &arg.val );
|
||||
if( semctl( semid, 0, SETVAL, arg ) == -1 ) perror( "semctl" );
|
||||
break;
|
||||
|
||||
case 'P':
|
||||
case 'p':
|
||||
i = semctl( semid, 0, GETPID, arg );
|
||||
if( i == -1 ) perror( "semctl" );
|
||||
else printf( "PID = %d\n", i );
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
case 'a':
|
||||
arg.array = array;
|
||||
i = semctl( semid, 0, GETALL, arg );
|
||||
if( i == -1 ) perror( "semctl" );
|
||||
else {
|
||||
for( i = 0; i < nsems; i++ ) {
|
||||
printf( "semval[%d] = %hu\n", i, arg.array[i] );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
case 'l':
|
||||
arg.array = array;
|
||||
for( i = 0; i < nsems; i++ ) {
|
||||
printf( "semval[%d] = ", i );
|
||||
scanf( "%hu", &arg.array[i] );
|
||||
}
|
||||
if( semctl( semid, 0, SETALL, arg ) == -1 )perror( "semctl" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
while( s[0] != 'x' );
|
||||
|
||||
if( semctl( semid, 0, IPC_RMID, arg ) == -1 ) {
|
||||
perror( "semctl" );
|
||||
exit( -1 );
|
||||
}
|
||||
|
||||
exit( 0 );
|
||||
}
|
||||
80
src/backend/port/qnx/tstshm.c
Normal file
80
src/backend/port/qnx/tstshm.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* tstshm.c
|
||||
* Test of System V Shared Memory Emulation
|
||||
*
|
||||
* Copyright (c) 1999, repas AEG Automation GmbH
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/qnx/Attic/tstshm.c,v 1.1 1999/12/16 01:25:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
int c, errflg = 0;
|
||||
char s[80];
|
||||
key_t key = 0x1000;
|
||||
size_t size = 256;
|
||||
int shmid = -1;
|
||||
caddr_t addr = NULL;
|
||||
|
||||
optarg = NULL;
|
||||
while( !errflg && ( c = getopt( argc, argv, "k:s:" ) ) != -1 ) {
|
||||
switch( c ) {
|
||||
case 'k': key = atoi( optarg ); break;
|
||||
case 's': size = atoi( optarg ); break;
|
||||
default: errflg++;
|
||||
}
|
||||
}
|
||||
if( errflg ) {
|
||||
printf( "usage: tstshm [-k key] [-s size]\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
do {
|
||||
printf( "shm(g)et, shm(a)t, shm(d)t, shm(c)tl, (w)rite, (r)ead, e(x)it: " );
|
||||
scanf( "%s", s );
|
||||
switch( s[0] ) {
|
||||
case 'g':
|
||||
shmid = shmget( key, size, IPC_CREAT | SHM_R | SHM_W );
|
||||
if( shmid == -1 ) perror( "shmget" );
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
addr = shmat( shmid, NULL, 0 );
|
||||
if( addr == ( void * )-1 ) perror( "shmat" );
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
if( shmdt( addr ) == -1 ) perror( "shmdt" );
|
||||
else addr = NULL;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
if( shmctl( shmid, IPC_RMID, NULL ) == -1 ) perror( "shmctl" );
|
||||
else shmid = -1;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
printf( "String to write: " );
|
||||
scanf( "%s", addr );
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
puts( addr );
|
||||
break;
|
||||
}
|
||||
}
|
||||
while( s[0] != 'x' );
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user