summaryrefslogtreecommitdiff
path: root/src/_syscall.h
blob: fb100151eb683c9c21f78b1fe20ee5868004f0cd (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
#ifndef ___SYSCALL_H__
#define ___SYSCALL_H__

#include <errno.h>
#ifndef ENOSYS
#include "errno/ENOSYS.c"
#endif

#include <nonstd/internal.h>

#define SYSCALL(_name, _type, _err, _a1, _a2, _a3, _a4, _a5, _a6) \
	static int _scno = -2; \
	if (_scno == -2) { \
		_scno = __syscall_lookup(_name); \
	} \
	long _ret = __syscall(_scno, _a1, _a2, _a3, _a4, _a5, _a6); \
	if (_ret < 0) { \
		errno = -_ret; \
		return _err; \
	} \
	return (_type)_ret

#define SYSCALL_NUMBER(_var, _name, _notfound) \
	static long _var = -2; \
	do { \
		if (_var == -2) { \
			(_var) = __syscall_lookup(_name); \
		} \
		if (_var == -1) { \
			errno = ENOSYS; \
			return (_notfound); } \
	} while (0)

long __syscall(long __number, ...);
long __syscall_lookup(const char *name);

#endif