-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sb2] Allow redirecting syscalls (not all are supported yet). JB#59837
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* | ||
* SPDX-FileCopyrightText: 2023, Jolla Ltd. | ||
* SPDX-License-Identifier: LGPL-2.1 | ||
* | ||
* syscallgate -- syscall() GATE for the scratchbox2 preload library | ||
* | ||
* Copyright (C) 2023 Jolla Ltd. | ||
*/ | ||
|
||
#include <asm-generic/unistd.h> | ||
#include <sys/syscall.h> | ||
#include <unistd.h> | ||
|
||
#include "libsb2.h" | ||
#include "exported.h" | ||
|
||
#define FORWARD_TO_WRAPPER(sysc, ...) \ | ||
case SYS_ ## sysc: { \ | ||
ret = sysc(__VA_ARGS__); \ | ||
} break | ||
|
||
extern long syscall_gate(int *result_errno_ptr, | ||
long (*real_syscall_ptr)(long number, ...), | ||
const char *realfnname, long number, va_list args) | ||
{ | ||
long arg0 = va_arg(args, long); | ||
long arg1 = va_arg(args, long); | ||
long arg2 = va_arg(args, long); | ||
long arg3 = va_arg(args, long); | ||
long arg4 = va_arg(args, long); | ||
long arg5 = va_arg(args, long); | ||
|
||
long ret; | ||
switch (number) { | ||
FORWARD_TO_WRAPPER(execve, arg0, arg1, arg2); | ||
FORWARD_TO_WRAPPER(openat, arg0, arg1, arg2, arg3); | ||
// FORWARD_TO_WRAPPER(open_by_handle_at, ...) | ||
FORWARD_TO_WRAPPER(open, arg0, arg1, arg2); | ||
FORWARD_TO_WRAPPER(connect, arg0, arg1, arg2); | ||
FORWARD_TO_WRAPPER(sendto, arg0, arg1, arg2, arg3, arg4, arg5); | ||
FORWARD_TO_WRAPPER(sendmsg, arg0, arg1, arg2); | ||
FORWARD_TO_WRAPPER(recvfrom, arg0, arg1, arg2, arg3, (struct sockaddr *)arg4, arg5); | ||
FORWARD_TO_WRAPPER(recvmsg, arg0, arg1, arg2); | ||
FORWARD_TO_WRAPPER(accept, arg0, arg1, arg2); | ||
FORWARD_TO_WRAPPER(accept4, arg0, arg1, arg2, arg3); | ||
FORWARD_TO_WRAPPER(utimensat, arg0, arg1, arg2, arg3); | ||
FORWARD_TO_WRAPPER(utime, arg0, arg1); | ||
FORWARD_TO_WRAPPER(utimes, arg0, arg1); | ||
FORWARD_TO_WRAPPER(fcntl, arg0, arg1, arg2); | ||
FORWARD_TO_WRAPPER(futimesat, arg0, arg1, arg2); | ||
default: { | ||
ret = real_syscall_ptr(number, arg0, arg1, arg2, arg3, arg4, arg5); | ||
break; | ||
} | ||
}; | ||
if (result_errno_ptr) *result_errno_ptr = errno; | ||
return ret; | ||
} | ||
|