You've already forked hexagonrpc
mirror of
https://github.com/linux-msm/hexagonrpc.git
synced 2026-02-25 13:13:52 -08:00
fastrpc: hexagonrpcd: hexagonfs: do not store file descriptor array
The file descriptor array maps file descriptors to their corresponding file descriptions, and is in static storage. Since there is range checking for file descriptors, there is still a benefit to having access to the file descriptor array. Accept the array as a parameter. In the future, this parameter can be removed in secondary functions if needed.
This commit is contained in:
@@ -47,6 +47,7 @@ struct apps_std_ctx {
|
||||
int rootfd;
|
||||
int adsp_avs_cfg_dirfd;
|
||||
int adsp_library_dirfd;
|
||||
struct hexagonfs_fd *fds[HEXAGONFS_MAX_FD];
|
||||
};
|
||||
|
||||
|
||||
@@ -81,10 +82,11 @@ static uint32_t apps_std_fclose(void *data,
|
||||
const struct fastrpc_io_buffer *inbufs,
|
||||
struct fastrpc_io_buffer *outbufs)
|
||||
{
|
||||
struct apps_std_ctx *ctx = data;
|
||||
const uint32_t *first_in = inbufs[0].p;
|
||||
int ret;
|
||||
|
||||
ret = hexagonfs_close(*first_in);
|
||||
ret = hexagonfs_close(ctx->fds, *first_in);
|
||||
if (ret) {
|
||||
fprintf(stderr, "Could not close: %s\n", strerror(-ret));
|
||||
return AEE_EFAILED;
|
||||
@@ -101,11 +103,13 @@ static uint32_t apps_std_fread(void *data,
|
||||
const struct fastrpc_io_buffer *inbufs,
|
||||
struct fastrpc_io_buffer *outbufs)
|
||||
{
|
||||
struct apps_std_ctx *ctx = data;
|
||||
const struct apps_std_fread_invoke *first_in = inbufs[0].p;
|
||||
struct apps_std_fread_return *first_out = outbufs[0].p;
|
||||
ssize_t ret;
|
||||
|
||||
ret = hexagonfs_read(first_in->fd, first_in->buf_size, outbufs[1].p);
|
||||
ret = hexagonfs_read(ctx->fds, first_in->fd,
|
||||
first_in->buf_size, outbufs[1].p);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Could not read file: %s\n", strerror(-ret));
|
||||
return AEE_EFAILED;
|
||||
@@ -127,6 +131,7 @@ static uint32_t apps_std_fseek(void *data,
|
||||
const struct fastrpc_io_buffer *inbufs,
|
||||
struct fastrpc_io_buffer *outbufs)
|
||||
{
|
||||
struct apps_std_ctx *ctx = data;
|
||||
struct {
|
||||
uint32_t fd;
|
||||
uint32_t pos;
|
||||
@@ -137,7 +142,7 @@ static uint32_t apps_std_fseek(void *data,
|
||||
|
||||
whence = apps_std_whence_table[first_in->whence];
|
||||
|
||||
ret = hexagonfs_lseek(first_in->fd, first_in->pos, whence);
|
||||
ret = hexagonfs_lseek(ctx->fds, first_in->fd, first_in->pos, whence);
|
||||
if (ret) {
|
||||
fprintf(stderr, "Could not seek stream: %s\n", strerror(-ret));
|
||||
return AEE_EFAILED;
|
||||
@@ -202,7 +207,7 @@ static uint32_t apps_std_fopen_with_env(void *data,
|
||||
return AEE_EFAILED;
|
||||
}
|
||||
|
||||
fd = hexagonfs_openat(ctx->rootfd, dirfd, inbufs[3].p);
|
||||
fd = hexagonfs_openat(ctx->fds, ctx->rootfd, dirfd, inbufs[3].p);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Could not open %s: %s\n",
|
||||
(const char *) inbufs[3].p,
|
||||
@@ -240,7 +245,7 @@ static uint32_t apps_std_opendir(void *data,
|
||||
return AEE_EFAILED;
|
||||
}
|
||||
|
||||
ret = hexagonfs_openat(ctx->rootfd, ctx->rootfd, inbufs[1].p);
|
||||
ret = hexagonfs_openat(ctx->fds, ctx->rootfd, ctx->rootfd, inbufs[1].p);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Could not open %s: %s\n",
|
||||
(const char *) inbufs[1].p,
|
||||
@@ -261,10 +266,11 @@ static uint32_t apps_std_closedir(void *data,
|
||||
const struct fastrpc_io_buffer *inbufs,
|
||||
struct fastrpc_io_buffer *outbufs)
|
||||
{
|
||||
struct apps_std_ctx *ctx = data;
|
||||
const uint64_t *dir = inbufs[0].p;
|
||||
int ret;
|
||||
|
||||
ret = hexagonfs_close(*dir);
|
||||
ret = hexagonfs_close(ctx->fds, *dir);
|
||||
if (ret)
|
||||
return AEE_EFAILED;
|
||||
|
||||
@@ -279,6 +285,7 @@ static uint32_t apps_std_readdir(void *data,
|
||||
const struct fastrpc_io_buffer *inbufs,
|
||||
struct fastrpc_io_buffer *outbufs)
|
||||
{
|
||||
struct apps_std_ctx *ctx = data;
|
||||
const uint64_t *dir = inbufs[0].p;
|
||||
struct {
|
||||
uint32_t inode;
|
||||
@@ -287,7 +294,7 @@ static uint32_t apps_std_readdir(void *data,
|
||||
} *first_out = outbufs[0].p;
|
||||
int ret;
|
||||
|
||||
ret = hexagonfs_readdir(*dir, 255, first_out->name);
|
||||
ret = hexagonfs_readdir(ctx->fds, *dir, 255, first_out->name);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Could not read from directory: %s\n",
|
||||
strerror(-ret));
|
||||
@@ -342,21 +349,21 @@ static uint32_t apps_std_stat(void *data,
|
||||
return AEE_EFAILED;
|
||||
}
|
||||
|
||||
fd = hexagonfs_openat(ctx->rootfd, ctx->rootfd, pathname);
|
||||
fd = hexagonfs_openat(ctx->fds, ctx->rootfd, ctx->rootfd, pathname);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Could not open %s: %s\n",
|
||||
pathname, strerror(-fd));
|
||||
goto err_free_pathname;
|
||||
}
|
||||
|
||||
ret = hexagonfs_fstat(fd, &stats);
|
||||
ret = hexagonfs_fstat(ctx->fds, fd, &stats);
|
||||
if (ret) {
|
||||
fprintf(stderr, "Could not stat %s: %s\n",
|
||||
pathname, strerror(-fd));
|
||||
goto err_free_pathname;
|
||||
}
|
||||
|
||||
hexagonfs_close(fd);
|
||||
hexagonfs_close(ctx->fds, fd);
|
||||
|
||||
#ifdef HEXAGONRPC_VERBOSE
|
||||
printf("stat(%s)\n", pathname);
|
||||
@@ -401,13 +408,17 @@ struct fastrpc_interface *fastrpc_apps_std_init(struct hexagonfs_dirent *root)
|
||||
|
||||
memcpy(iface, &apps_std_interface, sizeof(struct fastrpc_interface));
|
||||
|
||||
ctx->rootfd = hexagonfs_open_root(root);
|
||||
ctx->rootfd = hexagonfs_open_root(ctx->fds, root);
|
||||
|
||||
if (ctx->rootfd >= 0) {
|
||||
ctx->adsp_avs_cfg_dirfd = hexagonfs_openat(ctx->rootfd, ctx->rootfd,
|
||||
"/usr/lib/qcom/adsp/avs/");
|
||||
ctx->adsp_library_dirfd = hexagonfs_openat(ctx->rootfd, ctx->rootfd,
|
||||
"/usr/lib/qcom/adsp/");
|
||||
ctx->adsp_avs_cfg_dirfd = hexagonfs_openat(ctx->fds,
|
||||
ctx->rootfd,
|
||||
ctx->rootfd,
|
||||
"/usr/lib/qcom/adsp/avs/");
|
||||
ctx->adsp_library_dirfd = hexagonfs_openat(ctx->fds,
|
||||
ctx->rootfd,
|
||||
ctx->rootfd,
|
||||
"/usr/lib/qcom/adsp/");
|
||||
}
|
||||
|
||||
iface->data = ctx;
|
||||
@@ -422,6 +433,14 @@ err:
|
||||
|
||||
void fastrpc_apps_std_deinit(struct fastrpc_interface *iface)
|
||||
{
|
||||
struct apps_std_ctx *ctx = iface->data;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < HEXAGONFS_MAX_FD; i++) {
|
||||
if (ctx->fds[i] != NULL)
|
||||
hexagonfs_close(ctx->fds, i);
|
||||
}
|
||||
|
||||
free(iface->data);
|
||||
free(iface);
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
|
||||
#include "hexagonfs.h"
|
||||
|
||||
#define HEXAGONFS_MAX_FD 256
|
||||
|
||||
#define DEFINE_VIRT_DIR(dirname, files...) \
|
||||
(struct hexagonfs_dirent) { \
|
||||
.name = dirname, \
|
||||
@@ -132,8 +130,6 @@ struct hexagonfs_dirent hexagonfs_root_dir = DEFINE_VIRT_DIR("/",
|
||||
NULL,
|
||||
);
|
||||
|
||||
static struct hexagonfs_fd *fds[HEXAGONFS_MAX_FD];
|
||||
|
||||
static char *copy_segment_and_advance(const char *path,
|
||||
bool *trailing_slash,
|
||||
const char **next)
|
||||
@@ -183,7 +179,8 @@ static struct hexagonfs_fd *pop_dir(struct hexagonfs_fd *dir,
|
||||
return up;
|
||||
}
|
||||
|
||||
static int allocate_file_number(struct hexagonfs_fd *fd)
|
||||
static int allocate_file_number(struct hexagonfs_fd **fds,
|
||||
struct hexagonfs_fd *fd)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -212,7 +209,7 @@ static void destroy_file_descriptor(struct hexagonfs_fd *fd)
|
||||
}
|
||||
}
|
||||
|
||||
int hexagonfs_open_root(struct hexagonfs_dirent *root)
|
||||
int hexagonfs_open_root(struct hexagonfs_fd **fds, struct hexagonfs_dirent *root)
|
||||
{
|
||||
struct hexagonfs_fd *fd;
|
||||
int ret;
|
||||
@@ -229,7 +226,7 @@ int hexagonfs_open_root(struct hexagonfs_dirent *root)
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
ret = allocate_file_number(fd);
|
||||
ret = allocate_file_number(fds, fd);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
@@ -240,7 +237,7 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int hexagonfs_openat(int rootfd, int dirfd, const char *name)
|
||||
int hexagonfs_openat(struct hexagonfs_fd **fds, int rootfd, int dirfd, const char *name)
|
||||
{
|
||||
struct hexagonfs_fd *fd;
|
||||
const char *curr = name;
|
||||
@@ -280,7 +277,7 @@ int hexagonfs_openat(int rootfd, int dirfd, const char *name)
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
ret = allocate_file_number(fd);
|
||||
ret = allocate_file_number(fds, fd);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
@@ -292,7 +289,7 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int hexagonfs_close(int fileno)
|
||||
int hexagonfs_close(struct hexagonfs_fd **fds, int fileno)
|
||||
{
|
||||
struct hexagonfs_fd *fd;
|
||||
|
||||
@@ -311,7 +308,7 @@ int hexagonfs_close(int fileno)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hexagonfs_lseek(int fileno, off_t off, int whence)
|
||||
int hexagonfs_lseek(struct hexagonfs_fd **fds, int fileno, off_t off, int whence)
|
||||
{
|
||||
struct hexagonfs_fd *fd;
|
||||
|
||||
@@ -328,7 +325,7 @@ int hexagonfs_lseek(int fileno, off_t off, int whence)
|
||||
return fd->ops->seek(fd, off, whence);
|
||||
}
|
||||
|
||||
ssize_t hexagonfs_read(int fileno, size_t size, void *ptr)
|
||||
ssize_t hexagonfs_read(struct hexagonfs_fd **fds, int fileno, size_t size, void *ptr)
|
||||
{
|
||||
struct hexagonfs_fd *fd;
|
||||
|
||||
@@ -345,7 +342,7 @@ ssize_t hexagonfs_read(int fileno, size_t size, void *ptr)
|
||||
return fd->ops->read(fd, size, ptr);
|
||||
}
|
||||
|
||||
int hexagonfs_readdir(int fileno, size_t ent_size, char *ent)
|
||||
int hexagonfs_readdir(struct hexagonfs_fd **fds, int fileno, size_t ent_size, char *ent)
|
||||
{
|
||||
struct hexagonfs_fd *fd;
|
||||
|
||||
@@ -362,7 +359,7 @@ int hexagonfs_readdir(int fileno, size_t ent_size, char *ent)
|
||||
return fd->ops->readdir(fd, ent_size, ent);
|
||||
}
|
||||
|
||||
int hexagonfs_fstat(int fileno, struct stat *stats)
|
||||
int hexagonfs_fstat(struct hexagonfs_fd **fds, int fileno, struct stat *stats)
|
||||
{
|
||||
struct hexagonfs_fd *fd;
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define HEXAGONFS_MAX_FD 256
|
||||
|
||||
struct hexagonfs_fd;
|
||||
|
||||
struct hexagonfs_file_ops {
|
||||
@@ -68,13 +70,13 @@ extern struct hexagonfs_file_ops hexagonfs_virt_dir_ops;
|
||||
|
||||
extern struct hexagonfs_dirent hexagonfs_root_dir;
|
||||
|
||||
int hexagonfs_open_root(struct hexagonfs_dirent *root);
|
||||
int hexagonfs_openat(int rootfd, int dirfd, const char *name);
|
||||
int hexagonfs_close(int fileno);
|
||||
int hexagonfs_open_root(struct hexagonfs_fd **fds, struct hexagonfs_dirent *root);
|
||||
int hexagonfs_openat(struct hexagonfs_fd **fds, int rootfd, int dirfd, const char *name);
|
||||
int hexagonfs_close(struct hexagonfs_fd **fds, int fileno);
|
||||
|
||||
int hexagonfs_fstat(int fileno, struct stat *stats);
|
||||
int hexagonfs_lseek(int fileno, off_t pos, int whence);
|
||||
int hexagonfs_readdir(int fileno, size_t size, char *name);
|
||||
ssize_t hexagonfs_read(int fileno, size_t size, void *ptr);
|
||||
int hexagonfs_fstat(struct hexagonfs_fd **fds, int fileno, struct stat *stats);
|
||||
int hexagonfs_lseek(struct hexagonfs_fd **fds, int fileno, off_t pos, int whence);
|
||||
int hexagonfs_readdir(struct hexagonfs_fd **fds, int fileno, size_t size, char *name);
|
||||
ssize_t hexagonfs_read(struct hexagonfs_fd **fds, int fileno, size_t size, void *ptr);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user