Skip to content

Commit fb05db6

Browse files
committed
Add template for futex syscall
Signed-off-by: Jean-Pierre Miceli <jean-pierre.miceli@heig-vd.ch>
1 parent baaab35 commit fb05db6

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed

so3/include/futex.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2014-2018 Daniel Rossier <daniel.rossier@heig-vd.ch>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program; if not, write to the Free Software
15+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
*
17+
*/
18+
19+
#ifndef FUTEX_H
20+
#define FUTEX_H
21+
22+
#include <timer.h>
23+
#include <syscall.h>
24+
25+
/* Commands */
26+
#define FUTEX_WAIT 0
27+
#define FUTEX_WAKE 1
28+
#define FUTEX_FD 2
29+
#define FUTEX_REQUEUE 3
30+
#define FUTEX_CMP_REQUEUE 4
31+
#define FUTEX_WAKE_OP 5
32+
#define FUTEX_LOCK_PI 6
33+
#define FUTEX_UNLOCK_PI 7
34+
#define FUTEX_TRYLOCK_PI 8
35+
#define FUTEX_WAIT_BITSET 9
36+
37+
#define FUTEX_PRIVATE_FLAG 128
38+
#define FUTEX_CLOCK_REALTIME 256
39+
#define FUTEX_CMD_MASK ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME)
40+
41+
42+
SYSCALL_DECLARE(futex, u32 *uaddr, int op, u32 val, const struct timespec * utime,
43+
u32 *uaddr2, u32 val3)
44+
45+
#endif /* FUTEX_H */

so3/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ obj-y += main.o \
88
thread.o \
99
schedule.o \
1010
mutex.o \
11+
futex.o \
1112
spinlock.o \
1213
syscalls.o \
1314
softirq.o \

so3/kernel/futex.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (C) 2025 Jean-Pierre Miceli <jean-pierre.miceli@heig-vd.ch>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program; if not, write to the Free Software
15+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
*
17+
*/
18+
19+
#include <errno.h>
20+
#include <futex.h>
21+
22+
SYSCALL_DEFINE6(futex, u32 *, uaddr, int, op, u32, val,
23+
const struct timespec *, utime,
24+
u32 *, uaddr2, u32, val3)
25+
{
26+
27+
// unsigned int flags = futex_to_flags(op);
28+
int cmd = op & FUTEX_CMD_MASK;
29+
30+
switch (cmd) {
31+
case FUTEX_WAIT:
32+
break;
33+
case FUTEX_WAKE:
34+
break;
35+
default:
36+
printk("Futex cmd '%d' not supported !\n");
37+
return -EINVAL;
38+
}
39+
40+
return -ENOSYS;
41+
}
42+
43+
44+

so3/kernel/syscalls.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <signal.h>
2929
#include <timer.h>
3030
#include <net.h>
31+
#include <futex.h>
3132
#include <syscall.h>
3233

3334
extern void __get_syscall_args_ext(uint32_t *syscall_no);

so3/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ newfstatat
3737
mmap
3838
mmap2
3939
nanosleep
40+
futex
4041
pipe IPC_PIPE
4142
pipe2 IPC_PIPE
4243
rt_sigaction IPC_SIGNAL

0 commit comments

Comments
 (0)