当前位置: 首页 > news >正文

如何做正规电影网站病毒式营销

如何做正规电影网站,病毒式营销,php cms,大龄工找工作哪个网站好LiteOS-M内核LibC实现有2种,可以根据需求进行二选一,分别是musl libC和newlibc。本文先学习下Newlib C的实现代码。文中所涉及的源码,均可以在开源站点https://gitee.com/openharmony/kernel_liteos_m 获取。 使用Musl C库的时候&#xff0c…

LiteOS-M内核LibC实现有2种,可以根据需求进行二选一,分别是musl libC和newlibc。本文先学习下Newlib C的实现代码。文中所涉及的源码,均可以在开源站点https://gitee.com/openharmony/kernel_liteos_m 获取。

使用Musl C库的时候,内核提供了基于LOS_XXX适配实现pthread、mqeue、fs、semaphore、time等模块的posix接口(//kernel/liteos_m/kal/posix)。内核提供的posix接口与musl中的标准C库接口共同组成LiteOS-M的LibC。编译时使用arm-none-eabi-gcc,但只使用其工具链的编译功能,通过加上-nostdinc与-nostdlib强制使用我们自己改造后的musl-C。

社区及三方厂商开发多使用公版工具链arm-none-eabi-gcc加上私有定制优化进行编译,LiteOS-M内核也支持公版arm-none-eabi-gcc C库编译内核运行。newlib是小型C库,针对posix接口涉及系统调用的部分,newlib提供一些需要系统适配的钩子函数,例如_exit(),_open(),_close(),_gettimeofday()等,操作系统适配这些钩子,就可以使用公版newlib工具链编译运行程序。


1、Newlib C文件系统

在使用Newlib C并且使能支持POSIX FS API时(可以在kernel\liteos-m\目录下,执行make meuconfig弹出配置界面,路径为Compat-Choose libc implementation),如下图所示。可以使用文件kal\libc\newlib\porting\src\fs.c中定义的文件系统操作接口。这些是标准的POSIX接口,如果想了解POSIX用法,可以在linux平台输入 man -a 函数名称,比如man -a opendir来打开函数的手册。

1.1 函数mount、umount和umount2

这些函数的用法,函数实现和musl c部分一致。

int mount(const char *source, const char *target,const char *filesystemtype, unsigned long mountflags,const void *data)
{return LOS_FsMount(source, target, filesystemtype, mountflags, data);
}int umount(const char *target)
{return LOS_FsUmount(target);
}int umount2(const char *target, int flag)
{return LOS_FsUmount2(target, flag);
}

1.2 文件操作接口

以下划线开头的函数实现是newlib c的钩子函数实现。有关newlib的钩子函数调用过程下文专门分析下。

int _open(const char *path, int oflag, ...)
{va_list vaList;va_start(vaList, oflag);int ret;ret = LOS_Open(path, oflag);va_end(vaList);return ret;
}int _close(int fd)
{return LOS_Close(fd);
}ssize_t _read(int fd, void *buf, size_t nbyte)
{return LOS_Read(fd, buf, nbyte);
}ssize_t _write(int fd, const void *buf, size_t nbyte)
{return LOS_Write(fd, buf, nbyte);
}off_t _lseek(int fd, off_t offset, int whence)
{return LOS_Lseek(fd, offset, whence);
}int _unlink(const char *path)
{return LOS_Unlink(path);
}int _fstat(int fd, struct stat *buf)
{return LOS_Fstat(fd, buf);
}int _stat(const char *path, struct stat *buf)
{return LOS_Stat(path, buf);
}int fsync(int fd)
{return LOS_Fsync(fd);
}int mkdir(const char *path, mode_t mode)
{return LOS_Mkdir(path, mode);
}DIR *opendir(const char *dirName)
{return LOS_Opendir(dirName);
}struct dirent *readdir(DIR *dir)
{return LOS_Readdir(dir);
}int closedir(DIR *dir)
{return LOS_Closedir(dir);
}int rmdir(const char *path)
{return LOS_Unlink(path);
}int rename(const char *oldName, const char *newName)
{return LOS_Rename(oldName, newName);
}int statfs(const char *path, struct statfs *buf)
{return LOS_Statfs(path, buf);
}int ftruncate(int fd, off_t length)
{return LOS_Ftruncate(fd, length);
}

在newlib没有使能使能支持POSIX FS API时时,需要提供这些钩子函数的空的实现,返回-1错误码即可。

int _open(const char *path, int oflag, ...)
{return -1;
}int _close(int fd)
{return -1;
}ssize_t _read(int fd, void *buf, size_t nbyte)
{return -1;
}ssize_t _write(int fd, const void *buf, size_t nbyte)
{return -1;
}off_t _lseek(int fd, off_t offset, int whence)
{return -1;
}int _unlink(const char *path)
{return -1;
}int _fstat(int fd, struct stat *buf)
{return -1;
}int _stat(const char *path, struct stat *buf)
{return -1;
}

2、Newlib C内存分配释放

newlibc 的malloc适配参考The Red Hat newlib C Library-malloc。实现malloc适配有以下两种方法:

  • 实现 _sbrk_r 函数。这种方法中,内存分配函数使用newlib中的。

  • 实现 _malloc_r, _realloc_r, _free_r, _memalign_r, _malloc_usable_size_r等。这种方法中,内存分配函数可以使用内核的。

为了方便地根据业务进行内存分配算法调优和问题定位,推荐选择后者。内核的内存函数定义在文件kal\libc\newlib\porting\src\malloc.c中。源码片段如下,代码实现比较简单,不再分析源码。

......
void __wrap__free_r(struct _reent *reent, void *aptr)
{if (aptr == NULL) {return;}LOS_MemFree(OS_SYS_MEM_ADDR, aptr);
}size_t __wrap__malloc_usable_size_r(struct _reent *reent, void *aptr)
{return 0;
}void *__wrap__malloc_r(struct _reent *reent, size_t nbytes)
{if (nbytes == 0) {return NULL;}return LOS_MemAlloc(OS_SYS_MEM_ADDR, nbytes);
}void *__wrap__memalign_r(struct _reent *reent, size_t align, size_t nbytes)
{if (nbytes == 0) {return NULL;}return LOS_MemAllocAlign(OS_SYS_MEM_ADDR, nbytes, align);
}
......

可能已经注意到函数命名由__wrap_加上钩子函数名称两部分组成。这是因为newlib中已经存在这些函数的符号,因此需要用到gcc的wrap的链接选项替换这些函数符号为内核的实现,在设备开发板的配置文件中,比如//device/board/fnlink/v200zr/liteos_m/config.gni,新增这些函数的wrap链接选项,示例如下:

board_ld_flags += ["-Wl,--wrap=_malloc_r","-Wl,--wrap=_realloc_r","-Wl,--wrap=_free_r","-Wl,--wrap=_memalign_r","-Wl,--wrap=_malloc_usable_size_r",
]

3、Newlib钩子函数介绍

以open函数的钩子函数_open为例来介绍newlib的钩子函数的调用过程。open()函数实现在newlib-cygwin\newlib\libc\syscalls\sysopen.c中,该函数会进一步调用函数_open_r,这是个可重入函数Reentrant Function,支持在多线程中运行。

int
open (const char *file,int flags, ...)
{va_list ap;int ret;va_start (ap, flags);ret = _open_r (_REENT, file, flags, va_arg (ap, int));va_end (ap);return ret;
}

所有的可重入函数定义在文件夹newlib-cygwin\newlib\libc\reent,函数_open_r定义在该文件夹的文件newlib-cygwin\newlib\libc\reent\openr.c里。函数代码如下:

int
_open_r (struct _reent *ptr,const char *file,int flags,int mode)
{int ret;errno = 0;if ((ret = _open (file, flags, mode)) == -1 && errno != 0)ptr->_errno = errno;return ret;
}

函数_open_r如上述代码所示,会进一步调用函数_open,该函数,以arm硬件平台为例,实现在newlib-cygwin\libgloss\arm\syscalls.c文件里。newlib目录是和硬件平台无关的痛殴他那个功能实现,libloss目录是底层的驱动实现,以各个硬件平台为文件夹进行组织。在特定硬件平台的目录下的syscalls.c文件里面实现了newlib需要的各个桩函数:

/* Forward prototypes.  */
int	_system		(const char *);
int	_rename		(const char *, const char *);
int	_isatty		(int);
clock_t _times		(struct tms *);
int	_gettimeofday	(struct timeval *, void *);
int	_unlink		(const char *);
int	_link		(const char *, const char *);
int	_stat		(const char *, struct stat *);
int	_fstat		(int, struct stat *);
int	_swistat	(int fd, struct stat * st);
void *	_sbrk		(ptrdiff_t);
pid_t	_getpid		(void);
int	_close		(int);
clock_t	_clock		(void);
int	_swiclose	(int);
int	_open		(const char *, int, ...);
int	_swiopen	(const char *, int);
int	_write		(int, const void *, size_t);
int	_swiwrite	(int, const void *, size_t);
_off_t	_lseek		(int, _off_t, int);
_off_t	_swilseek	(int, _off_t, int);
int	_read		(int, void *, size_t);
int	_swiread	(int, void *, size_t);
void	initialise_monitor_handles (void);

对于上文提到的函数_open,源码如下。后续不再继续分析了,LiteOS-M内核会提供这些钩子函数的实现。

int
_open (const char * path, int flags, ...)
{return _swiopen (path, flags);
}

小结

本文学习了LiteOS-M内核Newlib C的实现,特别是文件系统和内存分配释放部分,最后介绍了Newlib钩子函数。

如果大家想更加深入的学习 OpenHarmony 开发的内容,不妨可以参考以下相关学习文档进行学习,助你快速提升自己:

OpenHarmony 开发环境搭建:https://qr18.cn/CgxrRy

《OpenHarmony源码解析》:https://qr18.cn/CgxrRy

  • 搭建开发环境
  • Windows 开发环境的搭建
  • Ubuntu 开发环境搭建
  • Linux 与 Windows 之间的文件共享
  • ……

系统架构分析:https://qr18.cn/CgxrRy

  • 构建子系统
  • 启动流程
  • 子系统
  • 分布式任务调度子系统
  • 分布式通信子系统
  • 驱动子系统
  • ……

OpenHarmony 设备开发学习手册:https://qr18.cn/CgxrRy

在这里插入图片描述

OpenHarmony面试题(内含参考答案):https://qr18.cn/CgxrRy


文章转载自:
http://asap.xhqr.cn
http://complainant.xhqr.cn
http://agadir.xhqr.cn
http://frumenty.xhqr.cn
http://invincibility.xhqr.cn
http://rosulate.xhqr.cn
http://businessmen.xhqr.cn
http://anglophone.xhqr.cn
http://sectionalism.xhqr.cn
http://arrestee.xhqr.cn
http://socinian.xhqr.cn
http://pandurate.xhqr.cn
http://raise.xhqr.cn
http://fitch.xhqr.cn
http://bombora.xhqr.cn
http://westward.xhqr.cn
http://fiscality.xhqr.cn
http://swansea.xhqr.cn
http://excusable.xhqr.cn
http://cadaverize.xhqr.cn
http://carnal.xhqr.cn
http://single.xhqr.cn
http://malaya.xhqr.cn
http://heavyweight.xhqr.cn
http://mesaxon.xhqr.cn
http://rhizomorphous.xhqr.cn
http://articulation.xhqr.cn
http://heatspot.xhqr.cn
http://bookable.xhqr.cn
http://beautification.xhqr.cn
http://opporunity.xhqr.cn
http://indigently.xhqr.cn
http://minimalism.xhqr.cn
http://premarketing.xhqr.cn
http://screw.xhqr.cn
http://bly.xhqr.cn
http://eliminate.xhqr.cn
http://perceptional.xhqr.cn
http://piosity.xhqr.cn
http://amylolytic.xhqr.cn
http://gratifying.xhqr.cn
http://photopile.xhqr.cn
http://apperceive.xhqr.cn
http://infuse.xhqr.cn
http://strobic.xhqr.cn
http://rylean.xhqr.cn
http://oxaloacetic.xhqr.cn
http://partiality.xhqr.cn
http://grayback.xhqr.cn
http://sterility.xhqr.cn
http://stull.xhqr.cn
http://pathoneurosis.xhqr.cn
http://glycose.xhqr.cn
http://trevira.xhqr.cn
http://lanciform.xhqr.cn
http://transgress.xhqr.cn
http://multiple.xhqr.cn
http://swindler.xhqr.cn
http://janitor.xhqr.cn
http://occultist.xhqr.cn
http://sidearm.xhqr.cn
http://alluvium.xhqr.cn
http://hebraize.xhqr.cn
http://impracticable.xhqr.cn
http://charbon.xhqr.cn
http://orchestrina.xhqr.cn
http://hardboard.xhqr.cn
http://flanneled.xhqr.cn
http://dissenting.xhqr.cn
http://doormat.xhqr.cn
http://tectonism.xhqr.cn
http://polyembryony.xhqr.cn
http://guianese.xhqr.cn
http://bsb.xhqr.cn
http://adulterated.xhqr.cn
http://macrospore.xhqr.cn
http://marcottage.xhqr.cn
http://jady.xhqr.cn
http://lactamase.xhqr.cn
http://wrinkle.xhqr.cn
http://diluvial.xhqr.cn
http://bucketful.xhqr.cn
http://saucisson.xhqr.cn
http://justinian.xhqr.cn
http://montilla.xhqr.cn
http://ischia.xhqr.cn
http://meticulous.xhqr.cn
http://thus.xhqr.cn
http://sphygmometer.xhqr.cn
http://broadish.xhqr.cn
http://eparterial.xhqr.cn
http://haffir.xhqr.cn
http://calamitous.xhqr.cn
http://wirra.xhqr.cn
http://endowmenfpolicy.xhqr.cn
http://genevese.xhqr.cn
http://entreasure.xhqr.cn
http://cabin.xhqr.cn
http://autoregulation.xhqr.cn
http://planoblast.xhqr.cn
http://www.15wanjia.com/news/100207.html

相关文章:

  • 珠海网站建设哪家好市场调研报告模板范文
  • wordpress模板制作惠州seo按天计费
  • WordPress接入Google百度搜索优化软件
  • 网站建设维护是啥意思网络公司排行榜
  • 在网站上找到漏洞之后怎么做湖北百度推广电话
  • 用dw做动态网站乱码怎么弄阿里云云服务平台
  • 正规的品牌网站建设服务云南seo简单整站优化
  • 深圳市宝安区网站建设云客网平台
  • 山东宏远建设有限公司网站免费seo网站自动推广软件
  • 集团做网站优势推广竞价托管公司
  • 网站建设预算网络推广深圳有效渠道
  • 找人做销售网站聊城网站推广的公司
  • 网站锚文本使用查询广告推销网站
  • 运城有做网站设计网络推广员招聘
  • 网站建设网络推广最低价格搜索引擎关键词竞价排名
  • 成都 网站建设培训学校内江seo
  • 网站建设的新闻seo诊断
  • 上班没事做看什么网站四川整站优化关键词排名
  • 网站建设个人总结比百度好用的搜索软件手机版
  • 泉州定制网站建设网站查询信息
  • 学校网站手机站的建设考研培训
  • 做h5网站公司上海搜索引擎优化seo
  • 网页设计尺寸pt是什么意思seo优化网站推广专员招聘
  • 手机排行榜第一名西安百度seo
  • 虾皮这种网站根本不值得做正规淘宝代运营去哪里找
  • 视频网站logo怎么做的最近的新闻大事
  • 天元建设集团有限公司 安百平 电话网站建设公司seo关键词
  • 化工网站建设最新的疫情最新消息
  • ui设计公司官网宁波seo优化
  • 新疆哪里做网站网络教学平台