What are bsdthread_register, ulock_wake and other system calls reported by dtruss? - system-calls

Here is an example interaction with dtruss on my macOS machine.
$ cat main.c
int main() {
return 0;
}
$ clang main.c
$ sudo dtruss ./a.out
dtrace: system integrity protection is on, some features will not be available
SYSCALL(args) = return
open("/dev/dtracehelper\0", 0x2, 0x7FFF5AF83930) = 3 0
ioctl(0x3, 0x80086804, 0x7FFF5AF838B8) = 0 0
close(0x3) = 0 0
thread_selfid(0x3, 0x80086804, 0x7FFF5AF838B8) = 5434813 0
bsdthread_register(0x7FFFAF245080, 0x7FFFAF245070, 0x2000) = 1073741919 0
ulock_wake(0x1, 0x7FFF5AF830EC, 0x0) = -1 Err#2
issetugid(0x1, 0x7FFF5AF830EC, 0x0) = 0 0
mprotect(0x104C7F000, 0x88, 0x1) = 0 0
mprotect(0x104C81000, 0x1000, 0x0) = 0 0
mprotect(0x104C97000, 0x1000, 0x0) = 0 0
mprotect(0x104C98000, 0x1000, 0x0) = 0 0
mprotect(0x104CAE000, 0x1000, 0x0) = 0 0
mprotect(0x104CAF000, 0x1000, 0x1) = 0 0
mprotect(0x104C7F000, 0x88, 0x3) = 0 0
mprotect(0x104C7F000, 0x88, 0x1) = 0 0
getpid(0x104C7F000, 0x88, 0x1) = 34522 0
stat64("/AppleInternal/XBS/.isChrooted\0", 0x7FFF5AF82FA8, 0x1) = -1 Err#2
stat64("/AppleInternal\0", 0x7FFF5AF83040, 0x1) = -1 Err#2
csops(0x86DA, 0x7, 0x7FFF5AF82AD0) = -1 Err#22
dtrace: error on enabled probe ID 2158 (ID 552: syscall::sysctl:return): invalid kernel access in action #10 at DIF offset 40
ulock_wake(0x1, 0x7FFF5AF83050, 0x0) = -1 Err#2
csops(0x86DA, 0x7, 0x7FFF5AF823B0) = -1 Err#22
Many of these system calls look familiar, but others don't. Specifically, what are thread_selfid, bsdthread_register, ulock_wake, csops, and dtrace? If these are system calls, they don't have man pages documenting them. Are they private system calls, or something else? Where does dtruss get their names from?

Yes, ULOCK_wake is part of a private systemcall for threads afaik.
You can see it in the xnu sourcecode as being systemcall number 516.

Related

What is the name of the POS1 key in xdotool?

I need xdotool to press pos1, but I don't know the name of this key. It's not pos1, POS1, Pos1, Beginning. How can I find the name of the key which is used by xdotool?
Execute
$ xev -event keyboard
and then just type the key you want to use.
Example output:
Outer window is 0x4a00001, inner window is 0x4a00002
KeymapNotify event, serial 24, synthetic NO, window 0x0,
keys: 4294967230 0 0 0 16 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
KeyRelease event, serial 25, synthetic NO, window 0x4a00001,
root 0x1a1, subw 0x0, time 109192145, (501,285), root:(503,393),
state 0x0, keycode 36 (keysym 0xff0d, Return), same_screen YES,
" XLookupString gives 1 bytes: (0d) "
XFilterEvent returns: False
KeyPress event, serial 28, synthetic NO, window 0x4a00001,
root 0x1a1, subw 0x0, time 109193882, (501,285), root:(503,393),
state 0x0, keycode 110 (keysym 0xff50, Home), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
KeyRelease event, serial 28, synthetic NO, window 0x4a00001,
root 0x1a1, subw 0x0, time 109193953, (501,285), root:(503,393),
state 0x0, keycode 110 (keysym 0xff50, Home), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False
^C
The interesting part is keycode 110 (keysym 0xff50, Home). So the name is Home.

