summaryrefslogtreecommitdiffhomepage
path: root/tests/tools/zos-shim/zos_shim.h
blob: 54f5fe99007485f3e5544d04a9ba4efa4ab3bc53 (plain)
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
/*
 * zos_shim.h - just enough of the z/OS C library's declarations to
 * compile src/sys_zos.c on Linux with -fsyntax-only (make zos-lint).
 *
 * This catches typos, type errors, missing includes and warnings in the
 * z/OS layer before it reaches a z/OS compiler.  It proves nothing about
 * behaviour, and the declarations are transcribed from the z/OS headers
 * (fcntl.h is in the project docs; the rest from the XL C/C++ Runtime
 * Library Reference), so a mismatch here is a mismatch to fix here.
 * Forced in with -include, after the real system headers.
 */
#ifndef ZOS_SHIM_H
#define ZOS_SHIM_H
/* Tell the sources they are being checked, not built: this is 64-bit
 * Linux, and sys_zos.c asserts the real build is 31-bit. */
#define ZASH_ZOS_SHIM 1
#include <fcntl.h>
#include <signal.h>
#include <spawn.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <unistd.h>

#define __MVS__ 1

/* <fcntl.h> with __FX (_OPEN_SYS_FILE_EXT) */
#define F_SETTAG 12
#define F_CONTROL_CVT 13
struct f_cnvrt {
    int cvtcmd;
    short pccsid;
    short fccsid;
};
#define SETCVTOFF 0
#define SETCVTON 1
#define SETAUTOCVTON 2
#define QUERYCVT 3
#define SETCVTALL 4
#define SETAUTOCVTALL 5

/* <sys/stat.h>: the tag lives in struct stat; Linux's has none, so the
 * shim's stat()/fstat() take a z/OS-shaped structure. */
typedef unsigned short __ccsid_t;
struct file_tag {
    unsigned short ft_ccsid;
    unsigned int ft_txtflag : 1;
    unsigned int ft_deferred : 1;
    unsigned int ft_rsvflags : 14;
};
struct zos_stat {
    mode_t st_mode;
    off_t st_size;
    struct file_tag st_tag;
};
/* "stat" names both the structure and the function, as on z/OS. */
int zos_stat(const char *, struct zos_stat *);
int zos_fstat(int, struct zos_stat *);
#define stat zos_stat
#define fstat zos_fstat

/* __chattr() and attrib_t (<sys/stat.h>, _OPEN_SYS_FILE_EXT) */
typedef struct {
    unsigned int att_filetagchg : 1;
    struct file_tag att_filetag;
} attrib_t;
int __chattr(char *, attrib_t *, int);

/* <_Ccsid.h> */
#define _CSNAME_LEN_MAX 16
__ccsid_t __toCcsid(char *);
int __toCSName(__ccsid_t, char *);

/* <_Nascii.h> */
#define _CVTSTATE_OFF 0
#define _CVTSTATE_ON 1
#define _CVTSTATE_QUERY 4
int __ae_autoconvert_state(int);

/* <stdlib.h>: storage below 2 GB, i.e. reachable with 31 bits */
void *__malloc31(size_t);
void __free31(void *);

/* <sys/utsname.h> */
int __osname(struct utsname *);

/* <stdlib.h> fetch() */
typedef int (*__fetch_t)(void);
__fetch_t fetch(const char *);
int release(void (*)(void));

/* <signal.h>: LE's abend signal.  The value is from EDC4H023. */
#ifndef SIGABND
#define SIGABND 18
#endif

/* <spawn.h> (z/OS spawn(), not posix_spawn) */
struct inheritance {
    short flags;
    pid_t pgroup;
    sigset_t sigmask;
    sigset_t sigdefault;
    int ctlttyfd;
};
#define SPAWN_SETGROUP 0x01
#define SPAWN_SETSIGMASK 0x02
#define SPAWN_SETSIGDEF 0x04
#define SPAWN_SETTCPGRP 0x08
#define SPAWN_NEWPGROUP (-1)
#define SPAWN_FDCLOSED (-1)
pid_t spawn(const char *, const int, const int[], const struct inheritance *,
            const char *[], const char *[]);

/* #pragma linkage is ignored by clang on Linux */
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#endif