Skip to content

Commit 2919321

Browse files
committed
[syscall] Update readv & writev from comments in MR #207
Signed-off-by: Jean-Pierre Miceli <jean-pierre.miceli@heig-vd.ch>
1 parent 99a1429 commit 2919321

File tree

11 files changed

+44
-69
lines changed

11 files changed

+44
-69
lines changed

so3/arch/arm64/include/asm/syscall_number.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
#define SYSCALL_MUTEX_LOCK 60
7272
#define SYSCALL_MUTEX_UNLOCK 61
7373

74-
#define SYSCALL_READV 66
74+
#define SYSCALL_READV 65
7575
#define SYSCALL_WRITEV 66
7676

7777
#define SYSCALL_NANOSLEEP 70

so3/devices/serial/pl011.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static irq_return_t pl011_int(int irq, void *dummy)
119119

120120
#ifdef CONFIG_IPC_SIGNAL
121121
if (current()->pcb != NULL)
122-
__do_kill(current()->pcb->pid, SIGINT);
122+
sys_do_kill(current()->pcb->pid, SIGINT);
123123
#endif
124124
}
125125

so3/fs/elf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ uint8_t *elf_load_buffer(const char *filename)
3535
struct stat st;
3636

3737
/* open and read file */
38-
fd = __do_open(filename, O_RDONLY);
38+
fd = sys_do_open(filename, O_RDONLY);
3939

4040
if (fd < 0)
4141
return NULL;
4242

43-
if (__do_stat(filename, &st))
43+
if (sys_do_stat(filename, &st))
4444
return NULL;
4545

4646
if (!st.st_size)
@@ -52,9 +52,9 @@ uint8_t *elf_load_buffer(const char *filename)
5252
return NULL;
5353
}
5454

55-
__do_read(fd, buffer, st.st_size);
55+
sys_do_read(fd, buffer, st.st_size);
5656

57-
__do_close(fd);
57+
sys_do_close(fd);
5858

5959
return buffer;
6060
}

so3/fs/vfs.c

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -467,43 +467,7 @@ static int do_write(int fd, const void *buffer, int count)
467467

468468
SYSCALL_DEFINE3(read, int, fd, void *, buffer, int, count)
469469
{
470-
int gfd;
471-
int ret;
472-
473-
/* FIXME Max size of buffer */
474-
if (!buffer || count < 0) {
475-
LOG_ERROR("Invalid inputs\n");
476-
return -EINVAL;
477-
}
478-
479-
mutex_lock(&vfs_lock);
480-
481-
gfd = vfs_get_gfd(fd);
482-
483-
/* FIXME: As for now the do_read/do_open only
484-
* support regular file VFS_TYPE_FILE, VFS_TYPE_IO and pipes
485-
*/
486-
if (open_fds[gfd]->type == VFS_TYPE_DIR) {
487-
mutex_unlock(&vfs_lock);
488-
return -EISDIR;
489-
}
490-
491-
if (!vfs_is_valid_gfd(gfd)) {
492-
mutex_unlock(&vfs_lock);
493-
return -EINVAL;
494-
}
495-
496-
if (!open_fds[gfd]->fops->read) {
497-
LOG_ERROR("No fops read\n");
498-
mutex_unlock(&vfs_lock);
499-
return -EBADF;
500-
}
501-
502-
mutex_unlock(&vfs_lock);
503-
504-
ret = open_fds[gfd]->fops->read(gfd, buffer, count);
505-
506-
return ret;
470+
return do_read(fd, buffer, count);
507471
}
508472

509473
/**
@@ -705,7 +669,7 @@ SYSCALL_DEFINE2(dup2, int, oldfd, int, newfd)
705669
}
706670

707671
if (vfs_get_gfd(oldfd) != vfs_get_gfd(newfd))
708-
__do_close(newfd);
672+
sys_do_close(newfd);
709673

710674
vfs_link_fd(newfd, vfs_get_gfd(oldfd));
711675

@@ -885,17 +849,21 @@ SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec *, vec, unsigned l
885849

886850
for (i = 0; i < vlen; i++) {
887851
ret = do_write(fd, (const void *)vec[i].iov_base, vec[i].iov_len);
852+
ret = do_read(fd, vec[i].iov_base, vec[i].iov_len);
888853
if (ret < 0) {
889-
/* Error on the fist loop --> return error code */
890-
if (i == 0)
891-
total = -1;
854+
break;
855+
} else if ((ret >= 0) && (ret < vec[i].iov_len)) {
856+
total += ret;
892857
break;
893858
}
894859

895860
total += ret;
896861
}
897862

898-
return total;
863+
if (total == 0)
864+
return ret;
865+
else
866+
return total;
899867
}
900868

