繁体   English   中英

OSX 上 getcwd 系统调用的问题

[英]Problems with getcwd syscall on OSX

有没有人知道如何使用 NASM 在 OSX 中获取当前工作目录? 系统调用 getcwd 在 osx 上不可用,并且 dtruss pwd 返回大量 stat 系统调用。 但是在手册中我找不到 stat 的哪个结构变量返回当前工作目录。 谢谢。

这个答案有点晚了,但仍然可以使用 2 个系统调用来实现。

  1. open_nocancel 0x2000018e (or open 0x2000005) 打开当前目录的文件描述符
  2. fcntl_nocancel 0x20000196 (或fcntl 0x2000005c) 用于读取实际路径

例子:

#define F_GETPATH 50     ; from <sys/fcntl.h>

currentDirConstant: 
db   ".",0 ; needs segment read permission  

outputPath:          
resb 1000 ; needs segment write permission

mov rdi,currentDirConstant; input path 1st argument
xor esi, esi        ; int flags 2nd argument, just use 0
xor edx, edx        ; int mode 3rd argument, just use 0
mov eax, 0x2000018e ; open_nocancel syscall number 
syscall        

mov edi,eax          ; file descriptor 1st argument of current dir from previous syscall
mov esi,F_GETPATH    ; fcntl cmd 2nd argument
mov rdx, outputPath  ; output buffer 3rd argument
mov eax, 0x20000196  ; fcntl_nocancel syscall number  
syscall

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM