diff --git a/src/Makefile b/src/Makefile index 0bed403a12a0197e2b7eeadb9808670ace8d1550..ed1da38d23eecfaee02f911ae78dca7a660e4a0d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -93,7 +93,6 @@ SRCDIRS += kernel/ SRCDIRS += drivers/ SRCDIRS += fs/ SRCDIRS += test/ -SRCDIRS += thirdpart/ SRCDIRS += time/ # diff --git a/src/include/thirdpart/elf.h b/src/include/process/elf.h similarity index 100% rename from src/include/thirdpart/elf.h rename to src/include/process/elf.h diff --git a/src/include/thirdpart/cpio.h b/src/include/thirdpart/cpio.h deleted file mode 100644 index e34ec23897709d1c31b0fff11ad0563b1196fbfe..0000000000000000000000000000000000000000 --- a/src/include/thirdpart/cpio.h +++ /dev/null @@ -1,99 +0,0 @@ -/** - * Copyright (c) 2018-2022, NXOS Development Team - * SPDX-License-Identifier: Apache-2.0 - * - * Contains: cpio unzip - * - * Change Logs: - * Date Author Notes - * 2022-1-29 GuEe-GUI,JasonHu Init - */ - -/* - * Copyright 2014, NICTA - * - * This software may be distributed and modified according to the terms of - * the BSD 2-Clause license. Note that NO WARRANTY is provided. - * See "LICENSE_BSD2.txt" for details. - * - * @TAG(NICTA_BSD) - */ - -#ifndef __THIRDPART_CPIO__ -#define __THIRDPART_CPIO__ - -/* Magic identifiers for the "cpio" file format. */ -#define CPIO_HEADER_MAGIC "070701" -#define CPIO_FOOTER_MAGIC "TRAILER!!!" -#define CPIO_ALIGNMENT 4 - -struct cpio_header { - char c_magic[6]; /* Magic header '070701'. */ - char c_ino[8]; /* "i-node" number. */ - char c_mode[8]; /* Permisions. */ - char c_uid[8]; /* User ID. */ - char c_gid[8]; /* Group ID. */ - char c_nlink[8]; /* Number of hard links. */ - char c_mtime[8]; /* Modification time. */ - char c_filesize[8]; /* File size. */ - char c_devmajor[8]; /* Major dev number. */ - char c_devminor[8]; /* Minor dev number. */ - char c_rdevmajor[8]; - char c_rdevminor[8]; - char c_namesize[8]; /* Length of filename in bytes. */ - char c_check[8]; /* Checksum. */ -}; - - -/** - * Stores information about the underlying implementation. - */ -struct cpio_info { - /// The number of files in the CPIO archive - unsigned int file_count; - /// The maximum size of a file name - unsigned int max_path_sz; -}; - - -/** - * Retrieve file information from a provided CPIO list index - * @param[in] archive The location of the CPIO archive - * @param[in] index The index of the CPIO entry to query - * @param[out] name A pointer to the file name of the entry. This name is not - * NULL terminated but it will not exceed max_path_sz as - * reported by cpio_info. - * @param[out] size The size of the file in question - * @return The location of the file in memory; NULL if the index - * exceeds the number of files in the CPIO archive. - */ -void *cpio_get_entry(void *archive, int index, const char **name, unsigned long *size); - -/** - * Retrieve file information from a provided file name - * @param[in] archive The location of the CPIO archive - * @param[in] name The name of the file in question. - * @param[out] size The retrieved size of the file in question - * @return The location of the file in memory; NULL if the file - * does not exist. - */ -void *cpio_get_file(void *archive, const char *name, unsigned long *size); - -/** - * Retrieves information about the provided CPIO archive - * @param[in] archive The location of the CPIO archive - * @param[out] info A CPIO info structure to populate - * @return Non-zero on error. - */ -int cpio_info(void *archive, struct cpio_info *info); - -/** - * Writes the list of file names contained within a CPIO archive into - * a provided buffer - * @param[in] archive The location of the CPIO archive - * @param[in] buf A memory location to store the CPIO file list to - * @param[in] buf_len The length of the provided buf - */ -void cpio_ls(void *archive, char **buf, unsigned long buf_len); - -#endif /* __THIRDPART_CPIO__ */ diff --git a/src/process/process.c b/src/process/process.c index 293172ba539bb0dbfdb5a2f2c332f009fdec9411..5bd9125165c8a2a530a9ffab1845fdb09786cd3a 100644 --- a/src/process/process.c +++ b/src/process/process.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include NX_PRIVATE void ProcessAppendThread(NX_Process *process, NX_Thread *thread) diff --git a/src/thirdpart/Makefile b/src/thirdpart/Makefile deleted file mode 100644 index 7858e6537c6cb1881f59e2bec469c0d176aecb24..0000000000000000000000000000000000000000 --- a/src/thirdpart/Makefile +++ /dev/null @@ -1 +0,0 @@ -SRC += *.c diff --git a/src/thirdpart/cpio.c b/src/thirdpart/cpio.c deleted file mode 100644 index 4c1798a4ede34677907696cabdfe4b186ca944a8..0000000000000000000000000000000000000000 --- a/src/thirdpart/cpio.c +++ /dev/null @@ -1,240 +0,0 @@ -/** - * Copyright (c) 2018-2022, NXOS Development Team - * SPDX-License-Identifier: Apache-2.0 - * - * Contains: cpio unzip - * - * Change Logs: - * Date Author Notes - * 2022-1-29 GuEe-GUI,JasonHu Init - */ - -/* - * Copyright 2014, NICTA - * - * This software may be distributed and modified according to the terms of - * the BSD 2-Clause license. Note that NO WARRANTY is provided. - * See "LICENSE_BSD2.txt" for details. - * - * @TAG(NICTA_BSD) - */ - -#include - -#ifndef NULL -#define NULL ((void *)0) -#endif - -/* Align 'n' up to the value 'align', which must be a power of two. */ -static unsigned long align_up(unsigned long n, unsigned long align) -{ - return (n + align - 1) & (~(align - 1)); -} - -/* Parse an ASCII hex string into an integer. */ -static unsigned long parse_hex_str(char *s, unsigned int max_len) -{ - unsigned long r = 0; - unsigned long i; - - for (i = 0; i < max_len; i++) { - r *= 16; - if (s[i] >= '0' && s[i] <= '9') { - r += s[i] - '0'; - } else if (s[i] >= 'a' && s[i] <= 'f') { - r += s[i] - 'a' + 10; - } else if (s[i] >= 'A' && s[i] <= 'F') { - r += s[i] - 'A' + 10; - } else { - return r; - } - continue; - } - return r; -} - -/* - * Compare up to 'n' characters in a string. - * - * We re-implement the wheel to avoid dependencies on 'libc', required for - * certain environments that are particularly impoverished. - */ -static int cpio_strncmp(const char *a, const char *b, unsigned long n) -{ - unsigned long i; - for (i = 0; i < n; i++) { - if (a[i] != b[i]) { - return a[i] - b[i]; - } - if (a[i] == 0) { - return 0; - } - } - return 0; -} - -/** - * This is an implementation of string copy because, cpi doesn't want to - * use string.h. - */ -static char* cpio_strcpy(char *to, const char *from) { - char *save = to; - while (*from != 0) { - *to = *from; - to++; - from++; - } - return save; -} - - -static unsigned int cpio_strlen(const char *str) { - const char *s; - for (s = str; *s; ++s) {} - return (s - str); -} - - - -/* - * Parse the header of the given CPIO entry. - * - * Return -1 if the header is not valid, 1 if it is EOF. - */ -int cpio_parse_header(struct cpio_header *archive, - const char **filename, unsigned long *_filesize, void **data, - struct cpio_header **next) -{ - unsigned long filesize; - /* Ensure magic header exists. */ - if (cpio_strncmp(archive->c_magic, CPIO_HEADER_MAGIC, - sizeof(archive->c_magic)) != 0) - return -1; - - /* Get filename and file size. */ - filesize = parse_hex_str(archive->c_filesize, sizeof(archive->c_filesize)); - *filename = ((char *)archive) + sizeof(struct cpio_header); - - /* Ensure filename is not the trailer indicating EOF. */ - if (cpio_strncmp(*filename, CPIO_FOOTER_MAGIC, sizeof(CPIO_FOOTER_MAGIC)) == 0) - return 1; - - /* Find offset to data. */ - unsigned long filename_length = parse_hex_str(archive->c_namesize, - sizeof(archive->c_namesize)); - *data = (void *)align_up(((unsigned long)archive) - + sizeof(struct cpio_header) + filename_length, CPIO_ALIGNMENT); - *next = (struct cpio_header *)align_up(((unsigned long)*data) + filesize, CPIO_ALIGNMENT); - if(_filesize){ - *_filesize = filesize; - } - return 0; -} - -/* - * Get the location of the data in the n'th entry in the given archive file. - * - * We also return a pointer to the name of the file (not NUL terminated). - * - * Return NULL if the n'th entry doesn't exist. - * - * Runs in O(n) time. - */ -void *cpio_get_entry(void *archive, int n, const char **name, unsigned long *size) -{ - int i; - struct cpio_header *header = archive; - void *result = NULL; - - /* Find n'th entry. */ - for (i = 0; i <= n; i++) { - struct cpio_header *next; - int error = cpio_parse_header(header, name, size, &result, &next); - if (error) - return NULL; - header = next; - } - - return result; -} - -/* - * Find the location and size of the file named "name" in the given 'cpio' - * archive. - * - * Return NULL if the entry doesn't exist. - * - * Runs in O(n) time. - */ -void *cpio_get_file(void *archive, const char *name, unsigned long *size) -{ - struct cpio_header *header = archive; - - /* Find n'th entry. */ - while (1) { - struct cpio_header *next; - void *result; - const char *current_filename; - - int error = cpio_parse_header(header, ¤t_filename, - size, &result, &next); - if (error) - return NULL; - if (cpio_strncmp(current_filename, name, -1) == 0) - return result; - header = next; - } -} - -int cpio_info(void *archive, struct cpio_info *info) { - struct cpio_header *header, *next; - const char *current_filename; - void *result; - int error; - unsigned long size, current_path_sz; - - if (info == NULL) return 1; - info->file_count = 0; - info->max_path_sz = 0; - - header = archive; - while (1) { - error = cpio_parse_header(header, ¤t_filename, &size, - &result, &next); - if (error == -1) { - return error; - } else if (error == 1) { - /* EOF */ - return 0; - } - info->file_count++; - header = next; - - // Check if this is the maximum file path size. - current_path_sz = cpio_strlen(current_filename); - if (current_path_sz > info->max_path_sz) { - info->max_path_sz = current_path_sz; - } - } - - return 0; -} - - -void cpio_ls(void *archive, char **buf, unsigned long buf_len) { - const char *current_filename; - struct cpio_header *header, *next; - void *result; - int error; - unsigned long i, size; - - header = archive; - for (i = 0; i < buf_len; i++) { - error = cpio_parse_header(header, ¤t_filename, &size, - &result, &next); - // Break on an error or nothing left to read. - if (error) break; - cpio_strcpy(buf[i], current_filename); - header = next; - } -}