passing data to torch.class(es) in lua

I'm trying to use the class function in Torch. however when calling what would be a member function with an argument, the argument is always nil. I know that class is an abstraction to emulate OO programming.
local RpnData, parent = torch.class('nn.RpnData', 'nn.Module')
function RpnData:__init()
parent.__init(self)
local scale = {8, 16, 32}
self._feat_stride = 1
self._allowed_border = 0;
end
function RpnData:Foo(input)
print("This will not work")
print(input)
end
local rpnnode = nn.RpnData()
local input = torch.Tensor( 5, 5):zero()
print(input)
rpnnode.Foo(input)
outputs:
Torch 7.0 Copyright (C) 2001-2011 Idiap, NEC Labs, NYU
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
[torch.DoubleTensor of size 5x5]
This will not work
nil
Can anyone suggest where i've gone wrong? Are there limitations to the Torch.class system?
Thanks in advance
Use rpnnode.Foo(rpnnode, input) or (better) rpnnode:Foo(input) - the colon is syntactic sugar, see Programming in Lua, 16.1.

Method does not update the current object MATLAB

I'm writing a code using Matlab OO programming. I came across a problem trying to write a method that changes the value of a matrix inside the same object.
I've tested my method and it does exactly what I want it to do but it does not save back the results.
Here is my code:
Take a look on : function obj = initCC(obj)
%% searchDat picks values for the object properties in a fite
%% Importa a função searchDat()
%%
classdef methExpl
%Classe de Metodos Explicitos
% Detailed explanation goes here
properties
%Declara Altura da Placa, Largura, Nós em X, Nós em Y, K, Matriz
%com a solução do passo atual, matriz com a solução do passo
%Variáveis Geométricas
%Altura e Largura
Height
Length
%Variáveis da Malha
%Número de nós em X e Número de nós em Y
%Passo de tempo
NodeX
NodeY
timeStep
%Propriedades Físicas
%Condutividade Térmica, Temperatura no Contorno
%Temperatura Inicial uniforme na chapa
kTerm
boundaryTemp
initTemp
%Soluções parciais
%Matriz com a solução da iteração atual
%Matriz com a solução da iteração passada
curMat
lastMat
end
properties (SetAccess = private)
%Arma
funTermMAT
erro = {}
end
methods
function obj = methExpl()
%Construtor da Classe
%Inicializa as variaveis com os valores no arquivo input.dat
%Inicializa a matriz
obj.Height = searchDat('[Height]','input.dat');
obj.Length = searchDat('[Length]','input.dat');
obj.NodeX = searchDat('[NodesX]','input.dat');
obj.NodeY = searchDat('[NodesY]','input.dat');
obj.kTerm = searchDat('[ThermalConductivity]','input.dat');
obj.boundaryTemp = searchDat('[BoundaryTemperature]','input.dat');
obj.initTemp = searchDat('[InitalTemperature]','input.dat');
obj.curMat = zeros(obj.NodeX,obj.NodeY);
%inicializa a matriz com a temperatura do contorno:
obj.initCC();
obj.lastMat = zeros(obj.NodeX,obj.NodeY);
end
function obj = initCC(obj)
%initCC Inicializa a matriz com a condição de contorno de
%temperatura
lim = size(obj.curMat);
for (i =1 : lim(1))
for (j = 1 : lim(2))
if (i==1) || (i == lim(1))
obj.curMat(i,j) = obj.boundaryTemp;
elseif (j==1) || (j ==lim(2))
obj.curMat(i,j) = obj.boundaryTemp
end
end
end
obj.curMat
end
end
end
Before quitting the initCC and get:
ans =
3 3 3 3 3 3 3 3 3 3 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 0 0 0 0 0 0 0 0 0 3
3 3 3 3 3 3 3 3 3 3 3
Which is exactly what I want.
If I call it from the outside after initializing it I get:
ans =
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
As if the result of the method I have created has been destroyed.
Just to put expand on the suggestions in the comments, you basically have two options. Firstly, you could simply capture the return of your initCC method which does correctly return the modified object, like so:
myObj = initCC(myObj);
Note that because of MATLAB's "copy on write" behaviour, this does not in fact incur any expensive copies of data.
The other option is to declare your class to be a handle, like so:
classdef methExpl < handle
...
end
then you don't need the return from initCC.

