xref: /freebsd/share/examples/kld/syscall/test/call.c (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1380a989bSDoug Rabson /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3f0cfa1b1SPedro F. Giffuni  *
4380a989bSDoug Rabson  * Copyright (c) 1999 Assar Westerlund
5380a989bSDoug Rabson  * All rights reserved.
6380a989bSDoug Rabson  *
7380a989bSDoug Rabson  * Redistribution and use in source and binary forms, with or without
8380a989bSDoug Rabson  * modification, are permitted provided that the following conditions
9380a989bSDoug Rabson  * are met:
10380a989bSDoug Rabson  * 1. Redistributions of source code must retain the above copyright
11380a989bSDoug Rabson  *    notice, this list of conditions and the following disclaimer.
12380a989bSDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
13380a989bSDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
14380a989bSDoug Rabson  *    documentation and/or other materials provided with the distribution.
15380a989bSDoug Rabson  *
16380a989bSDoug Rabson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17380a989bSDoug Rabson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18380a989bSDoug Rabson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19380a989bSDoug Rabson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20380a989bSDoug Rabson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21380a989bSDoug Rabson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22380a989bSDoug Rabson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23380a989bSDoug Rabson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24380a989bSDoug Rabson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25380a989bSDoug Rabson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26380a989bSDoug Rabson  * SUCH DAMAGE.
27380a989bSDoug Rabson  */
28380a989bSDoug Rabson 
29*ab3e6234SMaxim Konovalov #include <sys/param.h>
30d632071eSWojciech A. Koszek #include <sys/module.h>
31d632071eSWojciech A. Koszek #include <sys/syscall.h>
32d632071eSWojciech A. Koszek 
339fd7a1b3SGleb Smirnoff #include <err.h>
34380a989bSDoug Rabson #include <stdio.h>
356f31cdcdSWojciech A. Koszek #include <stdlib.h>
366f31cdcdSWojciech A. Koszek #include <unistd.h>
37380a989bSDoug Rabson 
38380a989bSDoug Rabson int
main(int argc __unused,char ** argv __unused)39d632071eSWojciech A. Koszek main(int argc __unused, char **argv __unused)
40380a989bSDoug Rabson {
419fd7a1b3SGleb Smirnoff 	int modid, syscall_num;
42bcb321b3SDoug Rabson 	struct module_stat stat;
43380a989bSDoug Rabson 
44bcb321b3SDoug Rabson 	stat.version = sizeof(stat);
459fd7a1b3SGleb Smirnoff 	if ((modid = modfind("sys/syscall")) == -1)
469fd7a1b3SGleb Smirnoff 		err(1, "modfind");
479fd7a1b3SGleb Smirnoff 	if (modstat(modid, &stat) != 0)
4860bd6434SGleb Smirnoff 		err(1, "modstat");
49bcb321b3SDoug Rabson 	syscall_num = stat.data.intval;
50380a989bSDoug Rabson 	return syscall (syscall_num);
51380a989bSDoug Rabson }
52