annotate test/syscall/syscall.c @ 663:127b569978cc default tip

- another tweak handling clang trying to be too smart (see last commit)
author Tassilo Philipp
date Sun, 24 Mar 2024 13:52:44 +0100
parents 6a34dcb2bbd7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 Package: dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Library: test
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 File: test/syscall/syscall.c
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 License:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
617
6a34dcb2bbd7 - test/syscalls: build fix for minix
Tassilo Philipp
parents: 588
diff changeset
9 Copyright (c) 2011-2022 Daniel Adler <dadler@uni-goettingen.de>,
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26 #include "dyncall.h"
617
6a34dcb2bbd7 - test/syscalls: build fix for minix
Tassilo Philipp
parents: 588
diff changeset
27 #if defined(DC__OS_Minix)
6a34dcb2bbd7 - test/syscalls: build fix for minix
Tassilo Philipp
parents: 588
diff changeset
28 # include <minix/callnr.h>
6a34dcb2bbd7 - test/syscalls: build fix for minix
Tassilo Philipp
parents: 588
diff changeset
29 # define SYS_write WRITE
6a34dcb2bbd7 - test/syscalls: build fix for minix
Tassilo Philipp
parents: 588
diff changeset
30 #elif defined(DC_UNIX) && !defined(DC__OS_BeOS)
6a34dcb2bbd7 - test/syscalls: build fix for minix
Tassilo Philipp
parents: 588
diff changeset
31 # include <sys/syscall.h>
6a34dcb2bbd7 - test/syscalls: build fix for minix
Tassilo Philipp
parents: 588
diff changeset
32 #endif
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 DCCallVM* callvm;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36 int syscall_write(int fd, char* buf, size_t len)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38 dcReset(callvm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39 dcArgInt(callvm, fd);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 dcArgPointer(callvm, buf);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41 dcArgInt(callvm, len);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 return dcCallInt(callvm, (DCpointer)(ptrdiff_t)SYS_write);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45 int main(int argc, char* argv[])
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 {
410
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
47 int r = -1;
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
48 callvm = dcNewCallVM(4096);
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
49 dcMode(callvm, DC_CALL_SYS_DEFAULT);
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
50
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
51 if(dcGetError(callvm) == DC_ERROR_NONE)
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
52 {
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
53 r = syscall_write(1/*stdout*/, "result: syscall: ", 17);
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
54 r += syscall_write(1/*stdout*/, r==17?"1":"0", 2);
588
dfc2e6ee8782 - more robust endian detection, on some platforms inclusion of endian.h led to assuming wrong endianness (subtle if inclusion was in
Tassilo Philipp
parents: 410
diff changeset
55 r += syscall_write(1/*stdout*/, "\n", 2);
410
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
56 }
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
57 return !(r == 19);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59