Create separated R-G-B array from loaded image

Sorry to bother, but it seem that I stuck with pretty easy task.
Simply, I want to create 3*m-by-3*n-by-3 RGB file from m-by-n-by-3 loaded image. Lets use folowing array as an example as example:
Image(:,:,1) = 0.5*ones(4);
Image(:,:,2) = ones(4);
Image(:,:,3) = 0.25*ones(4);
Image = uint8(255*Image); %3-D array, Red = 128, Green = 255, Blue = 64;
What I want to get is this:
ImageRGB(:,:,1) =
128 0 0 128 0 0 128 0 0 128 0 0
128 0 0 128 0 0 128 0 0 128 0 0
128 0 0 128 0 0 128 0 0 128 0 0
128 0 0 128 0 0 128 0 0 128 0 0
ImageRGB(:,:,2) =
0 255 0 0 255 0 0 255 0 0 255 0
0 255 0 0 255 0 0 255 0 0 255 0
0 255 0 0 255 0 0 255 0 0 255 0
0 255 0 0 255 0 0 255 0 0 255 0
ImageRGB(:,:,3) =
0 0 64 0 0 64 0 0 64 0 0 64
0 0 64 0 0 64 0 0 64 0 0 64
0 0 64 0 0 64 0 0 64 0 0 64
0 0 64 0 0 64 0 0 64 0 0 64
So far best I came up without using loops is this:
[i1,i2] = ndgrid(1:size(Image,1),[1:3:size(Image,2)*size(Image,3),2:3:size(Image,2)*size(Image,3),3:3:size(Image,2)*size(Image,3)]);
ImageRGB = accumarray([i1(:),i2(:),[ones(size(Image,1)*size(Image,2),1);2*ones(size(Image,1)*size(Image,2),1);3*ones(size(Image,1)*size(Image,2),1)] ],Image(:));
May be, there is some function I am not aware of, or more simple way to do this WITHOUT loops. Using them for such seemingly easy task feel just wrong.
What you have is completely fine, but it's very hard to read. Why not just do something very simple and very easy to understand:
ImageRGB = zeros(4,4*3,3);
ImageRGB(:,1:3:end,1) = Image(:,:,1);
ImageRGB(:,2:3:end,2) = Image(:,:,2);
ImageRGB(:,3:3:end,3) = Image(:,:,3);

Find all possible paths in a graph using Matlab Brute Force Search

