blob: b0ace74ea7f36a39d7c2fa6a75f39bf9d88434a7 [file] [log] [blame]
Eric Andersena2a978a2001-04-05 06:08:14 +00001/* vi: set sw=4 ts=4: */
2/*
3 * some system calls possibly missing from libc
4 *
Eric Andersenbdfd0d72001-10-24 05:00:29 +00005 * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
6 * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
Eric Andersena2a978a2001-04-05 06:08:14 +00007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#include <stdio.h>
25#include <errno.h>
26#include <unistd.h>
27/* Kernel headers before 2.1.mumble need this on the Alpha to get
28 _syscall* defined. */
29#define __LIBRARY__
30#include <sys/syscall.h>
Eric Andersen806c74f2002-03-12 00:35:40 +000031#if __GNU_LIBRARY__ < 5
32/* This is needed for libc5 */
Eric Andersena2a978a2001-04-05 06:08:14 +000033#include <asm/unistd.h>
Manuel Novoa III a2949aa2001-06-29 18:59:32 +000034#endif
Eric Andersena2a978a2001-04-05 06:08:14 +000035#include "libbb.h"
36
Eric Andersenacc77572001-04-05 06:24:28 +000037
Eric Andersen9260fc52001-10-24 00:44:11 +000038#if __GNU_LIBRARY__ < 5 || ((__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 1))
Eric Andersena2a978a2001-04-05 06:08:14 +000039/* These syscalls are not included as part of libc5 */
Eric Andersen82ab3d72003-05-26 18:48:56 +000040int delete_module(const char *name)
41{
42 return(syscall(__NR_delete_module, name));
43}
44int get_kernel_syms(__ptr_t ks)
45{
46 return(syscall(__NR_get_kernel_syms, ks));
47}
Eric Andersena2a978a2001-04-05 06:08:14 +000048
Eric Andersen64c8b172001-04-05 07:33:10 +000049/* This may have 5 arguments (for old 2.0 kernels) or 2 arguments
50 * (for 2.2 and 2.4 kernels). Use the greatest common denominator,
51 * and let the kernel cope with whatever it gets. Its good at that. */
Eric Andersen82ab3d72003-05-26 18:48:56 +000052int init_module(void *first, void *second, void *third, void *fourth, void *fifth)
53{
54 return(syscall(__NR_init_module, first, second, third, fourth, fifth));
55}
Eric Andersen64c8b172001-04-05 07:33:10 +000056
Eric Andersen82ab3d72003-05-26 18:48:56 +000057int query_module(const char *name, int which, void *buf, size_t bufsize, size_t *ret)
58{
Eric Andersena2a978a2001-04-05 06:08:14 +000059#ifndef __NR_query_module
60#warning This kernel does not support the query_module syscall
61#warning -> The query_module system call is being stubbed out...
Eric Andersen82ab3d72003-05-26 18:48:56 +000062 bb_error_msg("\n\nTo make this application work, you will need to recompile\n"
63 "BusyBox with a kernel supporting the query_module system call.\n");
64 errno=ENOSYS;
65 return -1;
Eric Andersena2a978a2001-04-05 06:08:14 +000066#else
Eric Andersen82ab3d72003-05-26 18:48:56 +000067 return(syscall(__NR_query_module, name, which, buf, bufsize, ret));
Eric Andersena2a978a2001-04-05 06:08:14 +000068#endif
Eric Andersen82ab3d72003-05-26 18:48:56 +000069}
Eric Andersena2a978a2001-04-05 06:08:14 +000070
71/* Jump through hoops to fixup error return codes */
Eric Andersena2a978a2001-04-05 06:08:14 +000072unsigned long create_module(const char *name, size_t size)
73{
Eric Andersen82ab3d72003-05-26 18:48:56 +000074 long ret = syscall(__NR_create_module, name, size);
Eric Andersena2a978a2001-04-05 06:08:14 +000075
Eric Andersen82ab3d72003-05-26 18:48:56 +000076 if (ret == -1 && errno > 125) {
77 ret = -errno;
78 errno = 0;
79 }
80 return ret;
Eric Andersena2a978a2001-04-05 06:08:14 +000081}
82
83#endif /* __GNU_LIBRARY__ < 5 */
84
85
86/* END CODE */
87/*
88Local Variables:
89c-file-style: "linux"
90c-basic-offset: 4
91tab-width: 4
92End:
93*/
94