diff --git a/th1520/hardware/camera/BUILD.gn b/th1520/hardware/camera/BUILD.gn index 979ebd2d288bb4bebfb0d274ae66a55642a66564..b789f2b52e019466b19c77a9598e004de65be33c 100644 --- a/th1520/hardware/camera/BUILD.gn +++ b/th1520/hardware/camera/BUILD.gn @@ -16,6 +16,8 @@ isp8000_dir = rebase_path("//device/soc/thead/th1520/hardware/isp8000") ohos_shared_library("camera_hal") { sources = [ "camera_hal/camera_hal.c", + "camera_hal/shm_open.c", + "camera_hal/strchrnul.c", ] include_dirs = [ "./include", diff --git a/th1520/hardware/camera/camera_hal/shm_open.c b/th1520/hardware/camera/camera_hal/shm_open.c new file mode 100644 index 0000000000000000000000000000000000000000..c86ac65234536212d90131db287959c9df382a47 --- /dev/null +++ b/th1520/hardware/camera/camera_hal/shm_open.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include +#include + +extern char *__strchrnul(const char *s, int c); + +char *__shm_mapname(const char *name, char *buf) +{ + char *p; + while (*name == '/') name++; + if (*(p = __strchrnul(name, '/')) || p==name || + (p-name <= 2 && name[0]=='.' && p[-1]=='.')) { + errno = EINVAL; + return 0; + } + if (p-name > NAME_MAX) { + errno = ENAMETOOLONG; + return 0; + } + memcpy(buf, "/dev/shm/", 9); + memcpy(buf+9, name, p-name+1); + return buf; +} + +int shm_open(const char *name, int flag, mode_t mode) +{ + int cs; + char buf[NAME_MAX+10]; + if (!(name = __shm_mapname(name, buf))) return -1; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); + int fd = open(name, flag|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK, mode); + pthread_setcancelstate(cs, 0); + return fd; +} + +int shm_unlink(const char *name) +{ + char buf[NAME_MAX+10]; + if (!(name = __shm_mapname(name, buf))) return -1; + return unlink(name); +} diff --git a/th1520/hardware/camera/camera_hal/strchrnul.c b/th1520/hardware/camera/camera_hal/strchrnul.c new file mode 100644 index 0000000000000000000000000000000000000000..fbdbc0c62ee743b0220a4889a240cd2698301e5e --- /dev/null +++ b/th1520/hardware/camera/camera_hal/strchrnul.c @@ -0,0 +1,27 @@ +#include +#include +#include + +#define ALIGN (sizeof(size_t)) +#define ONES ((size_t)-1/UCHAR_MAX) +#define HIGHS (ONES * (UCHAR_MAX/2+1)) +#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) + +char *__strchrnul(const char *s, int c) +{ + c = (unsigned char)c; + if (!c) return (char *)s + strlen(s); + +#ifdef __GNUC__ + typedef size_t __attribute__((__may_alias__)) word; + const word *w; + for (; (uintptr_t)s % ALIGN; s++) + if (!*s || *(unsigned char *)s == c) return (char *)s; + size_t k = ONES * c; + for (w = (void *)s; !HASZERO(*w) && !HASZERO(*w^k); w++); + s = (void *)w; +#endif + for (; *s && *(unsigned char *)s != c; s++); + return (char *)s; +} + diff --git a/th1520/hardware/loader/u-boot-with-spl.bin b/th1520/hardware/loader/u-boot-with-spl.bin index 1c50e1a9390ac49ea79849c7be6fe3c9ffc0baad..a4ac9326c78588d0673ae8cb7ed6ccb6ea4c4e90 100755 Binary files a/th1520/hardware/loader/u-boot-with-spl.bin and b/th1520/hardware/loader/u-boot-with-spl.bin differ