I need to find all paths with a graph, and save these paths. My starting nodes are A, B or C, and the final node is G. My graphs have maximum 16 unweighted vertices.
I made the Matlab code below, but this has problems with bifurcations. Also, I don't know how to impose the starting and the final nodes. Can anyone help me with this?
path = cell(1,10) ; % initialize
% one_graph ={'AH','BO','CN','EG','EN','EO','HO','KN'} % (Graph example)
one_graph ={'AH','BN','DH','DN','GN'} % (Graph example)
for p = 1:length(one_graph)
edge = one_graph(p);
% In each graph there is only 1:1 conections
% detect node 1
existing_node1 = edge{1}(1) ;
Index_existing_node1 = strfind(allnodes, existing_node1) ;
[row1,col1] = find(ismember(allnodes, existing_node1));
% detect node 2
existing_node2 = edge{1}(2) ;
Index_existing_node2 = strfind(allnodes, existing_node2);
[row2,col2] = find(ismember(allnodes, existing_node2));
path_nonz = path(~cellfun('isempty',path)) ;
t = length(path_nonz) ;
if t>0 % save the first 2 nodes in the path
ttt = strcmp(allnodes(row1), path{t});
ttt2 = strcmp(allnodes(row2), path{t});
end;
if t==0
path{t+1} = allnodes{row1} ;
path{t+2} = allnodes{row2} ;
elseif ttt == 1
% disp('connect right')
path{t+1} = allnodes{row2} ;
elseif ttt2 == 1
% disp('connect right')
path{t+1} = allnodes{row1} ;
else
disp('Not next vertex')
end
end
For example, for
one_graph ={'AH','BN','DH','DN','GN'} % (Graph example)
I should save the following paths:
path1 = AHDNG
path2 = BNG
and for
one_graph ={'AH','BO','CN','EG','EN','EO','HO','KN'} % (Graph example)
I should save the following paths:
path1 = AHOEG
path2 = BOEG
path3 = CNEG
UPDATE 1:
From the adjacency matrix B(:,:,1)
B =
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
I derive the proper adjacency list:
Asparse = sparse(B(:,:,1));
Asparse =
(8,1) 1
(14,2) 1
(8,4) 1
(14,4) 1
(14,7) 1
(1,8) 1
(4,8) 1
(2,14) 1
(4,14) 1
(7,14) 1
Then, I tried to use the BFS algorithm found on Matlab Website
[distances,times,pred] = bfs(Asparse,1);
But, this doesn't save the paths. It just saves the previous node of each current node (in pred) and the distance from the initial node to each node (in distances). Any idea, how to save each path?
I've had to write a custom function to do this since 1) most BFS/DFS functions stop when the goal is reached and 2) they explicitly ignore cycles, which are required for multiple paths to the same target.
I believe this will get you what you need. I've made a slight modification to the adjacency matrix in your example to create an edge from {2,7} and {7,2} so that there would be two paths from 2 to 14. Note that this is a recursive function, so if you get around 500 nodes or so you're going to have problems and we'll have to come up with a version that uses an explicit stack.
function paths = findpaths(Adj, nodes, currentPath, start, target)
paths = {};
nodes(start) = 0;
currentPath = [currentPath start];
childAdj = Adj(start,:) & nodes;
childList = find(childAdj);
childCount = numel(childList);
if childCount == 0 || start == target
if start == target
paths = [paths; currentPath];
end
return;
end
for idx = 1:childCount
currentNode = childList(idx);
newNodes = nodes;
newNodes(currentNode) = 0;
newPaths = findpaths(Adj, newNodes, currentPath, currentNode, target);
paths = [paths; newPaths];
end
end
If you call this function like this:
A =[
0 0 0 0 0 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 1 0 0 0 0 0 0 1;
0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 1 0 0 0 0 0 1;
0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 1 0 0 0 0 0 0 0 0 0 0 0 1;
1 0 0 1 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 1 0 1 0 0 1 0 0 0 0 0 0 0];
unusedNodes=ones(1,size(A,1));
start=2;
target=14;
emptyPath=[];
allPaths = findpaths(A, unusedNodes, emptyPath, start, target)
the output should be:
allPaths =
{
[1,1] =
2 7 14
[2,1] =
2 14
}
Naturally, you need to call this for each starting node.
Actually, you don't have to call this multiple times. There was one more tip I forgot to tell you. If your graph has n nodes and you introduce a new node n+1 that has edges only to your candidate start nodes, you can call the function once with the new node as the start.
So if I add node 15 to the graph above with edges:
{15,1}, {15,2}
%// I wouldn't bother with {1,15} and {2,15}, they're totally unnecessary
and call the function with start = 15, here's what I get:
allPaths =
{
[1,1] =
15 1 8 4 14
[2,1] =
15 2 7 14
[3,1] =
15 2 14
}
You now have all of the paths with one call, although you need to remove the new node 15 from the head of each path.