target: Provide errno definitions and fallback for unimplemented syscalls.

This commit is contained in:
Gareth McMullin 2016-07-04 13:23:05 +12:00
parent 82cb6c8e83
commit 26fab877da
2 changed files with 61 additions and 1 deletions

View File

@ -36,6 +36,28 @@ int jtag_scan(const uint8_t *lrlens);
bool target_foreach(void (*cb)(int i, target *t, void *context), void *context);
void target_list_free(void);
enum target_errno {
TARGET_EPERM = 1,
TARGET_ENOENT = 2,
TARGET_EINTR = 4,
TARGET_EBADF = 9,
TARGET_EACCES = 13,
TARGET_EFAULT = 14,
TARGET_EBUSY = 16,
TARGET_EEXIST = 17,
TARGET_ENODEV = 19,
TARGET_ENOTDIR = 20,
TARGET_EISDIR = 21,
TARGET_EINVAL = 22,
TARGET_EMFILE = 24,
TARGET_ENFILE = 23,
TARGET_EFBIG = 27,
TARGET_ENOSPC = 28,
TARGET_ESPIPE = 29,
TARGET_EROFS = 30,
TARGET_ENAMETOOLONG = 36,
};
enum target_open_flags {
TARGET_O_RDONLY = 0,
TARGET_O_WRONLY = 1,
@ -79,7 +101,7 @@ struct target_controller {
int (*isatty)(struct target_controller *, int fd);
int (*system)(struct target_controller *,
target_addr cmd, unsigned cmd_len);
int errno_;
enum target_errno errno_;
bool interrupted;
};

View File

@ -427,62 +427,100 @@ void tc_printf(target *t, const char *fmt, ...)
int tc_open(target *t, target_addr path, unsigned plen,
enum target_open_flags flags, mode_t mode)
{
if (t->tc->open == NULL) {
t->tc->errno_ = TARGET_ENFILE;
return -1;
}
return t->tc->open(t->tc, path, plen, flags, mode);
}
int tc_close(target *t, int fd)
{
if (t->tc->close == NULL) {
t->tc->errno_ = TARGET_EBADF;
return -1;
}
return t->tc->close(t->tc, fd);
}
int tc_read(target *t, int fd, target_addr buf, unsigned int count)
{
if (t->tc->read == NULL)
return 0;
return t->tc->read(t->tc, fd, buf, count);
}
int tc_write(target *t, int fd, target_addr buf, unsigned int count)
{
if (t->tc->write == NULL)
return 0;
return t->tc->write(t->tc, fd, buf, count);
}
long tc_lseek(target *t, int fd, long offset, enum target_seek_flag flag)
{
if (t->tc->lseek == NULL)
return 0;
return t->tc->lseek(t->tc, fd, offset, flag);
}
int tc_rename(target *t, target_addr oldpath, unsigned oldlen,
target_addr newpath, unsigned newlen)
{
if (t->tc->rename == NULL) {
t->tc->errno_ = TARGET_ENOENT;
return -1;
}
return t->tc->rename(t->tc, oldpath, oldlen, newpath, newlen);
}
int tc_unlink(target *t, target_addr path, unsigned plen)
{
if (t->tc->unlink == NULL) {
t->tc->errno_ = TARGET_ENOENT;
return -1;
}
return t->tc->unlink(t->tc, path, plen);
}
int tc_stat(target *t, target_addr path, unsigned plen, target_addr buf)
{
if (t->tc->stat == NULL) {
t->tc->errno_ = TARGET_ENOENT;
return -1;
}
return t->tc->stat(t->tc, path, plen, buf);
}
int tc_fstat(target *t, int fd, target_addr buf)
{
if (t->tc->fstat == NULL) {
return 0;
}
return t->tc->fstat(t->tc, fd, buf);
}
int tc_gettimeofday(target *t, target_addr tv, target_addr tz)
{
if (t->tc->gettimeofday == NULL) {
return -1;
}
return t->tc->gettimeofday(t->tc, tv, tz);
}
int tc_isatty(target *t, int fd)
{
if (t->tc->isatty == NULL) {
return 1;
}
return t->tc->isatty(t->tc, fd);
}
int tc_system(target *t, target_addr cmd, unsigned cmdlen)
{
if (t->tc->system == NULL) {
return -1;
}
return t->tc->system(t->tc, cmd, cmdlen);
}