901869
SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec *, vec,
@@ -908,16 +876,19 @@ SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec *, vec,
908876
for (i = 0; i < vlen; i++) {
909877
ret = do_read(fd, vec[i].iov_base, vec[i].iov_len);
910878
if (ret < 0) {
911-
/* Error on the fist loop --> return error code */
912-
if (i == 0)
913-
total = -1;
879+
break;
880+
} else if ((ret >= 0) && (ret < vec[i].iov_len)) {
881+
total += ret;
914882
break;
915883
}
916884

917885
total += ret;
918886
}
919887

920-
return total;
888+
if (total == 0)
889+
return ret;
890+
else
891+
return total;
921892
}
922893

923894
static void vfs_gfd_init(void)

so3/include/net/lwip/sockets.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ typedef u32_t socklen_t;
123123
#error "IOV_MAX larger than supported by LwIP"
124124
#endif /* IOV_MAX */
125125

126-
// #if !defined(iovec)
127-
// struct iovec {
128-
// void *iov_base;
129-
// size_t iov_len;
130-
// };
131-
// #endif
126+
#if !defined(iovec)
127+
struct iovec {
128+
void *iov_base;
129+
size_t iov_len;
130+
};
131+
#endif
132132

133133
typedef int msg_iovlen_t;
134134

so3/include/syscall.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,20 @@
8484
* __sys_SYSCALL_NAME taking syscall_args_t as arguments allowing for
8585
* a common interface between all syscall to put them in an array.
8686
*
87-
* do_SYSCALL_NAME actual function with the syscall implementation with
87+
* sys_do_SYSCALL_NAME actual function with the syscall implementation with
8888
* arguments define like a normal function. That function is automatically
8989
* called by __sys_SYCALL_NAME with the correct argument number and cast.
9090
*/
9191
#define SYSCALL_DECLARE(name, ...) \
9292
long __sys_##name(syscall_args_t *args); \
93-
inline long __do_##name(__VA_ARGS__);
93+
inline long sys_do_##name(__VA_ARGS__);
9494

9595
#define SYSCALL_DEFINE0(name) \
9696
long __sys_##name(syscall_args_t *unused) \
9797
{ \
98-
return __do_##name(); \
98+
return sys_do_##name(); \
9999
} \
100-
inline long __do_##name(void)
100+
inline long sys_do_##name(void)
101101
#define SYSCALL_DEFINE1(...) __SYSCALL_DEFINEx(1, __VA_ARGS__)
102102
#define SYSCALL_DEFINE2(...) __SYSCALL_DEFINEx(2, __VA_ARGS__)
103103
#define SYSCALL_DEFINE3(...) __SYSCALL_DEFINEx(3, __VA_ARGS__)
@@ -108,9 +108,9 @@
108108
#define __SYSCALL_DEFINEx(x, name, ...) \
109109
long __sys_##name(syscall_args_t *args) \
110110
{ \
111-
return __do_##name(__MAP_ARGS(x, args->args, __VA_ARGS__)); \
111+
return sys_do_##name(__MAP_ARGS(x, args->args, __VA_ARGS__)); \
112112
} \
113-
inline long __do_##name(__MAP(x, __M_DECL, __VA_ARGS__))
113+
inline long sys_do_##name(__MAP(x, __M_DECL, __VA_ARGS__))
114114

115115
typedef struct {
116116
unsigned long args[6];

so3/include/vfs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ struct iovec {
108108
size_t iov_len;
109109
};
110110

111+
#define iovec iovec
112+
113+
111114
struct file_operations {
112115
int (*open)(int fd, const char *path);
113116
int (*close)(int fd);

so3/kernel/process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ SYSCALL_DEFINE1(exit, int, exit_status)
925925
* locking in the low layers. */
926926

927927
for (i = 0; i < FD_MAX; i++)
928-
__do_close(i);
928+
sys_do_close(i);
929929

930930
local_irq_disable();
931931

@@ -944,7 +944,7 @@ SYSCALL_DEFINE1(exit, int, exit_status)
944944
#ifdef CONFIG_IPC_SIGNAL
945945

946946
/* Send the SIGCHLD signal to the parent */
947-
__do_kill(pcb->parent->pid, SIGCHLD);
947+
sys_do_kill(pcb->parent->pid, SIGCHLD);
948948

949949
#endif /* CONFIG_IPC_SIGNAL */
950950

so3/kernel/syscalls.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = {
6060
[SYSCALL_IOCTL] = __sys_ioctl,
6161
[SYSCALL_FCNTL] = __sys_fcntl,
6262
[SYSCALL_LSEEK] = __sys_lseek,
63+
[SYSCALL_READV] = __sys_readv,
6364
[SYSCALL_WRITEV] = __sys_writev,
6465
#ifdef CONFIG_IPC_PIPE
6566
[SYSCALL_PIPE] = __sys_pipe,

so3/kernel/thread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void thread_exit(int *exit_status)
272272
remove_tcb_from_pcb(current());
273273

274274
#ifdef CONFIG_PROC_ENV
275-
__do_exit(0);
275+
sys_do_exit(0);
276276
#endif
277277

278278
} else {

0 commit comments

Comments
 (0)