network: Ensure matching syscall prototypes

Ensure that kernel and user space system call protoypes are identical.
This commit is contained in:
Sebastian Huber
2016-04-22 09:14:34 +02:00
parent c6cb9bad75
commit 1641088178
6 changed files with 117 additions and 26 deletions

View File

@@ -255,6 +255,7 @@ lib_a_CPPFLAGS = $(AM_CPPFLAGS) $(lib_CPPFLAGS) -D__BSD_VISIBLE
lib_a_SOURCES = lib/getprotoby.c lib/rtems_bsdnet_ntp.c lib/ftpfs.c \
lib/syslog.c lib/tftpDriver.c
lib_a_SOURCES += rtems/rtems_syscall_api.c
endif
EXTRA_DIST += $(UNUSED_FILES)

View File

@@ -94,7 +94,8 @@ static struct sx sysctllock;
#define SYSCTL_INIT() sx_init(&sysctllock, "sysctl lock")
#endif
static int sysctl_root(SYSCTL_HANDLER_ARGS);
static int sysctl_root(struct sysctl_oid *oidp, const void *arg1,
intptr_t arg2, struct sysctl_req *req);
struct sysctl_oid_list sysctl__children; /* root list */
@@ -1094,7 +1095,7 @@ sysctl_wire_old_buffer(struct sysctl_req *req, size_t len)
}
int
sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid,
sysctl_find_oid(const int *name, u_int namelen, struct sysctl_oid **noid,
int *nindx, struct sysctl_req *req)
{
struct sysctl_oid *oid;
@@ -1138,7 +1139,8 @@ sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid,
*/
static int
sysctl_root(SYSCTL_HANDLER_ARGS)
sysctl_root(struct sysctl_oid *oidp, const void *arg1, intptr_t arg2,
struct sysctl_req *req)
{
struct sysctl_oid *oid;
int error, indx;
@@ -1197,6 +1199,7 @@ sysctl_root(SYSCTL_HANDLER_ARGS)
return (error);
}
#ifndef __rtems__
#ifndef _SYS_SYSPROTO_H_
struct sysctl_args {
int *name;
@@ -1240,14 +1243,15 @@ done2:
mtx_unlock(&Giant);
return (error);
}
#endif /* __rtems__ */
/*
* This is used from various compatibility syscalls too. That's why name
* must be in kernel space.
*/
int
userland_sysctl(struct thread *td, int *name, u_int namelen, void *old,
size_t *oldlenp, int inkernel, void *new, size_t newlen, size_t *retval)
userland_sysctl(struct thread *td, const int *name, u_int namelen, void *old,
size_t *oldlenp, int inkernel, const void *new, size_t newlen, size_t *retval)
{
int error = 0;
struct sysctl_req req, req2;

View File

@@ -28,11 +28,7 @@
#include <net/if.h>
#include <net/route.h>
/*
* Since we are "in the kernel", these do not get prototyped in sys/socket.h
*/
ssize_t send(int, const void *, size_t, int);
ssize_t recv(int, void *, size_t, int);
#include "rtems_syscall.h"
/*
* Hooks to RTEMS I/O system
@@ -145,7 +141,7 @@ socket (int domain, int type, int protocol)
}
int
bind (int s, struct sockaddr *name, int namelen)
bind (int s, const struct sockaddr *name, socklen_t namelen)
{
int error;
int ret = -1;
@@ -172,7 +168,7 @@ bind (int s, struct sockaddr *name, int namelen)
}
int
connect (int s, struct sockaddr *name, int namelen)
connect (int s, const struct sockaddr *name, socklen_t namelen)
{
int error;
int ret = -1;
@@ -244,7 +240,7 @@ listen (int s, int backlog)
}
int
accept (int s, struct sockaddr *name, int *namelen)
accept (int s, struct sockaddr *name, socklen_t *namelen)
{
int fd;
struct socket *head, *so;
@@ -412,7 +408,7 @@ sendmsg (int s, const struct msghdr *mp, int flags)
* Send a message to a host
*/
ssize_t
sendto (int s, const void *buf, size_t buflen, int flags, const struct sockaddr *to, int tolen)
sendto (int s, const void *buf, size_t buflen, int flags, const struct sockaddr *to, socklen_t tolen)
{
struct msghdr msg;
struct iovec iov;
@@ -526,7 +522,7 @@ recvmsg (int s, struct msghdr *mp, int flags)
* Receive a message from a host
*/
ssize_t
recvfrom (int s, void *buf, size_t buflen, int flags, const struct sockaddr *from, int *fromlen)
recvfrom (int s, void *buf, size_t buflen, int flags, struct sockaddr *from, socklen_t *fromlen)
{
struct msghdr msg;
struct iovec iov;
@@ -550,7 +546,7 @@ recvfrom (int s, void *buf, size_t buflen, int flags, const struct sockaddr *fro
}
int
setsockopt (int s, int level, int name, const void *val, int len)
setsockopt (int s, int level, int name, const void *val, socklen_t len)
{
struct socket *so;
struct mbuf *m = NULL;
@@ -585,7 +581,7 @@ setsockopt (int s, int level, int name, const void *val, int len)
}
int
getsockopt (int s, int level, int name, void *aval, int *avalsize)
getsockopt (int s, int level, int name, void *aval, socklen_t *avalsize)
{
struct socket *so;
struct mbuf *m = NULL, *m0;
@@ -628,7 +624,7 @@ getsockopt (int s, int level, int name, void *aval, int *avalsize)
}
static int
getpeersockname (int s, struct sockaddr *name, int *namelen, int pflag)
getpeersockname (int s, struct sockaddr *name, socklen_t *namelen, int pflag)
{
struct socket *so;
struct mbuf *m;
@@ -667,19 +663,19 @@ getpeersockname (int s, struct sockaddr *name, int *namelen, int pflag)
}
int
getpeername (int s, struct sockaddr *name, int *namelen)
getpeername (int s, struct sockaddr *name, socklen_t *namelen)
{
return getpeersockname (s, name, namelen, 1);
}
int
getsockname (int s, struct sockaddr *name, int *namelen)
getsockname (int s, struct sockaddr *name, socklen_t *namelen)
{
return getpeersockname (s, name, namelen, 0);
}
int
sysctl(int *name, u_int namelen, void *oldp,
size_t *oldlenp, void *newp, size_t newlen)
sysctl(const int *name, u_int namelen, void *oldp,
size_t *oldlenp, const void *newp, size_t newlen)
{
int error;
size_t j;

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2016 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems@embedded-brains.de>
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifndef _LIBNETWORKING_RTEMS_SYSCALL_H_
#define _LIBNETWORKING_RTEMS_SYSCALL_H_
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/time.h>
__BEGIN_DECLS
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
int accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
int bind(int, const struct sockaddr *, socklen_t);
int connect(int, const struct sockaddr *, socklen_t);
int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
int listen(int, int);
ssize_t recv(int, void *, size_t, int);
ssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict);
ssize_t recvmsg(int, struct msghdr *, int);
ssize_t send(int, const void *, size_t, int);
ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
ssize_t sendmsg(int, const struct msghdr *, int);
int setsockopt(int, int, int, const void *, socklen_t);
int shutdown(int, int);
int socket(int, int, int);
int socketpair(int, int, int, int *);
int sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
int sysctlbyname(const char *, void *, size_t *, const void *, size_t);
int sysctlnametomib(const char *, int *, size_t *);
__END_DECLS
#endif /* _LIBNETWORKING_RTEMS_SYSCALL_H_ */

View File

@@ -0,0 +1,20 @@
/*
* Copyright (c) 2016 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems@embedded-brains.de>
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
/* Ensure that kernel and user space system call protoypes are identical */
#include "rtems_syscall.h"

View File

@@ -132,7 +132,7 @@ struct sysctl_req {
size_t oldlen;
size_t oldidx;
int (*oldfunc)(struct sysctl_req *, const void *, size_t);
void *newptr;
const void *newptr;
size_t newlen;
size_t newidx;
int (*newfunc)(struct sysctl_req *, void *, size_t);
@@ -622,10 +622,10 @@ int kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old,
int kernel_sysctlbyname(struct thread *td, char *name,
void *old, size_t *oldlenp, void *new, size_t newlen,
size_t *retval);
int userland_sysctl(struct thread *td, int *name, u_int namelen, void *old,
size_t *oldlenp, int inkernel, void *new, size_t newlen,
int userland_sysctl(struct thread *td, const int *name, u_int namelen, void *old,
size_t *oldlenp, int inkernel, const void *new, size_t newlen,
size_t *retval);
int sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid,
int sysctl_find_oid(const int *name, u_int namelen, struct sysctl_oid **noid,
int *nindx, struct sysctl_req *req);
int sysctl_wire_old_buffer(struct sysctl_req *req, size_t len);